tony / oxwm

Merge pull request #39 from tonybanters/bugfixes-floating-fullscreen Browse files
Bar Flashing, Block Api, LSP, Fullscreen
Emzy committed 2025-11-17 parents 44c9e5e ae6ee0d commit d2136f3b4bb958f36598ac2fd13d5285aaff0c27
Showing 17 changed files with 1022 additions and 364 deletions. UnifiedSplit
+2 −0 .gitignore
@@ -8,3 +8,5 @@ result
8 # User config 8 # User config
9 src/config.rs 9 src/config.rs
10 10
11 +# Notes
12 +*.md
+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]
+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 +}
+26 −4 src/bin/main.rs
@@ -73,6 +73,8 @@ 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 + update_lsp_files()?;
76 } 78 }
77 79
78 lua_path 80 lua_path
@@ -102,18 +104,38 @@ fn init_config() -> Result<()> {
102 let config_path = config_dir.join("config.lua"); 104 let config_path = config_dir.join("config.lua");
103 std::fs::write(&config_path, config_template)?; 105 std::fs::write(&config_path, config_template)?;
104 106
105 - let oxwm_lua_template = include_str!("../../templates/oxwm.lua"); 107 + update_lsp_files()?;
106 - let oxwm_lua_path = config_dir.join("oxwm.lua");
107 - std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
108 108
109 println!("✓ Config created at {:?}", config_path); 109 println!("✓ Config created at {:?}", config_path);
110 - println!("✓ LSP definitions installed at {:?}", oxwm_lua_path); 110 + println!("✓ LSP definitions installed at {:?}/lib/oxwm.lua", config_dir);
111 println!(" Edit the file and reload with Mod+Shift+R"); 111 println!(" Edit the file and reload with Mod+Shift+R");
112 println!(" No compilation needed - changes take effect immediately!"); 112 println!(" No compilation needed - changes take effect immediately!");
113 113
114 Ok(()) 114 Ok(())
115 } 115 }
116 116
117 +fn update_lsp_files() -> Result<()> {
118 + let config_dir = get_config_path();
119 +
120 + let lib_dir = config_dir.join("lib");
121 + std::fs::create_dir_all(&lib_dir)?;
122 +
123 + let oxwm_lua_template = include_str!("../../templates/oxwm.lua");
124 + let oxwm_lua_path = lib_dir.join("oxwm.lua");
125 + std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
126 +
127 + let luarc_content = r#"{
128 + "workspace.library": [
129 + "lib"
130 + ]
131 +}
132 +"#;
133 + let luarc_path = config_dir.join(".luarc.json");
134 + std::fs::write(&luarc_path, luarc_content)?;
135 +
136 + Ok(())
137 +}
138 +
117 fn get_config_path() -> PathBuf { 139 fn get_config_path() -> PathBuf {
118 dirs::config_dir() 140 dirs::config_dir()
119 .expect("Could not find config directory") 141 .expect("Could not find config directory")
+1 −0 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,
+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 −0 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,
+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
+3 −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(),
@@ -209,7 +211,7 @@ impl KeybindOverlay {
209 }, 211 },
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".to_string(), 214 + KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(),
213 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(), 215 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(),
214 KeyAction::ChangeLayout => "Change Layout".to_string(), 216 KeyAction::ChangeLayout => "Change Layout".to_string(),
215 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(), 217 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(),
+369 −43 src/window_manager.rs Large diff collapsed, click to expand
@@ -25,6 +25,10 @@ struct AtomCache {
25 net_current_desktop: Atom, 25 net_current_desktop: Atom,
26 net_client_info: Atom, 26 net_client_info: Atom,
27 wm_state: Atom, 27 wm_state: Atom,
28 + wm_protocols: Atom,
29 + wm_delete_window: Atom,
30 + net_wm_state: Atom,
31 + net_wm_state_fullscreen: Atom,
28 } 32 }
29 33
30 impl AtomCache { 34 impl AtomCache {
@@ -41,10 +45,34 @@ impl AtomCache {
41 45
42 let wm_state = connection.intern_atom(false, b"WM_STATE")?.reply()?.atom; 46 let wm_state = connection.intern_atom(false, b"WM_STATE")?.reply()?.atom;
43 47
48 + let wm_protocols = connection
49 + .intern_atom(false, b"WM_PROTOCOLS")?
50 + .reply()?
51 + .atom;
52 +
53 + let wm_delete_window = connection
54 + .intern_atom(false, b"WM_DELETE_WINDOW")?
55 + .reply()?
56 + .atom;
57 +
58 + let net_wm_state = connection
59 + .intern_atom(false, b"_NET_WM_STATE")?
60 + .reply()?
61 + .atom;
62 +
63 + let net_wm_state_fullscreen = connection
64 + .intern_atom(false, b"_NET_WM_STATE_FULLSCREEN")?
65 + .reply()?
66 + .atom;
67 +
44 Ok(Self { 68 Ok(Self {
45 net_current_desktop, 69 net_current_desktop,
46 net_client_info, 70 net_client_info,
47 wm_state, 71 wm_state,
72 + wm_protocols,
73 + wm_delete_window,
74 + net_wm_state,
75 + net_wm_state_fullscreen,
48 }) 76 })
49 } 77 }
50 } 78 }
@@ -59,10 +87,13 @@ pub struct WindowManager {
59 layout: LayoutBox, 87 layout: LayoutBox,
60 window_tags: std::collections::HashMap<Window, TagMask>, 88 window_tags: std::collections::HashMap<Window, TagMask>,
61 window_monitor: std::collections::HashMap<Window, usize>, 89 window_monitor: std::collections::HashMap<Window, usize>,
62 - window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>,
63 gaps_enabled: bool, 90 gaps_enabled: bool,
64 floating_windows: HashSet<Window>, 91 floating_windows: HashSet<Window>,
92 + fullscreen_windows: HashSet<Window>,
93 + floating_geometry_before_fullscreen: std::collections::HashMap<Window, (i16, i16, u16, u16, u16)>,
65 bars: Vec<Bar>, 94 bars: Vec<Bar>,
95 + show_bar: bool,
96 + last_layout: Option<&'static str>,
66 monitors: Vec<Monitor>, 97 monitors: Vec<Monitor>,
67 selected_monitor: usize, 98 selected_monitor: usize,
68 atoms: AtomCache, 99 atoms: AtomCache,
@@ -182,10 +213,13 @@ impl WindowManager {
182 layout: Box::new(TilingLayout), 213 layout: Box::new(TilingLayout),
183 window_tags: std::collections::HashMap::new(), 214 window_tags: std::collections::HashMap::new(),
184 window_monitor: std::collections::HashMap::new(), 215 window_monitor: std::collections::HashMap::new(),
185 - window_geometries: std::collections::HashMap::new(),
186 gaps_enabled, 216 gaps_enabled,
187 floating_windows: HashSet::new(), 217 floating_windows: HashSet::new(),
218 + fullscreen_windows: HashSet::new(),
219 + floating_geometry_before_fullscreen: std::collections::HashMap::new(),
188 bars, 220 bars,
221 + show_bar: true,
222 + last_layout: None,
189 monitors, 223 monitors,
190 selected_monitor: 0, 224 selected_monitor: 0,
191 atoms, 225 atoms,
@@ -827,22 +861,6 @@ impl WindowManager {
827 Ok(()) 861 Ok(())
828 } 862 }
829 863
830 - fn toggle_fullscreen(&mut self) -> WmResult<()> {
831 - if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
832 - monitor.fullscreen_enabled = !monitor.fullscreen_enabled;
833 -
834 - if let Some(bar) = self.bars.get(self.selected_monitor) {
835 - if monitor.fullscreen_enabled {
836 - self.connection.unmap_window(bar.window())?;
837 - } else {
838 - self.connection.map_window(bar.window())?;
839 - }
840 - }
841 -
842 - self.apply_layout()?;
843 - }
844 - Ok(())
845 - }
846 864
847 fn get_layout_symbol(&self) -> String { 865 fn get_layout_symbol(&self) -> String {
848 let layout_name = self.layout.name(); 866 let layout_name = self.layout.name();
@@ -931,30 +949,31 @@ impl WindowManager {
931 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { 949 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> {
932 match action { 950 match action {
933 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, 951 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
952 + KeyAction::SpawnTerminal => {
953 + use std::process::Command;
954 + let terminal = &self.config.terminal;
955 + let _ = Command::new(terminal).spawn();
956 + }
934 KeyAction::KillClient => { 957 KeyAction::KillClient => {
935 if let Some(focused) = self 958 if let Some(focused) = self
936 .monitors 959 .monitors
937 .get(self.selected_monitor) 960 .get(self.selected_monitor)
938 .and_then(|m| m.focused_window) 961 .and_then(|m| m.focused_window)
939 { 962 {
940 - match self.connection.kill_client(focused) { 963 + self.kill_client(focused)?;
941 - Ok(_) => {
942 - self.connection.flush()?;
943 - }
944 - Err(e) => {
945 - eprintln!("Failed to kill window {}: {}", focused, e);
946 - }
947 - }
948 } 964 }
949 } 965 }
950 KeyAction::ToggleFullScreen => { 966 KeyAction::ToggleFullScreen => {
951 - self.toggle_fullscreen()?; 967 + self.fullscreen()?;
952 } 968 }
953 KeyAction::ChangeLayout => { 969 KeyAction::ChangeLayout => {
954 if let Arg::Str(layout_name) = arg { 970 if let Arg::Str(layout_name) = arg {
955 match layout_from_str(layout_name) { 971 match layout_from_str(layout_name) {
956 Ok(layout) => { 972 Ok(layout) => {
957 self.layout = layout; 973 self.layout = layout;
974 + if layout_name != "normie" && layout_name != "floating" {
975 + self.floating_windows.clear();
976 + }
958 self.apply_layout()?; 977 self.apply_layout()?;
959 self.update_bar()?; 978 self.update_bar()?;
960 } 979 }
@@ -968,6 +987,9 @@ impl WindowManager {
968 match layout_from_str(next_name) { 987 match layout_from_str(next_name) {
969 Ok(layout) => { 988 Ok(layout) => {
970 self.layout = layout; 989 self.layout = layout;
990 + if next_name != "normie" && next_name != "floating" {
991 + self.floating_windows.clear();
992 + }
971 self.apply_layout()?; 993 self.apply_layout()?;
972 self.update_bar()?; 994 self.update_bar()?;
973 } 995 }
@@ -1468,6 +1490,249 @@ impl WindowManager {
1468 Ok(()) 1490 Ok(())
1469 } 1491 }
1470 1492
1493 + fn kill_client(&self, window: Window) -> WmResult<()> {
1494 + // Try to send WM_DELETE_WINDOW message first (graceful close)
1495 + if self.send_event(window, self.atoms.wm_delete_window)? {
1496 + // Window supports WM_DELETE_WINDOW, it will close gracefully
1497 + self.connection.flush()?;
1498 + } else {
1499 + // Window doesn't support WM_DELETE_WINDOW, forcefully kill it
1500 + eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window);
1501 + self.connection.kill_client(window)?;
1502 + self.connection.flush()?;
1503 + }
1504 + Ok(())
1505 + }
1506 +
1507 + fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> {
1508 + // Check if the window supports this protocol
1509 + let protocols_reply = self.connection.get_property(
1510 + false,
1511 + window,
1512 + self.atoms.wm_protocols,
1513 + AtomEnum::ATOM,
1514 + 0,
1515 + 100,
1516 + )?.reply();
1517 +
1518 + let protocols_reply = match protocols_reply {
1519 + Ok(reply) => reply,
1520 + Err(_) => return Ok(false),
1521 + };
1522 +
1523 + let protocols: Vec<Atom> = protocols_reply
1524 + .value
1525 + .chunks_exact(4)
1526 + .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]))
1527 + .collect();
1528 +
1529 + if !protocols.contains(&protocol) {
1530 + return Ok(false);
1531 + }
1532 +
1533 + // Send a ClientMessage event
1534 + let event = x11rb::protocol::xproto::ClientMessageEvent {
1535 + response_type: x11rb::protocol::xproto::CLIENT_MESSAGE_EVENT,
1536 + format: 32,
1537 + sequence: 0,
1538 + window,
1539 + type_: self.atoms.wm_protocols,
1540 + data: x11rb::protocol::xproto::ClientMessageData::from([protocol, x11rb::CURRENT_TIME, 0, 0, 0]),
1541 + };
1542 +
1543 + self.connection.send_event(
1544 + false,
1545 + window,
1546 + EventMask::NO_EVENT,
1547 + event,
1548 + )?;
1549 + self.connection.flush()?;
1550 + Ok(true)
1551 + }
1552 +
1553 + fn fullscreen(&mut self) -> WmResult<()> {
1554 + if self.show_bar {
1555 + self.last_layout = Some(self.layout.name());
1556 + if let Ok(layout) = layout_from_str("monocle") {
1557 + self.layout = layout;
1558 + }
1559 + self.toggle_bar()?;
1560 + self.apply_layout()?;
1561 +
1562 + let border_width = self.config.border_width;
1563 + let windows: Vec<Window> = self.windows.iter()
1564 + .filter(|&&w| self.floating_windows.contains(&w) && self.is_window_visible(w))
1565 + .copied()
1566 + .collect();
1567 +
1568 + for window in windows {
1569 + if let Ok(geom) = self.connection.get_geometry(window)?.reply() {
1570 + self.floating_geometry_before_fullscreen.insert(
1571 + window,
1572 + (geom.x, geom.y, geom.width, geom.height, geom.border_width as u16),
1573 + );
1574 + }
1575 +
1576 + let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor);
1577 + let monitor = &self.monitors[monitor_idx];
1578 +
1579 + let (outer_gap_h, outer_gap_v) = if self.gaps_enabled {
1580 + (
1581 + self.config.gap_outer_horizontal,
1582 + self.config.gap_outer_vertical,
1583 + )
1584 + } else {
1585 + (0, 0)
1586 + };
1587 +
1588 + let x = monitor.x + outer_gap_h as i32;
1589 + let y = monitor.y + outer_gap_v as i32;
1590 + let width = monitor.width.saturating_sub(2 * outer_gap_h).saturating_sub(2 * border_width);
1591 + let height = monitor.height.saturating_sub(2 * outer_gap_v).saturating_sub(2 * border_width);
1592 +
1593 + self.connection.configure_window(
1594 + window,
1595 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1596 + .x(x)
1597 + .y(y)
1598 + .width(width)
1599 + .height(height),
1600 + )?;
1601 + }
1602 + self.connection.flush()?;
1603 + } else {
1604 + if let Some(last) = self.last_layout {
1605 + if let Ok(layout) = layout_from_str(last) {
1606 + self.layout = layout;
1607 + }
1608 + }
1609 + self.toggle_bar()?;
1610 + self.apply_layout()?;
1611 +
1612 + let windows: Vec<Window> = self.windows.iter()
1613 + .filter(|&&w| self.floating_windows.contains(&w) && self.is_window_visible(w))
1614 + .copied()
1615 + .collect();
1616 +
1617 + for window in windows {
1618 + if let Some(&(x, y, width, height, border_width)) = self.floating_geometry_before_fullscreen.get(&window) {
1619 + self.connection.configure_window(
1620 + window,
1621 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1622 + .x(x as i32)
1623 + .y(y as i32)
1624 + .width(width as u32)
1625 + .height(height as u32)
1626 + .border_width(border_width as u32),
1627 + )?;
1628 + self.floating_geometry_before_fullscreen.remove(&window);
1629 + }
1630 + }
1631 + self.connection.flush()?;
1632 + }
1633 + Ok(())
1634 + }
1635 +
1636 + fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> {
1637 + if fullscreen && !self.fullscreen_windows.contains(&window) {
1638 + let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec();
1639 + self.connection.change_property(
1640 + PropMode::REPLACE,
1641 + window,
1642 + self.atoms.net_wm_state,
1643 + AtomEnum::ATOM,
1644 + 32,
1645 + 1,
1646 + &bytes,
1647 + )?;
1648 +
1649 + self.fullscreen_windows.insert(window);
1650 +
1651 + let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor);
1652 + let monitor = &self.monitors[monitor_idx];
1653 +
1654 + if self.show_bar {
1655 + if let Some(bar) = self.bars.get(monitor_idx) {
1656 + self.connection.unmap_window(bar.window())?;
1657 + }
1658 + }
1659 +
1660 + self.connection.configure_window(
1661 + window,
1662 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1663 + .border_width(0)
1664 + .x(monitor.x)
1665 + .y(monitor.y)
1666 + .width(monitor.width as u32)
1667 + .height(monitor.height as u32)
1668 + .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE),
1669 + )?;
1670 +
1671 + self.connection.flush()?;
1672 + self.update_bar()?;
1673 + } else if !fullscreen && self.fullscreen_windows.contains(&window) {
1674 + self.connection.change_property(
1675 + PropMode::REPLACE,
1676 + window,
1677 + self.atoms.net_wm_state,
1678 + AtomEnum::ATOM,
1679 + 32,
1680 + 0,
1681 + &[],
1682 + )?;
1683 +
1684 + self.fullscreen_windows.remove(&window);
1685 +
1686 + self.connection.configure_window(
1687 + window,
1688 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1689 + .border_width(self.config.border_width),
1690 + )?;
1691 +
1692 + let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor);
1693 + if self.show_bar {
1694 + if let Some(bar) = self.bars.get(monitor_idx) {
1695 + self.connection.map_window(bar.window())?;
1696 + }
1697 + }
1698 +
1699 + self.apply_layout()?;
1700 + }
1701 +
1702 + Ok(())
1703 + }
1704 +
1705 + fn toggle_bar(&mut self) -> WmResult<()> {
1706 + self.show_bar = !self.show_bar;
1707 + if let Some(bar) = self.bars.get(self.selected_monitor) {
1708 + if self.show_bar {
1709 + self.connection.map_window(bar.window())?;
1710 + } else {
1711 + self.connection.unmap_window(bar.window())?;
1712 + }
1713 + self.connection.flush()?;
1714 + }
1715 + self.apply_layout()?;
1716 + Ok(())
1717 + }
1718 +
1719 + fn is_transient_window(&self, window: Window) -> bool {
1720 + let transient_for = self.connection
1721 + .get_property(
1722 + false,
1723 + window,
1724 + AtomEnum::WM_TRANSIENT_FOR,
1725 + AtomEnum::WINDOW,
1726 + 0,
1727 + 1,
1728 + )
1729 + .ok()
1730 + .and_then(|cookie| cookie.reply().ok())
1731 + .filter(|reply| !reply.value.is_empty());
1732 +
1733 + transient_for.is_some()
1734 + }
1735 +
1471 pub fn set_focus(&mut self, window: Window) -> WmResult<()> { 1736 pub fn set_focus(&mut self, window: Window) -> WmResult<()> {
1472 let old_focused = self.previous_focused; 1737 let old_focused = self.previous_focused;
1473 1738
@@ -1704,15 +1969,10 @@ impl WindowManager {
1704 return Ok(None); 1969 return Ok(None);
1705 } 1970 }
1706 1971
1707 - if let Ok(geom) = self.connection.get_geometry(event.window)?.reply() {
1708 - self.window_geometries
1709 - .insert(event.window, (geom.x, geom.y, geom.width, geom.height));
1710 - }
1711 -
1712 self.connection.map_window(event.window)?; 1972 self.connection.map_window(event.window)?;
1713 self.connection.change_window_attributes( 1973 self.connection.change_window_attributes(
1714 event.window, 1974 event.window,
1715 - &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW), 1975 + &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE),
1716 )?; 1976 )?;
1717 1977
1718 let selected_tags = self 1978 let selected_tags = self
@@ -1728,6 +1988,57 @@ impl WindowManager {
1728 self.set_wm_state(event.window, 1)?; 1988 self.set_wm_state(event.window, 1)?;
1729 let _ = self.save_client_tag(event.window, selected_tags); 1989 let _ = self.save_client_tag(event.window, selected_tags);
1730 1990
1991 + let is_transient = self.is_transient_window(event.window);
1992 + if is_transient {
1993 + self.floating_windows.insert(event.window);
1994 + }
1995 +
1996 + let is_normie_layout = self.layout.name() == "normie";
1997 + if is_normie_layout && !is_transient {
1998 + let mut pointer_x: i32 = 0;
1999 + let mut pointer_y: i32 = 0;
2000 + let mut root_return: x11::xlib::Window = 0;
2001 + let mut child_return: x11::xlib::Window = 0;
2002 + let mut win_x: i32 = 0;
2003 + let mut win_y: i32 = 0;
2004 + let mut mask_return: u32 = 0;
2005 +
2006 + let pointer_queried = unsafe {
2007 + x11::xlib::XQueryPointer(
2008 + self.display,
2009 + self.root as x11::xlib::Window,
2010 + &mut root_return,
2011 + &mut child_return,
2012 + &mut pointer_x,
2013 + &mut pointer_y,
2014 + &mut win_x,
2015 + &mut win_y,
2016 + &mut mask_return,
2017 + ) != 0
2018 + };
2019 +
2020 + if pointer_queried {
2021 + let window_width = (self.screen.width_in_pixels as f32 * 0.6) as u32;
2022 + let window_height = (self.screen.height_in_pixels as f32 * 0.6) as u32;
2023 +
2024 + let spawn_x = pointer_x - (window_width as i32 / 2);
2025 + let spawn_y = pointer_y - (window_height as i32 / 2);
2026 +
2027 + self.connection.configure_window(
2028 + event.window,
2029 + &ConfigureWindowAux::new()
2030 + .x(spawn_x)
2031 + .y(spawn_y)
2032 + .width(window_width)
2033 + .height(window_height)
2034 + .border_width(self.config.border_width)
2035 + .stack_mode(StackMode::ABOVE),
2036 + )?;
2037 +
2038 + self.floating_windows.insert(event.window);
2039 + }
2040 + }
2041 +
1731 self.apply_layout()?; 2042 self.apply_layout()?;
1732 self.update_bar()?; 2043 self.update_bar()?;
1733 self.set_focus(event.window)?; 2044 self.set_focus(event.window)?;
@@ -1870,6 +2181,22 @@ impl WindowManager {
1870 } 2181 }
1871 } 2182 }
1872 } 2183 }
2184 + Event::ClientMessage(event) => {
2185 + if event.type_ == self.atoms.net_wm_state {
2186 + if let Some(data) = event.data.as_data32().get(1) {
2187 + if *data == self.atoms.net_wm_state_fullscreen {
2188 + let action = event.data.as_data32()[0];
2189 + let fullscreen = match action {
2190 + 1 => true,
2191 + 0 => false,
2192 + 2 => !self.fullscreen_windows.contains(&event.window),
2193 + _ => return Ok(None),
2194 + };
2195 + self.set_window_fullscreen(event.window, fullscreen)?;
2196 + }
2197 + }
2198 + }
2199 + }
1873 _ => {} 2200 _ => {}
1874 } 2201 }
1875 Ok(None) 2202 Ok(None)
@@ -1881,13 +2208,9 @@ impl WindowManager {
1881 } 2208 }
1882 2209
1883 for (monitor_index, monitor) in self.monitors.iter().enumerate() { 2210 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
1884 - let border_width = if monitor.fullscreen_enabled { 2211 + let border_width = self.config.border_width;
1885 - 0
1886 - } else {
1887 - self.config.border_width
1888 - };
1889 2212
1890 - let gaps = if self.gaps_enabled && !monitor.fullscreen_enabled { 2213 + let gaps = if self.gaps_enabled {
1891 GapConfig { 2214 GapConfig {
1892 inner_horizontal: self.config.gap_inner_horizontal, 2215 inner_horizontal: self.config.gap_inner_horizontal,
1893 inner_vertical: self.config.gap_inner_vertical, 2216 inner_vertical: self.config.gap_inner_vertical,
@@ -1914,6 +2237,9 @@ impl WindowManager {
1914 if self.floating_windows.contains(&w) { 2237 if self.floating_windows.contains(&w) {
1915 return false; 2238 return false;
1916 } 2239 }
2240 + if self.fullscreen_windows.contains(&w) {
2241 + return false;
2242 + }
1917 if let Some(&tags) = self.window_tags.get(&w) { 2243 if let Some(&tags) = self.window_tags.get(&w) {
1918 (tags & monitor.selected_tags) != 0 2244 (tags & monitor.selected_tags) != 0
1919 } else { 2245 } else {
@@ -1923,13 +2249,13 @@ impl WindowManager {
1923 .copied() 2249 .copied()
1924 .collect(); 2250 .collect();
1925 2251
1926 - let bar_height = if monitor.fullscreen_enabled { 2252 + let bar_height = if self.show_bar {
1927 - 0
1928 - } else {
1929 self.bars 2253 self.bars
1930 .get(monitor_index) 2254 .get(monitor_index)
1931 .map(|b| b.height() as u32) 2255 .map(|b| b.height() as u32)
1932 .unwrap_or(0) 2256 .unwrap_or(0)
2257 + } else {
2258 + 0
1933 }; 2259 };
1934 let usable_height = monitor.height.saturating_sub(bar_height); 2260 let usable_height = monitor.height.saturating_sub(bar_height);
1935 2261
@@ -1968,10 +2294,10 @@ impl WindowManager {
1968 2294
1969 fn remove_window(&mut self, window: Window) -> WmResult<()> { 2295 fn remove_window(&mut self, window: Window) -> WmResult<()> {
1970 let initial_count = self.windows.len(); 2296 let initial_count = self.windows.len();
2297 +
1971 self.windows.retain(|&w| w != window); 2298 self.windows.retain(|&w| w != window);
1972 self.window_tags.remove(&window); 2299 self.window_tags.remove(&window);
1973 self.window_monitor.remove(&window); 2300 self.window_monitor.remove(&window);
1974 - self.window_geometries.remove(&window);
1975 self.floating_windows.remove(&window); 2301 self.floating_windows.remove(&window);
1976 2302
1977 if self.windows.len() < initial_count { 2303 if self.windows.len() < initial_count {
+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