Updated error handling in lua api, and configured restart correctly with super shift r keybind. also handled bar redraw correctly.
Browse files
+1 −1 Cargo.toml
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "oxwm" | 2 | name = "oxwm" |
| 3 | -version = "0.6.0" | 3 | +version = "0.7.0" |
| 4 | edition = "2024" | 4 | edition = "2024" |
| 5 | 5 | ||
| 6 | [lib] | 6 | [lib] |
+1 −1 default.nix
| @@ -8,7 +8,7 @@ | |||
| 8 | }: | 8 | }: |
| 9 | rustPlatform.buildRustPackage (finalAttrs: { | 9 | rustPlatform.buildRustPackage (finalAttrs: { |
| 10 | pname = "oxwm"; | 10 | pname = "oxwm"; |
| 11 | - version = "0.6.0"; | 11 | + version = "0.7.0"; |
| 12 | 12 | ||
| 13 | src = ./.; | 13 | src = ./.; |
| 14 | 14 | ||
+46 −42 resources/test-config.lua
| @@ -6,7 +6,9 @@ | |||
| 6 | ---Load type definitions for LSP | 6 | ---Load type definitions for LSP |
| 7 | ---@module 'oxwm' | 7 | ---@module 'oxwm' |
| 8 | 8 | ||
| 9 | --- Color palette | 9 | + |
| 10 | +-- Set variables as needed | ||
| 11 | +-- Colors | ||
| 10 | local colors = { | 12 | local colors = { |
| 11 | lavender = 0xa9b1d6, | 13 | lavender = 0xa9b1d6, |
| 12 | light_blue = 0x7aa2f7, | 14 | light_blue = 0x7aa2f7, |
| @@ -20,9 +22,11 @@ local colors = { | |||
| 20 | blue = 0x6dade3, | 22 | blue = 0x6dade3, |
| 21 | } | 23 | } |
| 22 | 24 | ||
| 25 | +local modkey = "Mod1"; | ||
| 26 | + | ||
| 23 | -- Basic settings | 27 | -- Basic settings |
| 24 | oxwm.set_terminal("st") | 28 | oxwm.set_terminal("st") |
| 25 | -oxwm.set_modkey("Mod1") | 29 | +oxwm.set_modkey(modkey) |
| 26 | oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }) | 30 | oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }) |
| 27 | 31 | ||
| 28 | -- Layout symbol overrides | 32 | -- Layout symbol overrides |
| @@ -51,68 +55,68 @@ oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) | |||
| 51 | 55 | ||
| 52 | -- Keychord: Mod1+Space then T to spawn terminal | 56 | -- Keychord: Mod1+Space then T to spawn terminal |
| 53 | oxwm.key.chord({ | 57 | oxwm.key.chord({ |
| 54 | - { { "Mod1" }, "Space" }, | 58 | + { { modkey }, "Space" }, |
| 55 | { {}, "T" } | 59 | { {}, "T" } |
| 56 | }, oxwm.spawn("st")) | 60 | }, oxwm.spawn("st")) |
| 57 | 61 | ||
| 58 | -- Basic window management | 62 | -- Basic window management |
| 59 | -oxwm.key.bind({ "Mod1" }, "Return", oxwm.spawn("st")) | 63 | +oxwm.key.bind({ modkey }, "Return", oxwm.spawn("st")) |
| 60 | -oxwm.key.bind({ "Mod1" }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) | 64 | +oxwm.key.bind({ modkey }, "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" })) | 65 | +oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) |
| 62 | -oxwm.key.bind({ "Mod1" }, "Q", oxwm.client.kill()) | 66 | +oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) |
| 63 | 67 | ||
| 64 | -- Keybind overlay | 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 | -- Client actions | 71 | -- Client actions |
| 68 | -oxwm.key.bind({ "Mod1", "Shift" }, "F", oxwm.client.toggle_fullscreen()) | 72 | +oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen()) |
| 69 | -oxwm.key.bind({ "Mod1", "Shift" }, "Space", oxwm.client.toggle_floating()) | 73 | +oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating()) |
| 70 | 74 | ||
| 71 | -- Layout management | 75 | -- Layout management |
| 72 | -oxwm.key.bind({ "Mod1" }, "F", oxwm.layout.set("normie")) | 76 | +oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie")) |
| 73 | -oxwm.key.bind({ "Mod1" }, "C", oxwm.layout.set("tiling")) | 77 | +oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling")) |
| 74 | -oxwm.key.bind({ "Mod1" }, "N", oxwm.layout.cycle()) | 78 | +oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle()) |
| 75 | 79 | ||
| 76 | -- Gaps toggle | 80 | -- Gaps toggle |
| 77 | -oxwm.key.bind({ "Mod1" }, "A", oxwm.toggle_gaps()) | 81 | +oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) |
| 78 | 82 | ||
| 79 | -- WM controls | 83 | -- WM controls |
| 80 | -oxwm.key.bind({ "Mod1", "Shift" }, "Q", oxwm.quit()) | 84 | +oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) |
| 81 | -oxwm.key.bind({ "Mod1", "Shift" }, "R", oxwm.restart()) | 85 | +oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) |
| 82 | 86 | ||
| 83 | -- Focus direction (vim keys) | 87 | -- Focus direction (vim keys) |
| 84 | -oxwm.key.bind({ "Mod1" }, "H", oxwm.client.focus_direction("left")) | 88 | +oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left")) |
| 85 | -oxwm.key.bind({ "Mod1" }, "J", oxwm.client.focus_direction("down")) | 89 | +oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down")) |
| 86 | -oxwm.key.bind({ "Mod1" }, "K", oxwm.client.focus_direction("up")) | 90 | +oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up")) |
| 87 | -oxwm.key.bind({ "Mod1" }, "L", oxwm.client.focus_direction("right")) | 91 | +oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right")) |
| 88 | 92 | ||
| 89 | -- Swap windows in direction | 93 | -- Swap windows in direction |
| 90 | -oxwm.key.bind({ "Mod1", "Shift" }, "H", oxwm.client.swap_direction("left")) | 94 | +oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left")) |
| 91 | -oxwm.key.bind({ "Mod1", "Shift" }, "J", oxwm.client.swap_direction("down")) | 95 | +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down")) |
| 92 | -oxwm.key.bind({ "Mod1", "Shift" }, "K", oxwm.client.swap_direction("up")) | 96 | +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up")) |
| 93 | -oxwm.key.bind({ "Mod1", "Shift" }, "L", oxwm.client.swap_direction("right")) | 97 | +oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right")) |
| 94 | 98 | ||
| 95 | -- Tag viewing | 99 | -- Tag viewing |
| 96 | -oxwm.key.bind({ "Mod1" }, "1", oxwm.tag.view(0)) | 100 | +oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0)) |
| 97 | -oxwm.key.bind({ "Mod1" }, "2", oxwm.tag.view(1)) | 101 | +oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1)) |
| 98 | -oxwm.key.bind({ "Mod1" }, "3", oxwm.tag.view(2)) | 102 | +oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2)) |
| 99 | -oxwm.key.bind({ "Mod1" }, "4", oxwm.tag.view(3)) | 103 | +oxwm.key.bind({ modkey }, "4", oxwm.tag.view(3)) |
| 100 | -oxwm.key.bind({ "Mod1" }, "5", oxwm.tag.view(4)) | 104 | +oxwm.key.bind({ modkey }, "5", oxwm.tag.view(4)) |
| 101 | -oxwm.key.bind({ "Mod1" }, "6", oxwm.tag.view(5)) | 105 | +oxwm.key.bind({ modkey }, "6", oxwm.tag.view(5)) |
| 102 | -oxwm.key.bind({ "Mod1" }, "7", oxwm.tag.view(6)) | 106 | +oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6)) |
| 103 | -oxwm.key.bind({ "Mod1" }, "8", oxwm.tag.view(7)) | 107 | +oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7)) |
| 104 | -oxwm.key.bind({ "Mod1" }, "9", oxwm.tag.view(8)) | 108 | +oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8)) |
| 105 | 109 | ||
| 106 | -- Move window to tag | 110 | -- Move window to tag |
| 107 | -oxwm.key.bind({ "Mod1", "Shift" }, "1", oxwm.tag.move_to(0)) | 111 | +oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0)) |
| 108 | -oxwm.key.bind({ "Mod1", "Shift" }, "2", oxwm.tag.move_to(1)) | 112 | +oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1)) |
| 109 | -oxwm.key.bind({ "Mod1", "Shift" }, "3", oxwm.tag.move_to(2)) | 113 | +oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2)) |
| 110 | -oxwm.key.bind({ "Mod1", "Shift" }, "4", oxwm.tag.move_to(3)) | 114 | +oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(3)) |
| 111 | -oxwm.key.bind({ "Mod1", "Shift" }, "5", oxwm.tag.move_to(4)) | 115 | +oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(4)) |
| 112 | -oxwm.key.bind({ "Mod1", "Shift" }, "6", oxwm.tag.move_to(5)) | 116 | +oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(5)) |
| 113 | -oxwm.key.bind({ "Mod1", "Shift" }, "7", oxwm.tag.move_to(6)) | 117 | +oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6)) |
| 114 | -oxwm.key.bind({ "Mod1", "Shift" }, "8", oxwm.tag.move_to(7)) | 118 | +oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7)) |
| 115 | -oxwm.key.bind({ "Mod1", "Shift" }, "9", oxwm.tag.move_to(8)) | 119 | +oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8)) |
| 116 | 120 | ||
| 117 | -- Status bar blocks | 121 | -- Status bar blocks |
| 118 | oxwm.bar.add_block("", "Battery", { | 122 | oxwm.bar.add_block("", "Battery", { |
+24 −0 src/bar/bar.rs
| @@ -347,4 +347,28 @@ impl Bar { | |||
| 347 | pub fn needs_redraw(&self) -> bool { | 347 | pub fn needs_redraw(&self) -> bool { |
| 348 | self.needs_redraw | 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 | let lua_path = config_dir.join("config.lua"); | 54 | let lua_path = config_dir.join("config.lua"); |
| 55 | 55 | ||
| 56 | if !lua_path.exists() { | 56 | if !lua_path.exists() { |
| 57 | - // Check if user had an old RON config | ||
| 58 | let ron_path = config_dir.join("config.ron"); | 57 | let ron_path = config_dir.join("config.ron"); |
| 59 | let had_ron_config = ron_path.exists(); | 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 | init_config()?; | 62 | init_config()?; |
| 64 | 63 | ||
| 65 | if had_ron_config { | 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 | println!(" Your old config.ron has been preserved, but is no longer used."); | 66 | println!(" Your old config.ron has been preserved, but is no longer used."); |
| 68 | println!(" Your settings have been reset to defaults."); | 67 | println!(" Your settings have been reset to defaults."); |
| 69 | println!(" Please manually port your configuration to the new Lua format."); | 68 | println!(" Please manually port your configuration to the new Lua format."); |
| @@ -86,12 +85,10 @@ fn init_config() -> Result<()> { | |||
| 86 | let config_dir = get_config_path(); | 85 | let config_dir = get_config_path(); |
| 87 | std::fs::create_dir_all(&config_dir)?; | 86 | std::fs::create_dir_all(&config_dir)?; |
| 88 | 87 | ||
| 89 | - // Copy config.lua template | ||
| 90 | let config_template = include_str!("../../templates/config.lua"); | 88 | let config_template = include_str!("../../templates/config.lua"); |
| 91 | let config_path = config_dir.join("config.lua"); | 89 | let config_path = config_dir.join("config.lua"); |
| 92 | std::fs::write(&config_path, config_template)?; | 90 | std::fs::write(&config_path, config_template)?; |
| 93 | 91 | ||
| 94 | - // Copy oxwm.lua API definitions for LSP support | ||
| 95 | let oxwm_lua_template = include_str!("../../templates/oxwm.lua"); | 92 | let oxwm_lua_template = include_str!("../../templates/oxwm.lua"); |
| 96 | let oxwm_lua_path = config_dir.join("oxwm.lua"); | 93 | let oxwm_lua_path = config_dir.join("oxwm.lua"); |
| 97 | std::fs::write(&oxwm_lua_path, oxwm_lua_template)?; | 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 | lua.load(input) | 29 | lua.load(input) |
| 30 | .exec() | 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 | let builder_data = builder.borrow().clone(); | 33 | let builder_data = builder.borrow().clone(); |
| 34 | 34 | ||
| @@ -59,7 +59,7 @@ pub fn parse_lua_config( | |||
| 59 | let config: Table = lua | 59 | let config: Table = lua |
| 60 | .load(input) | 60 | .load(input) |
| 61 | .eval() | 61 | .eval() |
| 62 | - .map_err(|e| ConfigError::LuaError(format!("Failed to execute Lua config: {}", e)))?; | 62 | + .map_err(|e| ConfigError::LuaError(format!("{}", e)))?; |
| 63 | let border_width: u32 = get_table_field(&config, "border_width")?; | 63 | let border_width: u32 = get_table_field(&config, "border_width")?; |
| 64 | let border_focused: u32 = parse_color(&config, "border_focused")?; | 64 | let border_focused: u32 = parse_color(&config, "border_focused")?; |
| 65 | let border_unfocused: u32 = parse_color(&config, "border_unfocused")?; | 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 | } else { | 363 | } else { |
| 364 | None | 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 | BlockCommand::DateTime(fmt) | 367 | BlockCommand::DateTime(fmt) |
| 368 | } | 368 | } |
| 369 | "Shell" => { | 369 | "Shell" => { |
| @@ -373,7 +373,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res | |||
| 373 | } else { | 373 | } else { |
| 374 | None | 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 | BlockCommand::Shell(cmd_str) | 377 | BlockCommand::Shell(cmd_str) |
| 378 | } | 378 | } |
| 379 | "Ram" => BlockCommand::Ram, | 379 | "Ram" => BlockCommand::Ram, |
| @@ -394,7 +394,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res | |||
| 394 | } else { | 394 | } else { |
| 395 | None | 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 | let charging: String = formats.get("charging")?; | 399 | let charging: String = formats.get("charging")?; |
| 400 | let discharging: String = formats.get("discharging")?; | 400 | let discharging: String = formats.get("discharging")?; |
| @@ -406,7 +406,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res | |||
| 406 | format_full: full, | 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 | let color_u32 = parse_color_value(color)?; | 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 | for i in 1..=t.len()? { | 572 | for i in 1..=t.len()? { |
| 573 | let mod_str: String = t.get(i)?; | 573 | let mod_str: String = t.get(i)?; |
| 574 | let mask = parse_modkey_string(&mod_str) | 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 | mods.push(mask); | 576 | mods.push(mask); |
| 577 | } | 577 | } |
| 578 | Ok(mods) | 578 | Ok(mods) |
| @@ -580,11 +580,11 @@ fn parse_modifiers_value(_lua: &Lua, value: Value) -> mlua::Result<Vec<KeyButMas | |||
| 580 | Value::String(s) => { | 580 | Value::String(s) => { |
| 581 | let s_str = s.to_str()?; | 581 | let s_str = s.to_str()?; |
| 582 | let mask = parse_modkey_string(&s_str) | 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 | Ok(vec![mask]) | 584 | Ok(vec![mask]) |
| 585 | } | 585 | } |
| 586 | _ => Err(mlua::Error::RuntimeError( | 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 | "Mod5" => Ok(KeyButMask::MOD5), | 598 | "Mod5" => Ok(KeyButMask::MOD5), |
| 599 | "Shift" => Ok(KeyButMask::SHIFT), | 599 | "Shift" => Ok(KeyButMask::SHIFT), |
| 600 | "Control" => Ok(KeyButMask::CONTROL), | 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 | fn parse_keysym(key: &str) -> mlua::Result<Keysym> { | 605 | fn parse_keysym(key: &str) -> mlua::Result<Keysym> { |
| 606 | keysyms::keysym_from_str(key) | 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 | fn parse_action_value(_lua: &Lua, value: Value) -> mlua::Result<(KeyAction, Arg)> { | 610 | fn parse_action_value(_lua: &Lua, value: Value) -> mlua::Result<(KeyAction, Arg)> { |
| 611 | match value { | 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 | Value::Table(t) => { | 617 | Value::Table(t) => { |
| 613 | - // Check if this table has our action metadata | ||
| 614 | if let Ok(action_name) = t.get::<String>("__action") { | 618 | if let Ok(action_name) = t.get::<String>("__action") { |
| 615 | let action = string_to_action(&action_name)?; | 619 | let action = string_to_action(&action_name)?; |
| 616 | let arg = if let Ok(arg_val) = t.get::<Value>("__arg") { | 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 | Err(mlua::Error::RuntimeError( | 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 | _ => Err(mlua::Error::RuntimeError( | 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 | "SmartMoveWin" => Ok(KeyAction::SmartMoveWin), | 656 | "SmartMoveWin" => Ok(KeyAction::SmartMoveWin), |
| 653 | "ExchangeClient" => Ok(KeyAction::ExchangeClient), | 657 | "ExchangeClient" => Ok(KeyAction::ExchangeClient), |
| 654 | "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay), | 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 | "left" => Ok(2), | 692 | "left" => Ok(2), |
| 689 | "right" => Ok(3), | 693 | "right" => Ok(3), |
| 690 | _ => Err(mlua::Error::RuntimeError( | 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 | let s = s.to_str()?; | 705 | let s = s.to_str()?; |
| 702 | if s.starts_with('#') { | 706 | if s.starts_with('#') { |
| 703 | u32::from_str_radix(&s[1..], 16) | 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 | } else if s.starts_with("0x") { | 709 | } else if s.starts_with("0x") { |
| 706 | u32::from_str_radix(&s[2..], 16) | 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 | } else { | 712 | } else { |
| 709 | s.parse::<u32>() | 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 | _ => Err(mlua::Error::RuntimeError( | 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 | impl std::fmt::Display for ConfigError { | 73 | impl std::fmt::Display for ConfigError { |
| 74 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 74 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 75 | match self { | 75 | match self { |
| 76 | - Self::LuaError(msg) => write!(f, "Lua config error: {}", msg), | 76 | + Self::LuaError(msg) => write!(f, "{}", msg), |
| 77 | - Self::InvalidModkey(key) => write!(f, "Invalid modkey: {}", key), | 77 | + Self::InvalidModkey(msg) => write!(f, "{}", msg), |
| 78 | - Self::UnknownKey(key) => write!(f, "Unknown key: {}", key), | 78 | + Self::UnknownKey(msg) => write!(f, "{}", msg), |
| 79 | - Self::UnknownAction(action) => write!(f, "Unknown action: {}", action), | 79 | + Self::UnknownAction(msg) => write!(f, "{}", msg), |
| 80 | - Self::UnknownBlockCommand(cmd) => write!(f, "Unknown block command: {}", cmd), | 80 | + Self::UnknownBlockCommand(msg) => write!(f, "{}", msg), |
| 81 | Self::MissingCommandArg { command, field } => { | 81 | Self::MissingCommandArg { command, field } => { |
| 82 | write!(f, "{} command requires {}", command, field) | 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 | screen_width: u16, | 55 | screen_width: u16, |
| 56 | screen_height: u16, | 56 | screen_height: u16, |
| 57 | ) -> Result<(), X11Error> { | 57 | ) -> Result<(), X11Error> { |
| 58 | - let max_line_width = (screen_width as i16 - PADDING * 4).max(300) as u16; | 58 | + let max_line_width = (screen_width as i16 / 2 - PADDING * 4).max(300) as u16; |
| 59 | - self.lines = self.wrap_text(error_text, font, max_line_width); | 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 | let mut content_width = 0u16; | 62 | let mut content_width = 0u16; |
| 62 | for line in &self.lines { | 63 | for line in &self.lines { |
+12 −3 src/window_manager.rs
| @@ -263,10 +263,15 @@ impl WindowManager { | |||
| 263 | .map_err(|e| format!("Failed to read config: {}", e))?; | 263 | .map_err(|e| format!("Failed to read config: {}", e))?; |
| 264 | 264 | ||
| 265 | let new_config = crate::config::parse_lua_config(&config_str, Some(&config_dir)) | 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 | self.config = new_config; | 268 | self.config = new_config; |
| 269 | self.error_message = None; | 269 | self.error_message = None; |
| 270 | + | ||
| 271 | + for bar in &mut self.bars { | ||
| 272 | + bar.update_from_config(&self.config); | ||
| 273 | + } | ||
| 274 | + | ||
| 270 | Ok(()) | 275 | Ok(()) |
| 271 | } | 276 | } |
| 272 | 277 | ||
| @@ -1773,16 +1778,20 @@ impl WindowManager { | |||
| 1773 | self.update_bar()?; | 1778 | self.update_bar()?; |
| 1774 | } | 1779 | } |
| 1775 | Err(err) => { | 1780 | Err(err) => { |
| 1781 | + eprintln!("Config reload error: {}", err); | ||
| 1776 | self.error_message = Some(err.clone()); | 1782 | self.error_message = Some(err.clone()); |
| 1777 | let screen_width = self.screen.width_in_pixels; | 1783 | let screen_width = self.screen.width_in_pixels; |
| 1778 | let screen_height = self.screen.height_in_pixels; | 1784 | let screen_height = self.screen.height_in_pixels; |
| 1779 | - let _ = self.overlay.show_error( | 1785 | + match self.overlay.show_error( |
| 1780 | &self.connection, | 1786 | &self.connection, |
| 1781 | &self.font, | 1787 | &self.font, |
| 1782 | &err, | 1788 | &err, |
| 1783 | screen_width, | 1789 | screen_width, |
| 1784 | screen_height, | 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 | _ => self.handle_key_action(action, &arg)?, | 1797 | _ => self.handle_key_action(action, &arg)?, |
+167 −90 templates/config.lua
| @@ -1,12 +1,30 @@ | |||
| 1 | ---@meta | 1 | ---@meta |
| 2 | ----OXWM Configuration File (Lua) | 2 | +------------------------------------------------------------------------------- |
| 3 | ----Using the new functional API | 3 | +-- OXWM Configuration File |
| 4 | ----Edit this file and reload with Mod+Shift+R (no compilation needed!) | 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 | ---Load type definitions for LSP | 12 | ---Load type definitions for LSP |
| 7 | ---@module 'oxwm' | 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 | local colors = { | 28 | local colors = { |
| 11 | fg = "#bbbbbb", | 29 | fg = "#bbbbbb", |
| 12 | red = "#f7768e", | 30 | red = "#f7768e", |
| @@ -20,111 +38,170 @@ local colors = { | |||
| 20 | purple = "#ad8ee6", | 38 | purple = "#ad8ee6", |
| 21 | } | 39 | } |
| 22 | 40 | ||
| 23 | --- Basic settings | 41 | +-- Workspace tags - can be numbers, names, or icons (requires a Nerd Font) |
| 24 | -oxwm.set_terminal("st") | 42 | +local tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9" } |
| 25 | -oxwm.set_modkey("Mod4") | 43 | + |
| 26 | -oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }) | 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 | oxwm.set_layout_symbol("tiling", "[T]") | 59 | oxwm.set_layout_symbol("tiling", "[T]") |
| 30 | oxwm.set_layout_symbol("normie", "[F]") | 60 | oxwm.set_layout_symbol("normie", "[F]") |
| 31 | 61 | ||
| 62 | +------------------------------------------------------------------------------- | ||
| 63 | +-- Appearance | ||
| 64 | +------------------------------------------------------------------------------- | ||
| 32 | -- Border configuration | 65 | -- Border configuration |
| 33 | -oxwm.border.set_width(2) | 66 | +oxwm.border.set_width(2) -- Width in pixels |
| 34 | -oxwm.border.set_focused_color(colors.blue) | 67 | +oxwm.border.set_focused_color(colors.blue) -- Color of focused window border |
| 35 | -oxwm.border.set_unfocused_color(colors.grey) | 68 | +oxwm.border.set_unfocused_color(colors.grey) -- Color of unfocused window borders |
| 36 | - | 69 | + |
| 37 | --- Gap configuration | 70 | +-- Gap configuration (space between windows and screen edges) |
| 38 | -oxwm.gaps.set_enabled(true) | 71 | +oxwm.gaps.set_enabled(true) -- Enable or disable gaps |
| 39 | -oxwm.gaps.set_inner(5, 5) -- horizontal, vertical | 72 | +oxwm.gaps.set_inner(5, 5) -- Inner gaps (horizontal, vertical) in pixels |
| 40 | -oxwm.gaps.set_outer(5, 5) -- horizontal, vertical | 73 | +oxwm.gaps.set_outer(5, 5) -- Outer gaps (horizontal, vertical) in pixels |
| 41 | - | 74 | + |
| 42 | --- Bar configuration | 75 | +------------------------------------------------------------------------------- |
| 43 | -oxwm.bar.set_font("monospace:style=Bold:size=10") | 76 | +-- Status Bar Configuration |
| 44 | - | 77 | +------------------------------------------------------------------------------- |
| 45 | --- Bar color schemes (for tag display) | 78 | +-- Font configuration |
| 46 | -oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444") | 79 | +oxwm.bar.set_font(bar_font) |
| 47 | -oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan) | 80 | + |
| 48 | -oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) | 81 | +-- Bar color schemes (for workspace tag display) |
| 49 | - | 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 | -- Keybindings | 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 | -- Basic window management | 98 | -- Basic window management |
| 53 | -oxwm.key.bind({ "Mod4" }, "Return", oxwm.spawn("st")) | 99 | +oxwm.key.bind({ modkey }, "Return", oxwm.spawn(terminal)) -- Spawn terminal |
| 54 | -oxwm.key.bind({ "Mod4" }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) | 100 | +oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) -- Application launcher |
| 55 | -oxwm.key.bind({ "Mod4" }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) | 101 | +oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) -- Screenshot selection |
| 56 | -oxwm.key.bind({ "Mod4" }, "Q", oxwm.client.kill()) | 102 | +oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) -- Close focused window |
| 57 | 103 | ||
| 58 | --- Keybind overlay | 104 | +-- Keybind overlay - Shows important keybindings on screen |
| 59 | -oxwm.key.bind({ "Mod4", "Shift" }, "Slash", oxwm.show_keybinds()) | 105 | +oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds()) |
| 60 | 106 | ||
| 61 | --- Client actions | 107 | +-- Window state toggles |
| 62 | -oxwm.key.bind({ "Mod4", "Shift" }, "F", oxwm.client.toggle_fullscreen()) | 108 | +oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen()) -- Toggle fullscreen |
| 63 | -oxwm.key.bind({ "Mod4", "Shift" }, "Space", oxwm.client.toggle_floating()) | 109 | +oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating()) -- Toggle floating mode |
| 64 | 110 | ||
| 65 | -- Layout management | 111 | -- Layout management |
| 66 | -oxwm.key.bind({ "Mod4" }, "F", oxwm.layout.set("normie")) | 112 | +oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie")) -- Set floating layout |
| 67 | -oxwm.key.bind({ "Mod4" }, "C", oxwm.layout.set("tiling")) | 113 | +oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling")) -- Set tiling layout |
| 68 | -oxwm.key.bind({ "Mod1" }, "N", oxwm.layout.cycle()) | 114 | +oxwm.key.bind({ "Mod1" }, "N", oxwm.layout.cycle()) -- Cycle through layouts |
| 69 | 115 | ||
| 70 | -- Gaps toggle | 116 | -- Gaps toggle |
| 71 | -oxwm.key.bind({ "Mod4" }, "A", oxwm.toggle_gaps()) | 117 | +oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) -- Toggle gaps on/off |
| 72 | - | 118 | + |
| 73 | --- WM controls | 119 | +-- Window manager controls |
| 74 | -oxwm.key.bind({ "Mod4", "Shift" }, "Q", oxwm.quit()) | 120 | +oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) -- Quit OXWM |
| 75 | -oxwm.key.bind({ "Mod4", "Shift" }, "R", oxwm.restart()) | 121 | +oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) -- Restart OXWM (reloads config) |
| 76 | - | 122 | + |
| 77 | --- Focus direction (vim keys: h=left=2, j=down=1, k=up=0, l=right=3) | 123 | +-- Focus movement (vim keys) |
| 78 | -oxwm.key.bind({ "Mod4" }, "H", oxwm.client.focus_direction("left")) | 124 | +oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left")) -- Focus window to the left |
| 79 | -oxwm.key.bind({ "Mod4" }, "J", oxwm.client.focus_direction("down")) | 125 | +oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down")) -- Focus window below |
| 80 | -oxwm.key.bind({ "Mod4" }, "K", oxwm.client.focus_direction("up")) | 126 | +oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up")) -- Focus window above |
| 81 | -oxwm.key.bind({ "Mod4" }, "L", oxwm.client.focus_direction("right")) | 127 | +oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right")) -- Focus window to the right |
| 82 | - | 128 | + |
| 83 | --- Monitor focus | 129 | +-- Multi-monitor support |
| 84 | -oxwm.key.bind({ "Mod4" }, "Comma", oxwm.focus_monitor(-1)) | 130 | +oxwm.key.bind({ modkey }, "Comma", oxwm.focus_monitor(-1)) -- Focus previous monitor |
| 85 | -oxwm.key.bind({ "Mod4" }, "Period", oxwm.focus_monitor(1)) | 131 | +oxwm.key.bind({ modkey }, "Period", oxwm.focus_monitor(1)) -- Focus next monitor |
| 86 | - | 132 | + |
| 87 | --- Tag viewing | 133 | +-- Workspace (tag) navigation |
| 88 | -oxwm.key.bind({ "Mod4" }, "1", oxwm.tag.view(0)) | 134 | +-- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0) |
| 89 | -oxwm.key.bind({ "Mod4" }, "2", oxwm.tag.view(1)) | 135 | +oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0)) |
| 90 | -oxwm.key.bind({ "Mod4" }, "3", oxwm.tag.view(2)) | 136 | +oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1)) |
| 91 | -oxwm.key.bind({ "Mod4" }, "4", oxwm.tag.view(3)) | 137 | +oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2)) |
| 92 | -oxwm.key.bind({ "Mod4" }, "5", oxwm.tag.view(4)) | 138 | +oxwm.key.bind({ modkey }, "4", oxwm.tag.view(3)) |
| 93 | -oxwm.key.bind({ "Mod4" }, "6", oxwm.tag.view(5)) | 139 | +oxwm.key.bind({ modkey }, "5", oxwm.tag.view(4)) |
| 94 | -oxwm.key.bind({ "Mod4" }, "7", oxwm.tag.view(6)) | 140 | +oxwm.key.bind({ modkey }, "6", oxwm.tag.view(5)) |
| 95 | -oxwm.key.bind({ "Mod4" }, "8", oxwm.tag.view(7)) | 141 | +oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6)) |
| 96 | -oxwm.key.bind({ "Mod4" }, "9", oxwm.tag.view(8)) | 142 | +oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7)) |
| 97 | - | 143 | +oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8)) |
| 98 | --- Move window to tag | 144 | + |
| 99 | -oxwm.key.bind({ "Mod4", "Shift" }, "1", oxwm.tag.move_to(0)) | 145 | +-- Move focused window to workspace N |
| 100 | -oxwm.key.bind({ "Mod4", "Shift" }, "2", oxwm.tag.move_to(1)) | 146 | +oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0)) |
| 101 | -oxwm.key.bind({ "Mod4", "Shift" }, "3", oxwm.tag.move_to(2)) | 147 | +oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1)) |
| 102 | -oxwm.key.bind({ "Mod4", "Shift" }, "4", oxwm.tag.move_to(3)) | 148 | +oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2)) |
| 103 | -oxwm.key.bind({ "Mod4", "Shift" }, "5", oxwm.tag.move_to(4)) | 149 | +oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(3)) |
| 104 | -oxwm.key.bind({ "Mod4", "Shift" }, "6", oxwm.tag.move_to(5)) | 150 | +oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(4)) |
| 105 | -oxwm.key.bind({ "Mod4", "Shift" }, "7", oxwm.tag.move_to(6)) | 151 | +oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(5)) |
| 106 | -oxwm.key.bind({ "Mod4", "Shift" }, "8", oxwm.tag.move_to(7)) | 152 | +oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6)) |
| 107 | -oxwm.key.bind({ "Mod4", "Shift" }, "9", oxwm.tag.move_to(8)) | 153 | +oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7)) |
| 108 | - | 154 | +oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8)) |
| 109 | --- Swap windows in direction | 155 | + |
| 110 | -oxwm.key.bind({ "Mod4", "Shift" }, "H", oxwm.client.swap_direction("left")) | 156 | +-- Swap windows in direction (vim keys with Shift) |
| 111 | -oxwm.key.bind({ "Mod4", "Shift" }, "J", oxwm.client.swap_direction("down")) | 157 | +oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left")) -- Swap with window to the left |
| 112 | -oxwm.key.bind({ "Mod4", "Shift" }, "K", oxwm.client.swap_direction("up")) | 158 | +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down")) -- Swap with window below |
| 113 | -oxwm.key.bind({ "Mod4", "Shift" }, "L", oxwm.client.swap_direction("right")) | 159 | +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up")) -- Swap with window above |
| 114 | - | 160 | +oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right")) -- Swap with window to the right |
| 115 | --- Keychord example: Mod4+Space then T to spawn terminal | 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 | oxwm.key.chord({ | 168 | oxwm.key.chord({ |
| 117 | - { { "Mod4" }, "Space" }, | 169 | + { { modkey }, "Space" }, |
| 118 | - { {}, "T" } | 170 | + { {}, "T" } |
| 119 | -}, oxwm.spawn("st")) | 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 | oxwm.bar.add_block("Ram: {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true) | 185 | oxwm.bar.add_block("Ram: {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true) |
| 123 | oxwm.bar.add_block(" │ ", "Static", " │ ", 999999999, colors.lavender, false) | 186 | oxwm.bar.add_block(" │ ", "Static", " │ ", 999999999, colors.lavender, false) |
| 124 | oxwm.bar.add_block("Kernel: {}", "Shell", "uname -r", 999999999, colors.red, true) | 187 | oxwm.bar.add_block("Kernel: {}", "Shell", "uname -r", 999999999, colors.red, true) |
| 125 | oxwm.bar.add_block(" │ ", "Static", " │ ", 999999999, colors.lavender, false) | 188 | oxwm.bar.add_block(" │ ", "Static", " │ ", 999999999, colors.lavender, false) |
| 126 | oxwm.bar.add_block("{}", "DateTime", "%a, %b %d - %-I:%M %P", 1, colors.cyan, true) | 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) | 191 | +-- Uncomment to add battery status (useful for laptops) |
| 129 | --- oxwm.autostart("picom") | 192 | +-- oxwm.bar.add_block("Bat: {}%", "Battery", { |
| 130 | --- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg") | 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 | ||