Store window size in config
This commit is contained in:
parent
6508fad2df
commit
b1ecd750cd
2 changed files with 28 additions and 11 deletions
22
src/gui.rs
22
src/gui.rs
|
@ -30,6 +30,7 @@ fn setup_gui(builder: Builder) -> Result<()> {
|
|||
.object("MainWindow")
|
||||
.ok_or(anyhow!("failed getting main window"))?;
|
||||
|
||||
window.resize(config.window_size.0 as i32, config.window_size.1 as i32);
|
||||
window.show_all();
|
||||
|
||||
// close event
|
||||
|
@ -38,6 +39,17 @@ fn setup_gui(builder: Builder) -> Result<()> {
|
|||
Inhibit(false)
|
||||
});
|
||||
|
||||
window.connect_configure_event(|_, event_configure| {
|
||||
if let Ok(mut config) = Config::load_config() {
|
||||
config.window_size = event_configure.size();
|
||||
save_config(config);
|
||||
}
|
||||
|
||||
Inhibit(true);
|
||||
|
||||
false
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -65,6 +77,13 @@ fn setup_save(builder: &Builder) -> Result<()> {
|
|||
config.commands[i] = Some(command);
|
||||
}
|
||||
|
||||
save_config(config);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn save_config(config: Config) {
|
||||
let home_dir = match std::env::var("HOME") {
|
||||
Ok(var) => var,
|
||||
Err(_) => {
|
||||
|
@ -76,9 +95,6 @@ fn setup_save(builder: &Builder) -> Result<()> {
|
|||
if let Err(err) = config.save(&format!("{}/.config/MacroBoard/commands.cfg", home_dir)) {
|
||||
println!("{}", err);
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_config(builder: &Builder, config: &Config) -> Result<()> {
|
||||
|
|
|
@ -14,6 +14,7 @@ pub const COMMAND_PAUSE: Duration = Duration::from_millis(1500);
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
pub window_size: (u32, u32),
|
||||
pub commands: [Option<String>; COMMAND_COUNT],
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue