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 292 [[package]]
293 293 name = "oxwm"
294 -version = "0.9.0"
294 +version = "0.9.1"
295 295 dependencies = [
296 296 "chrono",
297 297 "dirs",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 1 [package]
2 2 name = "oxwm"
3 -version = "0.9.0"
3 +version = "0.9.1"
4 4 edition = "2024"
5 5
6 6 [lib]
+2 −0 resources/test-config.lua
@@ -28,6 +28,8 @@ local colors = {
28 28 blue = 0x6dade3,
29 29 }
30 30
31 +asdf
32 +
31 33 local modkey = "Mod1"
32 34
33 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 34 let mut window_manager = oxwm::window_manager::WindowManager::new(config)?;
35 35
36 - if had_broken_config {
37 - window_manager.show_migration_overlay();
36 + if let Some(error) = config_error {
37 + window_manager.show_startup_config_error(&error);
38 38 }
39 39
40 40 let should_restart = window_manager.run()?;
@@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
54 54
55 55 fn load_config(
56 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 58 let config_path = if let Some(path) = custom_path {
59 59 path
60 60 } else {
@@ -86,21 +86,21 @@ fn load_config(
86 86
87 87 let config_directory = config_path.parent();
88 88
89 - let (mut config, had_error) =
89 + let (mut config, config_error) =
90 90 match oxwm::config::parse_lua_config(&config_string, config_directory) {
91 - Ok(config) => (config, false),
92 - Err(_error) => {
91 + Ok(config) => (config, None),
92 + Err(error) => {
93 93 let template = include_str!("../../templates/config.lua");
94 94 let config = oxwm::config::parse_lua_config(template, None).map_err(|error| {
95 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 101 config.path = Some(config_path);
102 102
103 - Ok((config, had_error))
103 + Ok((config, config_error))
104 104 }
105 105
106 106 fn init_config() -> Result<(), Box<dyn std::error::Error>> {
+3 −12 src/window_manager.rs
@@ -312,16 +312,7 @@ impl WindowManager {
312 312 Ok(window_manager)
313 313 }
314 314
315 - pub fn show_migration_overlay(&mut self) {
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 -
315 + pub fn show_startup_config_error(&mut self, error: &str) {
325 316 let monitor = &self.monitors[self.selected_monitor];
326 317 let monitor_x = monitor.screen_x as i16;
327 318 let monitor_y = monitor.screen_y as i16;
@@ -331,13 +322,13 @@ impl WindowManager {
331 322 if let Err(e) = self.overlay.show_error(
332 323 &self.connection,
333 324 &self.font,
334 - message,
325 + error,
335 326 monitor_x,
336 327 monitor_y,
337 328 screen_width,
338 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