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")
|
.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,22 +77,26 @@ fn setup_save(builder: &Builder) -> Result<()> {
|
||||||
config.commands[i] = Some(command);
|
config.commands[i] = Some(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
let home_dir = match std::env::var("HOME") {
|
save_config(config);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
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<()> {
|
fn apply_config(builder: &Builder, config: &Config) -> Result<()> {
|
||||||
for i in 0..COMMAND_COUNT {
|
for i in 0..COMMAND_COUNT {
|
||||||
if let Some(command) = &config.commands[i] {
|
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)]
|
#[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],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue