tony / oxwm

Updated error handling in lua api, and configured restart correctly with super shift r keybind. also handled bar redraw correctly. Browse files
tonybtw committed 2025-11-13 parent 89f2203 commit 39f847d81215af9360883ac48d990f30eb46122f
Showing 11 changed files with 285 additions and 169 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -297,7 +297,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
297 297
298 298 [[package]]
299 299 name = "oxwm"
300 -version = "0.6.0"
300 +version = "0.7.0"
301 301 dependencies = [
302 302 "anyhow",
303 303 "chrono",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 1 [package]
2 2 name = "oxwm"
3 -version = "0.6.0"
3 +version = "0.7.0"
4 4 edition = "2024"
5 5
6 6 [lib]
+46 −42 resources/test-config.lua
@@ -6,7 +6,9 @@
6 6 ---Load type definitions for LSP
7 7 ---@module 'oxwm'
8 8
9 --- Color palette
9 +
10 +-- Set variables as needed
11 +-- Colors
10 12 local colors = {
11 13 lavender = 0xa9b1d6,
12 14 light_blue = 0x7aa2f7,
@@ -20,9 +22,11 @@ local colors = {
20 22 blue = 0x6dade3,
21 23 }
22 24
25 +local modkey = "Mod1";
26 +
23 27 -- Basic settings
24 28 oxwm.set_terminal("st")
25 -oxwm.set_modkey("Mod1")
29 +oxwm.set_modkey(modkey)
26 30 oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" })
27 31
28 32 -- Layout symbol overrides
@@ -51,68 +55,68 @@ oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
51 55
52 56 -- Keychord: Mod1+Space then T to spawn terminal
53 57 oxwm.key.chord({
54 - { { "Mod1" }, "Space" },
58 + { { modkey }, "Space" },
55 59 { {}, "T" }
56 60 }, oxwm.spawn("st"))
57 61
58 62 -- Basic window management
59 -oxwm.key.bind({ "Mod1" }, "Return", oxwm.spawn("st"))
60 -oxwm.key.bind({ "Mod1" }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
61 -oxwm.key.bind({ "Mod1" }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
62 -oxwm.key.bind({ "Mod1" }, "Q", oxwm.client.kill())
63 +oxwm.key.bind({ modkey }, "Return", oxwm.spawn("st"))
64 +oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
65 +oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
66 +oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
63 67
64 68 -- Keybind overlay
65 -oxwm.key.bind({ "Mod1", "Shift" }, "Slash", oxwm.show_keybinds())
69 +oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
66 70
67 71 -- Client actions
68 -oxwm.key.bind({ "Mod1", "Shift" }, "F", oxwm.client.toggle_fullscreen())
69 -oxwm.key.bind({ "Mod1", "Shift" }, "Space", oxwm.client.toggle_floating())
72 +oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen())
73 +oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating())
70 74
71 75 -- Layout management
72 -oxwm.key.bind({ "Mod1" }, "F", oxwm.layout.set("normie"))
73 -oxwm.key.bind({ "Mod1" }, "C", oxwm.layout.set("tiling"))
74 -oxwm.key.bind({ "Mod1" }, "N", oxwm.layout.cycle())
76 +oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie"))
77 +oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling"))
78 +oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
75 79
76 80 -- Gaps toggle
77 -oxwm.key.bind({ "Mod1" }, "A", oxwm.toggle_gaps())
81 +oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
78 82
79 83 -- WM controls
80 -oxwm.key.bind({ "Mod1", "Shift" }, "Q", oxwm.quit())
81 -oxwm.key.bind({ "Mod1", "Shift" }, "R", oxwm.restart())
84 +oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
85 +oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
82 86
83 87 -- Focus direction (vim keys)
84 -oxwm.key.bind({ "Mod1" }, "H", oxwm.client.focus_direction("left"))
85 -oxwm.key.bind({ "Mod1" }, "J", oxwm.client.focus_direction("down"))
86 -oxwm.key.bind({ "Mod1" }, "K", oxwm.client.focus_direction("up"))
87 -oxwm.key.bind({ "Mod1" }, "L", oxwm.client.focus_direction("right"))
88 +oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left"))
89 +oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down"))
90 +oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up"))
91 +oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right"))
88 92
89 93 -- Swap windows in direction
90 -oxwm.key.bind({ "Mod1", "Shift" }, "H", oxwm.client.swap_direction("left"))
91 -oxwm.key.bind({ "Mod1", "Shift" }, "J", oxwm.client.swap_direction("down"))
92 -oxwm.key.bind({ "Mod1", "Shift" }, "K", oxwm.client.swap_direction("up"))
93 -oxwm.key.bind({ "Mod1", "Shift" }, "L", oxwm.client.swap_direction("right"))
94 +oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left"))
95 +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down"))
96 +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up"))
97 +oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right"))
94 98
95 99 -- Tag viewing
96 -oxwm.key.bind({ "Mod1" }, "1", oxwm.tag.view(0))
97 -oxwm.key.bind({ "Mod1" }, "2", oxwm.tag.view(1))
98 -oxwm.key.bind({ "Mod1" }, "3", oxwm.tag.view(2))
99 -oxwm.key.bind({ "Mod1" }, "4", oxwm.tag.view(3))
100 -oxwm.key.bind({ "Mod1" }, "5", oxwm.tag.view(4))
101 -oxwm.key.bind({ "Mod1" }, "6", oxwm.tag.view(5))
102 -oxwm.key.bind({ "Mod1" }, "7", oxwm.tag.view(6))
103 -oxwm.key.bind({ "Mod1" }, "8", oxwm.tag.view(7))
104 -oxwm.key.bind({ "Mod1" }, "9", oxwm.tag.view(8))
100 +oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
101 +oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
102 +oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
103 +oxwm.key.bind({ modkey }, "4", oxwm.tag.view(3))
104 +oxwm.key.bind({ modkey }, "5", oxwm.tag.view(4))
105 +oxwm.key.bind({ modkey }, "6", oxwm.tag.view(5))
106 +oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
107 +oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
108 +oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
105 109
106 110 -- Move window to tag
107 -oxwm.key.bind({ "Mod1", "Shift" }, "1", oxwm.tag.move_to(0))
108 -oxwm.key.bind({ "Mod1", "Shift" }, "2", oxwm.tag.move_to(1))
109 -oxwm.key.bind({ "Mod1", "Shift" }, "3", oxwm.tag.move_to(2))
110 -oxwm.key.bind({ "Mod1", "Shift" }, "4", oxwm.tag.move_to(3))
111 -oxwm.key.bind({ "Mod1", "Shift" }, "5", oxwm.tag.move_to(4))
112 -oxwm.key.bind({ "Mod1", "Shift" }, "6", oxwm.tag.move_to(5))
113 -oxwm.key.bind({ "Mod1", "Shift" }, "7", oxwm.tag.move_to(6))
114 -oxwm.key.bind({ "Mod1", "Shift" }, "8", oxwm.tag.move_to(7))
115 -oxwm.key.bind({ "Mod1", "Shift" }, "9", oxwm.tag.move_to(8))
111 +oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
112 +oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
113 +oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
114 +oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(3))
115 +oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(4))
116 +oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(5))
117 +oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
118 +oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
119 +oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
116 120
117 121 -- Status bar blocks
118 122 oxwm.bar.add_block("", "Battery", {
+24 −0 src/bar/bar.rs
@@ -347,4 +347,28 @@ impl Bar {
347 347 pub fn needs_redraw(&self) -> bool {
348 348 self.needs_redraw
349 349 }
350 +
351 + pub fn update_from_config(&mut self, config: &Config) {
352 + self.blocks = config
353 + .status_blocks
354 + .iter()
355 + .map(|block_config| block_config.to_block())
356 + .collect();
357 +
358 + self.block_underlines = config
359 + .status_blocks
360 + .iter()
361 + .map(|block_config| block_config.underline)
362 + .collect();
363 +
364 + self.block_last_updates = vec![Instant::now(); self.blocks.len()];
365 +
366 + self.tags = config.tags.clone();
367 + self.scheme_normal = config.scheme_normal;
368 + self.scheme_occupied = config.scheme_occupied;
369 + self.scheme_selected = config.scheme_selected;
370 +
371 + self.status_text.clear();
372 + self.needs_redraw = true;
373 + }
350 374 }
+1 −4 src/bin/main.rs
@@ -54,7 +54,6 @@ fn load_config(custom_path: Option<PathBuf>) -> Result<oxwm::Config> {
54 54 let lua_path = config_dir.join("config.lua");
55 55
56 56 if !lua_path.exists() {
57 - // Check if user had an old RON config
58 57 let ron_path = config_dir.join("config.ron");
59 58 let had_ron_config = ron_path.exists();
60 59
@@ -63,7 +62,7 @@ fn load_config(custom_path: Option<PathBuf>) -> Result<oxwm::Config> {
63 62 init_config()?;
64 63
65 64 if had_ron_config {
66 - println!("\n⚠️ NOTICE: OXWM has migrated to Lua configuration.");
65 + println!("\n NOTICE: OXWM has migrated to Lua configuration.");
67 66 println!(" Your old config.ron has been preserved, but is no longer used.");
68 67 println!(" Your settings have been reset to defaults.");
69 68 println!(" Please manually port your configuration to the new Lua format.");
@@ -86,12 +85,10 @@ fn init_config() -> Result<()> {
86 85 let config_dir = get_config_path();
87 86 std::fs::create_dir_all(&config_dir)?;
88 87
89 - // Copy config.lua template
90 88 let config_template = include_str!("../../templates/config.lua");
91 89 let config_path = config_dir.join("config.lua");
92 90 std::fs::write(&config_path, config_template)?;
93 91
94 - // Copy oxwm.lua API definitions for LSP support
95 92 let oxwm_lua_template = include_str!("../../templates/oxwm.lua");
96 93 let oxwm_lua_path = config_dir.join("oxwm.lua");
97 94 std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
+2 −2 src/config/lua.rs
@@ -28,7 +28,7 @@ pub fn parse_lua_config(
28 28
29 29 lua.load(input)
30 30 .exec()
31 - .map_err(|e| ConfigError::LuaError(format!("Failed to execute Lua config: {}", e)))?;
31 + .map_err(|e| ConfigError::LuaError(format!("{}", e)))?;
32 32
33 33 let builder_data = builder.borrow().clone();
34 34
@@ -59,7 +59,7 @@ pub fn parse_lua_config(
59 59 let config: Table = lua
60 60 .load(input)
61 61 .eval()
62 - .map_err(|e| ConfigError::LuaError(format!("Failed to execute Lua config: {}", e)))?;
62 + .map_err(|e| ConfigError::LuaError(format!("{}", e)))?;
63 63 let border_width: u32 = get_table_field(&config, "border_width")?;
64 64 let border_focused: u32 = parse_color(&config, "border_focused")?;
65 65 let border_unfocused: u32 = parse_color(&config, "border_unfocused")?;
+22 −18 src/config/lua_api.rs
@@ -363,7 +363,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
363 363 } else {
364 364 None
365 365 }
366 - }).ok_or_else(|| mlua::Error::RuntimeError("DateTime requires format string".into()))?;
366 + }).ok_or_else(|| mlua::Error::RuntimeError("oxwm.bar.add_block: DateTime command requires a format string as the third argument. example: oxwm.bar.add_block(\"\", \"DateTime\", \"%H:%M\", 60, 0xffffff, false)".into()))?;
367 367 BlockCommand::DateTime(fmt)
368 368 }
369 369 "Shell" => {
@@ -373,7 +373,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
373 373 } else {
374 374 None
375 375 }
376 - }).ok_or_else(|| mlua::Error::RuntimeError("Shell requires command string".into()))?;
376 + }).ok_or_else(|| mlua::Error::RuntimeError("oxwm.bar.add_block: Shell command requires a shell command string as the third argument. example: oxwm.bar.add_block(\"\", \"Shell\", \"date +%H:%M\", 60, 0xffffff, false)".into()))?;
377 377 BlockCommand::Shell(cmd_str)
378 378 }
379 379 "Ram" => BlockCommand::Ram,
@@ -394,7 +394,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
394 394 } else {
395 395 None
396 396 }
397 - }).ok_or_else(|| mlua::Error::RuntimeError("Battery requires formats table".into()))?;
397 + }).ok_or_else(|| mlua::Error::RuntimeError("oxwm.bar.add_block: Battery command requires a formats table as the third argument. example: {charging=\"CHR {percentage}%\", discharging=\"BAT {percentage}%\", full=\"FULL\"}".into()))?;
398 398
399 399 let charging: String = formats.get("charging")?;
400 400 let discharging: String = formats.get("discharging")?;
@@ -406,7 +406,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
406 406 format_full: full,
407 407 }
408 408 }
409 - _ => return Err(mlua::Error::RuntimeError(format!("Unknown block command: {}", command))),
409 + _ => return Err(mlua::Error::RuntimeError(format!("oxwm.bar.add_block: unknown block command '{}'. valid commands: DateTime, Shell, Ram, Static, Battery", command))),
410 410 };
411 411
412 412 let color_u32 = parse_color_value(color)?;
@@ -572,7 +572,7 @@ fn parse_modifiers_value(_lua: &Lua, value: Value) -> mlua::Result<Vec<KeyButMas
572 572 for i in 1..=t.len()? {
573 573 let mod_str: String = t.get(i)?;
574 574 let mask = parse_modkey_string(&mod_str)
575 - .map_err(|e| mlua::Error::RuntimeError(format!("{}", e)))?;
575 + .map_err(|e| mlua::Error::RuntimeError(format!("oxwm.key.bind: invalid modifier - {}", e)))?;
576 576 mods.push(mask);
577 577 }
578 578 Ok(mods)
@@ -580,11 +580,11 @@ fn parse_modifiers_value(_lua: &Lua, value: Value) -> mlua::Result<Vec<KeyButMas
580 580 Value::String(s) => {
581 581 let s_str = s.to_str()?;
582 582 let mask = parse_modkey_string(&s_str)
583 - .map_err(|e| mlua::Error::RuntimeError(format!("{}", e)))?;
583 + .map_err(|e| mlua::Error::RuntimeError(format!("oxwm.key.bind: invalid modifier - {}", e)))?;
584 584 Ok(vec![mask])
585 585 }
586 586 _ => Err(mlua::Error::RuntimeError(
587 - "modifiers must be string or table".into(),
587 + "oxwm.key.bind: first argument must be a table of modifiers like {\"Mod4\"} or {\"Mod4\", \"Shift\"}".into(),
588 588 )),
589 589 }
590 590 }
@@ -598,19 +598,23 @@ fn parse_modkey_string(s: &str) -> Result<KeyButMask, ConfigError> {
598 598 "Mod5" => Ok(KeyButMask::MOD5),
599 599 "Shift" => Ok(KeyButMask::SHIFT),
600 600 "Control" => Ok(KeyButMask::CONTROL),
601 - _ => Err(ConfigError::InvalidModkey(s.to_string())),
601 + _ => Err(ConfigError::InvalidModkey(format!("'{}' is not a valid modifier. Use one of: Mod1, Mod4, Shift, Control", s))),
602 602 }
603 603 }
604 604
605 605 fn parse_keysym(key: &str) -> mlua::Result<Keysym> {
606 606 keysyms::keysym_from_str(key)
607 - .ok_or_else(|| mlua::Error::RuntimeError(format!("Unknown key: {}", key)))
607 + .ok_or_else(|| mlua::Error::RuntimeError(format!("unknown key '{}'. valid keys include: Return, Space, A-Z, 0-9, F1-F12, Left, Right, Up, Down, etc. check oxwm.lua type definitions for the complete list", key)))
608 608 }
609 609
610 610 fn parse_action_value(_lua: &Lua, value: Value) -> mlua::Result<(KeyAction, Arg)> {
611 611 match value {
612 + Value::Function(_) => {
613 + Err(mlua::Error::RuntimeError(
614 + "action must be a function call, not a function reference. did you forget ()? example: oxwm.spawn('st') not oxwm.spawn".into()
615 + ))
616 + }
612 617 Value::Table(t) => {
613 - // Check if this table has our action metadata
614 618 if let Ok(action_name) = t.get::<String>("__action") {
615 619 let action = string_to_action(&action_name)?;
616 620 let arg = if let Ok(arg_val) = t.get::<Value>("__arg") {
@@ -622,11 +626,11 @@ fn parse_action_value(_lua: &Lua, value: Value) -> mlua::Result<(KeyAction, Arg)
622 626 }
623 627
624 628 Err(mlua::Error::RuntimeError(
625 - "action table missing __action field".into(),
629 + "action must be a table returned by oxwm functions like oxwm.spawn(), oxwm.client.kill(), oxwm.quit(), etc.".into(),
626 630 ))
627 631 }
628 632 _ => Err(mlua::Error::RuntimeError(
629 - "action must be a table returned by oxwm actions".into(),
633 + "action must be a table returned by oxwm functions like oxwm.spawn(), oxwm.client.kill(), oxwm.quit(), etc.".into(),
630 634 )),
631 635 }
632 636 }
@@ -652,7 +656,7 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
652 656 "SmartMoveWin" => Ok(KeyAction::SmartMoveWin),
653 657 "ExchangeClient" => Ok(KeyAction::ExchangeClient),
654 658 "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay),
655 - _ => Err(mlua::Error::RuntimeError(format!("Unknown action: {}", s))),
659 + _ => Err(mlua::Error::RuntimeError(format!("unknown action '{}'. this is an internal error, please report it", s))),
656 660 }
657 661 }
658 662
@@ -688,7 +692,7 @@ fn direction_string_to_int(dir: &str) -> mlua::Result<i64> {
688 692 "left" => Ok(2),
689 693 "right" => Ok(3),
690 694 _ => Err(mlua::Error::RuntimeError(
691 - format!("Invalid direction '{}', must be one of: up, down, left, right", dir)
695 + format!("invalid direction '{}'. must be one of: up, down, left, right", dir)
692 696 )),
693 697 }
694 698 }
@@ -701,17 +705,17 @@ fn parse_color_value(value: Value) -> mlua::Result<u32> {
701 705 let s = s.to_str()?;
702 706 if s.starts_with('#') {
703 707 u32::from_str_radix(&s[1..], 16)
704 - .map_err(|e| mlua::Error::RuntimeError(format!("Invalid hex color: {}", e)))
708 + .map_err(|e| mlua::Error::RuntimeError(format!("invalid hex color '{}': {}. use format like #ff0000 or 0xff0000", s, e)))
705 709 } else if s.starts_with("0x") {
706 710 u32::from_str_radix(&s[2..], 16)
707 - .map_err(|e| mlua::Error::RuntimeError(format!("Invalid hex color: {}", e)))
711 + .map_err(|e| mlua::Error::RuntimeError(format!("invalid hex color '{}': {}. use format like 0xff0000 or #ff0000", s, e)))
708 712 } else {
709 713 s.parse::<u32>()
710 - .map_err(|e| mlua::Error::RuntimeError(format!("Invalid color: {}", e)))
714 + .map_err(|e| mlua::Error::RuntimeError(format!("invalid color '{}': {}. use hex format like 0xff0000 or #ff0000", s, e)))
711 715 }
712 716 }
713 717 _ => Err(mlua::Error::RuntimeError(
714 - "color must be number or string".into(),
718 + "color must be a number (0xff0000) or string ('#ff0000' or '0xff0000')".into(),
715 719 )),
716 720 }
717 721 }
+6 −6 src/errors.rs
@@ -73,15 +73,15 @@ impl std::error::Error for X11Error {}
73 73 impl std::fmt::Display for ConfigError {
74 74 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75 75 match self {
76 - Self::LuaError(msg) => write!(f, "Lua config error: {}", msg),
77 - Self::InvalidModkey(key) => write!(f, "Invalid modkey: {}", key),
78 - Self::UnknownKey(key) => write!(f, "Unknown key: {}", key),
79 - Self::UnknownAction(action) => write!(f, "Unknown action: {}", action),
80 - Self::UnknownBlockCommand(cmd) => write!(f, "Unknown block command: {}", cmd),
76 + Self::LuaError(msg) => write!(f, "{}", msg),
77 + Self::InvalidModkey(msg) => write!(f, "{}", msg),
78 + Self::UnknownKey(msg) => write!(f, "{}", msg),
79 + Self::UnknownAction(msg) => write!(f, "{}", msg),
80 + Self::UnknownBlockCommand(msg) => write!(f, "{}", msg),
81 81 Self::MissingCommandArg { command, field } => {
82 82 write!(f, "{} command requires {}", command, field)
83 83 }
84 - Self::ValidationError(msg) => write!(f, "Config validation error: {}", msg),
84 + Self::ValidationError(msg) => write!(f, "{}", msg),
85 85 }
86 86 }
87 87 }
+3 −2 src/overlay/error.rs
@@ -55,8 +55,9 @@ impl ErrorOverlay {
55 55 screen_width: u16,
56 56 screen_height: u16,
57 57 ) -> Result<(), X11Error> {
58 - let max_line_width = (screen_width as i16 - PADDING * 4).max(300) as u16;
59 - self.lines = self.wrap_text(error_text, font, max_line_width);
58 + let max_line_width = (screen_width as i16 / 2 - PADDING * 4).max(300) as u16;
59 + let error_with_instruction = format!("{}\n\nFix the config file and reload.", error_text);
60 + self.lines = self.wrap_text(&error_with_instruction, font, max_line_width);
60 61
61 62 let mut content_width = 0u16;
62 63 for line in &self.lines {
+12 −3 src/window_manager.rs
@@ -263,10 +263,15 @@ impl WindowManager {
263 263 .map_err(|e| format!("Failed to read config: {}", e))?;
264 264
265 265 let new_config = crate::config::parse_lua_config(&config_str, Some(&config_dir))
266 - .map_err(|e| format!("Config error: {}", e))?;
266 + .map_err(|e| format!("{}", e))?;
267 267
268 268 self.config = new_config;
269 269 self.error_message = None;
270 +
271 + for bar in &mut self.bars {
272 + bar.update_from_config(&self.config);
273 + }
274 +
270 275 Ok(())
271 276 }
272 277
@@ -1773,16 +1778,20 @@ impl WindowManager {
1773 1778 self.update_bar()?;
1774 1779 }
1775 1780 Err(err) => {
1781 + eprintln!("Config reload error: {}", err);
1776 1782 self.error_message = Some(err.clone());
1777 1783 let screen_width = self.screen.width_in_pixels;
1778 1784 let screen_height = self.screen.height_in_pixels;
1779 - let _ = self.overlay.show_error(
1785 + match self.overlay.show_error(
1780 1786 &self.connection,
1781 1787 &self.font,
1782 1788 &err,
1783 1789 screen_width,
1784 1790 screen_height,
1785 - );
1791 + ) {
1792 + Ok(()) => eprintln!("Error modal displayed"),
1793 + Err(e) => eprintln!("Failed to show error modal: {:?}", e),
1794 + }
1786 1795 }
1787 1796 },
1788 1797 _ => self.handle_key_action(action, &arg)?,
+167 −90 templates/config.lua
@@ -1,12 +1,30 @@
1 1 ---@meta
2 ----OXWM Configuration File (Lua)
3 ----Using the new functional API
4 ----Edit this file and reload with Mod+Shift+R (no compilation needed!)
2 +-------------------------------------------------------------------------------
3 +-- OXWM Configuration File
4 +-------------------------------------------------------------------------------
5 +-- This is the default configuration for OXWM, a dynamic window manager.
6 +-- Edit this file and reload with Mod+Shift+R (no compilation needed!)
7 +--
8 +-- For more information about configuring OXWM, see the documentation.
9 +-- The Lua Language Server provides autocomplete and type checking.
10 +-------------------------------------------------------------------------------
5 11
6 12 ---Load type definitions for LSP
7 13 ---@module 'oxwm'
8 14
9 --- Color palette
15 +-------------------------------------------------------------------------------
16 +-- Variables
17 +-------------------------------------------------------------------------------
18 +-- Define your variables here for easy customization throughout the config.
19 +-- This makes it simple to change keybindings, colors, and settings in one place.
20 +
21 +-- Modifier key: "Mod4" is the Super/Windows key, "Mod1" is Alt
22 +local modkey = "Mod4"
23 +
24 +-- Terminal emulator command
25 +local terminal = "st"
26 +
27 +-- Color palette - customize these to match your theme
10 28 local colors = {
11 29 fg = "#bbbbbb",
12 30 red = "#f7768e",
@@ -20,111 +38,170 @@ local colors = {
20 38 purple = "#ad8ee6",
21 39 }
22 40
23 --- Basic settings
24 -oxwm.set_terminal("st")
25 -oxwm.set_modkey("Mod4")
26 -oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" })
41 +-- Workspace tags - can be numbers, names, or icons (requires a Nerd Font)
42 +local tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }
43 +
44 +-- Font for the status bar (use "fc-list" to see available fonts)
45 +local bar_font = "monospace:style=Bold:size=10"
46 +
47 +-------------------------------------------------------------------------------
48 +-- Basic Settings
49 +-------------------------------------------------------------------------------
50 +oxwm.set_terminal(terminal)
51 +oxwm.set_modkey(modkey)
52 +oxwm.set_tags(tags)
27 53
28 --- Layout symbol overrides
54 +-------------------------------------------------------------------------------
55 +-- Layouts
56 +-------------------------------------------------------------------------------
57 +-- Set custom symbols for layouts (displayed in the status bar)
58 +-- Available layouts: "tiling" (master-stack), "normie" (floating)
29 59 oxwm.set_layout_symbol("tiling", "[T]")
30 60 oxwm.set_layout_symbol("normie", "[F]")
31 61
62 +-------------------------------------------------------------------------------
63 +-- Appearance
64 +-------------------------------------------------------------------------------
32 65 -- Border configuration
33 -oxwm.border.set_width(2)
34 -oxwm.border.set_focused_color(colors.blue)
35 -oxwm.border.set_unfocused_color(colors.grey)
36 -
37 --- Gap configuration
38 -oxwm.gaps.set_enabled(true)
39 -oxwm.gaps.set_inner(5, 5) -- horizontal, vertical
40 -oxwm.gaps.set_outer(5, 5) -- horizontal, vertical
41 -
42 --- Bar configuration
43 -oxwm.bar.set_font("monospace:style=Bold:size=10")
44 -
45 --- Bar color schemes (for tag display)
46 -oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444")
47 -oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan)
48 -oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
49 -
66 +oxwm.border.set_width(2) -- Width in pixels
67 +oxwm.border.set_focused_color(colors.blue) -- Color of focused window border
68 +oxwm.border.set_unfocused_color(colors.grey) -- Color of unfocused window borders
69 +
70 +-- Gap configuration (space between windows and screen edges)
71 +oxwm.gaps.set_enabled(true) -- Enable or disable gaps
72 +oxwm.gaps.set_inner(5, 5) -- Inner gaps (horizontal, vertical) in pixels
73 +oxwm.gaps.set_outer(5, 5) -- Outer gaps (horizontal, vertical) in pixels
74 +
75 +-------------------------------------------------------------------------------
76 +-- Status Bar Configuration
77 +-------------------------------------------------------------------------------
78 +-- Font configuration
79 +oxwm.bar.set_font(bar_font)
80 +
81 +-- Bar color schemes (for workspace tag display)
82 +-- Parameters: foreground, background, border
83 +oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444") -- Unoccupied tags
84 +oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan) -- Occupied tags
85 +oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) -- Currently selected tag
86 +
87 +-------------------------------------------------------------------------------
50 88 -- Keybindings
89 +-------------------------------------------------------------------------------
90 +-- Keybindings are defined using oxwm.key.bind(modifiers, key, action)
91 +-- Modifiers: {"Mod4"}, {"Mod1"}, {"Shift"}, {"Control"}, or combinations like {"Mod4", "Shift"}
92 +-- Keys: Use uppercase for letters (e.g., "Return", "H", "J", "K", "L")
93 +-- Actions: Functions that return actions (e.g., oxwm.spawn(), oxwm.client.kill())
94 +--
95 +-- A list of available keysyms can be found in the X11 keysym definitions.
96 +-- Common keys: Return, Space, Tab, Escape, Backspace, Delete, Left, Right, Up, Down
51 97
52 98 -- Basic window management
53 -oxwm.key.bind({ "Mod4" }, "Return", oxwm.spawn("st"))
54 -oxwm.key.bind({ "Mod4" }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
55 -oxwm.key.bind({ "Mod4" }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
56 -oxwm.key.bind({ "Mod4" }, "Q", oxwm.client.kill())
99 +oxwm.key.bind({ modkey }, "Return", oxwm.spawn(terminal)) -- Spawn terminal
100 +oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) -- Application launcher
101 +oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) -- Screenshot selection
102 +oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) -- Close focused window
57 103
58 --- Keybind overlay
59 -oxwm.key.bind({ "Mod4", "Shift" }, "Slash", oxwm.show_keybinds())
104 +-- Keybind overlay - Shows important keybindings on screen
105 +oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
60 106
61 --- Client actions
62 -oxwm.key.bind({ "Mod4", "Shift" }, "F", oxwm.client.toggle_fullscreen())
63 -oxwm.key.bind({ "Mod4", "Shift" }, "Space", oxwm.client.toggle_floating())
107 +-- Window state toggles
108 +oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen()) -- Toggle fullscreen
109 +oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating()) -- Toggle floating mode
64 110
65 111 -- Layout management
66 -oxwm.key.bind({ "Mod4" }, "F", oxwm.layout.set("normie"))
67 -oxwm.key.bind({ "Mod4" }, "C", oxwm.layout.set("tiling"))
68 -oxwm.key.bind({ "Mod1" }, "N", oxwm.layout.cycle())
112 +oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie")) -- Set floating layout
113 +oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling")) -- Set tiling layout
114 +oxwm.key.bind({ "Mod1" }, "N", oxwm.layout.cycle()) -- Cycle through layouts
69 115
70 116 -- Gaps toggle
71 -oxwm.key.bind({ "Mod4" }, "A", oxwm.toggle_gaps())
72 -
73 --- WM controls
74 -oxwm.key.bind({ "Mod4", "Shift" }, "Q", oxwm.quit())
75 -oxwm.key.bind({ "Mod4", "Shift" }, "R", oxwm.restart())
76 -
77 --- Focus direction (vim keys: h=left=2, j=down=1, k=up=0, l=right=3)
78 -oxwm.key.bind({ "Mod4" }, "H", oxwm.client.focus_direction("left"))
79 -oxwm.key.bind({ "Mod4" }, "J", oxwm.client.focus_direction("down"))
80 -oxwm.key.bind({ "Mod4" }, "K", oxwm.client.focus_direction("up"))
81 -oxwm.key.bind({ "Mod4" }, "L", oxwm.client.focus_direction("right"))
82 -
83 --- Monitor focus
84 -oxwm.key.bind({ "Mod4" }, "Comma", oxwm.focus_monitor(-1))
85 -oxwm.key.bind({ "Mod4" }, "Period", oxwm.focus_monitor(1))
86 -
87 --- Tag viewing
88 -oxwm.key.bind({ "Mod4" }, "1", oxwm.tag.view(0))
89 -oxwm.key.bind({ "Mod4" }, "2", oxwm.tag.view(1))
90 -oxwm.key.bind({ "Mod4" }, "3", oxwm.tag.view(2))
91 -oxwm.key.bind({ "Mod4" }, "4", oxwm.tag.view(3))
92 -oxwm.key.bind({ "Mod4" }, "5", oxwm.tag.view(4))
93 -oxwm.key.bind({ "Mod4" }, "6", oxwm.tag.view(5))
94 -oxwm.key.bind({ "Mod4" }, "7", oxwm.tag.view(6))
95 -oxwm.key.bind({ "Mod4" }, "8", oxwm.tag.view(7))
96 -oxwm.key.bind({ "Mod4" }, "9", oxwm.tag.view(8))
97 -
98 --- Move window to tag
99 -oxwm.key.bind({ "Mod4", "Shift" }, "1", oxwm.tag.move_to(0))
100 -oxwm.key.bind({ "Mod4", "Shift" }, "2", oxwm.tag.move_to(1))
101 -oxwm.key.bind({ "Mod4", "Shift" }, "3", oxwm.tag.move_to(2))
102 -oxwm.key.bind({ "Mod4", "Shift" }, "4", oxwm.tag.move_to(3))
103 -oxwm.key.bind({ "Mod4", "Shift" }, "5", oxwm.tag.move_to(4))
104 -oxwm.key.bind({ "Mod4", "Shift" }, "6", oxwm.tag.move_to(5))
105 -oxwm.key.bind({ "Mod4", "Shift" }, "7", oxwm.tag.move_to(6))
106 -oxwm.key.bind({ "Mod4", "Shift" }, "8", oxwm.tag.move_to(7))
107 -oxwm.key.bind({ "Mod4", "Shift" }, "9", oxwm.tag.move_to(8))
108 -
109 --- Swap windows in direction
110 -oxwm.key.bind({ "Mod4", "Shift" }, "H", oxwm.client.swap_direction("left"))
111 -oxwm.key.bind({ "Mod4", "Shift" }, "J", oxwm.client.swap_direction("down"))
112 -oxwm.key.bind({ "Mod4", "Shift" }, "K", oxwm.client.swap_direction("up"))
113 -oxwm.key.bind({ "Mod4", "Shift" }, "L", oxwm.client.swap_direction("right"))
114 -
115 --- Keychord example: Mod4+Space then T to spawn terminal
117 +oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) -- Toggle gaps on/off
118 +
119 +-- Window manager controls
120 +oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) -- Quit OXWM
121 +oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) -- Restart OXWM (reloads config)
122 +
123 +-- Focus movement (vim keys)
124 +oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left")) -- Focus window to the left
125 +oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down")) -- Focus window below
126 +oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up")) -- Focus window above
127 +oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right")) -- Focus window to the right
128 +
129 +-- Multi-monitor support
130 +oxwm.key.bind({ modkey }, "Comma", oxwm.focus_monitor(-1)) -- Focus previous monitor
131 +oxwm.key.bind({ modkey }, "Period", oxwm.focus_monitor(1)) -- Focus next monitor
132 +
133 +-- Workspace (tag) navigation
134 +-- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0)
135 +oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
136 +oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
137 +oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
138 +oxwm.key.bind({ modkey }, "4", oxwm.tag.view(3))
139 +oxwm.key.bind({ modkey }, "5", oxwm.tag.view(4))
140 +oxwm.key.bind({ modkey }, "6", oxwm.tag.view(5))
141 +oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
142 +oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
143 +oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
144 +
145 +-- Move focused window to workspace N
146 +oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
147 +oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
148 +oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
149 +oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(3))
150 +oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(4))
151 +oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(5))
152 +oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
153 +oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
154 +oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
155 +
156 +-- Swap windows in direction (vim keys with Shift)
157 +oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left")) -- Swap with window to the left
158 +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down")) -- Swap with window below
159 +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up")) -- Swap with window above
160 +oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right")) -- Swap with window to the right
161 +
162 +-------------------------------------------------------------------------------
163 +-- Advanced: Keychords
164 +-------------------------------------------------------------------------------
165 +-- Keychords allow you to bind multiple-key sequences (like Emacs or Vim)
166 +-- Format: {{modifiers}, key1}, {{modifiers}, key2}, ...
167 +-- Example: Press Mod4+Space, then release and press T to spawn a terminal
116 168 oxwm.key.chord({
117 - { { "Mod4" }, "Space" },
118 - { {}, "T" }
119 -}, oxwm.spawn("st"))
169 + { { modkey }, "Space" },
170 + { {}, "T" }
171 +}, oxwm.spawn(terminal))
172 +
173 +-------------------------------------------------------------------------------
174 +-- Status Bar Blocks
175 +-------------------------------------------------------------------------------
176 +-- Add informational blocks to the status bar
177 +-- Format: oxwm.bar.add_block(format, type, data, update_interval, color, separator)
178 +-- format: Display format with {} placeholders
179 +-- type: Block type ("Ram", "DateTime", "Shell", "Static", "Battery")
180 +-- data: Type-specific data (command for Shell, format for DateTime, etc.)
181 +-- update_interval: Seconds between updates (large number for static content)
182 +-- color: Text color (from color palette)
183 +-- separator: Whether to add space after this block
120 184
121 --- Status bar blocks
122 185 oxwm.bar.add_block("Ram: {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true)
123 186 oxwm.bar.add_block(" │ ", "Static", " │ ", 999999999, colors.lavender, false)
124 187 oxwm.bar.add_block("Kernel: {}", "Shell", "uname -r", 999999999, colors.red, true)
125 188 oxwm.bar.add_block(" │ ", "Static", " │ ", 999999999, colors.lavender, false)
126 189 oxwm.bar.add_block("{}", "DateTime", "%a, %b %d - %-I:%M %P", 1, colors.cyan, true)
127 190
128 --- Autostart commands (runs once at startup)
129 --- oxwm.autostart("picom")
130 --- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg")
191 +-- Uncomment to add battery status (useful for laptops)
192 +-- oxwm.bar.add_block("Bat: {}%", "Battery", {
193 +-- charging = "⚡ Bat: {}%",
194 +-- discharging = "🔋 Bat: {}%",
195 +-- full = "✓ Bat: {}%"
196 +-- }, 30, colors.green, true)
197 +
198 +-------------------------------------------------------------------------------
199 +-- Autostart
200 +-------------------------------------------------------------------------------
201 +-- Commands to run once when OXWM starts
202 +-- Uncomment and modify these examples, or add your own
203 +
204 +-- oxwm.autostart("picom") -- Compositor for transparency and effects
205 +-- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg") -- Set wallpaper
206 +-- oxwm.autostart("dunst") -- Notification daemon
207 +-- oxwm.autostart("nm-applet") -- Network manager applet