Store window size in config
This commit is contained in:
parent
6508fad2df
commit
b1ecd750cd
2 changed files with 28 additions and 11 deletions
38
src/gui.rs
38
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] {
|
||||
|
|
|
@ -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