tony / oxwm

Fix bar flickering and improve configuration management Browse files
This release addresses several critical bugs and enhances the user experience:

- Implement double-buffered rendering for the status bar to eliminate flickering
- Restructure LSP configuration with automatic lib/ directory management and .luarc.json setup
- Refactor Lua API error handling, replacing verbose map_err chains with idiomatic ? operator
- Add monocle layout for maximized single-window view
- Consolidate fullscreen actions and improve floating window behavior
- Update test configuration with better documentation and cleaner bar block API
- Bump version to 0.7.1

The bar rendering now uses XPixmap for off-screen composition before copying to the window,
significantly reducing visual artifacts during updates. Configuration updates are now applied
automatically, ensuring LSP definitions stay in sync with the running version.
tonybtw committed 2025-11-16 parent 8a5cf95 commit 19dcad1c03a979220975e0b4dc28f1fa048b2c7a
Showing 17 changed files with 826 additions and 444 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -297,7 +297,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
297 297
298 298 [[package]]
299 299 name = "oxwm"
300 -version = "0.7.0"
300 +version = "0.7.1"
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.7.0"
3 +version = "0.7.1"
4 4 edition = "2024"
5 5
6 6 [lib]
+17 −0 PR Summary.md new file mode 100644
@@ -0,0 +1,17 @@
1 +# PR Summary
2 +
3 +## Fix bar flickering and improve configuration management
4 +
5 +This release addresses several critical bugs and enhances the user experience:
6 +
7 +- Implement double-buffered rendering for the status bar to eliminate flickering
8 +- Restructure LSP configuration with automatic lib/ directory management and .luarc.json setup
9 +- Refactor Lua API error handling, replacing verbose map_err chains with idiomatic ? operator
10 +- Add monocle layout for maximized single-window view
11 +- Consolidate fullscreen actions and improve floating window behavior
12 +- Update test configuration with better documentation and cleaner bar block API
13 +- Bump version to 0.7.1
14 +
15 +The bar rendering now uses XPixmap for off-screen composition before copying to the window,
16 +significantly reducing visual artifacts during updates. Configuration updates are now applied
17 +automatically, ensuring LSP definitions stay in sync with the running version.
+62 −40 resources/test-config.lua
@@ -3,12 +3,18 @@
3 3 ---Using the new functional API
4 4 ---Edit this file and reload with Mod+Alt+R
5 5
6 ----Load type definitions for LSP
6 +---Load type definitions for LSP (lua-language-server)
7 +---Option 1: Copy templates/oxwm.lua to the same directory as your config
8 +---Option 2: Add to your LSP settings (e.g., .luarc.json):
9 +--- {
10 +--- "workspace.library": [
11 +--- "/path/to/oxwm/templates"
12 +--- ]
13 +--- }
14 +---Option 3: Symlink templates/oxwm.lua to your config directory
7 15 ---@module 'oxwm'
8 16
9 17
10 --- Set variables as needed
11 --- Colors
12 18 local colors = {
13 19 lavender = 0xa9b1d6,
14 20 light_blue = 0x7aa2f7,
@@ -22,81 +28,63 @@ local colors = {
22 28 blue = 0x6dade3,
23 29 }
24 30
25 -local modkey = "Mod1";
31 +local modkey = "Mod1"
26 32
27 --- Basic settings
28 33 oxwm.set_terminal("st")
29 34 oxwm.set_modkey(modkey)
30 35 oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" })
31 36
32 --- Layout symbol overrides
33 37 oxwm.set_layout_symbol("tiling", "[T]")
34 38 oxwm.set_layout_symbol("normie", "[F]")
35 39
36 --- Border configuration
37 40 oxwm.border.set_width(2)
38 41 oxwm.border.set_focused_color(colors.blue)
39 42 oxwm.border.set_unfocused_color(colors.grey)
40 43
41 --- Gap configuration
42 44 oxwm.gaps.set_enabled(true)
43 45 oxwm.gaps.set_inner(5, 5)
44 46 oxwm.gaps.set_outer(5, 5)
45 47
46 --- Bar configuration
47 48 oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12")
48 49
49 --- Bar color schemes (for tag display)
50 50 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, 0x444444)
51 51 oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan)
52 52 oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
53 53
54 --- Keybindings
55 -
56 --- Keychord: Mod1+Space then T to spawn terminal
57 54 oxwm.key.chord({
58 55 { { modkey }, "Space" },
59 56 { {}, "T" }
60 57 }, oxwm.spawn("st"))
61 58
62 --- Basic window management
63 59 oxwm.key.bind({ modkey }, "Return", oxwm.spawn("st"))
64 60 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
65 61 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
66 62 oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
67 63
68 --- Keybind overlay
69 64 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
70 65
71 --- Client actions
72 66 oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen())
73 67 oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating())
74 68
75 --- Layout management
76 69 oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie"))
77 70 oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling"))
78 71 oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
79 72
80 --- Gaps toggle
81 73 oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
82 74
83 --- WM controls
84 75 oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
85 76 oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
86 77
87 --- Focus direction (vim keys)
88 78 oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left"))
89 79 oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down"))
90 80 oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up"))
91 81 oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right"))
92 82
93 --- Swap windows in direction
94 83 oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left"))
95 84 oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down"))
96 85 oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up"))
97 86 oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right"))
98 87
99 --- Tag viewing
100 88 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
101 89 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
102 90 oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
@@ -107,7 +95,6 @@ oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
107 95 oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
108 96 oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
109 97
110 --- Move window to tag
111 98 oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
112 99 oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
113 100 oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
@@ -118,20 +105,55 @@ oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
118 105 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
119 106 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
120 107
121 --- Status bar blocks
122 -oxwm.bar.add_block("", "Battery", {
123 - charging = "󰂄 Bat: {}%",
124 - discharging = "󰁹 Bat:{}%",
125 - full = "󰁹 Bat: {}%"
126 -}, 30, colors.green, true)
127 -
128 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false)
129 -oxwm.bar.add_block("󰍛 {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true)
130 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false)
131 -oxwm.bar.add_block(" {}", "Shell", "uname -r", 999999999, colors.red, true)
132 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false)
133 -oxwm.bar.add_block("󰸘 {}", "DateTime", "%a, %b %d - %-I:%M %P", 1, colors.cyan, true)
134 -
135 --- Autostart commands (runs once at startup)
136 --- oxwm.autostart("picom")
137 --- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg")
108 +oxwm.bar.set_blocks({
109 + oxwm.bar.block.battery({
110 + charging = "󰂄 Bat: {}%",
111 + discharging = "󰁹 Bat: {}%",
112 + full = "󰁹 Bat: {}%",
113 + format = "",
114 + interval = 30,
115 + color = colors.green,
116 + underline = true
117 + }),
118 + oxwm.bar.block.static({
119 + text = " │ ",
120 + format = "",
121 + interval = 999999999,
122 + color = colors.lavender,
123 + underline = false
124 + }),
125 + oxwm.bar.block.ram({
126 + format = "󰍛 {used}/{total} GB",
127 + interval = 5,
128 + color = colors.light_blue,
129 + underline = true
130 + }),
131 + oxwm.bar.block.static({
132 + text = " │ ",
133 + format = "",
134 + interval = 999999999,
135 + color = colors.lavender,
136 + underline = false
137 + }),
138 + oxwm.bar.block.shell({
139 + command = "uname -r",
140 + format = " {}",
141 + interval = 999999999,
142 + color = colors.red,
143 + underline = true
144 + }),
145 + oxwm.bar.block.static({
146 + text = " │ ",
147 + format = "",
148 + interval = 999999999,
149 + color = colors.lavender,
150 + underline = false
151 + }),
152 + oxwm.bar.block.datetime({
153 + format = "󰸘 {}",
154 + interval = 1,
155 + color = colors.cyan,
156 + underline = true,
157 + date_format = "%a, %b %d - %-I:%M %P"
158 + })
159 +})
+85 −42 src/bar/bar.rs
@@ -13,6 +13,8 @@ pub struct Bar {
13 13 width: u16,
14 14 height: u16,
15 15 graphics_context: Gcontext,
16 + pixmap: x11::xlib::Pixmap,
17 + display: *mut x11::xlib::Display,
16 18
17 19 font_draw: FontDraw,
18 20
@@ -77,8 +79,19 @@ impl Bar {
77 79
78 80 let visual = unsafe { x11::xlib::XDefaultVisual(display, screen_num as i32) };
79 81 let colormap = unsafe { x11::xlib::XDefaultColormap(display, screen_num as i32) };
82 + let depth = unsafe { x11::xlib::XDefaultDepth(display, screen_num as i32) };
80 83
81 - let font_draw = FontDraw::new(display, window as x11::xlib::Drawable, visual, colormap)?;
84 + let pixmap = unsafe {
85 + x11::xlib::XCreatePixmap(
86 + display,
87 + window as x11::xlib::Drawable,
88 + width as u32,
89 + height as u32,
90 + depth as u32,
91 + )
92 + };
93 +
94 + let font_draw = FontDraw::new(display, pixmap, visual, colormap)?;
82 95
83 96 let horizontal_padding = (font.height() as f32 * 0.4) as u16;
84 97
@@ -110,6 +123,8 @@ impl Bar {
110 123 width,
111 124 height,
112 125 graphics_context,
126 + pixmap,
127 + display,
113 128 font_draw,
114 129 tag_widths,
115 130 needs_redraw: true,
@@ -182,16 +197,22 @@ impl Bar {
182 197 self.graphics_context,
183 198 &ChangeGCAux::new().foreground(self.scheme_normal.background),
184 199 )?;
185 - connection.poly_fill_rectangle(
186 - self.window,
187 - self.graphics_context,
188 - &[Rectangle {
189 - x: 0,
190 - y: 0,
191 - width: self.width,
192 - height: self.height,
193 - }],
194 - )?;
200 + connection.flush()?;
201 +
202 + unsafe {
203 + let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
204 + x11::xlib::XSetForeground(display, gc, self.scheme_normal.background as u64);
205 + x11::xlib::XFillRectangle(
206 + display,
207 + self.pixmap,
208 + gc,
209 + 0,
210 + 0,
211 + self.width as u32,
212 + self.height as u32,
213 + );
214 + x11::xlib::XFreeGC(display, gc);
215 + }
195 216
196 217 let mut x_position: i16 = 0;
197 218
@@ -229,20 +250,20 @@ impl Bar {
229 250 let underline_width = tag_width - underline_padding;
230 251 let underline_x = x_position + (underline_padding / 2) as i16;
231 252
232 - connection.change_gc(
233 - self.graphics_context,
234 - &ChangeGCAux::new().foreground(scheme.underline),
235 - )?;
236 - connection.poly_fill_rectangle(
237 - self.window,
238 - self.graphics_context,
239 - &[Rectangle {
240 - x: underline_x,
241 - y: underline_y,
242 - width: underline_width,
243 - height: underline_height,
244 - }],
245 - )?;
253 + unsafe {
254 + let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
255 + x11::xlib::XSetForeground(display, gc, scheme.underline as u64);
256 + x11::xlib::XFillRectangle(
257 + display,
258 + self.pixmap,
259 + gc,
260 + underline_x as i32,
261 + underline_y as i32,
262 + underline_width as u32,
263 + underline_height as u32,
264 + );
265 + x11::xlib::XFreeGC(display, gc);
266 + }
246 267 }
247 268
248 269 x_position += tag_width as i16;
@@ -304,29 +325,43 @@ impl Bar {
304 325 let underline_width = text_width + underline_padding;
305 326 let underline_x = x_position - (underline_padding / 2) as i16;
306 327
307 - connection.change_gc(
308 - self.graphics_context,
309 - &ChangeGCAux::new().foreground(block.color()),
310 - )?;
311 -
312 - connection.poly_fill_rectangle(
313 - self.window,
314 - self.graphics_context,
315 - &[Rectangle {
316 - x: underline_x,
317 - y: underline_y,
318 - width: underline_width,
319 - height: underline_height,
320 - }],
321 - )?;
328 + unsafe {
329 + let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
330 + x11::xlib::XSetForeground(display, gc, block.color() as u64);
331 + x11::xlib::XFillRectangle(
332 + display,
333 + self.pixmap,
334 + gc,
335 + underline_x as i32,
336 + underline_y as i32,
337 + underline_width as u32,
338 + underline_height as u32,
339 + );
340 + x11::xlib::XFreeGC(display, gc);
341 + }
322 342 }
323 343 }
324 344 }
325 345 }
326 - connection.flush()?;
346 +
327 347 unsafe {
328 - x11::xlib::XFlush(display);
348 + let gc = x11::xlib::XCreateGC(display, self.window as x11::xlib::Drawable, 0, std::ptr::null_mut());
349 + x11::xlib::XCopyArea(
350 + display,
351 + self.pixmap,
352 + self.window as x11::xlib::Drawable,
353 + gc,
354 + 0,
355 + 0,
356 + self.width as u32,
357 + self.height as u32,
358 + 0,
359 + 0,
360 + );
361 + x11::xlib::XFreeGC(display, gc);
362 + x11::xlib::XSync(display, 0);
329 363 }
364 +
330 365 self.needs_redraw = false;
331 366
332 367 Ok(())
@@ -372,3 +407,11 @@ impl Bar {
372 407 self.needs_redraw = true;
373 408 }
374 409 }
410 +
411 +impl Drop for Bar {
412 + fn drop(&mut self) {
413 + unsafe {
414 + x11::xlib::XFreePixmap(self.display, self.pixmap);
415 + }
416 + }
417 +}
+31 −4 src/bin/main.rs
@@ -73,6 +73,9 @@ fn load_config(custom_path: Option<PathBuf>) -> Result<(oxwm::Config, bool)> {
73 73 println!(" Please manually port your configuration to the new Lua format.");
74 74 println!(" See the new config.lua template for examples.\n");
75 75 }
76 + } else {
77 + // Always update LSP files to match the running version
78 + update_lsp_files()?;
76 79 }
77 80
78 81 lua_path
@@ -102,18 +105,42 @@ fn init_config() -> Result<()> {
102 105 let config_path = config_dir.join("config.lua");
103 106 std::fs::write(&config_path, config_template)?;
104 107
105 - let oxwm_lua_template = include_str!("../../templates/oxwm.lua");
106 - let oxwm_lua_path = config_dir.join("oxwm.lua");
107 - std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
108 + // Update LSP files
109 + update_lsp_files()?;
108 110
109 111 println!("✓ Config created at {:?}", config_path);
110 - println!("✓ LSP definitions installed at {:?}", oxwm_lua_path);
112 + println!("✓ LSP definitions installed at {:?}/lib/oxwm.lua", config_dir);
111 113 println!(" Edit the file and reload with Mod+Shift+R");
112 114 println!(" No compilation needed - changes take effect immediately!");
113 115
114 116 Ok(())
115 117 }
116 118
119 +fn update_lsp_files() -> Result<()> {
120 + let config_dir = get_config_path();
121 +
122 + // Create lib directory for LSP files
123 + let lib_dir = config_dir.join("lib");
124 + std::fs::create_dir_all(&lib_dir)?;
125 +
126 + // Always overwrite oxwm.lua with the version from this binary
127 + let oxwm_lua_template = include_str!("../../templates/oxwm.lua");
128 + let oxwm_lua_path = lib_dir.join("oxwm.lua");
129 + std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
130 +
131 + // Create/update .luarc.json for LSP configuration
132 + let luarc_content = r#"{
133 + "workspace.library": [
134 + "lib"
135 + ]
136 +}
137 +"#;
138 + let luarc_path = config_dir.join(".luarc.json");
139 + std::fs::write(&luarc_path, luarc_content)?;
140 +
141 + Ok(())
142 +}
143 +
117 144 fn get_config_path() -> PathBuf {
118 145 dirs::config_dir()
119 146 .expect("Could not find config directory")
+1 −1 src/config/lua.rs
@@ -394,6 +394,7 @@ fn parse_key_action(kb_table: &Table) -> Result<KeyAction, ConfigError> {
394 394 fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> {
395 395 let action = match s {
396 396 "Spawn" => KeyAction::Spawn,
397 + "SpawnTerminal" => KeyAction::SpawnTerminal,
397 398 "KillClient" => KeyAction::KillClient,
398 399 "FocusStack" => KeyAction::FocusStack,
399 400 "FocusDirection" => KeyAction::FocusDirection,
@@ -404,7 +405,6 @@ fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> {
404 405 "ViewTag" => KeyAction::ViewTag,
405 406 "ToggleGaps" => KeyAction::ToggleGaps,
406 407 "ToggleFullScreen" => KeyAction::ToggleFullScreen,
407 - "ToggleWindowFullscreen" => KeyAction::ToggleWindowFullscreen,
408 408 "ToggleFloating" => KeyAction::ToggleFloating,
409 409 "ChangeLayout" => KeyAction::ChangeLayout,
410 410 "CycleLayout" => KeyAction::CycleLayout,
+294 −206 src/config/lua_api.rs Large diff collapsed, click to expand
@@ -75,8 +75,7 @@ type SharedBuilder = Rc<RefCell<ConfigBuilder>>;
75 75 pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
76 76 let builder = Rc::new(RefCell::new(ConfigBuilder::default()));
77 77
78 - let oxwm_table = lua.create_table()
79 - .map_err(|e| ConfigError::LuaError(format!("Failed to create oxwm table: {}", e)))?;
78 + let oxwm_table = lua.create_table()?;
80 79
81 80 register_spawn(&lua, &oxwm_table, builder.clone())?;
82 81 register_key_module(&lua, &oxwm_table, builder.clone())?;
@@ -88,8 +87,7 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
88 87 register_bar_module(&lua, &oxwm_table, builder.clone())?;
89 88 register_misc(&lua, &oxwm_table, builder.clone())?;
90 89
91 - lua.globals().set("oxwm", oxwm_table)
92 - .map_err(|e| ConfigError::LuaError(format!("Failed to set oxwm global: {}", e)))?;
90 + lua.globals().set("oxwm", oxwm_table)?;
93 91
94 92 Ok(builder)
95 93 }
@@ -97,15 +95,17 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
97 95 fn register_spawn(lua: &Lua, parent: &Table, _builder: SharedBuilder) -> Result<(), ConfigError> {
98 96 let spawn = lua.create_function(|lua, cmd: Value| {
99 97 create_action_table(lua, "Spawn", cmd)
100 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create spawn: {}", e)))?;
101 - parent.set("spawn", spawn)
102 - .map_err(|e| ConfigError::LuaError(format!("Failed to set spawn: {}", e)))?;
98 + })?;
99 + let spawn_terminal = lua.create_function(|lua, ()| {
100 + create_action_table(lua, "SpawnTerminal", Value::Nil)
101 + })?;
102 + parent.set("spawn", spawn)?;
103 + parent.set("spawn_terminal", spawn_terminal)?;
103 104 Ok(())
104 105 }
105 106
106 107 fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
107 - let key_table = lua.create_table()
108 - .map_err(|e| ConfigError::LuaError(format!("Failed to create key table: {}", e)))?;
108 + let key_table = lua.create_table()?;
109 109
110 110 let builder_clone = builder.clone();
111 111 let bind = lua.create_function(move |lua, (mods, key, action): (Value, String, Value)| {
@@ -117,7 +117,7 @@ fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
117 117 builder_clone.borrow_mut().keybindings.push(binding);
118 118
119 119 Ok(())
120 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create bind: {}", e)))?;
120 + })?;
121 121
122 122 let builder_clone = builder.clone();
123 123 let chord = lua.create_function(move |lua, (keys, action): (Table, Value)| {
@@ -139,38 +139,34 @@ fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
139 139 builder_clone.borrow_mut().keybindings.push(binding);
140 140
141 141 Ok(())
142 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create chord: {}", e)))?;
143 -
144 - key_table.set("bind", bind)
145 - .map_err(|e| ConfigError::LuaError(format!("Failed to set bind: {}", e)))?;
146 - key_table.set("chord", chord)
147 - .map_err(|e| ConfigError::LuaError(format!("Failed to set chord: {}", e)))?;
148 - parent.set("key", key_table)
149 - .map_err(|e| ConfigError::LuaError(format!("Failed to set key: {}", e)))?;
142 + })?;
143 +
144 + key_table.set("bind", bind)?;
145 + key_table.set("chord", chord)?;
146 + parent.set("key", key_table)?;
150 147 Ok(())
151 148 }
152 149
153 150 fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
154 - let gaps_table = lua.create_table()
155 - .map_err(|e| ConfigError::LuaError(format!("Failed to create gaps table: {}", e)))?;
151 + let gaps_table = lua.create_table()?;
156 152
157 153 let builder_clone = builder.clone();
158 154 let set_enabled = lua.create_function(move |_, enabled: bool| {
159 155 builder_clone.borrow_mut().gaps_enabled = enabled;
160 156 Ok(())
161 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_enabled: {}", e)))?;
157 + })?;
162 158
163 159 let builder_clone = builder.clone();
164 160 let enable = lua.create_function(move |_, ()| {
165 161 builder_clone.borrow_mut().gaps_enabled = true;
166 162 Ok(())
167 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create enable: {}", e)))?;
163 + })?;
168 164
169 165 let builder_clone = builder.clone();
170 166 let disable = lua.create_function(move |_, ()| {
171 167 builder_clone.borrow_mut().gaps_enabled = false;
172 168 Ok(())
173 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create disable: {}", e)))?;
169 + })?;
174 170
175 171 let builder_clone = builder.clone();
176 172 let set_inner = lua.create_function(move |_, (h, v): (u32, u32)| {
@@ -178,7 +174,7 @@ fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Re
178 174 b.gap_inner_horizontal = h;
179 175 b.gap_inner_vertical = v;
180 176 Ok(())
181 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_inner: {}", e)))?;
177 + })?;
182 178
183 179 let builder_clone = builder.clone();
184 180 let set_outer = lua.create_function(move |_, (h, v): (u32, u32)| {
@@ -186,227 +182,226 @@ fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Re
186 182 b.gap_outer_horizontal = h;
187 183 b.gap_outer_vertical = v;
188 184 Ok(())
189 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_outer: {}", e)))?;
190 -
191 - gaps_table.set("set_enabled", set_enabled)
192 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_enabled: {}", e)))?;
193 - gaps_table.set("enable", enable)
194 - .map_err(|e| ConfigError::LuaError(format!("Failed to set enable: {}", e)))?;
195 - gaps_table.set("disable", disable)
196 - .map_err(|e| ConfigError::LuaError(format!("Failed to set disable: {}", e)))?;
197 - gaps_table.set("set_inner", set_inner)
198 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_inner: {}", e)))?;
199 - gaps_table.set("set_outer", set_outer)
200 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_outer: {}", e)))?;
201 - parent.set("gaps", gaps_table)
202 - .map_err(|e| ConfigError::LuaError(format!("Failed to set gaps: {}", e)))?;
185 + })?;
186 +
187 + gaps_table.set("set_enabled", set_enabled)?;
188 + gaps_table.set("enable", enable)?;
189 + gaps_table.set("disable", disable)?;
190 + gaps_table.set("set_inner", set_inner)?;
191 + gaps_table.set("set_outer", set_outer)?;
192 + parent.set("gaps", gaps_table)?;
203 193 Ok(())
204 194 }
205 195
206 196 fn register_border_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
207 - let border_table = lua.create_table()
208 - .map_err(|e| ConfigError::LuaError(format!("Failed to create border table: {}", e)))?;
197 + let border_table = lua.create_table()?;
209 198
210 199 let builder_clone = builder.clone();
211 200 let set_width = lua.create_function(move |_, width: u32| {
212 201 builder_clone.borrow_mut().border_width = width;
213 202 Ok(())
214 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_width: {}", e)))?;
203 + })?;
215 204
216 205 let builder_clone = builder.clone();
217 206 let set_focused_color = lua.create_function(move |_, color: Value| {
218 207 let color_u32 = parse_color_value(color)?;
219 208 builder_clone.borrow_mut().border_focused = color_u32;
220 209 Ok(())
221 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_focused_color: {}", e)))?;
210 + })?;
222 211
223 212 let builder_clone = builder.clone();
224 213 let set_unfocused_color = lua.create_function(move |_, color: Value| {
225 214 let color_u32 = parse_color_value(color)?;
226 215 builder_clone.borrow_mut().border_unfocused = color_u32;
227 216 Ok(())
228 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_unfocused_color: {}", e)))?;
229 -
230 - border_table.set("set_width", set_width)
231 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_width: {}", e)))?;
232 - border_table.set("set_focused_color", set_focused_color)
233 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_focused_color: {}", e)))?;
234 - border_table.set("set_unfocused_color", set_unfocused_color)
235 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_unfocused_color: {}", e)))?;
236 - parent.set("border", border_table)
237 - .map_err(|e| ConfigError::LuaError(format!("Failed to set border: {}", e)))?;
217 + })?;
218 +
219 + border_table.set("set_width", set_width)?;
220 + border_table.set("set_focused_color", set_focused_color)?;
221 + border_table.set("set_unfocused_color", set_unfocused_color)?;
222 + parent.set("border", border_table)?;
238 223 Ok(())
239 224 }
240 225
241 226 fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
242 - let client_table = lua.create_table()
243 - .map_err(|e| ConfigError::LuaError(format!("Failed to create client table: {}", e)))?;
227 + let client_table = lua.create_table()?;
244 228
245 229 let kill = lua.create_function(|lua, ()| {
246 230 create_action_table(lua, "KillClient", Value::Nil)
247 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create kill: {}", e)))?;
231 + })?;
248 232
249 233 let toggle_fullscreen = lua.create_function(|lua, ()| {
250 234 create_action_table(lua, "ToggleFullScreen", Value::Nil)
251 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create toggle_fullscreen: {}", e)))?;
235 + })?;
252 236
253 237 let toggle_floating = lua.create_function(|lua, ()| {
254 238 create_action_table(lua, "ToggleFloating", Value::Nil)
255 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create toggle_floating: {}", e)))?;
239 + })?;
256 240
257 241 let focus_stack = lua.create_function(|lua, dir: i32| {
258 242 create_action_table(lua, "FocusStack", Value::Integer(dir as i64))
259 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create focus_stack: {}", e)))?;
243 + })?;
260 244
261 245 let focus_direction = lua.create_function(|lua, dir: String| {
262 246 let dir_int = direction_string_to_int(&dir)?;
263 247 create_action_table(lua, "FocusDirection", Value::Integer(dir_int))
264 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create focus_direction: {}", e)))?;
248 + })?;
265 249
266 250 let swap_direction = lua.create_function(|lua, dir: String| {
267 251 let dir_int = direction_string_to_int(&dir)?;
268 252 create_action_table(lua, "SwapDirection", Value::Integer(dir_int))
269 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create swap_direction: {}", e)))?;
253 + })?;
270 254
271 255 let smart_move = lua.create_function(|lua, dir: String| {
272 256 let dir_int = direction_string_to_int(&dir)?;
273 257 create_action_table(lua, "SmartMoveWin", Value::Integer(dir_int))
274 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create smart_move: {}", e)))?;
258 + })?;
275 259
276 260 let exchange = lua.create_function(|lua, ()| {
277 261 create_action_table(lua, "ExchangeClient", Value::Nil)
278 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create exchange: {}", e)))?;
279 -
280 - client_table.set("kill", kill)
281 - .map_err(|e| ConfigError::LuaError(format!("Failed to set kill: {}", e)))?;
282 - client_table.set("toggle_fullscreen", toggle_fullscreen)
283 - .map_err(|e| ConfigError::LuaError(format!("Failed to set toggle_fullscreen: {}", e)))?;
284 - client_table.set("toggle_floating", toggle_floating)
285 - .map_err(|e| ConfigError::LuaError(format!("Failed to set toggle_floating: {}", e)))?;
286 - client_table.set("focus_stack", focus_stack)
287 - .map_err(|e| ConfigError::LuaError(format!("Failed to set focus_stack: {}", e)))?;
288 - client_table.set("focus_direction", focus_direction)
289 - .map_err(|e| ConfigError::LuaError(format!("Failed to set focus_direction: {}", e)))?;
290 - client_table.set("swap_direction", swap_direction)
291 - .map_err(|e| ConfigError::LuaError(format!("Failed to set swap_direction: {}", e)))?;
292 - client_table.set("smart_move", smart_move)
293 - .map_err(|e| ConfigError::LuaError(format!("Failed to set smart_move: {}", e)))?;
294 - client_table.set("exchange", exchange)
295 - .map_err(|e| ConfigError::LuaError(format!("Failed to set exchange: {}", e)))?;
296 -
297 - parent.set("client", client_table)
298 - .map_err(|e| ConfigError::LuaError(format!("Failed to set client: {}", e)))?;
262 + })?;
263 +
264 + client_table.set("kill", kill)?;
265 + client_table.set("toggle_fullscreen", toggle_fullscreen)?;
266 + client_table.set("toggle_floating", toggle_floating)?;
267 + client_table.set("focus_stack", focus_stack)?;
268 + client_table.set("focus_direction", focus_direction)?;
269 + client_table.set("swap_direction", swap_direction)?;
270 + client_table.set("smart_move", smart_move)?;
271 + client_table.set("exchange", exchange)?;
272 +
273 + parent.set("client", client_table)?;
299 274 Ok(())
300 275 }
301 276
302 277 fn register_layout_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
303 - let layout_table = lua.create_table()
304 - .map_err(|e| ConfigError::LuaError(format!("Failed to create layout table: {}", e)))?;
278 + let layout_table = lua.create_table()?;
305 279
306 280 let cycle = lua.create_function(|lua, ()| {
307 281 create_action_table(lua, "CycleLayout", Value::Nil)
308 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create cycle: {}", e)))?;
282 + })?;
309 283
310 284 let set = lua.create_function(|lua, name: String| {
311 285 create_action_table(lua, "ChangeLayout", Value::String(lua.create_string(&name)?))
312 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set: {}", e)))?;
313 -
314 - layout_table.set("cycle", cycle)
315 - .map_err(|e| ConfigError::LuaError(format!("Failed to set cycle: {}", e)))?;
316 - layout_table.set("set", set)
317 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set: {}", e)))?;
318 - parent.set("layout", layout_table)
319 - .map_err(|e| ConfigError::LuaError(format!("Failed to set layout: {}", e)))?;
286 + })?;
287 +
288 + layout_table.set("cycle", cycle)?;
289 + layout_table.set("set", set)?;
290 + parent.set("layout", layout_table)?;
320 291 Ok(())
321 292 }
322 293
323 294 fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
324 - let tag_table = lua.create_table()
325 - .map_err(|e| ConfigError::LuaError(format!("Failed to create tag table: {}", e)))?;
295 + let tag_table = lua.create_table()?;
326 296
327 297 let view = lua.create_function(|lua, idx: i32| {
328 298 create_action_table(lua, "ViewTag", Value::Integer(idx as i64))
329 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create view: {}", e)))?;
299 + })?;
330 300
331 301 let move_to = lua.create_function(|lua, idx: i32| {
332 302 create_action_table(lua, "MoveToTag", Value::Integer(idx as i64))
333 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create move_to: {}", e)))?;
334 -
335 - tag_table.set("view", view)
336 - .map_err(|e| ConfigError::LuaError(format!("Failed to set view: {}", e)))?;
337 - tag_table.set("move_to", move_to)
338 - .map_err(|e| ConfigError::LuaError(format!("Failed to set move_to: {}", e)))?;
339 - parent.set("tag", tag_table)
340 - .map_err(|e| ConfigError::LuaError(format!("Failed to set tag: {}", e)))?;
303 + })?;
304 +
305 + tag_table.set("view", view)?;
306 + tag_table.set("move_to", move_to)?;
307 + parent.set("tag", tag_table)?;
341 308 Ok(())
342 309 }
343 310
344 311 fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
345 - let bar_table = lua.create_table()
346 - .map_err(|e| ConfigError::LuaError(format!("Failed to create bar table: {}", e)))?;
312 + let bar_table = lua.create_table()?;
347 313
348 314 let builder_clone = builder.clone();
349 315 let set_font = lua.create_function(move |_, font: String| {
350 316 builder_clone.borrow_mut().font = font;
351 317 Ok(())
352 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_font: {}", e)))?;
353 -
318 + })?;
319 +
320 + let block_table = lua.create_table()?;
321 +
322 + let ram = lua.create_function(|lua, config: Table| {
323 + create_block_config(lua, config, "Ram", None)
324 + })?;
325 +
326 + let datetime = lua.create_function(|lua, config: Table| {
327 + let date_format: String = config.get("date_format")
328 + .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.datetime: 'date_format' field is required (e.g., '%H:%M')".into()))?;
329 + create_block_config(lua, config, "DateTime", Some(Value::String(lua.create_string(&date_format)?)))
330 + })?;
331 +
332 + let shell = lua.create_function(|lua, config: Table| {
333 + let command: String = config.get("command")
334 + .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.shell: 'command' field is required".into()))?;
335 + create_block_config(lua, config, "Shell", Some(Value::String(lua.create_string(&command)?)))
336 + })?;
337 +
338 + let static_block = lua.create_function(|lua, config: Table| {
339 + let text: String = config.get("text")
340 + .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.static: 'text' field is required".into()))?;
341 + create_block_config(lua, config, "Static", Some(Value::String(lua.create_string(&text)?)))
342 + })?;
343 +
344 + let battery = lua.create_function(|lua, config: Table| {
345 + let charging: String = config.get("charging")
346 + .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.battery: 'charging' field is required".into()))?;
347 + let discharging: String = config.get("discharging")
348 + .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.battery: 'discharging' field is required".into()))?;
349 + let full: String = config.get("full")
350 + .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.battery: 'full' field is required".into()))?;
351 +
352 + let formats_table = lua.create_table()?;
353 + formats_table.set("charging", charging)?;
354 + formats_table.set("discharging", discharging)?;
355 + formats_table.set("full", full)?;
356 +
357 + create_block_config(lua, config, "Battery", Some(Value::Table(formats_table)))
358 + })?;
359 +
360 + block_table.set("ram", ram)?;
361 + block_table.set("datetime", datetime)?;
362 + block_table.set("shell", shell)?;
363 + block_table.set("static", static_block)?;
364 + block_table.set("battery", battery)?;
365 +
366 + // Deprecated add_block() function for backwards compatibility
367 + // This allows old configs to still work, but users should migrate to set_blocks()
354 368 let builder_clone = builder.clone();
355 - let add_block = lua.create_function(move |_, (format, command, arg, interval, color, underline): (String, String, Option<Value>, u64, Value, bool)| {
356 - use crate::bar::BlockCommand;
369 + let add_block = lua.create_function(move |_, (format, block_type, arg, interval, color, underline): (String, String, Value, u64, Value, Option<bool>)| -> mlua::Result<()> {
370 + eprintln!("WARNING: oxwm.bar.add_block() is deprecated. Please migrate to oxwm.bar.set_blocks() with block constructors.");
371 + eprintln!("See the migration guide for details.");
357 372
358 - let cmd = match command.as_str() {
373 + let cmd = match block_type.as_str() {
359 374 "DateTime" => {
360 - let fmt = arg.and_then(|v| {
361 - if let Value::String(s) = v {
362 - s.to_str().ok().map(|s| s.to_string())
363 - } else {
364 - None
365 - }
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)
375 + let fmt = if let Value::String(s) = arg {
376 + s.to_str()?.to_string()
377 + } else {
378 + return Err(mlua::Error::RuntimeError("DateTime block requires format string as third argument".into()));
379 + };
380 + crate::bar::BlockCommand::DateTime(fmt)
368 381 }
369 382 "Shell" => {
370 - let cmd_str = arg.and_then(|v| {
371 - if let Value::String(s) = v {
372 - s.to_str().ok().map(|s| s.to_string())
373 - } else {
374 - None
375 - }
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)
383 + let cmd_str = if let Value::String(s) = arg {
384 + s.to_str()?.to_string()
385 + } else {
386 + return Err(mlua::Error::RuntimeError("Shell block requires command string as third argument".into()));
387 + };
388 + crate::bar::BlockCommand::Shell(cmd_str)
378 389 }
379 - "Ram" => BlockCommand::Ram,
390 + "Ram" => crate::bar::BlockCommand::Ram,
380 391 "Static" => {
381 - let text = arg.and_then(|v| {
382 - if let Value::String(s) = v {
383 - s.to_str().ok().map(|s| s.to_string())
384 - } else {
385 - None
386 - }
387 - }).unwrap_or_default();
388 - BlockCommand::Static(text)
392 + let text = if let Value::String(s) = arg {
393 + s.to_str()?.to_string()
394 + } else {
395 + String::new()
396 + };
397 + crate::bar::BlockCommand::Static(text)
389 398 }
390 399 "Battery" => {
391 - let formats = arg.and_then(|v| {
392 - if let Value::Table(t) = v {
393 - Some(t)
394 - } else {
395 - None
396 - }
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 -
399 - let charging: String = formats.get("charging")?;
400 - let discharging: String = formats.get("discharging")?;
401 - let full: String = formats.get("full")?;
402 -
403 - BlockCommand::Battery {
404 - format_charging: charging,
405 - format_discharging: discharging,
406 - format_full: full,
407 - }
400 + return Err(mlua::Error::RuntimeError(
401 + "Battery block is not supported with add_block(). Please use oxwm.bar.set_blocks() with oxwm.bar.block.battery()".into()
402 + ));
408 403 }
409 - _ => return Err(mlua::Error::RuntimeError(format!("oxwm.bar.add_block: unknown block command '{}'. valid commands: DateTime, Shell, Ram, Static, Battery", command))),
404 + _ => return Err(mlua::Error::RuntimeError(format!("Unknown block type '{}'", block_type))),
410 405 };
411 406
412 407 let color_u32 = parse_color_value(color)?;
@@ -416,12 +411,98 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
416 411 command: cmd,
417 412 interval_secs: interval,
418 413 color: color_u32,
419 - underline,
414 + underline: underline.unwrap_or(false),
420 415 };
421 416
422 417 builder_clone.borrow_mut().status_blocks.push(block);
423 418 Ok(())
424 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create add_block: {}", e)))?;
419 + })?;
420 +
421 + let builder_clone = builder.clone();
422 + let set_blocks = lua.create_function(move |_, blocks: Table| {
423 + use crate::bar::BlockCommand;
424 +
425 + let mut block_configs = Vec::new();
426 +
427 + for i in 1..=blocks.len()? {
428 + let block_table: Table = blocks.get(i)?;
429 + let block_type: String = block_table.get("__block_type")?;
430 + let format: String = block_table.get("format").unwrap_or_default();
431 + let interval: u64 = block_table.get("interval")?;
432 + let color_val: Value = block_table.get("color")?;
433 + let underline: bool = block_table.get("underline").unwrap_or(false);
434 + let arg: Option<Value> = block_table.get("__arg").ok();
435 +
436 + let cmd = match block_type.as_str() {
437 + "DateTime" => {
438 + let fmt = arg.and_then(|v| {
439 + if let Value::String(s) = v {
440 + s.to_str().ok().map(|s| s.to_string())
441 + } else {
442 + None
443 + }
444 + }).ok_or_else(|| mlua::Error::RuntimeError("DateTime block missing format".into()))?;
445 + BlockCommand::DateTime(fmt)
446 + }
447 + "Shell" => {
448 + let cmd_str = arg.and_then(|v| {
449 + if let Value::String(s) = v {
450 + s.to_str().ok().map(|s| s.to_string())
451 + } else {
452 + None
453 + }
454 + }).ok_or_else(|| mlua::Error::RuntimeError("Shell block missing command".into()))?;
455 + BlockCommand::Shell(cmd_str)
456 + }
457 + "Ram" => BlockCommand::Ram,
458 + "Static" => {
459 + let text = arg.and_then(|v| {
460 + if let Value::String(s) = v {
461 + s.to_str().ok().map(|s| s.to_string())
462 + } else {
463 + None
464 + }
465 + }).unwrap_or_default();
466 + BlockCommand::Static(text)
467 + }
468 + "Battery" => {
469 + let formats = arg.and_then(|v| {
470 + if let Value::Table(t) = v {
471 + Some(t)
472 + } else {
473 + None
474 + }
475 + }).ok_or_else(|| mlua::Error::RuntimeError("Battery block missing formats".into()))?;
476 +
477 + let charging: String = formats.get("charging")?;
478 + let discharging: String = formats.get("discharging")?;
479 + let full: String = formats.get("full")?;
480 +
481 + BlockCommand::Battery {
482 + format_charging: charging,
483 + format_discharging: discharging,
484 + format_full: full,
485 + }
486 + }
487 + _ => return Err(mlua::Error::RuntimeError(format!("Unknown block type '{}'", block_type))),
488 + };
489 +
490 + let color_u32 = parse_color_value(color_val)?;
491 +
492 + let block = crate::bar::BlockConfig {
493 + format,
494 + command: cmd,
495 + interval_secs: interval,
496 + color: color_u32,
497 + underline,
498 + };
499 +
500 + block_configs.push(block);
501 + }
502 +
503 + builder_clone.borrow_mut().status_blocks = block_configs;
504 + Ok(())
505 + })?;
425 506
426 507 let builder_clone = builder.clone();
427 508 let set_scheme_normal = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
@@ -435,7 +516,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
435 516 underline,
436 517 };
437 518 Ok(())
438 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_scheme_normal: {}", e)))?;
519 + })?;
439 520
440 521 let builder_clone = builder.clone();
441 522 let set_scheme_occupied = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
@@ -449,7 +530,7 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
449 530 underline,
450 531 };
451 532 Ok(())
452 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_scheme_occupied: {}", e)))?;
533 + })?;
453 534
454 535 let builder_clone = builder.clone();
455 536 let set_scheme_selected = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
@@ -463,20 +544,16 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
463 544 underline,
464 545 };
465 546 Ok(())
466 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_scheme_selected: {}", e)))?;
467 -
468 - bar_table.set("set_font", set_font)
469 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_font: {}", e)))?;
470 - bar_table.set("add_block", add_block)
471 - .map_err(|e| ConfigError::LuaError(format!("Failed to set add_block: {}", e)))?;
472 - bar_table.set("set_scheme_normal", set_scheme_normal)
473 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_scheme_normal: {}", e)))?;
474 - bar_table.set("set_scheme_occupied", set_scheme_occupied)
475 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_scheme_occupied: {}", e)))?;
476 - bar_table.set("set_scheme_selected", set_scheme_selected)
477 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_scheme_selected: {}", e)))?;
478 - parent.set("bar", bar_table)
479 - .map_err(|e| ConfigError::LuaError(format!("Failed to set bar: {}", e)))?;
547 + })?;
548 +
549 + bar_table.set("set_font", set_font)?;
550 + bar_table.set("block", block_table)?;
551 + bar_table.set("add_block", add_block)?; // Deprecated, for backwards compatibility
552 + bar_table.set("set_blocks", set_blocks)?;
553 + bar_table.set("set_scheme_normal", set_scheme_normal)?;
554 + bar_table.set("set_scheme_occupied", set_scheme_occupied)?;
555 + bar_table.set("set_scheme_selected", set_scheme_selected)?;
556 + parent.set("bar", bar_table)?;
480 557 Ok(())
481 558 }
482 559
@@ -485,7 +562,7 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
485 562 let set_terminal = lua.create_function(move |_, term: String| {
486 563 builder_clone.borrow_mut().terminal = term;
487 564 Ok(())
488 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_terminal: {}", e)))?;
565 + })?;
489 566
490 567 let builder_clone = builder.clone();
491 568 let set_modkey = lua.create_function(move |_, modkey_str: String| {
@@ -493,37 +570,37 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
493 570 .map_err(|e| mlua::Error::RuntimeError(format!("{}", e)))?;
494 571 builder_clone.borrow_mut().modkey = modkey;
495 572 Ok(())
496 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_modkey: {}", e)))?;
573 + })?;
497 574
498 575 let builder_clone = builder.clone();
499 576 let set_tags = lua.create_function(move |_, tags: Vec<String>| {
500 577 builder_clone.borrow_mut().tags = tags;
501 578 Ok(())
502 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_tags: {}", e)))?;
579 + })?;
503 580
504 581 let quit = lua.create_function(|lua, ()| {
505 582 create_action_table(lua, "Quit", Value::Nil)
506 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create quit: {}", e)))?;
583 + })?;
507 584
508 585 let restart = lua.create_function(|lua, ()| {
509 586 create_action_table(lua, "Restart", Value::Nil)
510 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create restart: {}", e)))?;
587 + })?;
511 588
512 589 let recompile = lua.create_function(|lua, ()| {
513 590 create_action_table(lua, "Recompile", Value::Nil)
514 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create recompile: {}", e)))?;
591 + })?;
515 592
516 593 let toggle_gaps = lua.create_function(|lua, ()| {
517 594 create_action_table(lua, "ToggleGaps", Value::Nil)
518 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create toggle_gaps: {}", e)))?;
595 + })?;
519 596
520 597 let show_keybinds = lua.create_function(|lua, ()| {
521 598 create_action_table(lua, "ShowKeybindOverlay", Value::Nil)
522 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create show_keybinds: {}", e)))?;
599 + })?;
523 600
524 601 let focus_monitor = lua.create_function(|lua, idx: i32| {
525 602 create_action_table(lua, "FocusMonitor", Value::Integer(idx as i64))
526 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create focus_monitor: {}", e)))?;
603 + })?;
527 604
528 605 let builder_clone = builder.clone();
529 606 let set_layout_symbol = lua.create_function(move |_, (name, symbol): (String, String)| {
@@ -532,36 +609,25 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
532 609 symbol,
533 610 });
534 611 Ok(())
535 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_layout_symbol: {}", e)))?;
612 + })?;
536 613
537 614 let builder_clone = builder.clone();
538 615 let autostart = lua.create_function(move |_, cmd: String| {
539 616 builder_clone.borrow_mut().autostart.push(cmd);
540 617 Ok(())
541 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create autostart: {}", e)))?;
542 -
543 - parent.set("set_terminal", set_terminal)
544 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_terminal: {}", e)))?;
545 - parent.set("set_modkey", set_modkey)
546 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_modkey: {}", e)))?;
547 - parent.set("set_tags", set_tags)
548 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_tags: {}", e)))?;
549 - parent.set("set_layout_symbol", set_layout_symbol)
550 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_layout_symbol: {}", e)))?;
551 - parent.set("autostart", autostart)
552 - .map_err(|e| ConfigError::LuaError(format!("Failed to set autostart: {}", e)))?;
553 - parent.set("quit", quit)
554 - .map_err(|e| ConfigError::LuaError(format!("Failed to set quit: {}", e)))?;
555 - parent.set("restart", restart)
556 - .map_err(|e| ConfigError::LuaError(format!("Failed to set restart: {}", e)))?;
557 - parent.set("recompile", recompile)
558 - .map_err(|e| ConfigError::LuaError(format!("Failed to set recompile: {}", e)))?;
559 - parent.set("toggle_gaps", toggle_gaps)
560 - .map_err(|e| ConfigError::LuaError(format!("Failed to set toggle_gaps: {}", e)))?;
561 - parent.set("show_keybinds", show_keybinds)
562 - .map_err(|e| ConfigError::LuaError(format!("Failed to set show_keybinds: {}", e)))?;
563 - parent.set("focus_monitor", focus_monitor)
564 - .map_err(|e| ConfigError::LuaError(format!("Failed to set focus_monitor: {}", e)))?;
618 + })?;
619 +
620 + parent.set("set_terminal", set_terminal)?;
621 + parent.set("set_modkey", set_modkey)?;
622 + parent.set("set_tags", set_tags)?;
623 + parent.set("set_layout_symbol", set_layout_symbol)?;
624 + parent.set("autostart", autostart)?;
625 + parent.set("quit", quit)?;
626 + parent.set("restart", restart)?;
627 + parent.set("recompile", recompile)?;
628 + parent.set("toggle_gaps", toggle_gaps)?;
629 + parent.set("show_keybinds", show_keybinds)?;
630 + parent.set("focus_monitor", focus_monitor)?;
565 631 Ok(())
566 632 }
567 633
@@ -638,6 +704,7 @@ fn parse_action_value(_lua: &Lua, value: Value) -> mlua::Result<(KeyAction, Arg)
638 704 fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
639 705 match s {
640 706 "Spawn" => Ok(KeyAction::Spawn),
707 + "SpawnTerminal" => Ok(KeyAction::SpawnTerminal),
641 708 "KillClient" => Ok(KeyAction::KillClient),
642 709 "FocusStack" => Ok(KeyAction::FocusStack),
643 710 "FocusDirection" => Ok(KeyAction::FocusDirection),
@@ -719,3 +786,24 @@ fn parse_color_value(value: Value) -> mlua::Result<u32> {
719 786 )),
720 787 }
721 788 }
789 +
790 +fn create_block_config(lua: &Lua, config: Table, block_type: &str, arg: Option<Value>) -> mlua::Result<Table> {
791 + let table = lua.create_table()?;
792 + table.set("__block_type", block_type)?;
793 +
794 + let format: String = config.get("format").unwrap_or_default();
795 + let interval: u64 = config.get("interval")?;
796 + let color: Value = config.get("color")?;
797 + let underline: bool = config.get("underline").unwrap_or(false);
798 +
799 + table.set("format", format)?;
800 + table.set("interval", interval)?;
801 + table.set("color", color)?;
802 + table.set("underline", underline)?;
803 +
804 + if let Some(arg_val) = arg {
805 + table.set("__arg", arg_val)?;
806 + }
807 +
808 + Ok(table)
809 +}
+16 −0 src/errors.rs
@@ -161,3 +161,19 @@ impl From<x11rb::errors::ReplyOrIdError> for X11Error {
161 161 X11Error::ReplyOrIdError(value)
162 162 }
163 163 }
164 +
165 +impl From<mlua::Error> for ConfigError {
166 + fn from(err: mlua::Error) -> Self {
167 + ConfigError::LuaError(err.to_string())
168 + }
169 +}
170 +
171 +pub trait LuaResultExt<T> {
172 + fn lua_context(self, context: &str) -> Result<T, ConfigError>;
173 +}
174 +
175 +impl<T> LuaResultExt<T> for Result<T, mlua::Error> {
176 + fn lua_context(self, context: &str) -> Result<T, ConfigError> {
177 + self.map_err(|e| ConfigError::LuaError(format!("{}: {}", context, e)))
178 + }
179 +}
+1 −1 src/keyboard/handlers.rs
@@ -12,6 +12,7 @@ use crate::keyboard::keysyms::{self, Keysym};
12 12 #[derive(Debug, Copy, Clone, Deserialize, PartialEq)]
13 13 pub enum KeyAction {
14 14 Spawn,
15 + SpawnTerminal,
15 16 KillClient,
16 17 FocusStack,
17 18 FocusDirection,
@@ -22,7 +23,6 @@ pub enum KeyAction {
22 23 ViewTag,
23 24 ToggleGaps,
24 25 ToggleFullScreen,
25 - ToggleWindowFullscreen,
26 26 ToggleFloating,
27 27 ChangeLayout,
28 28 CycleLayout,
+8 −1 src/layout/mod.rs
@@ -1,4 +1,5 @@
1 1 pub mod grid;
2 +pub mod monocle;
2 3 pub mod normie;
3 4 pub mod tiling;
4 5
@@ -17,6 +18,7 @@ pub enum LayoutType {
17 18 Tiling,
18 19 Normie,
19 20 Grid,
21 + Monocle,
20 22 }
21 23
22 24 impl LayoutType {
@@ -25,6 +27,7 @@ impl LayoutType {
25 27 Self::Tiling => Box::new(tiling::TilingLayout),
26 28 Self::Normie => Box::new(normie::NormieLayout),
27 29 Self::Grid => Box::new(grid::GridLayout),
30 + Self::Monocle => Box::new(monocle::MonocleLayout),
28 31 }
29 32 }
30 33
@@ -32,7 +35,8 @@ impl LayoutType {
32 35 match self {
33 36 Self::Tiling => Self::Normie,
34 37 Self::Normie => Self::Grid,
35 - Self::Grid => Self::Tiling,
38 + Self::Grid => Self::Monocle,
39 + Self::Monocle => Self::Tiling,
36 40 }
37 41 }
38 42
@@ -41,6 +45,7 @@ impl LayoutType {
41 45 Self::Tiling => "tiling",
42 46 Self::Normie => "normie",
43 47 Self::Grid => "grid",
48 + Self::Monocle => "monocle",
44 49 }
45 50 }
46 51
@@ -49,6 +54,7 @@ impl LayoutType {
49 54 "tiling" => Ok(Self::Tiling),
50 55 "normie" | "floating" => Ok(Self::Normie),
51 56 "grid" => Ok(Self::Grid),
57 + "monocle" => Ok(Self::Monocle),
52 58 _ => Err(format!("Invalid Layout Type: {}", s)),
53 59 }
54 60 }
@@ -79,6 +85,7 @@ pub trait Layout {
79 85 fn symbol(&self) -> &'static str;
80 86 }
81 87
88 +#[derive(Clone)]
82 89 pub struct WindowGeometry {
83 90 pub x_coordinate: i32,
84 91 pub y_coordinate: i32,
+41 −0 src/layout/monocle.rs new file mode 100644
@@ -0,0 +1,41 @@
1 +use super::{GapConfig, Layout, WindowGeometry};
2 +use x11rb::protocol::xproto::Window;
3 +
4 +pub struct MonocleLayout;
5 +
6 +impl Layout for MonocleLayout {
7 + fn name(&self) -> &'static str {
8 + super::LayoutType::Monocle.as_str()
9 + }
10 +
11 + fn symbol(&self) -> &'static str {
12 + "[M]"
13 + }
14 +
15 + fn arrange(
16 + &self,
17 + windows: &[Window],
18 + screen_width: u32,
19 + screen_height: u32,
20 + gaps: &GapConfig,
21 + ) -> Vec<WindowGeometry> {
22 + let window_count = windows.len();
23 + if window_count == 0 {
24 + return Vec::new();
25 + }
26 +
27 + let x = gaps.outer_horizontal as i32;
28 + let y = gaps.outer_vertical as i32;
29 + let width = screen_width.saturating_sub(2 * gaps.outer_horizontal);
30 + let height = screen_height.saturating_sub(2 * gaps.outer_vertical);
31 +
32 + let geometry = WindowGeometry {
33 + x_coordinate: x,
34 + y_coordinate: y,
35 + width,
36 + height,
37 + };
38 +
39 + vec![geometry; window_count]
40 + }
41 +}
+0 −2 src/monitor.rs
@@ -13,7 +13,6 @@ pub struct Monitor {
13 13 pub height: u32,
14 14 pub selected_tags: u32,
15 15 pub focused_window: Option<Window>,
16 - pub fullscreen_enabled: bool,
17 16 }
18 17
19 18 impl Monitor {
@@ -25,7 +24,6 @@ impl Monitor {
25 24 height,
26 25 selected_tags: 1,
27 26 focused_window: None,
28 - fullscreen_enabled: false,
29 27 }
30 28 }
31 29
+2 −1 src/overlay/keybind.rs
@@ -141,6 +141,7 @@ impl KeybindOverlay {
141 141 KeyAction::Restart,
142 142 KeyAction::KillClient,
143 143 KeyAction::Spawn,
144 + KeyAction::SpawnTerminal,
144 145 KeyAction::ToggleFullScreen,
145 146 KeyAction::ToggleFloating,
146 147 KeyAction::CycleLayout,
@@ -200,6 +201,7 @@ impl KeybindOverlay {
200 201 Arg::Array(arr) if !arr.is_empty() => format!("Launch: {}", arr[0]),
201 202 _ => "Launch Program".to_string(),
202 203 },
204 + KeyAction::SpawnTerminal => "Launch Terminal".to_string(),
203 205 KeyAction::FocusStack => "Focus Next/Previous Window".to_string(),
204 206 KeyAction::FocusDirection => "Focus Window in Direction".to_string(),
205 207 KeyAction::SwapDirection => "Swap Window in Direction".to_string(),
@@ -210,7 +212,6 @@ impl KeybindOverlay {
210 212 KeyAction::MoveToTag => "Move Window to Workspace".to_string(),
211 213 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(),
212 214 KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(),
213 - KeyAction::ToggleWindowFullscreen => "Toggle Window Fullscreen".to_string(),
214 215 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(),
215 216 KeyAction::ChangeLayout => "Change Layout".to_string(),
216 217 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(),
+154 −121 src/window_manager.rs
@@ -87,11 +87,12 @@ pub struct WindowManager {
87 87 layout: LayoutBox,
88 88 window_tags: std::collections::HashMap<Window, TagMask>,
89 89 window_monitor: std::collections::HashMap<Window, usize>,
90 - window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>,
91 90 gaps_enabled: bool,
92 91 floating_windows: HashSet<Window>,
93 92 fullscreen_windows: HashSet<Window>,
94 93 bars: Vec<Bar>,
94 + show_bar: bool,
95 + last_layout: Option<&'static str>,
95 96 monitors: Vec<Monitor>,
96 97 selected_monitor: usize,
97 98 atoms: AtomCache,
@@ -211,11 +212,12 @@ impl WindowManager {
211 212 layout: Box::new(TilingLayout),
212 213 window_tags: std::collections::HashMap::new(),
213 214 window_monitor: std::collections::HashMap::new(),
214 - window_geometries: std::collections::HashMap::new(),
215 215 gaps_enabled,
216 216 floating_windows: HashSet::new(),
217 217 fullscreen_windows: HashSet::new(),
218 218 bars,
219 + show_bar: true,
220 + last_layout: None,
219 221 monitors,
220 222 selected_monitor: 0,
221 223 atoms,
@@ -857,22 +859,6 @@ impl WindowManager {
857 859 Ok(())
858 860 }
859 861
860 - fn toggle_fullscreen(&mut self) -> WmResult<()> {
861 - if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
862 - monitor.fullscreen_enabled = !monitor.fullscreen_enabled;
863 -
864 - if let Some(bar) = self.bars.get(self.selected_monitor) {
865 - if monitor.fullscreen_enabled {
866 - self.connection.unmap_window(bar.window())?;
867 - } else {
868 - self.connection.map_window(bar.window())?;
869 - }
870 - }
871 -
872 - self.apply_layout()?;
873 - }
874 - Ok(())
875 - }
876 862
877 863 fn get_layout_symbol(&self) -> String {
878 864 let layout_name = self.layout.name();
@@ -961,6 +947,11 @@ impl WindowManager {
961 947 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> {
962 948 match action {
963 949 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
950 + KeyAction::SpawnTerminal => {
951 + use std::process::Command;
952 + let terminal = &self.config.terminal;
953 + let _ = Command::new(terminal).spawn();
954 + }
964 955 KeyAction::KillClient => {
965 956 if let Some(focused) = self
966 957 .monitors
@@ -971,45 +962,16 @@ impl WindowManager {
971 962 }
972 963 }
973 964 KeyAction::ToggleFullScreen => {
974 - // Smart fullscreen:
975 - // - In normie (floating) layout: always fullscreen the focused window
976 - // - With explicitly floating window: fullscreen that window
977 - // - Otherwise: do monitor-level fullscreen (hide bar)
978 - let is_normie_layout = self.layout.name() == "normie";
979 -
980 - if let Some(focused) = self
981 - .monitors
982 - .get(self.selected_monitor)
983 - .and_then(|m| m.focused_window)
984 - {
985 - if is_normie_layout || self.floating_windows.contains(&focused) {
986 - // In floating layout or window is floating - do per-window fullscreen
987 - let is_fullscreen = self.fullscreen_windows.contains(&focused);
988 - self.set_window_fullscreen(focused, !is_fullscreen)?;
989 - } else {
990 - // Window is tiled - do monitor fullscreen
991 - self.toggle_fullscreen()?;
992 - }
993 - } else {
994 - // No focused window - do monitor fullscreen
995 - self.toggle_fullscreen()?;
996 - }
997 - }
998 - KeyAction::ToggleWindowFullscreen => {
999 - if let Some(focused) = self
1000 - .monitors
1001 - .get(self.selected_monitor)
1002 - .and_then(|m| m.focused_window)
1003 - {
1004 - let is_fullscreen = self.fullscreen_windows.contains(&focused);
1005 - self.set_window_fullscreen(focused, !is_fullscreen)?;
1006 - }
965 + self.fullscreen()?;
1007 966 }
1008 967 KeyAction::ChangeLayout => {
1009 968 if let Arg::Str(layout_name) = arg {
1010 969 match layout_from_str(layout_name) {
1011 970 Ok(layout) => {
1012 971 self.layout = layout;
972 + if layout_name != "normie" && layout_name != "floating" {
973 + self.floating_windows.clear();
974 + }
1013 975 self.apply_layout()?;
1014 976 self.update_bar()?;
1015 977 }
@@ -1023,6 +985,9 @@ impl WindowManager {
1023 985 match layout_from_str(next_name) {
1024 986 Ok(layout) => {
1025 987 self.layout = layout;
988 + if next_name != "normie" && next_name != "floating" {
989 + self.floating_windows.clear();
990 + }
1026 991 self.apply_layout()?;
1027 992 self.update_bar()?;
1028 993 }
@@ -1583,14 +1548,26 @@ impl WindowManager {
1583 1548 Ok(true)
1584 1549 }
1585 1550
1586 - fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> {
1587 - if fullscreen && !self.fullscreen_windows.contains(&window) {
1588 - // Save current geometry before fullscreen
1589 - if let Ok(geom) = self.connection.get_geometry(window)?.reply() {
1590 - self.window_geometries.insert(window, (geom.x, geom.y, geom.width, geom.height));
1551 + fn fullscreen(&mut self) -> WmResult<()> {
1552 + if self.show_bar {
1553 + self.last_layout = Some(self.layout.name());
1554 + if let Ok(layout) = layout_from_str("monocle") {
1555 + self.layout = layout;
1591 1556 }
1557 + } else {
1558 + if let Some(last) = self.last_layout {
1559 + if let Ok(layout) = layout_from_str(last) {
1560 + self.layout = layout;
1561 + }
1562 + }
1563 + }
1564 + self.toggle_bar()?;
1565 + Ok(())
1566 + }
1592 1567
1593 - // Set the _NET_WM_STATE property to fullscreen
1568 + fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> {
1569 + if fullscreen && !self.fullscreen_windows.contains(&window) {
1570 + let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec();
1594 1571 self.connection.change_property(
1595 1572 PropMode::REPLACE,
1596 1573 window,
@@ -1598,56 +1575,82 @@ impl WindowManager {
1598 1575 AtomEnum::ATOM,
1599 1576 32,
1600 1577 1,
1601 - &self.atoms.net_wm_state_fullscreen.to_ne_bytes(),
1578 + &bytes,
1602 1579 )?;
1603 1580
1604 1581 self.fullscreen_windows.insert(window);
1582 +
1583 + self.connection.configure_window(
1584 + window,
1585 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1586 + .border_width(0),
1587 + )?;
1588 +
1605 1589 self.floating_windows.insert(window);
1606 1590
1607 - // Get monitor dimensions
1608 - let window_mon = self.window_monitor.get(&window).copied().unwrap_or(self.selected_monitor);
1609 - let monitor = &self.monitors[window_mon];
1591 + let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor);
1592 + let monitor = &self.monitors[monitor_idx];
1610 1593
1611 - // Make window fullscreen across the entire monitor
1612 1594 self.connection.configure_window(
1613 1595 window,
1614 - &ConfigureWindowAux::new()
1596 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1615 1597 .x(monitor.x)
1616 1598 .y(monitor.y)
1617 - .width(monitor.width)
1618 - .height(monitor.height)
1619 - .border_width(0)
1620 - .stack_mode(StackMode::ABOVE),
1599 + .width(monitor.width as u32)
1600 + .height(monitor.height as u32),
1601 + )?;
1602 +
1603 + self.connection.configure_window(
1604 + window,
1605 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1606 + .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE),
1621 1607 )?;
1622 1608
1623 1609 self.connection.flush()?;
1624 1610 } else if !fullscreen && self.fullscreen_windows.contains(&window) {
1625 - // Clear the _NET_WM_STATE property
1626 - self.connection.delete_property(window, self.atoms.net_wm_state)?;
1611 + self.connection.change_property(
1612 + PropMode::REPLACE,
1613 + window,
1614 + self.atoms.net_wm_state,
1615 + AtomEnum::ATOM,
1616 + 32,
1617 + 0,
1618 + &[],
1619 + )?;
1627 1620
1628 1621 self.fullscreen_windows.remove(&window);
1629 1622
1630 - // Restore saved geometry
1631 - if let Some((x, y, width, height)) = self.window_geometries.get(&window) {
1632 - self.connection.configure_window(
1633 - window,
1634 - &ConfigureWindowAux::new()
1635 - .x(*x as i32)
1636 - .y(*y as i32)
1637 - .width(*width as u32)
1638 - .height(*height as u32)
1639 - .border_width(self.config.border_width),
1640 - )?;
1623 + if !self.is_transient_window(window) {
1624 + self.floating_windows.remove(&window);
1641 1625 }
1642 1626
1627 + self.connection.configure_window(
1628 + window,
1629 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1630 + .border_width(self.config.border_width),
1631 + )?;
1632 +
1643 1633 self.apply_layout()?;
1634 + }
1635 +
1636 + Ok(())
1637 + }
1638 +
1639 + fn toggle_bar(&mut self) -> WmResult<()> {
1640 + self.show_bar = !self.show_bar;
1641 + if let Some(bar) = self.bars.get(self.selected_monitor) {
1642 + if self.show_bar {
1643 + self.connection.map_window(bar.window())?;
1644 + } else {
1645 + self.connection.unmap_window(bar.window())?;
1646 + }
1644 1647 self.connection.flush()?;
1645 1648 }
1649 + self.apply_layout()?;
1646 1650 Ok(())
1647 1651 }
1648 1652
1649 1653 fn is_transient_window(&self, window: Window) -> bool {
1650 - // Check if window is transient (e.g., dialog, modal)
1651 1654 let transient_for = self.connection
1652 1655 .get_property(
1653 1656 false,
@@ -1900,11 +1903,6 @@ impl WindowManager {
1900 1903 return Ok(None);
1901 1904 }
1902 1905
1903 - if let Ok(geom) = self.connection.get_geometry(event.window)?.reply() {
1904 - self.window_geometries
1905 - .insert(event.window, (geom.x, geom.y, geom.width, geom.height));
1906 - }
1907 -
1908 1906 self.connection.map_window(event.window)?;
1909 1907 self.connection.change_window_attributes(
1910 1908 event.window,
@@ -1924,37 +1922,61 @@ impl WindowManager {
1924 1922 self.set_wm_state(event.window, 1)?;
1925 1923 let _ = self.save_client_tag(event.window, selected_tags);
1926 1924
1927 - // Auto-float transient windows (e.g., dialogs, modals)
1928 - if self.is_transient_window(event.window) {
1925 + let is_transient = self.is_transient_window(event.window);
1926 + if is_transient {
1929 1927 self.floating_windows.insert(event.window);
1930 1928 }
1931 1929
1930 + let is_normie_layout = self.layout.name() == "normie";
1931 + if is_normie_layout && !is_transient {
1932 + let mut pointer_x: i32 = 0;
1933 + let mut pointer_y: i32 = 0;
1934 + let mut root_return: x11::xlib::Window = 0;
1935 + let mut child_return: x11::xlib::Window = 0;
1936 + let mut win_x: i32 = 0;
1937 + let mut win_y: i32 = 0;
1938 + let mut mask_return: u32 = 0;
1939 +
1940 + let pointer_queried = unsafe {
1941 + x11::xlib::XQueryPointer(
1942 + self.display,
1943 + self.root as x11::xlib::Window,
1944 + &mut root_return,
1945 + &mut child_return,
1946 + &mut pointer_x,
1947 + &mut pointer_y,
1948 + &mut win_x,
1949 + &mut win_y,
1950 + &mut mask_return,
1951 + ) != 0
1952 + };
1953 +
1954 + if pointer_queried {
1955 + let window_width = (self.screen.width_in_pixels as f32 * 0.6) as u32;
1956 + let window_height = (self.screen.height_in_pixels as f32 * 0.6) as u32;
1957 +
1958 + let spawn_x = pointer_x - (window_width as i32 / 2);
1959 + let spawn_y = pointer_y - (window_height as i32 / 2);
1960 +
1961 + self.connection.configure_window(
1962 + event.window,
1963 + &ConfigureWindowAux::new()
1964 + .x(spawn_x)
1965 + .y(spawn_y)
1966 + .width(window_width)
1967 + .height(window_height)
1968 + .border_width(self.config.border_width)
1969 + .stack_mode(StackMode::ABOVE),
1970 + )?;
1971 +
1972 + self.floating_windows.insert(event.window);
1973 + }
1974 + }
1975 +
1932 1976 self.apply_layout()?;
1933 1977 self.update_bar()?;
1934 1978 self.set_focus(event.window)?;
1935 1979 }
1936 - Event::ClientMessage(event) => {
1937 - // Handle _NET_WM_STATE fullscreen requests from clients
1938 - if event.type_ == self.atoms.net_wm_state {
1939 - let data = event.data.as_data32();
1940 - let action = data[0]; // 0 = remove, 1 = add, 2 = toggle
1941 - let property1 = data[1];
1942 - let property2 = data[2];
1943 -
1944 - if property1 == self.atoms.net_wm_state_fullscreen || property2 == self.atoms.net_wm_state_fullscreen {
1945 - if self.windows.contains(&event.window) {
1946 - let is_fullscreen = self.fullscreen_windows.contains(&event.window);
1947 - let should_fullscreen = match action {
1948 - 0 => false, // Remove
1949 - 1 => true, // Add
1950 - 2 => !is_fullscreen, // Toggle
1951 - _ => is_fullscreen,
1952 - };
1953 - self.set_window_fullscreen(event.window, should_fullscreen)?;
1954 - }
1955 - }
1956 - }
1957 - }
1958 1980 Event::UnmapNotify(event) => {
1959 1981 if self.windows.contains(&event.window) && self.is_window_visible(event.window) {
1960 1982 self.remove_window(event.window)?;
@@ -2093,6 +2115,22 @@ impl WindowManager {
2093 2115 }
2094 2116 }
2095 2117 }
2118 + Event::ClientMessage(event) => {
2119 + if event.type_ == self.atoms.net_wm_state {
2120 + if let Some(data) = event.data.as_data32().get(1) {
2121 + if *data == self.atoms.net_wm_state_fullscreen {
2122 + let action = event.data.as_data32()[0];
2123 + let fullscreen = match action {
2124 + 1 => true,
2125 + 0 => false,
2126 + 2 => !self.fullscreen_windows.contains(&event.window),
2127 + _ => return Ok(None),
2128 + };
2129 + self.set_window_fullscreen(event.window, fullscreen)?;
2130 + }
2131 + }
2132 + }
2133 + }
2096 2134 _ => {}
2097 2135 }
2098 2136 Ok(None)
@@ -2104,13 +2142,9 @@ impl WindowManager {
2104 2142 }
2105 2143
2106 2144 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
2107 - let border_width = if monitor.fullscreen_enabled {
2108 - 0
2109 - } else {
2110 - self.config.border_width
2111 - };
2145 + let border_width = self.config.border_width;
2112 2146
2113 - let gaps = if self.gaps_enabled && !monitor.fullscreen_enabled {
2147 + let gaps = if self.gaps_enabled {
2114 2148 GapConfig {
2115 2149 inner_horizontal: self.config.gap_inner_horizontal,
2116 2150 inner_vertical: self.config.gap_inner_vertical,
@@ -2146,13 +2180,13 @@ impl WindowManager {
2146 2180 .copied()
2147 2181 .collect();
2148 2182
2149 - let bar_height = if monitor.fullscreen_enabled {
2150 - 0
2151 - } else {
2183 + let bar_height = if self.show_bar {
2152 2184 self.bars
2153 2185 .get(monitor_index)
2154 2186 .map(|b| b.height() as u32)
2155 2187 .unwrap_or(0)
2188 + } else {
2189 + 0
2156 2190 };
2157 2191 let usable_height = monitor.height.saturating_sub(bar_height);
2158 2192
@@ -2191,12 +2225,11 @@ impl WindowManager {
2191 2225
2192 2226 fn remove_window(&mut self, window: Window) -> WmResult<()> {
2193 2227 let initial_count = self.windows.len();
2228 +
2194 2229 self.windows.retain(|&w| w != window);
2195 2230 self.window_tags.remove(&window);
2196 2231 self.window_monitor.remove(&window);
2197 - self.window_geometries.remove(&window);
2198 2232 self.floating_windows.remove(&window);
2199 - self.fullscreen_windows.remove(&window);
2200 2233
2201 2234 if self.windows.len() < initial_count {
2202 2235 let focused = self
+58 −19 templates/config.lua
@@ -173,27 +173,66 @@ oxwm.key.chord({
173 173 -------------------------------------------------------------------------------
174 174 -- Status Bar Blocks
175 175 -------------------------------------------------------------------------------
176 --- Add informational blocks to the status bar
177 --- Format: oxwm.bar.add_block(format, type, data, update_interval, color, separator)
176 +-- Add informational blocks to the status bar using block constructors
177 +-- Each block is created with oxwm.bar.block.<type>() and configured with a table:
178 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)
179 +-- interval: Seconds between updates
182 180 -- color: Text color (from color palette)
183 --- separator: Whether to add space after this block
184 -
185 -oxwm.bar.add_block("Ram: {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true)
186 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false)
187 -oxwm.bar.add_block("Kernel: {}", "Shell", "uname -r", 999999999, colors.red, true)
188 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false)
189 -oxwm.bar.add_block("{}", "DateTime", "%a, %b %d - %-I:%M %P", 1, colors.cyan, true)
190 -
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)
181 +-- underline: Whether to underline the block
182 +--
183 +-- Available block types:
184 +-- ram(config) - Memory usage
185 +-- datetime(config) - Date and time (requires date_format field)
186 +-- shell(config) - Shell command output (requires command field)
187 +-- static(config) - Static text (requires text field)
188 +-- battery(config) - Battery status (requires charging, discharging, full fields)
189 +
190 +oxwm.bar.set_blocks({
191 + oxwm.bar.block.ram({
192 + format = "Ram: {used}/{total} GB",
193 + interval = 5,
194 + color = colors.light_blue,
195 + underline = true,
196 + }),
197 + oxwm.bar.block.static({
198 + format = "{}",
199 + text = " │ ",
200 + interval = 999999999,
201 + color = colors.lavender,
202 + underline = false,
203 + }),
204 + oxwm.bar.block.shell({
205 + format = "Kernel: {}",
206 + command = "uname -r",
207 + interval = 999999999,
208 + color = colors.red,
209 + underline = true,
210 + }),
211 + oxwm.bar.block.static({
212 + format = "{}",
213 + text = " │ ",
214 + interval = 999999999,
215 + color = colors.lavender,
216 + underline = false,
217 + }),
218 + oxwm.bar.block.datetime({
219 + format = "{}",
220 + date_format = "%a, %b %d - %-I:%M %P",
221 + interval = 1,
222 + color = colors.cyan,
223 + underline = true,
224 + }),
225 + -- Uncomment to add battery status (useful for laptops)
226 + -- oxwm.bar.block.battery({
227 + -- format = "Bat: {}%",
228 + -- charging = "⚡ Bat: {}%",
229 + -- discharging = "🔋 Bat: {}%",
230 + -- full = "✓ Bat: {}%",
231 + -- interval = 30,
232 + -- color = colors.green,
233 + -- underline = true,
234 + -- }),
235 +})
197 236
198 237 -------------------------------------------------------------------------------
199 238 -- Autostart
+54 −4 templates/oxwm.lua
@@ -1,6 +1,18 @@
1 1 ---@meta
2 2
3 ----OXWM Configuration API
3 +---OXWM Configuration API Type Definitions
4 +---
5 +---DO NOT EDIT THIS FILE
6 +---This file is automatically generated and managed by OXWM.
7 +---It will be overwritten on every OXWM update to match the running version.
8 +---
9 +---Location: ~/.config/oxwm/lib/oxwm.lua
10 +---Configured via: ~/.config/oxwm/.luarc.json
11 +---
12 +---This file provides LSP autocomplete and type checking for your config.lua.
13 +---To use it, add this to the top of your config.lua:
14 +--- ---@module 'oxwm'
15 +---
4 16 ---@class oxwm
5 17 oxwm = {}
6 18
@@ -9,6 +21,10 @@ oxwm = {}
9 21 ---@return table Action table for keybinding
10 22 function oxwm.spawn(cmd) end
11 23
24 +---Spawn the configured terminal emulator
25 +---@return table Action table for keybinding
26 +function oxwm.spawn_terminal() end
27 +
12 28 ---Set the terminal emulator
13 29 ---@param terminal string Terminal command (e.g., "st", "alacritty")
14 30 function oxwm.set_terminal(terminal) end
@@ -181,15 +197,49 @@ oxwm.bar = {}
181 197 ---@param font string Font string (e.g., "monospace:style=Bold:size=10")
182 198 function oxwm.bar.set_font(font) end
183 199
184 ----Add a status bar block
200 +---DEPRECATED: Add a status bar block (use oxwm.bar.set_blocks with block constructors instead)
201 +---@deprecated
185 202 ---@param format string Format string with {} placeholders
186 ----@param command "DateTime"|"Shell"|"Ram"|"Static"|"Battery" Block command type
187 ----@param arg string|table|nil Command argument (format for DateTime, command for Shell, text for Static, formats table for Battery, nil for Ram)
203 +---@param command "DateTime"|"Shell"|"Ram"|"Static" Block command type (Battery not supported)
204 +---@param arg string|nil Command argument (format for DateTime, command for Shell, text for Static, nil for Ram)
188 205 ---@param interval integer Update interval in seconds
189 206 ---@param color string|integer Color as hex string or integer
190 207 ---@param underline boolean Whether to underline the block
191 208 function oxwm.bar.add_block(format, command, arg, interval, color, underline) end
192 209
210 +---Set status bar blocks using block constructors
211 +---@param blocks table[] Array of block configurations created with oxwm.bar.block.*
212 +function oxwm.bar.set_blocks(blocks) end
213 +
214 +---Block constructors module
215 +---@class oxwm.bar.block
216 +oxwm.bar.block = {}
217 +
218 +---Create a RAM usage block
219 +---@param config {format: string, interval: integer, color: string|integer, underline: boolean} Block configuration
220 +---@return table Block configuration
221 +function oxwm.bar.block.ram(config) end
222 +
223 +---Create a date/time block
224 +---@param config {format: string, date_format: string, interval: integer, color: string|integer, underline: boolean} Block configuration (format is display template with {}, date_format is strftime format)
225 +---@return table Block configuration
226 +function oxwm.bar.block.datetime(config) end
227 +
228 +---Create a shell command block
229 +---@param config {format: string, command: string, interval: integer, color: string|integer, underline: boolean} Block configuration
230 +---@return table Block configuration
231 +function oxwm.bar.block.shell(config) end
232 +
233 +---Create a static text block
234 +---@param config {format: string, text: string, interval: integer, color: string|integer, underline: boolean} Block configuration
235 +---@return table Block configuration
236 +function oxwm.bar.block.static(config) end
237 +
238 +---Create a battery status block
239 +---@param config {format: string, charging: string, discharging: string, full: string, interval: integer, color: string|integer, underline: boolean} Block configuration
240 +---@return table Block configuration
241 +function oxwm.bar.block.battery(config) end
242 +
193 243 ---Set normal tag color scheme (unselected, no windows)
194 244 ---@param foreground string|integer Foreground color
195 245 ---@param background string|integer Background color