tony / oxwm

Added proper error message for first load of oxwm. Browse files
tonybtw committed 2025-12-22 parent 35465e8 commit 6d17811ab27a0e8a7603a33f0a4a9c2953991ce2
Showing 5 changed files with 16 additions and 23 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -291,7 +291,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
291 291
292 [[package]] 292 [[package]]
293 name = "oxwm" 293 name = "oxwm"
294 -version = "0.9.0" 294 +version = "0.9.1"
295 dependencies = [ 295 dependencies = [
296 "chrono", 296 "chrono",
297 "dirs", 297 "dirs",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 [package] 1 [package]
2 name = "oxwm" 2 name = "oxwm"
3 -version = "0.9.0" 3 +version = "0.9.1"
4 edition = "2024" 4 edition = "2024"
5 5
6 [lib] 6 [lib]
+2 −0 resources/test-config.lua
@@ -28,6 +28,8 @@ local colors = {
28 blue = 0x6dade3, 28 blue = 0x6dade3,
29 } 29 }
30 30
31 +asdf
32 +
31 local modkey = "Mod1" 33 local modkey = "Mod1"
32 34
33 oxwm.set_terminal("st") 35 oxwm.set_terminal("st")
+9 −9 src/bin/main.rs
@@ -29,12 +29,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
29 _ => {} 29 _ => {}
30 } 30 }
31 31
32 - let (config, had_broken_config) = load_config(custom_config_path)?; 32 + let (config, config_error) = load_config(custom_config_path)?;
33 33
34 let mut window_manager = oxwm::window_manager::WindowManager::new(config)?; 34 let mut window_manager = oxwm::window_manager::WindowManager::new(config)?;
35 35
36 - if had_broken_config { 36 + if let Some(error) = config_error {
37 - window_manager.show_migration_overlay(); 37 + window_manager.show_startup_config_error(&error);
38 } 38 }
39 39
40 let should_restart = window_manager.run()?; 40 let should_restart = window_manager.run()?;
@@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
54 54
55 fn load_config( 55 fn load_config(
56 custom_path: Option<PathBuf>, 56 custom_path: Option<PathBuf>,
57 -) -> Result<(oxwm::Config, bool), Box<dyn std::error::Error>> { 57 +) -> Result<(oxwm::Config, Option<String>), Box<dyn std::error::Error>> {
58 let config_path = if let Some(path) = custom_path { 58 let config_path = if let Some(path) = custom_path {
59 path 59 path
60 } else { 60 } else {
@@ -86,21 +86,21 @@ fn load_config(
86 86
87 let config_directory = config_path.parent(); 87 let config_directory = config_path.parent();
88 88
89 - let (mut config, had_error) = 89 + let (mut config, config_error) =
90 match oxwm::config::parse_lua_config(&config_string, config_directory) { 90 match oxwm::config::parse_lua_config(&config_string, config_directory) {
91 - Ok(config) => (config, false), 91 + Ok(config) => (config, None),
92 - Err(_error) => { 92 + Err(error) => {
93 let template = include_str!("../../templates/config.lua"); 93 let template = include_str!("../../templates/config.lua");
94 let config = oxwm::config::parse_lua_config(template, None).map_err(|error| { 94 let config = oxwm::config::parse_lua_config(template, None).map_err(|error| {
95 format!("Failed to parse default template config: {}", error) 95 format!("Failed to parse default template config: {}", error)
96 })?; 96 })?;
97 - (config, true) 97 + (config, Some(format!("{}", error)))
98 } 98 }
99 }; 99 };
100 100
101 config.path = Some(config_path); 101 config.path = Some(config_path);
102 102
103 - Ok((config, had_error)) 103 + Ok((config, config_error))
104 } 104 }
105 105
106 fn init_config() -> Result<(), Box<dyn std::error::Error>> { 106 fn init_config() -> Result<(), Box<dyn std::error::Error>> {
+3 −12 src/window_manager.rs
@@ -312,16 +312,7 @@ impl WindowManager {
312 Ok(window_manager) 312 Ok(window_manager)
313 } 313 }
314 314
315 - pub fn show_migration_overlay(&mut self) { 315 + pub fn show_startup_config_error(&mut self, error: &str) {
316 - let message = "We are on version 0.8.0 now.\n\n\
317 - Your config file has been deprecated once again.\n\
318 - Backup your current config, and run oxwm --init to generate a new one with correct values.\n\n\
319 - Please reach out to Tony, or check out the\n\
320 - documentation for help with migration.\n\n\
321 - We appreciate you testing oxwm!\n\n\
322 - Press Mod+Shift+/ to see keybinds\n\
323 - Press Mod+Shift+R to reload after fixing your config";
324 -
325 let monitor = &self.monitors[self.selected_monitor]; 316 let monitor = &self.monitors[self.selected_monitor];
326 let monitor_x = monitor.screen_x as i16; 317 let monitor_x = monitor.screen_x as i16;
327 let monitor_y = monitor.screen_y as i16; 318 let monitor_y = monitor.screen_y as i16;
@@ -331,13 +322,13 @@ impl WindowManager {
331 if let Err(e) = self.overlay.show_error( 322 if let Err(e) = self.overlay.show_error(
332 &self.connection, 323 &self.connection,
333 &self.font, 324 &self.font,
334 - message, 325 + error,
335 monitor_x, 326 monitor_x,
336 monitor_y, 327 monitor_y,
337 screen_width, 328 screen_width,
338 screen_height, 329 screen_height,
339 ) { 330 ) {
340 - eprintln!("Failed to show migration overlay: {:?}", e); 331 + eprintln!("Failed to show config error overlay: {:?}", e);
341 } 332 }
342 } 333 }
343 334