diff --git a/src/gui.rs b/src/gui.rs index b9b76ac..014e19d 100644 --- a/src/gui.rs +++ b/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,22 +77,26 @@ fn setup_save(builder: &Builder) -> Result<()> { config.commands[i] = Some(command); } - let home_dir = match std::env::var("HOME") { - Ok(var) => var, - Err(_) => { - println!("failed getting home directory"); - return; - } - }; - - if let Err(err) = config.save(&format!("{}/.config/MacroBoard/commands.cfg", home_dir)) { - println!("{}", err); - } + save_config(config); }); Ok(()) } +fn save_config(config: Config) { + let home_dir = match std::env::var("HOME") { + Ok(var) => var, + Err(_) => { + println!("failed getting home directory"); + return; + } + }; + + if let Err(err) = config.save(&format!("{}/.config/MacroBoard/commands.cfg", home_dir)) { + println!("{}", err); + } +} + fn apply_config(builder: &Builder, config: &Config) -> Result<()> { for i in 0..COMMAND_COUNT { if let Some(command) = &config.commands[i] { diff --git a/src/shared/config.rs b/src/shared/config.rs index 3717fae..c7ddc58 100644 --- a/src/shared/config.rs +++ b/src/shared/config.rs @@ -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; COMMAND_COUNT], }