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 [[package]] 298 [[package]]
299 name = "oxwm" 299 name = "oxwm"
300 -version = "0.7.0" 300 +version = "0.7.1"
301 dependencies = [ 301 dependencies = [
302 "anyhow", 302 "anyhow",
303 "chrono", 303 "chrono",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 [package] 1 [package]
2 name = "oxwm" 2 name = "oxwm"
3 -version = "0.7.0" 3 +version = "0.7.1"
4 edition = "2024" 4 edition = "2024"
5 5
6 [lib] 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 ---Using the new functional API 3 ---Using the new functional API
4 ---Edit this file and reload with Mod+Alt+R 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 ---@module 'oxwm' 15 ---@module 'oxwm'
8 16
9 17
10 --- Set variables as needed
11 --- Colors
12 local colors = { 18 local colors = {
13 lavender = 0xa9b1d6, 19 lavender = 0xa9b1d6,
14 light_blue = 0x7aa2f7, 20 light_blue = 0x7aa2f7,
@@ -22,81 +28,63 @@ local colors = {
22 blue = 0x6dade3, 28 blue = 0x6dade3,
23 } 29 }
24 30
25 -local modkey = "Mod1"; 31 +local modkey = "Mod1"
26 32
27 --- Basic settings
28 oxwm.set_terminal("st") 33 oxwm.set_terminal("st")
29 oxwm.set_modkey(modkey) 34 oxwm.set_modkey(modkey)
30 oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }) 35 oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" })
31 36
32 --- Layout symbol overrides
33 oxwm.set_layout_symbol("tiling", "[T]") 37 oxwm.set_layout_symbol("tiling", "[T]")
34 oxwm.set_layout_symbol("normie", "[F]") 38 oxwm.set_layout_symbol("normie", "[F]")
35 39
36 --- Border configuration
37 oxwm.border.set_width(2) 40 oxwm.border.set_width(2)
38 oxwm.border.set_focused_color(colors.blue) 41 oxwm.border.set_focused_color(colors.blue)
39 oxwm.border.set_unfocused_color(colors.grey) 42 oxwm.border.set_unfocused_color(colors.grey)
40 43
41 --- Gap configuration
42 oxwm.gaps.set_enabled(true) 44 oxwm.gaps.set_enabled(true)
43 oxwm.gaps.set_inner(5, 5) 45 oxwm.gaps.set_inner(5, 5)
44 oxwm.gaps.set_outer(5, 5) 46 oxwm.gaps.set_outer(5, 5)
45 47
46 --- Bar configuration
47 oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12") 48 oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12")
48 49
49 --- Bar color schemes (for tag display)
50 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, 0x444444) 50 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, 0x444444)
51 oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan) 51 oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan)
52 oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) 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 oxwm.key.chord({ 54 oxwm.key.chord({
58 { { modkey }, "Space" }, 55 { { modkey }, "Space" },
59 { {}, "T" } 56 { {}, "T" }
60 }, oxwm.spawn("st")) 57 }, oxwm.spawn("st"))
61 58
62 --- Basic window management
63 oxwm.key.bind({ modkey }, "Return", oxwm.spawn("st")) 59 oxwm.key.bind({ modkey }, "Return", oxwm.spawn("st"))
64 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) 60 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
65 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) 61 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
66 oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) 62 oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
67 63
68 --- Keybind overlay
69 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds()) 64 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
70 65
71 --- Client actions
72 oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen()) 66 oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen())
73 oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating()) 67 oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating())
74 68
75 --- Layout management
76 oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie")) 69 oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie"))
77 oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling")) 70 oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling"))
78 oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle()) 71 oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
79 72
80 --- Gaps toggle
81 oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) 73 oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
82 74
83 --- WM controls
84 oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) 75 oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
85 oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) 76 oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
86 77
87 --- Focus direction (vim keys)
88 oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left")) 78 oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left"))
89 oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down")) 79 oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down"))
90 oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up")) 80 oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up"))
91 oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right")) 81 oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right"))
92 82
93 --- Swap windows in direction
94 oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left")) 83 oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left"))
95 oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down")) 84 oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down"))
96 oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up")) 85 oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up"))
97 oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right")) 86 oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right"))
98 87
99 --- Tag viewing
100 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0)) 88 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
101 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1)) 89 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
102 oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2)) 90 oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
@@ -107,7 +95,6 @@ oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
107 oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7)) 95 oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
108 oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8)) 96 oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
109 97
110 --- Move window to tag
111 oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0)) 98 oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
112 oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1)) 99 oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
113 oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2)) 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 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7)) 105 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
119 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8)) 106 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
120 107
121 --- Status bar blocks 108 +oxwm.bar.set_blocks({
122 -oxwm.bar.add_block("", "Battery", { 109 + oxwm.bar.block.battery({
123 - charging = "󰂄 Bat: {}%", 110 + charging = "󰂄 Bat: {}%",
124 - discharging = "󰁹 Bat:{}%", 111 + discharging = "󰁹 Bat: {}%",
125 - full = "󰁹 Bat: {}%" 112 + full = "󰁹 Bat: {}%",
126 -}, 30, colors.green, true) 113 + format = "",
127 - 114 + interval = 30,
128 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false) 115 + color = colors.green,
129 -oxwm.bar.add_block("󰍛 {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true) 116 + underline = true
130 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false) 117 + }),
131 -oxwm.bar.add_block(" {}", "Shell", "uname -r", 999999999, colors.red, true) 118 + oxwm.bar.block.static({
132 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false) 119 + text = " │ ",
133 -oxwm.bar.add_block("󰸘 {}", "DateTime", "%a, %b %d - %-I:%M %P", 1, colors.cyan, true) 120 + format = "",
134 - 121 + interval = 999999999,
135 --- Autostart commands (runs once at startup) 122 + color = colors.lavender,
136 --- oxwm.autostart("picom") 123 + underline = false
137 --- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg") 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 width: u16, 13 width: u16,
14 height: u16, 14 height: u16,
15 graphics_context: Gcontext, 15 graphics_context: Gcontext,
16 + pixmap: x11::xlib::Pixmap,
17 + display: *mut x11::xlib::Display,
16 18
17 font_draw: FontDraw, 19 font_draw: FontDraw,
18 20
@@ -77,8 +79,19 @@ impl Bar {
77 79
78 let visual = unsafe { x11::xlib::XDefaultVisual(display, screen_num as i32) }; 80 let visual = unsafe { x11::xlib::XDefaultVisual(display, screen_num as i32) };
79 let colormap = unsafe { x11::xlib::XDefaultColormap(display, screen_num as i32) }; 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 let horizontal_padding = (font.height() as f32 * 0.4) as u16; 96 let horizontal_padding = (font.height() as f32 * 0.4) as u16;
84 97
@@ -110,6 +123,8 @@ impl Bar {
110 width, 123 width,
111 height, 124 height,
112 graphics_context, 125 graphics_context,
126 + pixmap,
127 + display,
113 font_draw, 128 font_draw,
114 tag_widths, 129 tag_widths,
115 needs_redraw: true, 130 needs_redraw: true,
@@ -182,16 +197,22 @@ impl Bar {
182 self.graphics_context, 197 self.graphics_context,
183 &ChangeGCAux::new().foreground(self.scheme_normal.background), 198 &ChangeGCAux::new().foreground(self.scheme_normal.background),
184 )?; 199 )?;
185 - connection.poly_fill_rectangle( 200 + connection.flush()?;
186 - self.window, 201 +
187 - self.graphics_context, 202 + unsafe {
188 - &[Rectangle { 203 + let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
189 - x: 0, 204 + x11::xlib::XSetForeground(display, gc, self.scheme_normal.background as u64);
190 - y: 0, 205 + x11::xlib::XFillRectangle(
191 - width: self.width, 206 + display,
192 - height: self.height, 207 + self.pixmap,
193 - }], 208 + gc,
194 - )?; 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 let mut x_position: i16 = 0; 217 let mut x_position: i16 = 0;
197 218
@@ -229,20 +250,20 @@ impl Bar {
229 let underline_width = tag_width - underline_padding; 250 let underline_width = tag_width - underline_padding;
230 let underline_x = x_position + (underline_padding / 2) as i16; 251 let underline_x = x_position + (underline_padding / 2) as i16;
231 252
232 - connection.change_gc( 253 + unsafe {
233 - self.graphics_context, 254 + let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
234 - &ChangeGCAux::new().foreground(scheme.underline), 255 + x11::xlib::XSetForeground(display, gc, scheme.underline as u64);
235 - )?; 256 + x11::xlib::XFillRectangle(
236 - connection.poly_fill_rectangle( 257 + display,
237 - self.window, 258 + self.pixmap,
238 - self.graphics_context, 259 + gc,
239 - &[Rectangle { 260 + underline_x as i32,
240 - x: underline_x, 261 + underline_y as i32,
241 - y: underline_y, 262 + underline_width as u32,
242 - width: underline_width, 263 + underline_height as u32,
243 - height: underline_height, 264 + );
244 - }], 265 + x11::xlib::XFreeGC(display, gc);
245 - )?; 266 + }
246 } 267 }
247 268
248 x_position += tag_width as i16; 269 x_position += tag_width as i16;
@@ -304,29 +325,43 @@ impl Bar {
304 let underline_width = text_width + underline_padding; 325 let underline_width = text_width + underline_padding;
305 let underline_x = x_position - (underline_padding / 2) as i16; 326 let underline_x = x_position - (underline_padding / 2) as i16;
306 327
307 - connection.change_gc( 328 + unsafe {
308 - self.graphics_context, 329 + let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
309 - &ChangeGCAux::new().foreground(block.color()), 330 + x11::xlib::XSetForeground(display, gc, block.color() as u64);
310 - )?; 331 + x11::xlib::XFillRectangle(
311 - 332 + display,
312 - connection.poly_fill_rectangle( 333 + self.pixmap,
313 - self.window, 334 + gc,
314 - self.graphics_context, 335 + underline_x as i32,
315 - &[Rectangle { 336 + underline_y as i32,
316 - x: underline_x, 337 + underline_width as u32,
317 - y: underline_y, 338 + underline_height as u32,
318 - width: underline_width, 339 + );
319 - height: underline_height, 340 + x11::xlib::XFreeGC(display, gc);
320 - }], 341 + }
321 - )?;
322 } 342 }
323 } 343 }
324 } 344 }
325 } 345 }
326 - connection.flush()?; 346 +
327 unsafe { 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 self.needs_redraw = false; 365 self.needs_redraw = false;
331 366
332 Ok(()) 367 Ok(())
@@ -372,3 +407,11 @@ impl Bar {
372 self.needs_redraw = true; 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 println!(" Please manually port your configuration to the new Lua format."); 73 println!(" Please manually port your configuration to the new Lua format.");
74 println!(" See the new config.lua template for examples.\n"); 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 lua_path 81 lua_path
@@ -102,18 +105,42 @@ fn init_config() -> Result<()> {
102 let config_path = config_dir.join("config.lua"); 105 let config_path = config_dir.join("config.lua");
103 std::fs::write(&config_path, config_template)?; 106 std::fs::write(&config_path, config_template)?;
104 107
105 - let oxwm_lua_template = include_str!("../../templates/oxwm.lua"); 108 + // Update LSP files
106 - let oxwm_lua_path = config_dir.join("oxwm.lua"); 109 + update_lsp_files()?;
107 - std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
108 110
109 println!("✓ Config created at {:?}", config_path); 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 println!(" Edit the file and reload with Mod+Shift+R"); 113 println!(" Edit the file and reload with Mod+Shift+R");
112 println!(" No compilation needed - changes take effect immediately!"); 114 println!(" No compilation needed - changes take effect immediately!");
113 115
114 Ok(()) 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 fn get_config_path() -> PathBuf { 144 fn get_config_path() -> PathBuf {
118 dirs::config_dir() 145 dirs::config_dir()
119 .expect("Could not find config directory") 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 fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> { 394 fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> {
395 let action = match s { 395 let action = match s {
396 "Spawn" => KeyAction::Spawn, 396 "Spawn" => KeyAction::Spawn,
397 + "SpawnTerminal" => KeyAction::SpawnTerminal,
397 "KillClient" => KeyAction::KillClient, 398 "KillClient" => KeyAction::KillClient,
398 "FocusStack" => KeyAction::FocusStack, 399 "FocusStack" => KeyAction::FocusStack,
399 "FocusDirection" => KeyAction::FocusDirection, 400 "FocusDirection" => KeyAction::FocusDirection,
@@ -404,7 +405,6 @@ fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> {
404 "ViewTag" => KeyAction::ViewTag, 405 "ViewTag" => KeyAction::ViewTag,
405 "ToggleGaps" => KeyAction::ToggleGaps, 406 "ToggleGaps" => KeyAction::ToggleGaps,
406 "ToggleFullScreen" => KeyAction::ToggleFullScreen, 407 "ToggleFullScreen" => KeyAction::ToggleFullScreen,
407 - "ToggleWindowFullscreen" => KeyAction::ToggleWindowFullscreen,
408 "ToggleFloating" => KeyAction::ToggleFloating, 408 "ToggleFloating" => KeyAction::ToggleFloating,
409 "ChangeLayout" => KeyAction::ChangeLayout, 409 "ChangeLayout" => KeyAction::ChangeLayout,
410 "CycleLayout" => KeyAction::CycleLayout, 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 pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> { 75 pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
76 let builder = Rc::new(RefCell::new(ConfigBuilder::default())); 76 let builder = Rc::new(RefCell::new(ConfigBuilder::default()));
77 77
78 - let oxwm_table = lua.create_table() 78 + let oxwm_table = lua.create_table()?;
79 - .map_err(|e| ConfigError::LuaError(format!("Failed to create oxwm table: {}", e)))?;
80 79
81 register_spawn(&lua, &oxwm_table, builder.clone())?; 80 register_spawn(&lua, &oxwm_table, builder.clone())?;
82 register_key_module(&lua, &oxwm_table, builder.clone())?; 81 register_key_module(&lua, &oxwm_table, builder.clone())?;
@@ -88,8 +87,7 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
88 register_bar_module(&lua, &oxwm_table, builder.clone())?; 87 register_bar_module(&lua, &oxwm_table, builder.clone())?;
89 register_misc(&lua, &oxwm_table, builder.clone())?; 88 register_misc(&lua, &oxwm_table, builder.clone())?;
90 89
91 - lua.globals().set("oxwm", oxwm_table) 90 + lua.globals().set("oxwm", oxwm_table)?;
92 - .map_err(|e| ConfigError::LuaError(format!("Failed to set oxwm global: {}", e)))?;
93 91
94 Ok(builder) 92 Ok(builder)
95 } 93 }
@@ -97,15 +95,17 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
97 fn register_spawn(lua: &Lua, parent: &Table, _builder: SharedBuilder) -> Result<(), ConfigError> { 95 fn register_spawn(lua: &Lua, parent: &Table, _builder: SharedBuilder) -> Result<(), ConfigError> {
98 let spawn = lua.create_function(|lua, cmd: Value| { 96 let spawn = lua.create_function(|lua, cmd: Value| {
99 create_action_table(lua, "Spawn", cmd) 97 create_action_table(lua, "Spawn", cmd)
100 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create spawn: {}", e)))?; 98 + })?;
101 - parent.set("spawn", spawn) 99 + let spawn_terminal = lua.create_function(|lua, ()| {
102 - .map_err(|e| ConfigError::LuaError(format!("Failed to set spawn: {}", e)))?; 100 + create_action_table(lua, "SpawnTerminal", Value::Nil)
101 + })?;
102 + parent.set("spawn", spawn)?;
103 + parent.set("spawn_terminal", spawn_terminal)?;
103 Ok(()) 104 Ok(())
104 } 105 }
105 106
106 fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 107 fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
107 - let key_table = lua.create_table() 108 + let key_table = lua.create_table()?;
108 - .map_err(|e| ConfigError::LuaError(format!("Failed to create key table: {}", e)))?;
109 109
110 let builder_clone = builder.clone(); 110 let builder_clone = builder.clone();
111 let bind = lua.create_function(move |lua, (mods, key, action): (Value, String, Value)| { 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 builder_clone.borrow_mut().keybindings.push(binding); 117 builder_clone.borrow_mut().keybindings.push(binding);
118 118
119 Ok(()) 119 Ok(())
120 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create bind: {}", e)))?; 120 + })?;
121 121
122 let builder_clone = builder.clone(); 122 let builder_clone = builder.clone();
123 let chord = lua.create_function(move |lua, (keys, action): (Table, Value)| { 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 builder_clone.borrow_mut().keybindings.push(binding); 139 builder_clone.borrow_mut().keybindings.push(binding);
140 140
141 Ok(()) 141 Ok(())
142 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create chord: {}", e)))?; 142 + })?;
143 - 143 +
144 - key_table.set("bind", bind) 144 + key_table.set("bind", bind)?;
145 - .map_err(|e| ConfigError::LuaError(format!("Failed to set bind: {}", e)))?; 145 + key_table.set("chord", chord)?;
146 - key_table.set("chord", chord) 146 + parent.set("key", key_table)?;
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)))?;
150 Ok(()) 147 Ok(())
151 } 148 }
152 149
153 fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 150 fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
154 - let gaps_table = lua.create_table() 151 + let gaps_table = lua.create_table()?;
155 - .map_err(|e| ConfigError::LuaError(format!("Failed to create gaps table: {}", e)))?;
156 152
157 let builder_clone = builder.clone(); 153 let builder_clone = builder.clone();
158 let set_enabled = lua.create_function(move |_, enabled: bool| { 154 let set_enabled = lua.create_function(move |_, enabled: bool| {
159 builder_clone.borrow_mut().gaps_enabled = enabled; 155 builder_clone.borrow_mut().gaps_enabled = enabled;
160 Ok(()) 156 Ok(())
161 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_enabled: {}", e)))?; 157 + })?;
162 158
163 let builder_clone = builder.clone(); 159 let builder_clone = builder.clone();
164 let enable = lua.create_function(move |_, ()| { 160 let enable = lua.create_function(move |_, ()| {
165 builder_clone.borrow_mut().gaps_enabled = true; 161 builder_clone.borrow_mut().gaps_enabled = true;
166 Ok(()) 162 Ok(())
167 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create enable: {}", e)))?; 163 + })?;
168 164
169 let builder_clone = builder.clone(); 165 let builder_clone = builder.clone();
170 let disable = lua.create_function(move |_, ()| { 166 let disable = lua.create_function(move |_, ()| {
171 builder_clone.borrow_mut().gaps_enabled = false; 167 builder_clone.borrow_mut().gaps_enabled = false;
172 Ok(()) 168 Ok(())
173 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create disable: {}", e)))?; 169 + })?;
174 170
175 let builder_clone = builder.clone(); 171 let builder_clone = builder.clone();
176 let set_inner = lua.create_function(move |_, (h, v): (u32, u32)| { 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 b.gap_inner_horizontal = h; 174 b.gap_inner_horizontal = h;
179 b.gap_inner_vertical = v; 175 b.gap_inner_vertical = v;
180 Ok(()) 176 Ok(())
181 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_inner: {}", e)))?; 177 + })?;
182 178
183 let builder_clone = builder.clone(); 179 let builder_clone = builder.clone();
184 let set_outer = lua.create_function(move |_, (h, v): (u32, u32)| { 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 b.gap_outer_horizontal = h; 182 b.gap_outer_horizontal = h;
187 b.gap_outer_vertical = v; 183 b.gap_outer_vertical = v;
188 Ok(()) 184 Ok(())
189 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_outer: {}", e)))?; 185 + })?;
190 - 186 +
191 - gaps_table.set("set_enabled", set_enabled) 187 + gaps_table.set("set_enabled", set_enabled)?;
192 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_enabled: {}", e)))?; 188 + gaps_table.set("enable", enable)?;
193 - gaps_table.set("enable", enable) 189 + gaps_table.set("disable", disable)?;
194 - .map_err(|e| ConfigError::LuaError(format!("Failed to set enable: {}", e)))?; 190 + gaps_table.set("set_inner", set_inner)?;
195 - gaps_table.set("disable", disable) 191 + gaps_table.set("set_outer", set_outer)?;
196 - .map_err(|e| ConfigError::LuaError(format!("Failed to set disable: {}", e)))?; 192 + parent.set("gaps", gaps_table)?;
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)))?;
203 Ok(()) 193 Ok(())
204 } 194 }
205 195
206 fn register_border_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 196 fn register_border_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
207 - let border_table = lua.create_table() 197 + let border_table = lua.create_table()?;
208 - .map_err(|e| ConfigError::LuaError(format!("Failed to create border table: {}", e)))?;
209 198
210 let builder_clone = builder.clone(); 199 let builder_clone = builder.clone();
211 let set_width = lua.create_function(move |_, width: u32| { 200 let set_width = lua.create_function(move |_, width: u32| {
212 builder_clone.borrow_mut().border_width = width; 201 builder_clone.borrow_mut().border_width = width;
213 Ok(()) 202 Ok(())
214 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_width: {}", e)))?; 203 + })?;
215 204
216 let builder_clone = builder.clone(); 205 let builder_clone = builder.clone();
217 let set_focused_color = lua.create_function(move |_, color: Value| { 206 let set_focused_color = lua.create_function(move |_, color: Value| {
218 let color_u32 = parse_color_value(color)?; 207 let color_u32 = parse_color_value(color)?;
219 builder_clone.borrow_mut().border_focused = color_u32; 208 builder_clone.borrow_mut().border_focused = color_u32;
220 Ok(()) 209 Ok(())
221 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_focused_color: {}", e)))?; 210 + })?;
222 211
223 let builder_clone = builder.clone(); 212 let builder_clone = builder.clone();
224 let set_unfocused_color = lua.create_function(move |_, color: Value| { 213 let set_unfocused_color = lua.create_function(move |_, color: Value| {
225 let color_u32 = parse_color_value(color)?; 214 let color_u32 = parse_color_value(color)?;
226 builder_clone.borrow_mut().border_unfocused = color_u32; 215 builder_clone.borrow_mut().border_unfocused = color_u32;
227 Ok(()) 216 Ok(())
228 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_unfocused_color: {}", e)))?; 217 + })?;
229 - 218 +
230 - border_table.set("set_width", set_width) 219 + border_table.set("set_width", set_width)?;
231 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_width: {}", e)))?; 220 + border_table.set("set_focused_color", set_focused_color)?;
232 - border_table.set("set_focused_color", set_focused_color) 221 + border_table.set("set_unfocused_color", set_unfocused_color)?;
233 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_focused_color: {}", e)))?; 222 + parent.set("border", border_table)?;
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)))?;
238 Ok(()) 223 Ok(())
239 } 224 }
240 225
241 fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> { 226 fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
242 - let client_table = lua.create_table() 227 + let client_table = lua.create_table()?;
243 - .map_err(|e| ConfigError::LuaError(format!("Failed to create client table: {}", e)))?;
244 228
245 let kill = lua.create_function(|lua, ()| { 229 let kill = lua.create_function(|lua, ()| {
246 create_action_table(lua, "KillClient", Value::Nil) 230 create_action_table(lua, "KillClient", Value::Nil)
247 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create kill: {}", e)))?; 231 + })?;
248 232
249 let toggle_fullscreen = lua.create_function(|lua, ()| { 233 let toggle_fullscreen = lua.create_function(|lua, ()| {
250 create_action_table(lua, "ToggleFullScreen", Value::Nil) 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 let toggle_floating = lua.create_function(|lua, ()| { 237 let toggle_floating = lua.create_function(|lua, ()| {
254 create_action_table(lua, "ToggleFloating", Value::Nil) 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 let focus_stack = lua.create_function(|lua, dir: i32| { 241 let focus_stack = lua.create_function(|lua, dir: i32| {
258 create_action_table(lua, "FocusStack", Value::Integer(dir as i64)) 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 let focus_direction = lua.create_function(|lua, dir: String| { 245 let focus_direction = lua.create_function(|lua, dir: String| {
262 let dir_int = direction_string_to_int(&dir)?; 246 let dir_int = direction_string_to_int(&dir)?;
263 create_action_table(lua, "FocusDirection", Value::Integer(dir_int)) 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 let swap_direction = lua.create_function(|lua, dir: String| { 250 let swap_direction = lua.create_function(|lua, dir: String| {
267 let dir_int = direction_string_to_int(&dir)?; 251 let dir_int = direction_string_to_int(&dir)?;
268 create_action_table(lua, "SwapDirection", Value::Integer(dir_int)) 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 let smart_move = lua.create_function(|lua, dir: String| { 255 let smart_move = lua.create_function(|lua, dir: String| {
272 let dir_int = direction_string_to_int(&dir)?; 256 let dir_int = direction_string_to_int(&dir)?;
273 create_action_table(lua, "SmartMoveWin", Value::Integer(dir_int)) 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 let exchange = lua.create_function(|lua, ()| { 260 let exchange = lua.create_function(|lua, ()| {
277 create_action_table(lua, "ExchangeClient", Value::Nil) 261 create_action_table(lua, "ExchangeClient", Value::Nil)
278 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create exchange: {}", e)))?; 262 + })?;
279 - 263 +
280 - client_table.set("kill", kill) 264 + client_table.set("kill", kill)?;
281 - .map_err(|e| ConfigError::LuaError(format!("Failed to set kill: {}", e)))?; 265 + client_table.set("toggle_fullscreen", toggle_fullscreen)?;
282 - client_table.set("toggle_fullscreen", toggle_fullscreen) 266 + client_table.set("toggle_floating", toggle_floating)?;
283 - .map_err(|e| ConfigError::LuaError(format!("Failed to set toggle_fullscreen: {}", e)))?; 267 + client_table.set("focus_stack", focus_stack)?;
284 - client_table.set("toggle_floating", toggle_floating) 268 + client_table.set("focus_direction", focus_direction)?;
285 - .map_err(|e| ConfigError::LuaError(format!("Failed to set toggle_floating: {}", e)))?; 269 + client_table.set("swap_direction", swap_direction)?;
286 - client_table.set("focus_stack", focus_stack) 270 + client_table.set("smart_move", smart_move)?;
287 - .map_err(|e| ConfigError::LuaError(format!("Failed to set focus_stack: {}", e)))?; 271 + client_table.set("exchange", exchange)?;
288 - client_table.set("focus_direction", focus_direction) 272 +
289 - .map_err(|e| ConfigError::LuaError(format!("Failed to set focus_direction: {}", e)))?; 273 + parent.set("client", client_table)?;
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)))?;
299 Ok(()) 274 Ok(())
300 } 275 }
301 276
302 fn register_layout_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> { 277 fn register_layout_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
303 - let layout_table = lua.create_table() 278 + let layout_table = lua.create_table()?;
304 - .map_err(|e| ConfigError::LuaError(format!("Failed to create layout table: {}", e)))?;
305 279
306 let cycle = lua.create_function(|lua, ()| { 280 let cycle = lua.create_function(|lua, ()| {
307 create_action_table(lua, "CycleLayout", Value::Nil) 281 create_action_table(lua, "CycleLayout", Value::Nil)
308 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create cycle: {}", e)))?; 282 + })?;
309 283
310 let set = lua.create_function(|lua, name: String| { 284 let set = lua.create_function(|lua, name: String| {
311 create_action_table(lua, "ChangeLayout", Value::String(lua.create_string(&name)?)) 285 create_action_table(lua, "ChangeLayout", Value::String(lua.create_string(&name)?))
312 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set: {}", e)))?; 286 + })?;
313 - 287 +
314 - layout_table.set("cycle", cycle) 288 + layout_table.set("cycle", cycle)?;
315 - .map_err(|e| ConfigError::LuaError(format!("Failed to set cycle: {}", e)))?; 289 + layout_table.set("set", set)?;
316 - layout_table.set("set", set) 290 + parent.set("layout", layout_table)?;
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)))?;
320 Ok(()) 291 Ok(())
321 } 292 }
322 293
323 fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> { 294 fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
324 - let tag_table = lua.create_table() 295 + let tag_table = lua.create_table()?;
325 - .map_err(|e| ConfigError::LuaError(format!("Failed to create tag table: {}", e)))?;
326 296
327 let view = lua.create_function(|lua, idx: i32| { 297 let view = lua.create_function(|lua, idx: i32| {
328 create_action_table(lua, "ViewTag", Value::Integer(idx as i64)) 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 let move_to = lua.create_function(|lua, idx: i32| { 301 let move_to = lua.create_function(|lua, idx: i32| {
332 create_action_table(lua, "MoveToTag", Value::Integer(idx as i64)) 302 create_action_table(lua, "MoveToTag", Value::Integer(idx as i64))
333 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create move_to: {}", e)))?; 303 + })?;
334 - 304 +
335 - tag_table.set("view", view) 305 + tag_table.set("view", view)?;
336 - .map_err(|e| ConfigError::LuaError(format!("Failed to set view: {}", e)))?; 306 + tag_table.set("move_to", move_to)?;
337 - tag_table.set("move_to", move_to) 307 + parent.set("tag", tag_table)?;
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)))?;
341 Ok(()) 308 Ok(())
342 } 309 }
343 310
344 fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 311 fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
345 - let bar_table = lua.create_table() 312 + let bar_table = lua.create_table()?;
346 - .map_err(|e| ConfigError::LuaError(format!("Failed to create bar table: {}", e)))?;
347 313
348 let builder_clone = builder.clone(); 314 let builder_clone = builder.clone();
349 let set_font = lua.create_function(move |_, font: String| { 315 let set_font = lua.create_function(move |_, font: String| {
350 builder_clone.borrow_mut().font = font; 316 builder_clone.borrow_mut().font = font;
351 Ok(()) 317 Ok(())
352 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_font: {}", e)))?; 318 + })?;
353 - 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 let builder_clone = builder.clone(); 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)| { 369 + let add_block = lua.create_function(move |_, (format, block_type, arg, interval, color, underline): (String, String, Value, u64, Value, Option<bool>)| -> mlua::Result<()> {
356 - use crate::bar::BlockCommand; 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 "DateTime" => { 374 "DateTime" => {
360 - let fmt = arg.and_then(|v| { 375 + let fmt = if let Value::String(s) = arg {
361 - if let Value::String(s) = v { 376 + s.to_str()?.to_string()
362 - s.to_str().ok().map(|s| s.to_string()) 377 + } else {
363 - } else { 378 + return Err(mlua::Error::RuntimeError("DateTime block requires format string as third argument".into()));
364 - None 379 + };
365 - } 380 + crate::bar::BlockCommand::DateTime(fmt)
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)
368 } 381 }
369 "Shell" => { 382 "Shell" => {
370 - let cmd_str = arg.and_then(|v| { 383 + let cmd_str = if let Value::String(s) = arg {
371 - if let Value::String(s) = v { 384 + s.to_str()?.to_string()
372 - s.to_str().ok().map(|s| s.to_string()) 385 + } else {
373 - } else { 386 + return Err(mlua::Error::RuntimeError("Shell block requires command string as third argument".into()));
374 - None 387 + };
375 - } 388 + crate::bar::BlockCommand::Shell(cmd_str)
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)
378 } 389 }
379 - "Ram" => BlockCommand::Ram, 390 + "Ram" => crate::bar::BlockCommand::Ram,
380 "Static" => { 391 "Static" => {
381 - let text = arg.and_then(|v| { 392 + let text = if let Value::String(s) = arg {
382 - if let Value::String(s) = v { 393 + s.to_str()?.to_string()
383 - s.to_str().ok().map(|s| s.to_string()) 394 + } else {
384 - } else { 395 + String::new()
385 - None 396 + };
386 - } 397 + crate::bar::BlockCommand::Static(text)
387 - }).unwrap_or_default();
388 - BlockCommand::Static(text)
389 } 398 }
390 "Battery" => { 399 "Battery" => {
391 - let formats = arg.and_then(|v| { 400 + return Err(mlua::Error::RuntimeError(
392 - if let Value::Table(t) = v { 401 + "Battery block is not supported with add_block(). Please use oxwm.bar.set_blocks() with oxwm.bar.block.battery()".into()
393 - Some(t) 402 + ));
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 - }
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 let color_u32 = parse_color_value(color)?; 407 let color_u32 = parse_color_value(color)?;
@@ -416,12 +411,98 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
416 command: cmd, 411 command: cmd,
417 interval_secs: interval, 412 interval_secs: interval,
418 color: color_u32, 413 color: color_u32,
419 - underline, 414 + underline: underline.unwrap_or(false),
420 }; 415 };
421 416
422 builder_clone.borrow_mut().status_blocks.push(block); 417 builder_clone.borrow_mut().status_blocks.push(block);
423 Ok(()) 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 let builder_clone = builder.clone(); 507 let builder_clone = builder.clone();
427 let set_scheme_normal = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| { 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 underline, 516 underline,
436 }; 517 };
437 Ok(()) 518 Ok(())
438 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_scheme_normal: {}", e)))?; 519 + })?;
439 520
440 let builder_clone = builder.clone(); 521 let builder_clone = builder.clone();
441 let set_scheme_occupied = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| { 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 underline, 530 underline,
450 }; 531 };
451 Ok(()) 532 Ok(())
452 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_scheme_occupied: {}", e)))?; 533 + })?;
453 534
454 let builder_clone = builder.clone(); 535 let builder_clone = builder.clone();
455 let set_scheme_selected = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| { 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 underline, 544 underline,
464 }; 545 };
465 Ok(()) 546 Ok(())
466 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_scheme_selected: {}", e)))?; 547 + })?;
467 - 548 +
468 - bar_table.set("set_font", set_font) 549 + bar_table.set("set_font", set_font)?;
469 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_font: {}", e)))?; 550 + bar_table.set("block", block_table)?;
470 - bar_table.set("add_block", add_block) 551 + bar_table.set("add_block", add_block)?; // Deprecated, for backwards compatibility
471 - .map_err(|e| ConfigError::LuaError(format!("Failed to set add_block: {}", e)))?; 552 + bar_table.set("set_blocks", set_blocks)?;
472 - bar_table.set("set_scheme_normal", set_scheme_normal) 553 + bar_table.set("set_scheme_normal", set_scheme_normal)?;
473 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_scheme_normal: {}", e)))?; 554 + bar_table.set("set_scheme_occupied", set_scheme_occupied)?;
474 - bar_table.set("set_scheme_occupied", set_scheme_occupied) 555 + bar_table.set("set_scheme_selected", set_scheme_selected)?;
475 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_scheme_occupied: {}", e)))?; 556 + parent.set("bar", bar_table)?;
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)))?;
480 Ok(()) 557 Ok(())
481 } 558 }
482 559
@@ -485,7 +562,7 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
485 let set_terminal = lua.create_function(move |_, term: String| { 562 let set_terminal = lua.create_function(move |_, term: String| {
486 builder_clone.borrow_mut().terminal = term; 563 builder_clone.borrow_mut().terminal = term;
487 Ok(()) 564 Ok(())
488 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_terminal: {}", e)))?; 565 + })?;
489 566
490 let builder_clone = builder.clone(); 567 let builder_clone = builder.clone();
491 let set_modkey = lua.create_function(move |_, modkey_str: String| { 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 .map_err(|e| mlua::Error::RuntimeError(format!("{}", e)))?; 570 .map_err(|e| mlua::Error::RuntimeError(format!("{}", e)))?;
494 builder_clone.borrow_mut().modkey = modkey; 571 builder_clone.borrow_mut().modkey = modkey;
495 Ok(()) 572 Ok(())
496 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_modkey: {}", e)))?; 573 + })?;
497 574
498 let builder_clone = builder.clone(); 575 let builder_clone = builder.clone();
499 let set_tags = lua.create_function(move |_, tags: Vec<String>| { 576 let set_tags = lua.create_function(move |_, tags: Vec<String>| {
500 builder_clone.borrow_mut().tags = tags; 577 builder_clone.borrow_mut().tags = tags;
501 Ok(()) 578 Ok(())
502 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_tags: {}", e)))?; 579 + })?;
503 580
504 let quit = lua.create_function(|lua, ()| { 581 let quit = lua.create_function(|lua, ()| {
505 create_action_table(lua, "Quit", Value::Nil) 582 create_action_table(lua, "Quit", Value::Nil)
506 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create quit: {}", e)))?; 583 + })?;
507 584
508 let restart = lua.create_function(|lua, ()| { 585 let restart = lua.create_function(|lua, ()| {
509 create_action_table(lua, "Restart", Value::Nil) 586 create_action_table(lua, "Restart", Value::Nil)
510 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create restart: {}", e)))?; 587 + })?;
511 588
512 let recompile = lua.create_function(|lua, ()| { 589 let recompile = lua.create_function(|lua, ()| {
513 create_action_table(lua, "Recompile", Value::Nil) 590 create_action_table(lua, "Recompile", Value::Nil)
514 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create recompile: {}", e)))?; 591 + })?;
515 592
516 let toggle_gaps = lua.create_function(|lua, ()| { 593 let toggle_gaps = lua.create_function(|lua, ()| {
517 create_action_table(lua, "ToggleGaps", Value::Nil) 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 let show_keybinds = lua.create_function(|lua, ()| { 597 let show_keybinds = lua.create_function(|lua, ()| {
521 create_action_table(lua, "ShowKeybindOverlay", Value::Nil) 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 let focus_monitor = lua.create_function(|lua, idx: i32| { 601 let focus_monitor = lua.create_function(|lua, idx: i32| {
525 create_action_table(lua, "FocusMonitor", Value::Integer(idx as i64)) 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 let builder_clone = builder.clone(); 605 let builder_clone = builder.clone();
529 let set_layout_symbol = lua.create_function(move |_, (name, symbol): (String, String)| { 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 symbol, 609 symbol,
533 }); 610 });
534 Ok(()) 611 Ok(())
535 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create set_layout_symbol: {}", e)))?; 612 + })?;
536 613
537 let builder_clone = builder.clone(); 614 let builder_clone = builder.clone();
538 let autostart = lua.create_function(move |_, cmd: String| { 615 let autostart = lua.create_function(move |_, cmd: String| {
539 builder_clone.borrow_mut().autostart.push(cmd); 616 builder_clone.borrow_mut().autostart.push(cmd);
540 Ok(()) 617 Ok(())
541 - }).map_err(|e| ConfigError::LuaError(format!("Failed to create autostart: {}", e)))?; 618 + })?;
542 - 619 +
543 - parent.set("set_terminal", set_terminal) 620 + parent.set("set_terminal", set_terminal)?;
544 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_terminal: {}", e)))?; 621 + parent.set("set_modkey", set_modkey)?;
545 - parent.set("set_modkey", set_modkey) 622 + parent.set("set_tags", set_tags)?;
546 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_modkey: {}", e)))?; 623 + parent.set("set_layout_symbol", set_layout_symbol)?;
547 - parent.set("set_tags", set_tags) 624 + parent.set("autostart", autostart)?;
548 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_tags: {}", e)))?; 625 + parent.set("quit", quit)?;
549 - parent.set("set_layout_symbol", set_layout_symbol) 626 + parent.set("restart", restart)?;
550 - .map_err(|e| ConfigError::LuaError(format!("Failed to set set_layout_symbol: {}", e)))?; 627 + parent.set("recompile", recompile)?;
551 - parent.set("autostart", autostart) 628 + parent.set("toggle_gaps", toggle_gaps)?;
552 - .map_err(|e| ConfigError::LuaError(format!("Failed to set autostart: {}", e)))?; 629 + parent.set("show_keybinds", show_keybinds)?;
553 - parent.set("quit", quit) 630 + parent.set("focus_monitor", focus_monitor)?;
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)))?;
565 Ok(()) 631 Ok(())
566 } 632 }
567 633
@@ -638,6 +704,7 @@ fn parse_action_value(_lua: &Lua, value: Value) -> mlua::Result<(KeyAction, Arg)
638 fn string_to_action(s: &str) -> mlua::Result<KeyAction> { 704 fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
639 match s { 705 match s {
640 "Spawn" => Ok(KeyAction::Spawn), 706 "Spawn" => Ok(KeyAction::Spawn),
707 + "SpawnTerminal" => Ok(KeyAction::SpawnTerminal),
641 "KillClient" => Ok(KeyAction::KillClient), 708 "KillClient" => Ok(KeyAction::KillClient),
642 "FocusStack" => Ok(KeyAction::FocusStack), 709 "FocusStack" => Ok(KeyAction::FocusStack),
643 "FocusDirection" => Ok(KeyAction::FocusDirection), 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 X11Error::ReplyOrIdError(value) 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 #[derive(Debug, Copy, Clone, Deserialize, PartialEq)] 12 #[derive(Debug, Copy, Clone, Deserialize, PartialEq)]
13 pub enum KeyAction { 13 pub enum KeyAction {
14 Spawn, 14 Spawn,
15 + SpawnTerminal,
15 KillClient, 16 KillClient,
16 FocusStack, 17 FocusStack,
17 FocusDirection, 18 FocusDirection,
@@ -22,7 +23,6 @@ pub enum KeyAction {
22 ViewTag, 23 ViewTag,
23 ToggleGaps, 24 ToggleGaps,
24 ToggleFullScreen, 25 ToggleFullScreen,
25 - ToggleWindowFullscreen,
26 ToggleFloating, 26 ToggleFloating,
27 ChangeLayout, 27 ChangeLayout,
28 CycleLayout, 28 CycleLayout,
+8 −1 src/layout/mod.rs
@@ -1,4 +1,5 @@
1 pub mod grid; 1 pub mod grid;
2 +pub mod monocle;
2 pub mod normie; 3 pub mod normie;
3 pub mod tiling; 4 pub mod tiling;
4 5
@@ -17,6 +18,7 @@ pub enum LayoutType {
17 Tiling, 18 Tiling,
18 Normie, 19 Normie,
19 Grid, 20 Grid,
21 + Monocle,
20 } 22 }
21 23
22 impl LayoutType { 24 impl LayoutType {
@@ -25,6 +27,7 @@ impl LayoutType {
25 Self::Tiling => Box::new(tiling::TilingLayout), 27 Self::Tiling => Box::new(tiling::TilingLayout),
26 Self::Normie => Box::new(normie::NormieLayout), 28 Self::Normie => Box::new(normie::NormieLayout),
27 Self::Grid => Box::new(grid::GridLayout), 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 match self { 35 match self {
33 Self::Tiling => Self::Normie, 36 Self::Tiling => Self::Normie,
34 Self::Normie => Self::Grid, 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 Self::Tiling => "tiling", 45 Self::Tiling => "tiling",
42 Self::Normie => "normie", 46 Self::Normie => "normie",
43 Self::Grid => "grid", 47 Self::Grid => "grid",
48 + Self::Monocle => "monocle",
44 } 49 }
45 } 50 }
46 51
@@ -49,6 +54,7 @@ impl LayoutType {
49 "tiling" => Ok(Self::Tiling), 54 "tiling" => Ok(Self::Tiling),
50 "normie" | "floating" => Ok(Self::Normie), 55 "normie" | "floating" => Ok(Self::Normie),
51 "grid" => Ok(Self::Grid), 56 "grid" => Ok(Self::Grid),
57 + "monocle" => Ok(Self::Monocle),
52 _ => Err(format!("Invalid Layout Type: {}", s)), 58 _ => Err(format!("Invalid Layout Type: {}", s)),
53 } 59 }
54 } 60 }
@@ -79,6 +85,7 @@ pub trait Layout {
79 fn symbol(&self) -> &'static str; 85 fn symbol(&self) -> &'static str;
80 } 86 }
81 87
88 +#[derive(Clone)]
82 pub struct WindowGeometry { 89 pub struct WindowGeometry {
83 pub x_coordinate: i32, 90 pub x_coordinate: i32,
84 pub y_coordinate: i32, 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 pub height: u32, 13 pub height: u32,
14 pub selected_tags: u32, 14 pub selected_tags: u32,
15 pub focused_window: Option<Window>, 15 pub focused_window: Option<Window>,
16 - pub fullscreen_enabled: bool,
17 } 16 }
18 17
19 impl Monitor { 18 impl Monitor {
@@ -25,7 +24,6 @@ impl Monitor {
25 height, 24 height,
26 selected_tags: 1, 25 selected_tags: 1,
27 focused_window: None, 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 KeyAction::Restart, 141 KeyAction::Restart,
142 KeyAction::KillClient, 142 KeyAction::KillClient,
143 KeyAction::Spawn, 143 KeyAction::Spawn,
144 + KeyAction::SpawnTerminal,
144 KeyAction::ToggleFullScreen, 145 KeyAction::ToggleFullScreen,
145 KeyAction::ToggleFloating, 146 KeyAction::ToggleFloating,
146 KeyAction::CycleLayout, 147 KeyAction::CycleLayout,
@@ -200,6 +201,7 @@ impl KeybindOverlay {
200 Arg::Array(arr) if !arr.is_empty() => format!("Launch: {}", arr[0]), 201 Arg::Array(arr) if !arr.is_empty() => format!("Launch: {}", arr[0]),
201 _ => "Launch Program".to_string(), 202 _ => "Launch Program".to_string(),
202 }, 203 },
204 + KeyAction::SpawnTerminal => "Launch Terminal".to_string(),
203 KeyAction::FocusStack => "Focus Next/Previous Window".to_string(), 205 KeyAction::FocusStack => "Focus Next/Previous Window".to_string(),
204 KeyAction::FocusDirection => "Focus Window in Direction".to_string(), 206 KeyAction::FocusDirection => "Focus Window in Direction".to_string(),
205 KeyAction::SwapDirection => "Swap Window in Direction".to_string(), 207 KeyAction::SwapDirection => "Swap Window in Direction".to_string(),
@@ -210,7 +212,6 @@ impl KeybindOverlay {
210 KeyAction::MoveToTag => "Move Window to Workspace".to_string(), 212 KeyAction::MoveToTag => "Move Window to Workspace".to_string(),
211 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(), 213 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(),
212 KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(), 214 KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(),
213 - KeyAction::ToggleWindowFullscreen => "Toggle Window Fullscreen".to_string(),
214 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(), 215 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(),
215 KeyAction::ChangeLayout => "Change Layout".to_string(), 216 KeyAction::ChangeLayout => "Change Layout".to_string(),
216 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(), 217 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(),
+154 −121 src/window_manager.rs
@@ -87,11 +87,12 @@ pub struct WindowManager {
87 layout: LayoutBox, 87 layout: LayoutBox,
88 window_tags: std::collections::HashMap<Window, TagMask>, 88 window_tags: std::collections::HashMap<Window, TagMask>,
89 window_monitor: std::collections::HashMap<Window, usize>, 89 window_monitor: std::collections::HashMap<Window, usize>,
90 - window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>,
91 gaps_enabled: bool, 90 gaps_enabled: bool,
92 floating_windows: HashSet<Window>, 91 floating_windows: HashSet<Window>,
93 fullscreen_windows: HashSet<Window>, 92 fullscreen_windows: HashSet<Window>,
94 bars: Vec<Bar>, 93 bars: Vec<Bar>,
94 + show_bar: bool,
95 + last_layout: Option<&'static str>,
95 monitors: Vec<Monitor>, 96 monitors: Vec<Monitor>,
96 selected_monitor: usize, 97 selected_monitor: usize,
97 atoms: AtomCache, 98 atoms: AtomCache,
@@ -211,11 +212,12 @@ impl WindowManager {
211 layout: Box::new(TilingLayout), 212 layout: Box::new(TilingLayout),
212 window_tags: std::collections::HashMap::new(), 213 window_tags: std::collections::HashMap::new(),
213 window_monitor: std::collections::HashMap::new(), 214 window_monitor: std::collections::HashMap::new(),
214 - window_geometries: std::collections::HashMap::new(),
215 gaps_enabled, 215 gaps_enabled,
216 floating_windows: HashSet::new(), 216 floating_windows: HashSet::new(),
217 fullscreen_windows: HashSet::new(), 217 fullscreen_windows: HashSet::new(),
218 bars, 218 bars,
219 + show_bar: true,
220 + last_layout: None,
219 monitors, 221 monitors,
220 selected_monitor: 0, 222 selected_monitor: 0,
221 atoms, 223 atoms,
@@ -857,22 +859,6 @@ impl WindowManager {
857 Ok(()) 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 fn get_layout_symbol(&self) -> String { 863 fn get_layout_symbol(&self) -> String {
878 let layout_name = self.layout.name(); 864 let layout_name = self.layout.name();
@@ -961,6 +947,11 @@ impl WindowManager {
961 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { 947 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> {
962 match action { 948 match action {
963 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, 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 KeyAction::KillClient => { 955 KeyAction::KillClient => {
965 if let Some(focused) = self 956 if let Some(focused) = self
966 .monitors 957 .monitors
@@ -971,45 +962,16 @@ impl WindowManager {
971 } 962 }
972 } 963 }
973 KeyAction::ToggleFullScreen => { 964 KeyAction::ToggleFullScreen => {
974 - // Smart fullscreen: 965 + self.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 - }
1007 } 966 }
1008 KeyAction::ChangeLayout => { 967 KeyAction::ChangeLayout => {
1009 if let Arg::Str(layout_name) = arg { 968 if let Arg::Str(layout_name) = arg {
1010 match layout_from_str(layout_name) { 969 match layout_from_str(layout_name) {
1011 Ok(layout) => { 970 Ok(layout) => {
1012 self.layout = layout; 971 self.layout = layout;
972 + if layout_name != "normie" && layout_name != "floating" {
973 + self.floating_windows.clear();
974 + }
1013 self.apply_layout()?; 975 self.apply_layout()?;
1014 self.update_bar()?; 976 self.update_bar()?;
1015 } 977 }
@@ -1023,6 +985,9 @@ impl WindowManager {
1023 match layout_from_str(next_name) { 985 match layout_from_str(next_name) {
1024 Ok(layout) => { 986 Ok(layout) => {
1025 self.layout = layout; 987 self.layout = layout;
988 + if next_name != "normie" && next_name != "floating" {
989 + self.floating_windows.clear();
990 + }
1026 self.apply_layout()?; 991 self.apply_layout()?;
1027 self.update_bar()?; 992 self.update_bar()?;
1028 } 993 }
@@ -1583,14 +1548,26 @@ impl WindowManager {
1583 Ok(true) 1548 Ok(true)
1584 } 1549 }
1585 1550
1586 - fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> { 1551 + fn fullscreen(&mut self) -> WmResult<()> {
1587 - if fullscreen && !self.fullscreen_windows.contains(&window) { 1552 + if self.show_bar {
1588 - // Save current geometry before fullscreen 1553 + self.last_layout = Some(self.layout.name());
1589 - if let Ok(geom) = self.connection.get_geometry(window)?.reply() { 1554 + if let Ok(layout) = layout_from_str("monocle") {
1590 - self.window_geometries.insert(window, (geom.x, geom.y, geom.width, geom.height)); 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 self.connection.change_property( 1571 self.connection.change_property(
1595 PropMode::REPLACE, 1572 PropMode::REPLACE,
1596 window, 1573 window,
@@ -1598,56 +1575,82 @@ impl WindowManager {
1598 AtomEnum::ATOM, 1575 AtomEnum::ATOM,
1599 32, 1576 32,
1600 1, 1577 1,
1601 - &self.atoms.net_wm_state_fullscreen.to_ne_bytes(), 1578 + &bytes,
1602 )?; 1579 )?;
1603 1580
1604 self.fullscreen_windows.insert(window); 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 self.floating_windows.insert(window); 1589 self.floating_windows.insert(window);
1606 1590
1607 - // Get monitor dimensions 1591 + let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor);
1608 - let window_mon = self.window_monitor.get(&window).copied().unwrap_or(self.selected_monitor); 1592 + let monitor = &self.monitors[monitor_idx];
1609 - let monitor = &self.monitors[window_mon];
1610 1593
1611 - // Make window fullscreen across the entire monitor
1612 self.connection.configure_window( 1594 self.connection.configure_window(
1613 window, 1595 window,
1614 - &ConfigureWindowAux::new() 1596 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1615 .x(monitor.x) 1597 .x(monitor.x)
1616 .y(monitor.y) 1598 .y(monitor.y)
1617 - .width(monitor.width) 1599 + .width(monitor.width as u32)
1618 - .height(monitor.height) 1600 + .height(monitor.height as u32),
1619 - .border_width(0) 1601 + )?;
1620 - .stack_mode(StackMode::ABOVE), 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 self.connection.flush()?; 1609 self.connection.flush()?;
1624 } else if !fullscreen && self.fullscreen_windows.contains(&window) { 1610 } else if !fullscreen && self.fullscreen_windows.contains(&window) {
1625 - // Clear the _NET_WM_STATE property 1611 + self.connection.change_property(
1626 - self.connection.delete_property(window, self.atoms.net_wm_state)?; 1612 + PropMode::REPLACE,
1613 + window,
1614 + self.atoms.net_wm_state,
1615 + AtomEnum::ATOM,
1616 + 32,
1617 + 0,
1618 + &[],
1619 + )?;
1627 1620
1628 self.fullscreen_windows.remove(&window); 1621 self.fullscreen_windows.remove(&window);
1629 1622
1630 - // Restore saved geometry 1623 + if !self.is_transient_window(window) {
1631 - if let Some((x, y, width, height)) = self.window_geometries.get(&window) { 1624 + self.floating_windows.remove(&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 - )?;
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 self.apply_layout()?; 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 self.connection.flush()?; 1647 self.connection.flush()?;
1645 } 1648 }
1649 + self.apply_layout()?;
1646 Ok(()) 1650 Ok(())
1647 } 1651 }
1648 1652
1649 fn is_transient_window(&self, window: Window) -> bool { 1653 fn is_transient_window(&self, window: Window) -> bool {
1650 - // Check if window is transient (e.g., dialog, modal)
1651 let transient_for = self.connection 1654 let transient_for = self.connection
1652 .get_property( 1655 .get_property(
1653 false, 1656 false,
@@ -1900,11 +1903,6 @@ impl WindowManager {
1900 return Ok(None); 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 self.connection.map_window(event.window)?; 1906 self.connection.map_window(event.window)?;
1909 self.connection.change_window_attributes( 1907 self.connection.change_window_attributes(
1910 event.window, 1908 event.window,
@@ -1924,37 +1922,61 @@ impl WindowManager {
1924 self.set_wm_state(event.window, 1)?; 1922 self.set_wm_state(event.window, 1)?;
1925 let _ = self.save_client_tag(event.window, selected_tags); 1923 let _ = self.save_client_tag(event.window, selected_tags);
1926 1924
1927 - // Auto-float transient windows (e.g., dialogs, modals) 1925 + let is_transient = self.is_transient_window(event.window);
1928 - if self.is_transient_window(event.window) { 1926 + if is_transient {
1929 self.floating_windows.insert(event.window); 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 self.apply_layout()?; 1976 self.apply_layout()?;
1933 self.update_bar()?; 1977 self.update_bar()?;
1934 self.set_focus(event.window)?; 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 Event::UnmapNotify(event) => { 1980 Event::UnmapNotify(event) => {
1959 if self.windows.contains(&event.window) && self.is_window_visible(event.window) { 1981 if self.windows.contains(&event.window) && self.is_window_visible(event.window) {
1960 self.remove_window(event.window)?; 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 Ok(None) 2136 Ok(None)
@@ -2104,13 +2142,9 @@ impl WindowManager {
2104 } 2142 }
2105 2143
2106 for (monitor_index, monitor) in self.monitors.iter().enumerate() { 2144 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
2107 - let border_width = if monitor.fullscreen_enabled { 2145 + let border_width = self.config.border_width;
2108 - 0
2109 - } else {
2110 - self.config.border_width
2111 - };
2112 2146
2113 - let gaps = if self.gaps_enabled && !monitor.fullscreen_enabled { 2147 + let gaps = if self.gaps_enabled {
2114 GapConfig { 2148 GapConfig {
2115 inner_horizontal: self.config.gap_inner_horizontal, 2149 inner_horizontal: self.config.gap_inner_horizontal,
2116 inner_vertical: self.config.gap_inner_vertical, 2150 inner_vertical: self.config.gap_inner_vertical,
@@ -2146,13 +2180,13 @@ impl WindowManager {
2146 .copied() 2180 .copied()
2147 .collect(); 2181 .collect();
2148 2182
2149 - let bar_height = if monitor.fullscreen_enabled { 2183 + let bar_height = if self.show_bar {
2150 - 0
2151 - } else {
2152 self.bars 2184 self.bars
2153 .get(monitor_index) 2185 .get(monitor_index)
2154 .map(|b| b.height() as u32) 2186 .map(|b| b.height() as u32)
2155 .unwrap_or(0) 2187 .unwrap_or(0)
2188 + } else {
2189 + 0
2156 }; 2190 };
2157 let usable_height = monitor.height.saturating_sub(bar_height); 2191 let usable_height = monitor.height.saturating_sub(bar_height);
2158 2192
@@ -2191,12 +2225,11 @@ impl WindowManager {
2191 2225
2192 fn remove_window(&mut self, window: Window) -> WmResult<()> { 2226 fn remove_window(&mut self, window: Window) -> WmResult<()> {
2193 let initial_count = self.windows.len(); 2227 let initial_count = self.windows.len();
2228 +
2194 self.windows.retain(|&w| w != window); 2229 self.windows.retain(|&w| w != window);
2195 self.window_tags.remove(&window); 2230 self.window_tags.remove(&window);
2196 self.window_monitor.remove(&window); 2231 self.window_monitor.remove(&window);
2197 - self.window_geometries.remove(&window);
2198 self.floating_windows.remove(&window); 2232 self.floating_windows.remove(&window);
2199 - self.fullscreen_windows.remove(&window);
2200 2233
2201 if self.windows.len() < initial_count { 2234 if self.windows.len() < initial_count {
2202 let focused = self 2235 let focused = self
+58 −19 templates/config.lua
@@ -173,27 +173,66 @@ oxwm.key.chord({
173 ------------------------------------------------------------------------------- 173 -------------------------------------------------------------------------------
174 -- Status Bar Blocks 174 -- Status Bar Blocks
175 ------------------------------------------------------------------------------- 175 -------------------------------------------------------------------------------
176 --- Add informational blocks to the status bar 176 +-- Add informational blocks to the status bar using block constructors
177 --- Format: oxwm.bar.add_block(format, type, data, update_interval, color, separator) 177 +-- Each block is created with oxwm.bar.block.<type>() and configured with a table:
178 -- format: Display format with {} placeholders 178 -- format: Display format with {} placeholders
179 --- type: Block type ("Ram", "DateTime", "Shell", "Static", "Battery") 179 +-- interval: Seconds between updates
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) 180 -- color: Text color (from color palette)
183 --- separator: Whether to add space after this block 181 +-- underline: Whether to underline the block
184 - 182 +--
185 -oxwm.bar.add_block("Ram: {used}/{total} GB", "Ram", nil, 5, colors.light_blue, true) 183 +-- Available block types:
186 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false) 184 +-- ram(config) - Memory usage
187 -oxwm.bar.add_block("Kernel: {}", "Shell", "uname -r", 999999999, colors.red, true) 185 +-- datetime(config) - Date and time (requires date_format field)
188 -oxwm.bar.add_block(" │ ", "Static", "", 999999999, colors.lavender, false) 186 +-- shell(config) - Shell command output (requires command field)
189 -oxwm.bar.add_block("{}", "DateTime", "%a, %b %d - %-I:%M %P", 1, colors.cyan, true) 187 +-- static(config) - Static text (requires text field)
190 - 188 +-- battery(config) - Battery status (requires charging, discharging, full fields)
191 --- Uncomment to add battery status (useful for laptops) 189 +
192 --- oxwm.bar.add_block("Bat: {}%", "Battery", { 190 +oxwm.bar.set_blocks({
193 --- charging = "⚡ Bat: {}%", 191 + oxwm.bar.block.ram({
194 --- discharging = "🔋 Bat: {}%", 192 + format = "Ram: {used}/{total} GB",
195 --- full = "✓ Bat: {}%" 193 + interval = 5,
196 --- }, 30, colors.green, true) 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 -- Autostart 238 -- Autostart
+54 −4 templates/oxwm.lua
@@ -1,6 +1,18 @@
1 ---@meta 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 ---@class oxwm 16 ---@class oxwm
5 oxwm = {} 17 oxwm = {}
6 18
@@ -9,6 +21,10 @@ oxwm = {}
9 ---@return table Action table for keybinding 21 ---@return table Action table for keybinding
10 function oxwm.spawn(cmd) end 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 ---Set the terminal emulator 28 ---Set the terminal emulator
13 ---@param terminal string Terminal command (e.g., "st", "alacritty") 29 ---@param terminal string Terminal command (e.g., "st", "alacritty")
14 function oxwm.set_terminal(terminal) end 30 function oxwm.set_terminal(terminal) end
@@ -181,15 +197,49 @@ oxwm.bar = {}
181 ---@param font string Font string (e.g., "monospace:style=Bold:size=10") 197 ---@param font string Font string (e.g., "monospace:style=Bold:size=10")
182 function oxwm.bar.set_font(font) end 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 ---@param format string Format string with {} placeholders 202 ---@param format string Format string with {} placeholders
186 ----@param command "DateTime"|"Shell"|"Ram"|"Static"|"Battery" Block command type 203 +---@param command "DateTime"|"Shell"|"Ram"|"Static" Block command type (Battery not supported)
187 ----@param arg string|table|nil Command argument (format for DateTime, command for Shell, text for Static, formats table for Battery, nil for Ram) 204 +---@param arg string|nil Command argument (format for DateTime, command for Shell, text for Static, nil for Ram)
188 ---@param interval integer Update interval in seconds 205 ---@param interval integer Update interval in seconds
189 ---@param color string|integer Color as hex string or integer 206 ---@param color string|integer Color as hex string or integer
190 ---@param underline boolean Whether to underline the block 207 ---@param underline boolean Whether to underline the block
191 function oxwm.bar.add_block(format, command, arg, interval, color, underline) end 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 ---Set normal tag color scheme (unselected, no windows) 243 ---Set normal tag color scheme (unselected, no windows)
194 ---@param foreground string|integer Foreground color 244 ---@param foreground string|integer Foreground color
195 ---@param background string|integer Background color 245 ---@param background string|integer Background color