Store window size in config

This commit is contained in:
hodasemi 2022-08-03 15:27:25 +02:00
parent 6508fad2df
commit b1ecd750cd
2 changed files with 28 additions and 11 deletions

View file

@ -30,6 +30,7 @@ fn setup_gui(builder: Builder) -> Result<()> {
.object("MainWindow") .object("MainWindow")
.ok_or(anyhow!("failed getting main window"))?; .ok_or(anyhow!("failed getting main window"))?;
window.resize(config.window_size.0 as i32, config.window_size.1 as i32);
window.show_all(); window.show_all();
// close event // close event
@ -38,6 +39,17 @@ fn setup_gui(builder: Builder) -> Result<()> {
Inhibit(false) 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(()) Ok(())
} }
@ -65,6 +77,13 @@ fn setup_save(builder: &Builder) -> Result<()> {
config.commands[i] = Some(command); config.commands[i] = Some(command);
} }
save_config(config);
});
Ok(())
}
fn save_config(config: Config) {
let home_dir = match std::env::var("HOME") { let home_dir = match std::env::var("HOME") {
Ok(var) => var, Ok(var) => var,
Err(_) => { Err(_) => {
@ -76,9 +95,6 @@ fn setup_save(builder: &Builder) -> Result<()> {
if let Err(err) = config.save(&format!("{}/.config/MacroBoard/commands.cfg", home_dir)) { if let Err(err) = config.save(&format!("{}/.config/MacroBoard/commands.cfg", home_dir)) {
println!("{}", err); println!("{}", err);
} }
});
Ok(())
} }
fn apply_config(builder: &Builder, config: &Config) -> Result<()> { fn apply_config(builder: &Builder, config: &Config) -> Result<()> {

View file

@ -14,6 +14,7 @@ pub const COMMAND_PAUSE: Duration = Duration::from_millis(1500);
#[derive(Debug, Serialize, Deserialize, Default)] #[derive(Debug, Serialize, Deserialize, Default)]
pub struct Config { pub struct Config {
pub window_size: (u32, u32),
pub commands: [Option<String>; COMMAND_COUNT], pub commands: [Option<String>; COMMAND_COUNT],
} }