tony / oxwm

Merge remote-tracking branch 'origin/master' into fix-memory-leak Browse files
tonybtw committed 2025-12-21 parents f5e670c 3bd419c commit 9c34022387076b3e6db29e76352f7f9f4206ea58
Showing 2 changed files with 20 additions and 15 deletions. UnifiedSplit
+15 −12 src/bin/main.rs
@@ -86,18 +86,21 @@ fn load_config(
86 86
87 let config_directory = config_path.parent(); 87 let config_directory = config_path.parent();
88 88
89 - match oxwm::config::parse_lua_config(&config_string, config_directory) { 89 + let (mut config, had_error) =
90 - Ok(mut config) => { 90 + match oxwm::config::parse_lua_config(&config_string, config_directory) {
91 - config.path = Some(config_path); 91 + Ok(config) => (config, false),
92 - Ok((config, false)) 92 + Err(_error) => {
93 - } 93 + let template = include_str!("../../templates/config.lua");
94 - Err(_error) => { 94 + let config = oxwm::config::parse_lua_config(template, None).map_err(|error| {
95 - let template = include_str!("../../templates/config.lua"); 95 + format!("Failed to parse default template config: {}", error)
96 - let config = oxwm::config::parse_lua_config(template, None) 96 + })?;
97 - .map_err(|error| format!("Failed to parse default template config: {}", error))?; 97 + (config, true)
98 - Ok((config, true)) 98 + }
99 - } 99 + };
100 - } 100 +
101 + config.path = Some(config_path);
102 +
103 + Ok((config, had_error))
101 } 104 }
102 105
103 fn init_config() -> Result<(), Box<dyn std::error::Error>> { 106 fn init_config() -> Result<(), Box<dyn std::error::Error>> {
+5 −3 src/window_manager.rs
@@ -347,7 +347,7 @@ impl WindowManager {
347 347
348 fn try_reload_config(&mut self) -> Result<(), String> { 348 fn try_reload_config(&mut self) -> Result<(), String> {
349 let lua_path = 349 let lua_path =
350 - self.config.path.take().ok_or( 350 + self.config.path.as_ref().ok_or(
351 "Could not find config file. Config path should've been set while loading", 351 "Could not find config file. Config path should've been set while loading",
352 )?; 352 )?;
353 353
@@ -355,7 +355,7 @@ impl WindowManager {
355 return Err("Could not find config file, has it been moved?".to_string()); 355 return Err("Could not find config file, has it been moved?".to_string());
356 } 356 }
357 357
358 - let config_str = std::fs::read_to_string(&lua_path) 358 + let config_str = std::fs::read_to_string(lua_path)
359 .map_err(|e| format!("Failed to read config: {}", e))?; 359 .map_err(|e| format!("Failed to read config: {}", e))?;
360 360
361 let config_dir = lua_path.parent(); 361 let config_dir = lua_path.parent();
@@ -363,8 +363,10 @@ impl WindowManager {
363 let new_config = crate::config::parse_lua_config(&config_str, config_dir) 363 let new_config = crate::config::parse_lua_config(&config_str, config_dir)
364 .map_err(|e| format!("{}", e))?; 364 .map_err(|e| format!("{}", e))?;
365 365
366 + let lua_path = self.config.path.take();
367 +
366 self.config = new_config; 368 self.config = new_config;
367 - self.config.path = Some(lua_path); 369 + self.config.path = lua_path;
368 self.error_message = None; 370 self.error_message = None;
369 371
370 for bar in &mut self.bars { 372 for bar in &mut self.bars {