tony / oxwm

Merge pull request #46 from tonybanters/dwm-refactor Browse files
Client/Monitor Refactor
Tony, btw. committed 2025-12-03 parents 8d0e55b f7feb5d commit f456fd7449f41db3ebdc7b6e45a403eabab95ff1
Showing 25 changed files with 3217 additions and 1371 deletions. UnifiedSplit
+1 −0 .gitignore
@@ -9,4 +9,5 @@ result
9 src/config.rs 9 src/config.rs
10 10
11 # Notes 11 # Notes
12 +notes/
12 *.md 13 *.md
+1 −1 Cargo.lock
@@ -291,7 +291,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
291 291
292 [[package]] 292 [[package]]
293 name = "oxwm" 293 name = "oxwm"
294 -version = "0.7.3" 294 +version = "0.8.0"
295 dependencies = [ 295 dependencies = [
296 "chrono", 296 "chrono",
297 "dirs", 297 "dirs",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 [package] 1 [package]
2 name = "oxwm" 2 name = "oxwm"
3 -version = "0.7.3" 3 +version = "0.8.0"
4 edition = "2024" 4 edition = "2024"
5 5
6 [lib] 6 [lib]
+5 −0 flake.nix
@@ -67,6 +67,11 @@
67 environment.systemPackages = [ 67 environment.systemPackages = [
68 cfg.package 68 cfg.package
69 ]; 69 ];
70 +
71 + environment.pathsToLink = [
72 + "/share/oxwm"
73 + "/share/xsessions"
74 + ];
70 }; 75 };
71 }; 76 };
72 }; 77 };
+132 −79 readme.org
@@ -11,22 +11,26 @@
11 - [[#building-from-source][Building from Source]] 11 - [[#building-from-source][Building from Source]]
12 - [[#setting-up-oxwm][Setting up OXWM]] 12 - [[#setting-up-oxwm][Setting up OXWM]]
13 - [[#configuration][Configuration]] 13 - [[#configuration][Configuration]]
14 + - [[#quick-example][Quick Example]]
15 + - [[#features][Features]]
16 + - [[#key-configuration-areas][Key Configuration Areas]]
17 + - [[#creating-your-config][Creating Your Config]]
14 - [[#contributing][Contributing]] 18 - [[#contributing][Contributing]]
15 - [[#key-bindings][Key Bindings]] 19 - [[#key-bindings][Key Bindings]]
16 -- [[#features][Features]] 20 +- [[#features-1][Features]]
17 - [[#testing-with-xephyr][Testing with Xephyr]] 21 - [[#testing-with-xephyr][Testing with Xephyr]]
18 - [[#project-structure][Project Structure]] 22 - [[#project-structure][Project Structure]]
19 - [[#architecture-notes][Architecture Notes]] 23 - [[#architecture-notes][Architecture Notes]]
24 + - [[#lua-configuration-system][Lua Configuration System]]
20 - [[#tag-system][Tag System]] 25 - [[#tag-system][Tag System]]
21 - [[#status-bar][Status Bar]] 26 - [[#status-bar][Status Bar]]
22 - [[#layout-system][Layout System]] 27 - [[#layout-system][Layout System]]
23 - [[#current-todo-list][Current Todo List:]] 28 - [[#current-todo-list][Current Todo List:]]
24 - - [[#priority-high-02][PRIORITY High]] 29 + - [[#priority-high-04][PRIORITY High]]
25 - - [[#priority-medium-14][PRIORITY Medium]]
26 - - [[#priority-low-11][PRIORITY Low]]
27 - [[#development-roadmap][Development Roadmap]] 30 - [[#development-roadmap][Development Roadmap]]
28 - - [[#current-focus][Current Focus]] 31 + - [[#current-focus-v080][Current Focus (v0.8.0)]]
29 - - [[#future-enhancements][Future Enhancements]] 32 + - [[#completed-features-88][Completed Features]]
33 + - [[#future-enhancements-][Future Enhancements]]
30 - [[#license][License]] 34 - [[#license][License]]
31 35
32 * OXWM — DWM but Better (and oxidized) 36 * OXWM — DWM but Better (and oxidized)
@@ -181,8 +185,21 @@ oxwm.key.bind({ "Mod4" }, "Q", oxwm.client.kill())
181 oxwm.key.bind({ "Mod4", "Shift" }, "Q", oxwm.quit()) 185 oxwm.key.bind({ "Mod4", "Shift" }, "Q", oxwm.quit())
182 186
183 -- Add status bar blocks 187 -- Add status bar blocks
184 -oxwm.bar.add_block("{}", "DateTime", "%H:%M", 60, "#0db9d7", true) 188 +oxwm.bar.set_blocks({
185 -oxwm.bar.add_block("RAM: {used}/{total} GB", "Ram", nil, 5, "#7aa2f7", true) 189 + oxwm.bar.block.datetime({
190 + format = "{}",
191 + date_format = "%H:%M",
192 + interval = 60,
193 + color = "#0db9d7",
194 + underline = true,
195 + }),
196 + oxwm.bar.block.ram({
197 + format = "RAM: {used}/{total} GB",
198 + interval = 5,
199 + color = "#7aa2f7",
200 + underline = true,
201 + }),
202 +})
186 #+end_src 203 #+end_src
187 204
188 ** Features 205 ** Features
@@ -220,38 +237,75 @@ When contributing to OXWM:
220 4. Document any new features or keybindings 237 4. Document any new features or keybindings
221 238
222 * Key Bindings 239 * Key Bindings
223 -Default keybindings (customizable in config.rs): 240 +Default keybindings (fully customizable in =~/.config/oxwm/config.lua=):
224 - 241 +
225 -| Binding | Action | 242 +| Binding | Action |
226 -|-------------------+-------------------------| 243 +|------------------------+-----------------------------------|
227 -| Super+Return | Spawn terminal | 244 +| Super+Return | Spawn terminal |
228 -| Super+J/K | Cycle focus down/up | 245 +| Super+J/K | Cycle focus through stack |
229 -| Super+Q | Kill focused window | 246 +| Super+Q | Kill focused window |
230 -| Super+Shift+Q | Quit WM | 247 +| Super+Shift+Q | Quit WM |
231 -| Super+Shift+R | Hot reload WM | 248 +| Super+Shift+R | Hot reload WM |
232 -| Super+1-9 | View tag 1-9 | 249 +| Super+1-9 | View tag 1-9 |
233 -| Super+Shift+1-9 | Move window to tag 1-9 | 250 +| Super+Shift+1-9 | Move window to tag 1-9 |
234 -| Super+S | Screenshot (maim) | 251 +| Super+Ctrl+1-9 | Toggle tag view (multi-tag) |
235 -| Super+D | dmenu launcher | 252 +| Super+Ctrl+Shift+1-9 | Toggle window tag (sticky) |
236 -| Super+A | Toggle gaps | 253 +| Super+S | Screenshot (maim) |
237 -| Super+Shift+F | Toggle fullscreen | 254 +| Super+D | dmenu launcher |
238 -| Super+Shift+Space | Toggle floating | 255 +| Super+A | Toggle gaps |
256 +| Super+Shift+F | Toggle fullscreen |
257 +| Super+Shift+Space | Toggle floating |
258 +| Super+F | Set normie (floating) layout |
259 +| Super+C | Set tiling layout |
260 +| Super+N | Cycle layouts |
261 +| Super+Comma/Period | Focus prev/next monitor |
262 +| Super+Shift+Comma/. | Send window to prev/next monitor |
263 +| Super+[/] | Decrease/increase master area |
264 +| Super+I/P | Inc/dec number of master windows |
265 +| Super+Shift+/ | Show keybinds overlay |
266 +| Super+Button1 (drag) | Move window (floating) |
267 +| Super+Button3 (drag) | Resize window (floating) |
239 268
240 * Features 269 * Features
241 -- Dynamic tiling layout with master/stack 270 +- *Dynamic Tiling Layout* with adjustable master/stack split
242 -- Tag-based workspaces (9 tags by default) 271 + - Master area resizing (mfact)
243 -- Configurable gaps between windows 272 + - Multiple master windows support (nmaster)
244 -- Status bar with modular block system 273 +- *Tag-Based Workspaces* (9 tags by default)
245 - - Battery, RAM, datetime, shell commands 274 + - Multi-tag viewing (see multiple tags at once)
246 - - Custom colors and update intervals 275 + - Sticky windows (window visible on multiple tags)
276 +- *Multiple Layouts*
277 + - Tiling (master/stack)
278 + - Normie (floating-by-default)
279 + - Monocle (fullscreen stacking)
280 + - Grid (equal-sized grid)
281 + - Tabbed (tabbed windows)
282 +- *Lua Configuration System*
283 + - Hot reload without restarting X (=Mod+Shift+R=)
284 + - LSP support with type definitions and autocomplete
285 + - No compilation needed - instant config changes
286 +- *Built-in Status Bar* with modular block system
287 + - Battery, RAM, datetime, shell commands, static text
288 + - Custom colors, update intervals, and underlines
247 - Click-to-switch tags 289 - Click-to-switch tags
248 -- Window focus cycling 290 + - Multi-monitor support (one bar per monitor)
249 -- Hot reload without restarting X 291 +- *Advanced Window Management*
250 -- Persistent window tags across restarts 292 + - Window focus cycling through stack
251 -- Mouse hover to focus 293 + - Fullscreen mode
252 -- Border indicators for focused windows 294 + - Floating window support
253 -- Fullscreen mode 295 + - Mouse hover to focus (follow mouse)
254 -- Move Windows with Super HJKL 296 + - Border indicators for focused windows
297 + - Configurable gaps (smartgaps support)
298 + - Window rules (auto-tag, auto-float by class/title)
299 +- *Multi-Monitor Support*
300 + - RandR multi-monitor detection
301 + - Independent tags per monitor
302 + - Move windows between monitors
303 +- *Keychord Support*
304 + - Multi-key sequences (Emacs/Vim style)
305 + - Example: =Mod+Space= then =T= to spawn terminal
306 +- *Persistent State*
307 + - Window tags persist across WM restarts
308 + - Uses X11 properties for state storage
255 309
256 * Testing with Xephyr 310 * Testing with Xephyr
257 Test OXWM in a nested X server without affecting your current session: 311 Test OXWM in a nested X server without affecting your current session:
@@ -340,7 +394,11 @@ src/
340 │ 394 │
341 ├── layout/ 395 ├── layout/
342 │ ├── mod.rs [Layout trait definition] 396 │ ├── mod.rs [Layout trait definition]
343 -│ └── tiling.rs [Tiling layout implementation] 397 +│ ├── tiling.rs [Tiling layout with master/stack]
398 +│ ├── monocle.rs [Fullscreen stacking layout]
399 +│ ├── grid.rs [Equal-sized grid layout]
400 +│ ├── tabbed.rs [Tabbed container layout]
401 +│ └── normie.rs [Floating-by-default layout]
344 │ 402 │
345 └── errors.rs [Error types: WmError, ConfigError, etc.] 403 └── errors.rs [Error types: WmError, ConfigError, etc.]
346 404
@@ -373,48 +431,43 @@ The bar uses a performance-optimized approach with a modular block system:
373 The tiling layout divides the screen into a master area (left half) and stack area (right half). The master window occupies the full height of the master area, while stack windows split the stack area vertically. Gaps are configurable and can be toggled at runtime. 431 The tiling layout divides the screen into a master area (left half) and stack area (right half). The master window occupies the full height of the master area, while stack windows split the stack area vertically. Gaps are configurable and can be toggled at runtime.
374 432
375 * TODO Current Todo List: 433 * TODO Current Todo List:
376 -** PRIORITY High [0/2] 434 +** PRIORITY High [0/4]
377 -- [ ] Convert keycodes to keysyms for cross-keyboard compatibility 435 +- [ ] Add Window Titles to Bar
378 - - Current hardcoded keycodes only work on specific keyboards 436 + - Show focused window title in status bar
379 - - Need to use XKeysymToKeycode() for runtime conversion 437 + - Truncate if too long
380 - - Follow DWM's approach: keysym → keycode conversion 438 + - Update on window focus change
381 -- [ ] Fix fullscreen to persist across tags 439 +- [ ] Add Horizontal Scroll Layout
382 - - Fullscreen state should be maintained when switching tags 440 + - Master window on left, stack scrolls horizontally
383 - - Window should remain fullscreen when returning to its tag 441 + - Alternative to vertical tiling
384 - 442 +- [ ] Add Hide Empty Tag Numbers Option
385 -** PRIORITY Medium [2/4] 443 + - Option to hide tags with no windows
386 -- [ ] Add keybindings to increase/decrease window size 444 + - Configurable via =oxwm.bar.set_hide_empty_tags(bool)=
387 - - Master area resize (Mod+H / Mod+L) 445 +- [ ] Add Swap Stack Bind
388 - - Individual window resize for floating windows 446 + - Keybind to swap focused window with master
389 -- [X] Keychords 447 + - Similar to dwm's zoom function (=Mod+Return=)
390 - - Implemented with =oxwm.key.chord()= in the functional API 448 + - Should work bidirectionally
391 - - Example: =oxwm.key.chord({ { {"Mod4"}, "Space" }, { {}, "T" } }, oxwm.spawn("st"))=
392 -- [X] Fix cursor on hover for bar
393 - - Bar should show pointer cursor on hover
394 - - Indicate clickable tag areas
395 -- [ ] Add auto-detect terminal to default config
396 - - Auto-detect available terminal emulator
397 - - Priority order: st → alacritty → kitty → wezterm → xterm
398 - - Fallback to xterm if none found
399 -
400 -** PRIORITY Low [1/1]
401 -- [X] Create AUR package
402 - - Write PKGBUILD
403 - - Submit to AUR
404 - - Add installation instructions to README
405 * Development Roadmap 449 * Development Roadmap
406 -** Current Focus 450 +** Current Focus (v0.8.0)
407 -- Multi-monitor support 451 +- Refactoring to align with dwm's proven patterns
408 -- Additional layouts (monocle, floating) 452 +- Improving core window management reliability
409 -- Master area resizing 453 +- Maintaining Lua config and bar features while simplifying internals
410 -- Window swapping in layout 454 +
411 - 455 +** Completed Features [8/8]
412 -** Future Enhancements 456 +- [X] Multi-monitor support with RandR
413 -- Per-window floating behavior 457 +- [X] Multiple layouts (tiling, monocle, grid, tabbed, normie)
414 -- Per-program rules (auto-tag assignment, floating rules) 458 +- [X] Master area resizing (mfact) and nmaster support
415 -- External bar support (polybar, etc) 459 +- [X] Window rules (per-program auto-tag, floating)
416 -- Scratchpad functionality 460 +- [X] Lua configuration with hot-reload
417 -- Window minimize/restore 461 +- [X] Built-in status bar with modular blocks
462 +- [X] Keychord support (multi-key sequences)
463 +- [X] Tag persistence across restarts
464 +
465 +** Future Enhancements [/]
466 +- [ ] Scratchpad functionality
467 +- [ ] Dynamic monitor hotplugging (currently only on startup)
468 +- [ ] External bar support (polybar, waybar compatibility)
469 +- [ ] Additional layouts (deck, spiral, dwindle)
470 +- [ ] Window minimize/restore
418 471
419 * License 472 * License
420 [[https://www.gnu.org/licenses/gpl-3.0.en.html][GPL v3]] 473 [[https://www.gnu.org/licenses/gpl-3.0.en.html][GPL v3]]
+47 −8 resources/test-config.lua
@@ -42,9 +42,14 @@ oxwm.border.set_focused_color(colors.blue)
42 oxwm.border.set_unfocused_color(colors.grey) 42 oxwm.border.set_unfocused_color(colors.grey)
43 43
44 oxwm.gaps.set_enabled(true) 44 oxwm.gaps.set_enabled(true)
45 +oxwm.gaps.set_smart(true) -- Disable outer gaps when only 1 window (dwm smartgaps)
45 oxwm.gaps.set_inner(5, 5) 46 oxwm.gaps.set_inner(5, 5)
46 oxwm.gaps.set_outer(5, 5) 47 oxwm.gaps.set_outer(5, 5)
47 48
49 +oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
50 +oxwm.rule.add({ instance = "gimp", tag = 5 })
51 +oxwm.rule.add({ instance = "mpv", floating = true })
52 +
48 oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12") 53 oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12")
49 54
50 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, 0x444444) 55 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, 0x444444)
@@ -72,19 +77,28 @@ oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
72 77
73 oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) 78 oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
74 79
80 +-- Master area controls
81 +oxwm.key.bind({ modkey }, "BracketLeft", oxwm.set_master_factor(-5)) -- Decrease master area
82 +oxwm.key.bind({ modkey }, "BracketRight", oxwm.set_master_factor(5)) -- Increase master area
83 +oxwm.key.bind({ modkey }, "I", oxwm.inc_num_master(1)) -- More master windows
84 +oxwm.key.bind({ modkey }, "P", oxwm.inc_num_master(-1)) -- Fewer master windows
85 +
86 +-- Multi-monitor controls (dwm-style)
87 +oxwm.key.bind({ modkey }, "Comma", oxwm.monitor.focus(-1)) -- Focus previous monitor
88 +oxwm.key.bind({ modkey }, "Period", oxwm.monitor.focus(1)) -- Focus next monitor
89 +oxwm.key.bind({ modkey, "Shift" }, "Comma", oxwm.monitor.tag(-1)) -- Send window to previous monitor
90 +oxwm.key.bind({ modkey, "Shift" }, "Period", oxwm.monitor.tag(1)) -- Send window to next monitor
91 +
75 oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) 92 oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
76 oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) 93 oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
77 94
78 -oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left")) 95 +oxwm.key.bind({ modkey }, "J", oxwm.client.focus_stack(1))
79 -oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down")) 96 +oxwm.key.bind({ modkey }, "K", oxwm.client.focus_stack(-1))
80 -oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up"))
81 -oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right"))
82 97
83 -oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left")) 98 +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1))
84 -oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down")) 99 +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1))
85 -oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up"))
86 -oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right"))
87 100
101 +-- View tag (switch workspace)
88 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0)) 102 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
89 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1)) 103 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
90 oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2)) 104 oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
@@ -95,6 +109,7 @@ oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
95 oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7)) 109 oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
96 oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8)) 110 oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
97 111
112 +-- Move window to tag
98 oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0)) 113 oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
99 oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1)) 114 oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
100 oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2)) 115 oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
@@ -105,6 +120,30 @@ oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
105 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7)) 120 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
106 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8)) 121 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
107 122
123 +-- Toggle view (view multiple tags at once) - dwm-style multi-tag viewing
124 +-- Example: Mod+Ctrl+2 while on tag 1 will show BOTH tags 1 and 2
125 +oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(0))
126 +oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(1))
127 +oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(2))
128 +oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(3))
129 +oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(4))
130 +oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(5))
131 +oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(6))
132 +oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(7))
133 +oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(8))
134 +
135 +-- Toggle tag (window on multiple tags) - dwm-style sticky windows
136 +-- Example: Mod+Ctrl+Shift+2 puts focused window on BOTH current tag and tag 2
137 +oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(0))
138 +oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(1))
139 +oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(2))
140 +oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(3))
141 +oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(4))
142 +oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(5))
143 +oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
144 +oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
145 +oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
146 +
108 oxwm.bar.set_blocks({ 147 oxwm.bar.set_blocks({
109 oxwm.bar.block.battery({ 148 oxwm.bar.block.battery({
110 format = "Bat: {}%", 149 format = "Bat: {}%",
+0 −46 src/bin/main.rs
@@ -101,59 +101,13 @@ fn init_config() -> Result<(), Box<dyn std::error::Error>> {
101 let config_path = config_directory.join("config.lua"); 101 let config_path = config_directory.join("config.lua");
102 std::fs::write(&config_path, config_template)?; 102 std::fs::write(&config_path, config_template)?;
103 103
104 - update_lsp_files()?;
105 -
106 println!("✓ Config created at {:?}", config_path); 104 println!("✓ Config created at {:?}", config_path);
107 - println!("✓ LSP definitions installed at {:?}/lib/oxwm.lua", config_directory);
108 println!(" Edit the file and reload with Mod+Shift+R"); 105 println!(" Edit the file and reload with Mod+Shift+R");
109 println!(" No compilation needed - changes take effect immediately!"); 106 println!(" No compilation needed - changes take effect immediately!");
110 107
111 Ok(()) 108 Ok(())
112 } 109 }
113 110
114 -fn update_lsp_files() -> Result<(), Box<dyn std::error::Error>> {
115 - let config_directory = get_config_path();
116 -
117 - let system_paths = [
118 - PathBuf::from("/usr/share/oxwm/oxwm.lua"),
119 - PathBuf::from("/usr/local/share/oxwm/oxwm.lua"),
120 - ];
121 -
122 - let system_oxwm_lua = system_paths.iter().find(|path| path.exists());
123 -
124 - let luarc_content = if let Some(system_path) = system_oxwm_lua {
125 - format!(
126 - r#"{{
127 - "workspace.library": [
128 - "{}"
129 - ]
130 -}}
131 -"#,
132 - system_path.parent().unwrap().display()
133 - )
134 - } else {
135 - let library_directory = config_directory.join("lib");
136 - std::fs::create_dir_all(&library_directory)?;
137 -
138 - let oxwm_lua_template = include_str!("../../templates/oxwm.lua");
139 - let oxwm_lua_path = library_directory.join("oxwm.lua");
140 - std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
141 -
142 - r#"{
143 - "workspace.library": [
144 - "lib"
145 - ]
146 -}
147 -"#
148 - .to_string()
149 - };
150 -
151 - let luarc_path = config_directory.join(".luarc.json");
152 - std::fs::write(&luarc_path, luarc_content)?;
153 -
154 - Ok(())
155 -}
156 -
157 fn get_config_path() -> PathBuf { 111 fn get_config_path() -> PathBuf {
158 dirs::config_dir() 112 dirs::config_dir()
159 .expect("Could not find config directory") 113 .expect("Could not find config directory")
+88 −0 src/client/mod.rs new file mode 100644
@@ -0,0 +1,88 @@
1 +use x11rb::protocol::xproto::Window;
2 +
3 +pub type TagMask = u32;
4 +
5 +#[derive(Debug, Clone)]
6 +pub struct Client {
7 + pub name: String,
8 + pub min_aspect: f32,
9 + pub max_aspect: f32,
10 + pub x_position: i16,
11 + pub y_position: i16,
12 + pub width: u16,
13 + pub height: u16,
14 + pub old_x_position: i16,
15 + pub old_y_position: i16,
16 + pub old_width: u16,
17 + pub old_height: u16,
18 + pub base_width: i32,
19 + pub base_height: i32,
20 + pub increment_width: i32,
21 + pub increment_height: i32,
22 + pub max_width: i32,
23 + pub max_height: i32,
24 + pub min_width: i32,
25 + pub min_height: i32,
26 + pub hints_valid: bool,
27 + pub border_width: u16,
28 + pub old_border_width: u16,
29 + pub tags: TagMask,
30 + pub is_fixed: bool,
31 + pub is_floating: bool,
32 + pub is_urgent: bool,
33 + pub never_focus: bool,
34 + pub old_state: bool,
35 + pub is_fullscreen: bool,
36 + pub next: Option<Window>,
37 + pub stack_next: Option<Window>,
38 + pub monitor_index: usize,
39 + pub window: Window,
40 +}
41 +
42 +impl Client {
43 + pub fn new(window: Window, monitor_index: usize, tags: TagMask) -> Self {
44 + Self {
45 + name: String::new(),
46 + min_aspect: 0.0,
47 + max_aspect: 0.0,
48 + x_position: 0,
49 + y_position: 0,
50 + width: 0,
51 + height: 0,
52 + old_x_position: 0,
53 + old_y_position: 0,
54 + old_width: 0,
55 + old_height: 0,
56 + base_width: 0,
57 + base_height: 0,
58 + increment_width: 0,
59 + increment_height: 0,
60 + max_width: 0,
61 + max_height: 0,
62 + min_width: 0,
63 + min_height: 0,
64 + hints_valid: false,
65 + border_width: 0,
66 + old_border_width: 0,
67 + tags,
68 + is_fixed: false,
69 + is_floating: false,
70 + is_urgent: false,
71 + never_focus: false,
72 + old_state: false,
73 + is_fullscreen: false,
74 + next: None,
75 + stack_next: None,
76 + monitor_index,
77 + window,
78 + }
79 + }
80 +
81 + pub fn width_with_border(&self) -> u16 {
82 + self.width.saturating_add(2 * self.border_width)
83 + }
84 +
85 + pub fn height_with_border(&self) -> u16 {
86 + self.height.saturating_add(2 * self.border_width)
87 + }
88 +}
+2 −0 src/config/lua.rs
@@ -32,6 +32,7 @@ pub fn parse_lua_config(
32 border_unfocused: builder_data.border_unfocused, 32 border_unfocused: builder_data.border_unfocused,
33 font: builder_data.font, 33 font: builder_data.font,
34 gaps_enabled: builder_data.gaps_enabled, 34 gaps_enabled: builder_data.gaps_enabled,
35 + smartgaps_enabled: builder_data.smartgaps_enabled,
35 gap_inner_horizontal: builder_data.gap_inner_horizontal, 36 gap_inner_horizontal: builder_data.gap_inner_horizontal,
36 gap_inner_vertical: builder_data.gap_inner_vertical, 37 gap_inner_vertical: builder_data.gap_inner_vertical,
37 gap_outer_horizontal: builder_data.gap_outer_horizontal, 38 gap_outer_horizontal: builder_data.gap_outer_horizontal,
@@ -41,6 +42,7 @@ pub fn parse_lua_config(
41 tags: builder_data.tags, 42 tags: builder_data.tags,
42 layout_symbols: builder_data.layout_symbols, 43 layout_symbols: builder_data.layout_symbols,
43 keybindings: builder_data.keybindings, 44 keybindings: builder_data.keybindings,
45 + window_rules: builder_data.window_rules,
44 status_blocks: builder_data.status_blocks, 46 status_blocks: builder_data.status_blocks,
45 scheme_normal: builder_data.scheme_normal, 47 scheme_normal: builder_data.scheme_normal,
46 scheme_occupied: builder_data.scheme_occupied, 48 scheme_occupied: builder_data.scheme_occupied,
+99 −38 src/config/lua_api.rs
@@ -16,6 +16,7 @@ pub struct ConfigBuilder {
16 pub border_unfocused: u32, 16 pub border_unfocused: u32,
17 pub font: String, 17 pub font: String,
18 pub gaps_enabled: bool, 18 pub gaps_enabled: bool,
19 + pub smartgaps_enabled: bool,
19 pub gap_inner_horizontal: u32, 20 pub gap_inner_horizontal: u32,
20 pub gap_inner_vertical: u32, 21 pub gap_inner_vertical: u32,
21 pub gap_outer_horizontal: u32, 22 pub gap_outer_horizontal: u32,
@@ -25,6 +26,7 @@ pub struct ConfigBuilder {
25 pub tags: Vec<String>, 26 pub tags: Vec<String>,
26 pub layout_symbols: Vec<crate::LayoutSymbolOverride>, 27 pub layout_symbols: Vec<crate::LayoutSymbolOverride>,
27 pub keybindings: Vec<KeyBinding>, 28 pub keybindings: Vec<KeyBinding>,
29 + pub window_rules: Vec<crate::WindowRule>,
28 pub status_blocks: Vec<BlockConfig>, 30 pub status_blocks: Vec<BlockConfig>,
29 pub scheme_normal: ColorScheme, 31 pub scheme_normal: ColorScheme,
30 pub scheme_occupied: ColorScheme, 32 pub scheme_occupied: ColorScheme,
@@ -40,6 +42,7 @@ impl Default for ConfigBuilder {
40 border_unfocused: 0xbbbbbb, 42 border_unfocused: 0xbbbbbb,
41 font: "monospace:style=Bold:size=10".to_string(), 43 font: "monospace:style=Bold:size=10".to_string(),
42 gaps_enabled: true, 44 gaps_enabled: true,
45 + smartgaps_enabled: true,
43 gap_inner_horizontal: 5, 46 gap_inner_horizontal: 5,
44 gap_inner_vertical: 5, 47 gap_inner_vertical: 5,
45 gap_outer_horizontal: 5, 48 gap_outer_horizontal: 5,
@@ -49,6 +52,7 @@ impl Default for ConfigBuilder {
49 tags: vec!["1".into(), "2".into(), "3".into()], 52 tags: vec!["1".into(), "2".into(), "3".into()],
50 layout_symbols: Vec::new(), 53 layout_symbols: Vec::new(),
51 keybindings: Vec::new(), 54 keybindings: Vec::new(),
55 + window_rules: Vec::new(),
52 status_blocks: Vec::new(), 56 status_blocks: Vec::new(),
53 scheme_normal: ColorScheme { 57 scheme_normal: ColorScheme {
54 foreground: 0xffffff, 58 foreground: 0xffffff,
@@ -84,6 +88,8 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
84 register_client_module(&lua, &oxwm_table)?; 88 register_client_module(&lua, &oxwm_table)?;
85 register_layout_module(&lua, &oxwm_table)?; 89 register_layout_module(&lua, &oxwm_table)?;
86 register_tag_module(&lua, &oxwm_table)?; 90 register_tag_module(&lua, &oxwm_table)?;
91 + register_monitor_module(&lua, &oxwm_table)?;
92 + register_rule_module(&lua, &oxwm_table, builder.clone())?;
87 register_bar_module(&lua, &oxwm_table, builder.clone())?; 93 register_bar_module(&lua, &oxwm_table, builder.clone())?;
88 register_misc(&lua, &oxwm_table, builder.clone())?; 94 register_misc(&lua, &oxwm_table, builder.clone())?;
89 95
@@ -184,11 +190,18 @@ fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Re
184 Ok(()) 190 Ok(())
185 })?; 191 })?;
186 192
193 + let builder_clone = builder.clone();
194 + let set_smart = lua.create_function(move |_, enabled: bool| {
195 + builder_clone.borrow_mut().smartgaps_enabled = enabled;
196 + Ok(())
197 + })?;
198 +
187 gaps_table.set("set_enabled", set_enabled)?; 199 gaps_table.set("set_enabled", set_enabled)?;
188 gaps_table.set("enable", enable)?; 200 gaps_table.set("enable", enable)?;
189 gaps_table.set("disable", disable)?; 201 gaps_table.set("disable", disable)?;
190 gaps_table.set("set_inner", set_inner)?; 202 gaps_table.set("set_inner", set_inner)?;
191 gaps_table.set("set_outer", set_outer)?; 203 gaps_table.set("set_outer", set_outer)?;
204 + gaps_table.set("set_smart", set_smart)?;
192 parent.set("gaps", gaps_table)?; 205 parent.set("gaps", gaps_table)?;
193 Ok(()) 206 Ok(())
194 } 207 }
@@ -242,33 +255,15 @@ fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError>
242 create_action_table(lua, "FocusStack", Value::Integer(dir as i64)) 255 create_action_table(lua, "FocusStack", Value::Integer(dir as i64))
243 })?; 256 })?;
244 257
245 - let focus_direction = lua.create_function(|lua, dir: String| { 258 + let move_stack = lua.create_function(|lua, dir: i32| {
246 - let dir_int = direction_string_to_int(&dir)?; 259 + create_action_table(lua, "MoveStack", Value::Integer(dir as i64))
247 - create_action_table(lua, "FocusDirection", Value::Integer(dir_int))
248 - })?;
249 -
250 - let swap_direction = lua.create_function(|lua, dir: String| {
251 - let dir_int = direction_string_to_int(&dir)?;
252 - create_action_table(lua, "SwapDirection", Value::Integer(dir_int))
253 - })?;
254 -
255 - let smart_move = lua.create_function(|lua, dir: String| {
256 - let dir_int = direction_string_to_int(&dir)?;
257 - create_action_table(lua, "SmartMoveWin", Value::Integer(dir_int))
258 - })?;
259 -
260 - let exchange = lua.create_function(|lua, ()| {
261 - create_action_table(lua, "ExchangeClient", Value::Nil)
262 })?; 260 })?;
263 261
264 client_table.set("kill", kill)?; 262 client_table.set("kill", kill)?;
265 client_table.set("toggle_fullscreen", toggle_fullscreen)?; 263 client_table.set("toggle_fullscreen", toggle_fullscreen)?;
266 client_table.set("toggle_floating", toggle_floating)?; 264 client_table.set("toggle_floating", toggle_floating)?;
267 client_table.set("focus_stack", focus_stack)?; 265 client_table.set("focus_stack", focus_stack)?;
268 - client_table.set("focus_direction", focus_direction)?; 266 + client_table.set("move_stack", move_stack)?;
269 - client_table.set("swap_direction", swap_direction)?;
270 - client_table.set("smart_move", smart_move)?;
271 - client_table.set("exchange", exchange)?;
272 267
273 parent.set("client", client_table)?; 268 parent.set("client", client_table)?;
274 Ok(()) 269 Ok(())
@@ -298,16 +293,82 @@ fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
298 create_action_table(lua, "ViewTag", Value::Integer(idx as i64)) 293 create_action_table(lua, "ViewTag", Value::Integer(idx as i64))
299 })?; 294 })?;
300 295
296 + let toggleview = lua.create_function(|lua, idx: i32| {
297 + create_action_table(lua, "ToggleView", Value::Integer(idx as i64))
298 + })?;
299 +
301 let move_to = lua.create_function(|lua, idx: i32| { 300 let move_to = lua.create_function(|lua, idx: i32| {
302 create_action_table(lua, "MoveToTag", Value::Integer(idx as i64)) 301 create_action_table(lua, "MoveToTag", Value::Integer(idx as i64))
303 })?; 302 })?;
304 303
304 + let toggletag = lua.create_function(|lua, idx: i32| {
305 + create_action_table(lua, "ToggleTag", Value::Integer(idx as i64))
306 + })?;
307 +
305 tag_table.set("view", view)?; 308 tag_table.set("view", view)?;
309 + tag_table.set("toggleview", toggleview)?;
306 tag_table.set("move_to", move_to)?; 310 tag_table.set("move_to", move_to)?;
311 + tag_table.set("toggletag", toggletag)?;
307 parent.set("tag", tag_table)?; 312 parent.set("tag", tag_table)?;
308 Ok(()) 313 Ok(())
309 } 314 }
310 315
316 +fn register_monitor_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
317 + let monitor_table = lua.create_table()?;
318 +
319 + let focus = lua.create_function(|lua, direction: i64| {
320 + create_action_table(lua, "FocusMonitor", Value::Integer(direction))
321 + })?;
322 +
323 + let tag = lua.create_function(|lua, direction: i64| {
324 + create_action_table(lua, "TagMonitor", Value::Integer(direction))
325 + })?;
326 +
327 + monitor_table.set("focus", focus)?;
328 + monitor_table.set("tag", tag)?;
329 + parent.set("monitor", monitor_table)?;
330 + Ok(())
331 +}
332 +
333 +fn register_rule_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
334 + let rule_table = lua.create_table()?;
335 +
336 + let builder_clone = builder.clone();
337 + let add = lua.create_function(move |_, config: Table| {
338 + let class: Option<String> = config.get("class").ok();
339 + let instance: Option<String> = config.get("instance").ok();
340 + let title: Option<String> = config.get("title").ok();
341 + let is_floating: Option<bool> = config.get("floating").ok();
342 + let monitor: Option<usize> = config.get("monitor").ok();
343 +
344 + let tags: Option<u32> = if let Ok(tag_index) = config.get::<i32>("tag") {
345 + if tag_index > 0 {
346 + Some(1 << (tag_index - 1))
347 + } else {
348 + None
349 + }
350 + } else {
351 + None
352 + };
353 +
354 + let rule = crate::WindowRule {
355 + class,
356 + instance,
357 + title,
358 + tags,
359 + is_floating,
360 + monitor,
361 + };
362 +
363 + builder_clone.borrow_mut().window_rules.push(rule);
364 + Ok(())
365 + })?;
366 +
367 + rule_table.set("add", add)?;
368 + parent.set("rule", rule_table)?;
369 + Ok(())
370 +}
371 +
311 fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 372 fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> {
312 let bar_table = lua.create_table()?; 373 let bar_table = lua.create_table()?;
313 374
@@ -594,6 +655,14 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
594 create_action_table(lua, "ToggleGaps", Value::Nil) 655 create_action_table(lua, "ToggleGaps", Value::Nil)
595 })?; 656 })?;
596 657
658 + let set_master_factor = lua.create_function(|lua, delta: i32| {
659 + create_action_table(lua, "SetMasterFactor", Value::Integer(delta as i64))
660 + })?;
661 +
662 + let inc_num_master = lua.create_function(|lua, delta: i32| {
663 + create_action_table(lua, "IncNumMaster", Value::Integer(delta as i64))
664 + })?;
665 +
597 let show_keybinds = lua.create_function(|lua, ()| { 666 let show_keybinds = lua.create_function(|lua, ()| {
598 create_action_table(lua, "ShowKeybindOverlay", Value::Nil) 667 create_action_table(lua, "ShowKeybindOverlay", Value::Nil)
599 })?; 668 })?;
@@ -626,6 +695,8 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
626 parent.set("restart", restart)?; 695 parent.set("restart", restart)?;
627 parent.set("recompile", recompile)?; 696 parent.set("recompile", recompile)?;
628 parent.set("toggle_gaps", toggle_gaps)?; 697 parent.set("toggle_gaps", toggle_gaps)?;
698 + parent.set("set_master_factor", set_master_factor)?;
699 + parent.set("inc_num_master", inc_num_master)?;
629 parent.set("show_keybinds", show_keybinds)?; 700 parent.set("show_keybinds", show_keybinds)?;
630 parent.set("focus_monitor", focus_monitor)?; 701 parent.set("focus_monitor", focus_monitor)?;
631 Ok(()) 702 Ok(())
@@ -707,21 +778,23 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
707 "SpawnTerminal" => Ok(KeyAction::SpawnTerminal), 778 "SpawnTerminal" => Ok(KeyAction::SpawnTerminal),
708 "KillClient" => Ok(KeyAction::KillClient), 779 "KillClient" => Ok(KeyAction::KillClient),
709 "FocusStack" => Ok(KeyAction::FocusStack), 780 "FocusStack" => Ok(KeyAction::FocusStack),
710 - "FocusDirection" => Ok(KeyAction::FocusDirection), 781 + "MoveStack" => Ok(KeyAction::MoveStack),
711 - "SwapDirection" => Ok(KeyAction::SwapDirection),
712 "Quit" => Ok(KeyAction::Quit), 782 "Quit" => Ok(KeyAction::Quit),
713 "Restart" => Ok(KeyAction::Restart), 783 "Restart" => Ok(KeyAction::Restart),
714 "Recompile" => Ok(KeyAction::Recompile), 784 "Recompile" => Ok(KeyAction::Recompile),
715 "ViewTag" => Ok(KeyAction::ViewTag), 785 "ViewTag" => Ok(KeyAction::ViewTag),
786 + "ToggleView" => Ok(KeyAction::ToggleView),
787 + "MoveToTag" => Ok(KeyAction::MoveToTag),
788 + "ToggleTag" => Ok(KeyAction::ToggleTag),
716 "ToggleGaps" => Ok(KeyAction::ToggleGaps), 789 "ToggleGaps" => Ok(KeyAction::ToggleGaps),
790 + "SetMasterFactor" => Ok(KeyAction::SetMasterFactor),
791 + "IncNumMaster" => Ok(KeyAction::IncNumMaster),
717 "ToggleFullScreen" => Ok(KeyAction::ToggleFullScreen), 792 "ToggleFullScreen" => Ok(KeyAction::ToggleFullScreen),
718 "ToggleFloating" => Ok(KeyAction::ToggleFloating), 793 "ToggleFloating" => Ok(KeyAction::ToggleFloating),
719 "ChangeLayout" => Ok(KeyAction::ChangeLayout), 794 "ChangeLayout" => Ok(KeyAction::ChangeLayout),
720 "CycleLayout" => Ok(KeyAction::CycleLayout), 795 "CycleLayout" => Ok(KeyAction::CycleLayout),
721 - "MoveToTag" => Ok(KeyAction::MoveToTag),
722 "FocusMonitor" => Ok(KeyAction::FocusMonitor), 796 "FocusMonitor" => Ok(KeyAction::FocusMonitor),
723 - "SmartMoveWin" => Ok(KeyAction::SmartMoveWin), 797 + "TagMonitor" => Ok(KeyAction::TagMonitor),
724 - "ExchangeClient" => Ok(KeyAction::ExchangeClient),
725 "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay), 798 "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay),
726 _ => Err(mlua::Error::RuntimeError(format!("unknown action '{}'. this is an internal error, please report it", s))), 799 _ => Err(mlua::Error::RuntimeError(format!("unknown action '{}'. this is an internal error, please report it", s))),
727 } 800 }
@@ -752,18 +825,6 @@ fn create_action_table(lua: &Lua, action_name: &str, arg: Value) -> mlua::Result
752 Ok(table) 825 Ok(table)
753 } 826 }
754 827
755 -fn direction_string_to_int(dir: &str) -> mlua::Result<i64> {
756 - match dir {
757 - "up" => Ok(0),
758 - "down" => Ok(1),
759 - "left" => Ok(2),
760 - "right" => Ok(3),
761 - _ => Err(mlua::Error::RuntimeError(
762 - format!("invalid direction '{}'. must be one of: up, down, left, right", dir)
763 - )),
764 - }
765 -}
766 -
767 fn parse_color_value(value: Value) -> mlua::Result<u32> { 828 fn parse_color_value(value: Value) -> mlua::Result<u32> {
768 match value { 829 match value {
769 Value::Integer(i) => Ok(i as u32), 830 Value::Integer(i) => Ok(i as u32),
+46 −21 src/keyboard/handlers.rs
@@ -15,22 +15,24 @@ pub enum KeyAction {
15 SpawnTerminal, 15 SpawnTerminal,
16 KillClient, 16 KillClient,
17 FocusStack, 17 FocusStack,
18 - FocusDirection, 18 + MoveStack,
19 - SwapDirection,
20 Quit, 19 Quit,
21 Restart, 20 Restart,
22 Recompile, 21 Recompile,
23 ViewTag, 22 ViewTag,
23 + ToggleView,
24 + MoveToTag,
25 + ToggleTag,
24 ToggleGaps, 26 ToggleGaps,
25 ToggleFullScreen, 27 ToggleFullScreen,
26 ToggleFloating, 28 ToggleFloating,
27 ChangeLayout, 29 ChangeLayout,
28 CycleLayout, 30 CycleLayout,
29 - MoveToTag,
30 FocusMonitor, 31 FocusMonitor,
31 - SmartMoveWin, 32 + TagMonitor,
32 - ExchangeClient,
33 ShowKeybindOverlay, 33 ShowKeybindOverlay,
34 + SetMasterFactor,
35 + IncNumMaster,
34 None, 36 None,
35 } 37 }
36 38
@@ -148,6 +150,13 @@ pub fn setup_keybinds(
148 let (keysym_to_keycode, _) = build_keysym_maps(connection)?; 150 let (keysym_to_keycode, _) = build_keysym_maps(connection)?;
149 let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new(); 151 let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new();
150 152
153 + let ignore_modifiers = [
154 + 0,
155 + u16::from(ModMask::LOCK),
156 + u16::from(ModMask::M2),
157 + u16::from(ModMask::LOCK | ModMask::M2),
158 + ];
159 +
151 for keybinding in keybindings { 160 for keybinding in keybindings {
152 if keybinding.keys.is_empty() { 161 if keybinding.keys.is_empty() {
153 continue; 162 continue;
@@ -158,17 +167,20 @@ pub fn setup_keybinds(
158 167
159 if let Some(keycodes) = keysym_to_keycode.get(&first_key.keysym) { 168 if let Some(keycodes) = keysym_to_keycode.get(&first_key.keysym) {
160 if let Some(&keycode) = keycodes.first() { 169 if let Some(&keycode) = keycodes.first() {
161 - let key_tuple = (modifier_mask, keycode); 170 + for &ignore_mask in &ignore_modifiers {
162 - 171 + let grab_mask = modifier_mask | ignore_mask;
163 - if grabbed_keys.insert(key_tuple) { 172 + let key_tuple = (grab_mask, keycode);
164 - connection.grab_key( 173 +
165 - false, 174 + if grabbed_keys.insert(key_tuple) {
166 - root, 175 + connection.grab_key(
167 - modifier_mask.into(), 176 + false,
168 - keycode, 177 + root,
169 - GrabMode::ASYNC, 178 + grab_mask.into(),
170 - GrabMode::ASYNC, 179 + keycode,
171 - )?; 180 + GrabMode::ASYNC,
181 + GrabMode::ASYNC,
182 + )?;
183 + }
172 } 184 }
173 } 185 }
174 } 186 }
@@ -209,6 +221,8 @@ fn handle_first_key(
209 ) -> KeychordResult { 221 ) -> KeychordResult {
210 let mut candidates = Vec::new(); 222 let mut candidates = Vec::new();
211 223
224 + let clean_state = event.state & !(u16::from(ModMask::LOCK) | u16::from(ModMask::M2));
225 +
212 for (keybinding_index, keybinding) in keybindings.iter().enumerate() { 226 for (keybinding_index, keybinding) in keybindings.iter().enumerate() {
213 if keybinding.keys.is_empty() { 227 if keybinding.keys.is_empty() {
214 continue; 228 continue;
@@ -217,7 +231,7 @@ fn handle_first_key(
217 let first_key = &keybinding.keys[0]; 231 let first_key = &keybinding.keys[0];
218 let modifier_mask = modifiers_to_mask(&first_key.modifiers); 232 let modifier_mask = modifiers_to_mask(&first_key.modifiers);
219 233
220 - if event_keysym == first_key.keysym && event.state == modifier_mask.into() { 234 + if event_keysym == first_key.keysym && clean_state == modifier_mask.into() {
221 if keybinding.keys.len() == 1 { 235 if keybinding.keys.len() == 1 {
222 return KeychordResult::Completed(keybinding.func, keybinding.arg.clone()); 236 return KeychordResult::Completed(keybinding.func, keybinding.arg.clone());
223 } else { 237 } else {
@@ -242,6 +256,8 @@ fn handle_next_key(
242 ) -> KeychordResult { 256 ) -> KeychordResult {
243 let mut new_candidates = Vec::new(); 257 let mut new_candidates = Vec::new();
244 258
259 + let clean_state = event.state & !(u16::from(ModMask::LOCK) | u16::from(ModMask::M2));
260 +
245 for &candidate_index in candidates { 261 for &candidate_index in candidates {
246 let keybinding = &keybindings[candidate_index]; 262 let keybinding = &keybindings[candidate_index];
247 263
@@ -251,12 +267,11 @@ fn handle_next_key(
251 267
252 let next_key = &keybinding.keys[keys_pressed]; 268 let next_key = &keybinding.keys[keys_pressed];
253 let required_mask = modifiers_to_mask(&next_key.modifiers); 269 let required_mask = modifiers_to_mask(&next_key.modifiers);
254 - let event_state: u16 = event.state.into();
255 270
256 let modifiers_match = if next_key.modifiers.is_empty() { 271 let modifiers_match = if next_key.modifiers.is_empty() {
257 true 272 true
258 } else { 273 } else {
259 - (event_state & required_mask) == required_mask 274 + (clean_state & required_mask) == required_mask.into()
260 }; 275 };
261 276
262 if event_keysym == next_key.keysym && modifiers_match { 277 if event_keysym == next_key.keysym && modifiers_match {
@@ -275,7 +290,7 @@ fn handle_next_key(
275 } 290 }
276 } 291 }
277 292
278 -pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> Result<()> { 293 +pub fn handle_spawn_action(action: KeyAction, arg: &Arg, selected_monitor: usize) -> Result<()> {
279 if let KeyAction::Spawn = action { 294 if let KeyAction::Spawn = action {
280 match arg { 295 match arg {
281 Arg::Str(command) => match Command::new(command.as_str()).spawn() { 296 Arg::Str(command) => match Command::new(command.as_str()).spawn() {
@@ -293,7 +308,17 @@ pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> Result<()> {
293 return Ok(()); 308 return Ok(());
294 }; 309 };
295 310
296 - let args_str: Vec<&str> = args.iter().map(|s| s.as_str()).collect(); 311 + let mut args_vec: Vec<String> = args.to_vec();
312 +
313 + let is_dmenu = cmd.contains("dmenu");
314 + let has_monitor_flag = args.iter().any(|arg| arg == "-m");
315 +
316 + if is_dmenu && !has_monitor_flag {
317 + args_vec.insert(0, selected_monitor.to_string());
318 + args_vec.insert(0, "-m".to_string());
319 + }
320 +
321 + let args_str: Vec<&str> = args_vec.iter().map(|s| s.as_str()).collect();
297 match Command::new(cmd.as_str()).args(&args_str).spawn() { 322 match Command::new(cmd.as_str()).args(&args_str).spawn() {
298 Err(error) if error.kind() == ErrorKind::NotFound => { 323 Err(error) if error.kind() == ErrorKind::NotFound => {
299 eprintln!( 324 eprintln!(
+3 −0 src/layout/grid.rs
@@ -18,6 +18,9 @@ impl Layout for GridLayout {
18 screen_width: u32, 18 screen_width: u32,
19 screen_height: u32, 19 screen_height: u32,
20 gaps: &GapConfig, 20 gaps: &GapConfig,
21 + _master_factor: f32,
22 + _num_master: i32,
23 + _smartgaps_enabled: bool,
21 ) -> Vec<WindowGeometry> { 24 ) -> Vec<WindowGeometry> {
22 let window_count = windows.len(); 25 let window_count = windows.len();
23 if window_count == 0 { 26 if window_count == 0 {
+3 −0 src/layout/mod.rs
@@ -86,6 +86,9 @@ pub trait Layout {
86 screen_width: u32, 86 screen_width: u32,
87 screen_height: u32, 87 screen_height: u32,
88 gaps: &GapConfig, 88 gaps: &GapConfig,
89 + master_factor: f32,
90 + num_master: i32,
91 + smartgaps_enabled: bool,
89 ) -> Vec<WindowGeometry>; 92 ) -> Vec<WindowGeometry>;
90 fn name(&self) -> &'static str; 93 fn name(&self) -> &'static str;
91 fn symbol(&self) -> &'static str; 94 fn symbol(&self) -> &'static str;
+3 −0 src/layout/monocle.rs
@@ -18,6 +18,9 @@ impl Layout for MonocleLayout {
18 screen_width: u32, 18 screen_width: u32,
19 screen_height: u32, 19 screen_height: u32,
20 gaps: &GapConfig, 20 gaps: &GapConfig,
21 + _master_factor: f32,
22 + _num_master: i32,
23 + _smartgaps_enabled: bool,
21 ) -> Vec<WindowGeometry> { 24 ) -> Vec<WindowGeometry> {
22 let window_count = windows.len(); 25 let window_count = windows.len();
23 if window_count == 0 { 26 if window_count == 0 {
+7 −23 src/layout/normie.rs
@@ -15,30 +15,14 @@ impl Layout for NormieLayout {
15 15
16 fn arrange( 16 fn arrange(
17 &self, 17 &self,
18 - windows: &[Window], 18 + _windows: &[Window],
19 - screen_width: u32, 19 + _screen_width: u32,
20 - screen_height: u32, 20 + _screen_height: u32,
21 _gaps: &GapConfig, 21 _gaps: &GapConfig,
22 + _master_factor: f32,
23 + _num_master: i32,
24 + _smartgaps_enabled: bool,
22 ) -> Vec<WindowGeometry> { 25 ) -> Vec<WindowGeometry> {
23 - const DEFAULT_WIDTH_RATIO: f32 = 0.6; 26 + Vec::new()
24 - const DEFAULT_HEIGHT_RATIO: f32 = 0.6;
25 -
26 - windows
27 - .iter()
28 - .map(|_| {
29 - let width = ((screen_width as f32) * DEFAULT_WIDTH_RATIO) as u32;
30 - let height = ((screen_height as f32) * DEFAULT_HEIGHT_RATIO) as u32;
31 -
32 - let x = ((screen_width - width) / 2) as i32;
33 - let y = ((screen_height - height) / 2) as i32;
34 -
35 - WindowGeometry {
36 - x_coordinate: x,
37 - y_coordinate: y,
38 - width,
39 - height,
40 - }
41 - })
42 - .collect()
43 } 27 }
44 } 28 }
+3 −0 src/layout/tabbed.rs
@@ -20,6 +20,9 @@ impl Layout for TabbedLayout {
20 screen_width: u32, 20 screen_width: u32,
21 screen_height: u32, 21 screen_height: u32,
22 gaps: &GapConfig, 22 gaps: &GapConfig,
23 + _master_factor: f32,
24 + _num_master: i32,
25 + _smartgaps_enabled: bool,
23 ) -> Vec<WindowGeometry> { 26 ) -> Vec<WindowGeometry> {
24 let window_count = windows.len(); 27 let window_count = windows.len();
25 if window_count == 0 { 28 if window_count == 0 {
+136 −43 src/layout/tiling.rs
@@ -3,6 +3,73 @@ use x11rb::protocol::xproto::Window;
3 3
4 pub struct TilingLayout; 4 pub struct TilingLayout;
5 5
6 +struct GapValues {
7 + outer_horizontal: u32,
8 + outer_vertical: u32,
9 + inner_horizontal: u32,
10 + inner_vertical: u32,
11 +}
12 +
13 +struct FactValues {
14 + master_facts: f32,
15 + stack_facts: f32,
16 + master_remainder: i32,
17 + stack_remainder: i32,
18 +}
19 +
20 +impl TilingLayout {
21 + fn getgaps(gaps: &GapConfig, window_count: usize, smartgaps_enabled: bool) -> GapValues {
22 + let outer_enabled = if smartgaps_enabled && window_count == 1 {
23 + 0
24 + } else {
25 + 1
26 + };
27 + let inner_enabled = 1;
28 +
29 + GapValues {
30 + outer_horizontal: gaps.outer_horizontal * outer_enabled,
31 + outer_vertical: gaps.outer_vertical * outer_enabled,
32 + inner_horizontal: gaps.inner_horizontal * inner_enabled,
33 + inner_vertical: gaps.inner_vertical * inner_enabled,
34 + }
35 + }
36 +
37 + fn getfacts(
38 + window_count: usize,
39 + num_master: i32,
40 + master_size: i32,
41 + stack_size: i32,
42 + ) -> FactValues {
43 + let num_master = num_master.max(0) as usize;
44 + let master_facts = window_count.min(num_master) as f32;
45 + let stack_facts = if window_count > num_master {
46 + (window_count - num_master) as f32
47 + } else {
48 + 0.0
49 + };
50 +
51 + let mut master_total = 0;
52 + let mut stack_total = 0;
53 +
54 + for i in 0..window_count {
55 + if i < num_master {
56 + master_total += (master_size as f32 / master_facts) as i32;
57 + } else {
58 + if stack_facts > 0.0 {
59 + stack_total += (stack_size as f32 / stack_facts) as i32;
60 + }
61 + }
62 + }
63 +
64 + FactValues {
65 + master_facts,
66 + stack_facts,
67 + master_remainder: master_size - master_total,
68 + stack_remainder: stack_size - stack_total,
69 + }
70 + }
71 +}
72 +
6 impl Layout for TilingLayout { 73 impl Layout for TilingLayout {
7 fn name(&self) -> &'static str { 74 fn name(&self) -> &'static str {
8 super::LayoutType::Tiling.as_str() 75 super::LayoutType::Tiling.as_str()
@@ -18,68 +85,94 @@ impl Layout for TilingLayout {
18 screen_width: u32, 85 screen_width: u32,
19 screen_height: u32, 86 screen_height: u32,
20 gaps: &GapConfig, 87 gaps: &GapConfig,
88 + master_factor: f32,
89 + num_master: i32,
90 + smartgaps_enabled: bool,
21 ) -> Vec<WindowGeometry> { 91 ) -> Vec<WindowGeometry> {
22 let window_count = windows.len(); 92 let window_count = windows.len();
23 if window_count == 0 { 93 if window_count == 0 {
24 return Vec::new(); 94 return Vec::new();
25 } 95 }
26 96
27 - if window_count == 1 { 97 + let gap_values = Self::getgaps(gaps, window_count, smartgaps_enabled);
28 - let x = gaps.outer_horizontal as i32; 98 +
29 - let y = gaps.outer_vertical as i32; 99 + let outer_gap_horizontal = gap_values.outer_horizontal;
30 - let width = screen_width.saturating_sub(2 * gaps.outer_horizontal); 100 + let outer_gap_vertical = gap_values.outer_vertical;
31 - let height = screen_height.saturating_sub(2 * gaps.outer_vertical); 101 + let inner_gap_horizontal = gap_values.inner_horizontal;
32 - 102 + let inner_gap_vertical = gap_values.inner_vertical;
33 - vec![WindowGeometry { 103 +
34 - x_coordinate: x, 104 + let mut stack_x = outer_gap_vertical as i32;
35 - y_coordinate: y, 105 + let mut stack_y = outer_gap_horizontal as i32;
36 - width, 106 + let master_x = outer_gap_vertical as i32;
37 - height, 107 + let mut master_y = outer_gap_horizontal as i32;
38 - }] 108 +
109 + let num_master_usize = num_master.max(0) as usize;
110 + let master_count = window_count.min(num_master_usize);
111 + let stack_count = if window_count > num_master_usize {
112 + window_count - num_master_usize
39 } else { 113 } else {
40 - let mut geometries = Vec::new(); 114 + 0
115 + };
41 116
42 - let master_width = (screen_width / 2) 117 + let master_height = (screen_height as i32)
43 - .saturating_sub(gaps.outer_horizontal) 118 + - (2 * outer_gap_horizontal) as i32
44 - .saturating_sub(gaps.inner_horizontal / 2); 119 + - (inner_gap_horizontal as i32 * (master_count.saturating_sub(1)) as i32);
120 + let stack_height = (screen_height as i32)
121 + - (2 * outer_gap_horizontal) as i32
122 + - (inner_gap_horizontal as i32 * stack_count.saturating_sub(1) as i32);
123 + let mut stack_width = (screen_width as i32) - (2 * outer_gap_vertical) as i32;
124 + let mut master_width = stack_width;
45 125
46 - let master_x = gaps.outer_horizontal as i32; 126 + if num_master > 0 && window_count > num_master_usize {
47 - let master_y = gaps.outer_vertical as i32; 127 + stack_width = ((master_width as f32 - inner_gap_vertical as f32) * (1.0 - master_factor)) as i32;
48 - let master_height = screen_height.saturating_sub(2 * gaps.outer_vertical); 128 + master_width = master_width - inner_gap_vertical as i32 - stack_width;
129 + stack_x = master_x + master_width + inner_gap_vertical as i32;
130 + }
49 131
50 - geometries.push(WindowGeometry { 132 + let facts = Self::getfacts(window_count, num_master, master_height, stack_height);
51 - x_coordinate: master_x,
52 - y_coordinate: master_y,
53 - width: master_width,
54 - height: master_height,
55 - });
56 133
57 - let stack_count = window_count - 1; 134 + let mut geometries = Vec::new();
58 - let stack_x = (screen_width / 2 + gaps.inner_horizontal / 2) as i32;
59 - let stack_width = (screen_width / 2)
60 - .saturating_sub(gaps.outer_horizontal)
61 - .saturating_sub(gaps.inner_horizontal / 2);
62 135
63 - let total_stack_height = screen_height.saturating_sub(2 * gaps.outer_vertical); 136 + for (i, _window) in windows.iter().enumerate() {
137 + if i < num_master_usize {
138 + let window_height = (master_height as f32 / facts.master_facts) as i32
139 + + if (i as i32) < facts.master_remainder {
140 + 1
141 + } else {
142 + 0
143 + };
64 144
65 - let total_inner_gaps = gaps.inner_vertical * (stack_count as u32 - 1); 145 + geometries.push(WindowGeometry {
66 - let stack_height = 146 + x_coordinate: master_x,
67 - total_stack_height.saturating_sub(total_inner_gaps) / stack_count as u32; 147 + y_coordinate: master_y,
148 + width: master_width as u32,
149 + height: window_height as u32,
150 + });
68 151
69 - for i in 1..window_count { 152 + master_y += window_height + inner_gap_horizontal as i32;
70 - let stack_index = i - 1; 153 + } else {
71 - let y_offset = gaps.outer_vertical 154 + let window_height = if facts.stack_facts > 0.0 {
72 - + (stack_index as u32) * (stack_height + gaps.inner_vertical); 155 + (stack_height as f32 / facts.stack_facts) as i32
156 + + if ((i - num_master_usize) as i32) < facts.stack_remainder {
157 + 1
158 + } else {
159 + 0
160 + }
161 + } else {
162 + stack_height
163 + };
73 164
74 geometries.push(WindowGeometry { 165 geometries.push(WindowGeometry {
75 x_coordinate: stack_x, 166 x_coordinate: stack_x,
76 - y_coordinate: y_offset as i32, 167 + y_coordinate: stack_y,
77 - width: stack_width, 168 + width: stack_width as u32,
78 - height: stack_height, 169 + height: window_height as u32,
79 }); 170 });
80 - }
81 171
82 - return geometries; 172 + stack_y += window_height + inner_gap_horizontal as i32;
173 + }
83 } 174 }
175 +
176 + geometries
84 } 177 }
85 } 178 }
+27 −24 src/lib.rs
@@ -1,4 +1,5 @@
1 pub mod bar; 1 pub mod bar;
2 +pub mod client;
2 pub mod config; 3 pub mod config;
3 pub mod errors; 4 pub mod errors;
4 pub mod keyboard; 5 pub mod keyboard;
@@ -11,6 +12,7 @@ pub mod window_manager;
11 pub mod prelude { 12 pub mod prelude {
12 pub use crate::ColorScheme; 13 pub use crate::ColorScheme;
13 pub use crate::LayoutSymbolOverride; 14 pub use crate::LayoutSymbolOverride;
15 + pub use crate::WindowRule;
14 pub use crate::bar::{BlockCommand, BlockConfig}; 16 pub use crate::bar::{BlockCommand, BlockConfig};
15 pub use crate::keyboard::{Arg, KeyAction, handlers::KeyBinding, keysyms}; 17 pub use crate::keyboard::{Arg, KeyAction, handlers::KeyBinding, keysyms};
16 pub use x11rb::protocol::xproto::KeyButMask; 18 pub use x11rb::protocol::xproto::KeyButMask;
@@ -22,6 +24,25 @@ pub struct LayoutSymbolOverride {
22 pub symbol: String, 24 pub symbol: String,
23 } 25 }
24 26
27 +#[derive(Clone)]
28 +pub struct WindowRule {
29 + pub class: Option<String>,
30 + pub instance: Option<String>,
31 + pub title: Option<String>,
32 + pub tags: Option<u32>,
33 + pub is_floating: Option<bool>,
34 + pub monitor: Option<usize>,
35 +}
36 +
37 +impl WindowRule {
38 + pub fn matches(&self, class: &str, instance: &str, title: &str) -> bool {
39 + let class_matches = self.class.as_ref().map_or(true, |c| class.contains(c.as_str()));
40 + let instance_matches = self.instance.as_ref().map_or(true, |i| instance.contains(i.as_str()));
41 + let title_matches = self.title.as_ref().map_or(true, |t| title.contains(t.as_str()));
42 + class_matches && instance_matches && title_matches
43 + }
44 +}
45 +
25 #[derive(Clone)] 46 #[derive(Clone)]
26 pub struct Config { 47 pub struct Config {
27 // Appearance 48 // Appearance
@@ -32,6 +53,7 @@ pub struct Config {
32 53
33 // Gaps 54 // Gaps
34 pub gaps_enabled: bool, 55 pub gaps_enabled: bool,
56 + pub smartgaps_enabled: bool,
35 pub gap_inner_horizontal: u32, 57 pub gap_inner_horizontal: u32,
36 pub gap_inner_vertical: u32, 58 pub gap_inner_vertical: u32,
37 pub gap_outer_horizontal: u32, 59 pub gap_outer_horizontal: u32,
@@ -50,6 +72,9 @@ pub struct Config {
50 // Keybindings 72 // Keybindings
51 pub keybindings: Vec<crate::keyboard::handlers::Key>, 73 pub keybindings: Vec<crate::keyboard::handlers::Key>,
52 74
75 + // Window rules
76 + pub window_rules: Vec<WindowRule>,
77 +
53 // Status bar 78 // Status bar
54 pub status_blocks: Vec<crate::bar::BlockConfig>, 79 pub status_blocks: Vec<crate::bar::BlockConfig>,
55 80
@@ -86,6 +111,7 @@ impl Default for Config {
86 border_unfocused: 0xbbbbbb, 111 border_unfocused: 0xbbbbbb,
87 font: "monospace:size=10".to_string(), 112 font: "monospace:size=10".to_string(),
88 gaps_enabled: false, 113 gaps_enabled: false,
114 + smartgaps_enabled: true,
89 gap_inner_horizontal: 0, 115 gap_inner_horizontal: 0,
90 gap_inner_vertical: 0, 116 gap_inner_vertical: 0,
91 gap_outer_horizontal: 0, 117 gap_outer_horizontal: 0,
@@ -148,30 +174,6 @@ impl Default for Config {
148 KeyAction::FocusStack, 174 KeyAction::FocusStack,
149 Arg::Int(1), 175 Arg::Int(1),
150 ), 176 ),
151 - KeyBinding::single_key(
152 - vec![MODKEY, SHIFT],
153 - keysyms::XK_K,
154 - KeyAction::ExchangeClient,
155 - Arg::Int(0), // UP
156 - ),
157 - KeyBinding::single_key(
158 - vec![MODKEY, SHIFT],
159 - keysyms::XK_J,
160 - KeyAction::ExchangeClient,
161 - Arg::Int(1), // DOWN
162 - ),
163 - KeyBinding::single_key(
164 - vec![MODKEY, SHIFT],
165 - keysyms::XK_H,
166 - KeyAction::ExchangeClient,
167 - Arg::Int(2), // LEFT
168 - ),
169 - KeyBinding::single_key(
170 - vec![MODKEY, SHIFT],
171 - keysyms::XK_L,
172 - KeyAction::ExchangeClient,
173 - Arg::Int(3), // RIGHT
174 - ),
175 KeyBinding::single_key( 177 KeyBinding::single_key(
176 vec![MODKEY], 178 vec![MODKEY],
177 keysyms::XK_1, 179 keysyms::XK_1,
@@ -281,6 +283,7 @@ impl Default for Config {
281 Arg::Int(8), 283 Arg::Int(8),
282 ), 284 ),
283 ], 285 ],
286 + window_rules: vec![],
284 status_blocks: vec![crate::bar::BlockConfig { 287 status_blocks: vec![crate::bar::BlockConfig {
285 format: "{}".to_string(), 288 format: "{}".to_string(),
286 command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()), 289 command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()),
+64 −22 src/monitor.rs
@@ -7,31 +7,73 @@ type WmResult<T> = Result<T, WmError>;
7 7
8 #[derive(Debug, Clone)] 8 #[derive(Debug, Clone)]
9 pub struct Monitor { 9 pub struct Monitor {
10 - pub x: i32, 10 + pub layout_symbol: String,
11 - pub y: i32, 11 + pub master_factor: f32,
12 - pub width: u32, 12 + pub num_master: i32,
13 - pub height: u32, 13 + pub monitor_number: usize,
14 - pub selected_tags: u32, 14 + pub bar_y_position: i32,
15 - pub focused_window: Option<Window>, 15 + pub screen_x: i32,
16 + pub screen_y: i32,
17 + pub screen_width: i32,
18 + pub screen_height: i32,
19 + pub window_area_x: i32,
20 + pub window_area_y: i32,
21 + pub window_area_width: i32,
22 + pub window_area_height: i32,
23 + pub gap_inner_horizontal: i32,
24 + pub gap_inner_vertical: i32,
25 + pub gap_outer_horizontal: i32,
26 + pub gap_outer_vertical: i32,
27 + pub selected_tags_index: usize,
28 + pub selected_layout_index: usize,
29 + pub tagset: [u32; 2],
30 + pub show_bar: bool,
31 + pub top_bar: bool,
32 + pub clients_head: Option<Window>,
33 + pub selected_client: Option<Window>,
34 + pub stack_head: Option<Window>,
35 + pub bar_window: Option<Window>,
36 + pub layout_indices: [usize; 2],
16 } 37 }
17 38
18 impl Monitor { 39 impl Monitor {
19 pub fn new(x: i32, y: i32, width: u32, height: u32) -> Self { 40 pub fn new(x: i32, y: i32, width: u32, height: u32) -> Self {
20 Self { 41 Self {
21 - x, 42 + layout_symbol: String::from("[]"),
22 - y, 43 + master_factor: 0.55,
23 - width, 44 + num_master: 1,
24 - height, 45 + monitor_number: 0,
25 - selected_tags: 1, 46 + bar_y_position: 0,
26 - focused_window: None, 47 + screen_x: x,
48 + screen_y: y,
49 + screen_width: width as i32,
50 + screen_height: height as i32,
51 + window_area_x: x,
52 + window_area_y: y,
53 + window_area_width: width as i32,
54 + window_area_height: height as i32,
55 + gap_inner_horizontal: 3,
56 + gap_inner_vertical: 3,
57 + gap_outer_horizontal: 3,
58 + gap_outer_vertical: 3,
59 + selected_tags_index: 0,
60 + selected_layout_index: 0,
61 + tagset: [1, 1],
62 + show_bar: true,
63 + top_bar: true,
64 + clients_head: None,
65 + selected_client: None,
66 + stack_head: None,
67 + bar_window: None,
68 + layout_indices: [0, 1],
27 } 69 }
28 } 70 }
29 71
30 pub fn contains_point(&self, x: i32, y: i32) -> bool { 72 pub fn contains_point(&self, x: i32, y: i32) -> bool {
31 - x >= self.x 73 + x >= self.screen_x
32 - && x < self.x + self.width as i32 74 + && x < self.screen_x + self.screen_width
33 - && y >= self.y 75 + && y >= self.screen_y
34 - && y < self.y + self.height as i32 76 + && y < self.screen_y + self.screen_height
35 } 77 }
36 } 78 }
37 79
@@ -77,10 +119,10 @@ pub fn detect_monitors(
77 let height_in_pixels = screen_info.height as u32; 119 let height_in_pixels = screen_info.height as u32;
78 120
79 let is_duplicate_monitor = monitors.iter().any(|monitor| { 121 let is_duplicate_monitor = monitors.iter().any(|monitor| {
80 - monitor.x == x_position 122 + monitor.screen_x == x_position
81 - && monitor.y == y_position 123 + && monitor.screen_y == y_position
82 - && monitor.width == width_in_pixels 124 + && monitor.screen_width == width_in_pixels as i32
83 - && monitor.height == height_in_pixels 125 + && monitor.screen_height == height_in_pixels as i32
84 }); 126 });
85 127
86 if !is_duplicate_monitor { 128 if !is_duplicate_monitor {
@@ -98,8 +140,8 @@ pub fn detect_monitors(
98 monitors = fallback_monitors(); 140 monitors = fallback_monitors();
99 } 141 }
100 142
101 - monitors.sort_by(|a, b| match a.y.cmp(&b.y) { 143 + monitors.sort_by(|a, b| match a.screen_y.cmp(&b.screen_y) {
102 - std::cmp::Ordering::Equal => a.x.cmp(&b.x), 144 + std::cmp::Ordering::Equal => a.screen_x.cmp(&b.screen_x),
103 other => other, 145 other => other,
104 }); 146 });
105 147
+4 −2 src/overlay/error.rs
@@ -48,6 +48,8 @@ impl ErrorOverlay {
48 connection: &RustConnection, 48 connection: &RustConnection,
49 font: &Font, 49 font: &Font,
50 error_text: &str, 50 error_text: &str,
51 + monitor_x: i16,
52 + monitor_y: i16,
51 screen_width: u16, 53 screen_width: u16,
52 screen_height: u16, 54 screen_height: u16,
53 ) -> Result<(), X11Error> { 55 ) -> Result<(), X11Error> {
@@ -67,8 +69,8 @@ impl ErrorOverlay {
67 let line_height = font.height() + LINE_SPACING as u16; 69 let line_height = font.height() + LINE_SPACING as u16;
68 let height = (self.lines.len() as u16 * line_height) + (PADDING as u16 * 2); 70 let height = (self.lines.len() as u16 * line_height) + (PADDING as u16 * 2);
69 71
70 - let x = ((screen_width - width) / 2) as i16; 72 + let x = monitor_x + ((screen_width - width) / 2) as i16;
71 - let y = ((screen_height - height) / 2) as i16; 73 + let y = monitor_y + ((screen_height - height) / 2) as i16;
72 74
73 self.base.configure(connection, x, y, width, height)?; 75 self.base.configure(connection, x, y, width, height)?;
74 self.base.show(connection)?; 76 self.base.show(connection)?;
+9 −4 src/overlay/keybind.rs
@@ -203,21 +203,26 @@ impl KeybindOverlay {
203 }, 203 },
204 KeyAction::SpawnTerminal => "Launch Terminal".to_string(), 204 KeyAction::SpawnTerminal => "Launch Terminal".to_string(),
205 KeyAction::FocusStack => "Focus Next/Previous Window".to_string(), 205 KeyAction::FocusStack => "Focus Next/Previous Window".to_string(),
206 - KeyAction::FocusDirection => "Focus Window in Direction".to_string(), 206 + KeyAction::MoveStack => "Move Window Up/Down Stack".to_string(),
207 - KeyAction::SwapDirection => "Swap Window in Direction".to_string(),
208 KeyAction::ViewTag => match &binding.arg { 207 KeyAction::ViewTag => match &binding.arg {
209 Arg::Int(n) => format!("View Workspace {}", n), 208 Arg::Int(n) => format!("View Workspace {}", n),
210 _ => "View Workspace".to_string(), 209 _ => "View Workspace".to_string(),
211 }, 210 },
211 + KeyAction::ToggleView => match &binding.arg {
212 + Arg::Int(n) => format!("Toggle View Workspace {}", n),
213 + _ => "Toggle View Workspace".to_string(),
214 + },
212 KeyAction::MoveToTag => "Move Window to Workspace".to_string(), 215 KeyAction::MoveToTag => "Move Window to Workspace".to_string(),
216 + KeyAction::ToggleTag => "Toggle Window on Workspace".to_string(),
213 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(), 217 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(),
214 KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(), 218 KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(),
215 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(), 219 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(),
216 KeyAction::ChangeLayout => "Change Layout".to_string(), 220 KeyAction::ChangeLayout => "Change Layout".to_string(),
217 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(), 221 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(),
218 KeyAction::FocusMonitor => "Focus Next Monitor".to_string(), 222 KeyAction::FocusMonitor => "Focus Next Monitor".to_string(),
219 - KeyAction::SmartMoveWin => "Smart Move Window".to_string(), 223 + KeyAction::TagMonitor => "Send Window to Monitor".to_string(),
220 - KeyAction::ExchangeClient => "Exchange Client Windows".to_string(), 224 + KeyAction::SetMasterFactor => "Adjust Master Area Size".to_string(),
225 + KeyAction::IncNumMaster => "Adjust Number of Master Windows".to_string(),
221 KeyAction::None => "No Action".to_string(), 226 KeyAction::None => "No Action".to_string(),
222 } 227 }
223 } 228 }
+5 −21 src/tab_bar.rs
@@ -106,7 +106,7 @@ impl TabBar {
106 &mut self, 106 &mut self,
107 connection: &RustConnection, 107 connection: &RustConnection,
108 font: &Font, 108 font: &Font,
109 - windows: &[Window], 109 + windows: &[(Window, String)],
110 focused_window: Option<Window>, 110 focused_window: Option<Window>,
111 ) -> Result<(), X11Error> { 111 ) -> Result<(), X11Error> {
112 connection.change_gc( 112 connection.change_gc(
@@ -142,7 +142,7 @@ impl TabBar {
142 let tab_width = self.width / windows.len() as u16; 142 let tab_width = self.width / windows.len() as u16;
143 let mut x_position: i16 = 0; 143 let mut x_position: i16 = 0;
144 144
145 - for (index, &window) in windows.iter().enumerate() { 145 + for (index, &(window, ref title)) in windows.iter().enumerate() {
146 let is_focused = Some(window) == focused_window; 146 let is_focused = Some(window) == focused_window;
147 let scheme = if is_focused { 147 let scheme = if is_focused {
148 &self.scheme_selected 148 &self.scheme_selected
@@ -150,11 +150,10 @@ impl TabBar {
150 &self.scheme_normal 150 &self.scheme_normal
151 }; 151 };
152 152
153 - let title = self.get_window_title(connection, window);
154 let display_title = if title.is_empty() { 153 let display_title = if title.is_empty() {
155 format!("Window {}", index + 1) 154 format!("Window {}", index + 1)
156 } else { 155 } else {
157 - title 156 + title.clone()
158 }; 157 };
159 158
160 let text_width = font.text_width(&display_title); 159 let text_width = font.text_width(&display_title);
@@ -213,24 +212,9 @@ impl TabBar {
213 } 212 }
214 } 213 }
215 214
216 - fn get_window_title(&self, connection: &RustConnection, window: Window) -> String {
217 - connection
218 - .get_property(false, window, AtomEnum::WM_NAME, AtomEnum::STRING, 0, 1024)
219 - .ok()
220 - .and_then(|cookie| cookie.reply().ok())
221 - .and_then(|reply| {
222 - if reply.value.is_empty() {
223 - None
224 - } else {
225 - std::str::from_utf8(&reply.value).ok().map(|s| s.to_string())
226 - }
227 - })
228 - .unwrap_or_default()
229 - }
230 -
231 pub fn get_clicked_window( 215 pub fn get_clicked_window(
232 &self, 216 &self,
233 - windows: &[Window], 217 + windows: &[(Window, String)],
234 click_x: i16, 218 click_x: i16,
235 ) -> Option<Window> { 219 ) -> Option<Window> {
236 if windows.is_empty() { 220 if windows.is_empty() {
@@ -240,7 +224,7 @@ impl TabBar {
240 let tab_width = self.width / windows.len() as u16; 224 let tab_width = self.width / windows.len() as u16;
241 let tab_index = (click_x as u16 / tab_width) as usize; 225 let tab_index = (click_x as u16 / tab_width) as usize;
242 226
243 - windows.get(tab_index).copied() 227 + windows.get(tab_index).map(|&(win, _)| win)
244 } 228 }
245 229
246 pub fn reposition( 230 pub fn reposition(
+2377 −914 src/window_manager.rs Large diff collapsed, click to expand
@@ -1,5 +1,6 @@
1 use crate::Config; 1 use crate::Config;
2 use crate::bar::Bar; 2 use crate::bar::Bar;
3 +use crate::client::{Client, TagMask};
3 use crate::errors::WmError; 4 use crate::errors::WmError;
4 use crate::keyboard::{self, Arg, KeyAction, handlers}; 5 use crate::keyboard::{self, Arg, KeyAction, handlers};
5 use crate::layout::GapConfig; 6 use crate::layout::GapConfig;
@@ -7,7 +8,7 @@ use crate::layout::tiling::TilingLayout;
7 use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}; 8 use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout};
8 use crate::monitor::{Monitor, detect_monitors}; 9 use crate::monitor::{Monitor, detect_monitors};
9 use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; 10 use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay};
10 -use std::collections::HashSet; 11 +use std::collections::{HashMap, HashSet};
11 use std::process::Command; 12 use std::process::Command;
12 use x11rb::cursor::Handle as CursorHandle; 13 use x11rb::cursor::Handle as CursorHandle;
13 14
@@ -16,11 +17,6 @@ use x11rb::protocol::Event;
16 use x11rb::protocol::xproto::*; 17 use x11rb::protocol::xproto::*;
17 use x11rb::rust_connection::RustConnection; 18 use x11rb::rust_connection::RustConnection;
18 19
19 -const DEFAULT_FLOAT_WIDTH_RATIO: f32 = 0.5;
20 -const DEFAULT_FLOAT_HEIGHT_RATIO: f32 = 0.5;
21 -const SMART_MOVE_STEP_RATIO_VERTICAL: i32 = 4;
22 -const SMART_MOVE_STEP_RATIO_HORIZONTAL: i32 = 6;
23 -
24 #[derive(Debug, Clone, Copy)] 20 #[derive(Debug, Clone, Copy)]
25 pub struct CachedGeometry { 21 pub struct CachedGeometry {
26 pub x_position: i16, 22 pub x_position: i16,
@@ -30,7 +26,6 @@ pub struct CachedGeometry {
30 pub border_width: u16, 26 pub border_width: u16,
31 } 27 }
32 28
33 -pub type TagMask = u32;
34 pub fn tag_mask(tag: usize) -> TagMask { 29 pub fn tag_mask(tag: usize) -> TagMask {
35 1 << tag 30 1 << tag
36 } 31 }
@@ -43,6 +38,15 @@ struct AtomCache {
43 wm_delete_window: Atom, 38 wm_delete_window: Atom,
44 net_wm_state: Atom, 39 net_wm_state: Atom,
45 net_wm_state_fullscreen: Atom, 40 net_wm_state_fullscreen: Atom,
41 + net_wm_window_type: Atom,
42 + net_wm_window_type_dialog: Atom,
43 + wm_name: Atom,
44 + net_wm_name: Atom,
45 + utf8_string: Atom,
46 + wm_normal_hints: Atom,
47 + wm_hints: Atom,
48 + wm_transient_for: Atom,
49 + net_active_window: Atom,
46 } 50 }
47 51
48 impl AtomCache { 52 impl AtomCache {
@@ -79,6 +83,24 @@ impl AtomCache {
79 .reply()? 83 .reply()?
80 .atom; 84 .atom;
81 85
86 + let net_wm_window_type = connection
87 + .intern_atom(false, b"_NET_WM_WINDOW_TYPE")?
88 + .reply()?
89 + .atom;
90 +
91 + let net_wm_window_type_dialog = connection
92 + .intern_atom(false, b"_NET_WM_WINDOW_TYPE_DIALOG")?
93 + .reply()?
94 + .atom;
95 +
96 + let wm_name = AtomEnum::WM_NAME.into();
97 + let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom;
98 + let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom;
99 + let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into();
100 + let wm_hints = AtomEnum::WM_HINTS.into();
101 + let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into();
102 + let net_active_window = connection.intern_atom(false, b"_NET_ACTIVE_WINDOW")?.reply()?.atom;
103 +
82 Ok(Self { 104 Ok(Self {
83 net_current_desktop, 105 net_current_desktop,
84 net_client_info, 106 net_client_info,
@@ -87,6 +109,15 @@ impl AtomCache {
87 wm_delete_window, 109 wm_delete_window,
88 net_wm_state, 110 net_wm_state,
89 net_wm_state_fullscreen, 111 net_wm_state_fullscreen,
112 + net_wm_window_type,
113 + net_wm_window_type_dialog,
114 + wm_name,
115 + net_wm_name,
116 + utf8_string,
117 + wm_normal_hints,
118 + wm_hints,
119 + wm_transient_for,
120 + net_active_window,
90 }) 121 })
91 } 122 }
92 } 123 }
@@ -98,14 +129,13 @@ pub struct WindowManager {
98 root: Window, 129 root: Window,
99 screen: Screen, 130 screen: Screen,
100 windows: Vec<Window>, 131 windows: Vec<Window>,
132 + clients: HashMap<Window, Client>,
101 layout: LayoutBox, 133 layout: LayoutBox,
102 - window_tags: std::collections::HashMap<Window, TagMask>, 134 + window_geometry_cache: HashMap<Window, CachedGeometry>,
103 - window_monitor: std::collections::HashMap<Window, usize>,
104 - window_geometry_cache: std::collections::HashMap<Window, CachedGeometry>,
105 gaps_enabled: bool, 135 gaps_enabled: bool,
106 floating_windows: HashSet<Window>, 136 floating_windows: HashSet<Window>,
107 fullscreen_windows: HashSet<Window>, 137 fullscreen_windows: HashSet<Window>,
108 - floating_geometry_before_fullscreen: std::collections::HashMap<Window, (i16, i16, u16, u16, u16)>, 138 + floating_geometry_before_fullscreen: HashMap<Window, (i16, i16, u16, u16, u16)>,
109 bars: Vec<Bar>, 139 bars: Vec<Bar>,
110 tab_bars: Vec<crate::tab_bar::TabBar>, 140 tab_bars: Vec<crate::tab_bar::TabBar>,
111 show_bar: bool, 141 show_bar: bool,
@@ -154,29 +184,40 @@ impl WindowManager {
154 )? 184 )?
155 .check()?; 185 .check()?;
156 186
157 - connection.grab_button( 187 + let ignore_modifiers = [
158 - false, 188 + 0,
159 - root, 189 + u16::from(ModMask::LOCK),
160 - EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, 190 + u16::from(ModMask::M2),
161 - GrabMode::SYNC, 191 + u16::from(ModMask::LOCK | ModMask::M2),
162 - GrabMode::ASYNC, 192 + ];
163 - x11rb::NONE,
164 - x11rb::NONE,
165 - ButtonIndex::M1,
166 - u16::from(config.modkey).into(),
167 - )?;
168 193
169 - connection.grab_button( 194 + for &ignore_mask in &ignore_modifiers {
170 - false, 195 + let grab_mask = u16::from(config.modkey) | ignore_mask;
171 - root, 196 +
172 - EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, 197 + connection.grab_button(
173 - GrabMode::SYNC, 198 + false,
174 - GrabMode::ASYNC, 199 + root,
175 - x11rb::NONE, 200 + EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE,
176 - x11rb::NONE, 201 + GrabMode::SYNC,
177 - ButtonIndex::M3, 202 + GrabMode::ASYNC,
178 - u16::from(config.modkey).into(), 203 + x11rb::NONE,
179 - )?; 204 + x11rb::NONE,
205 + ButtonIndex::M1,
206 + grab_mask.into(),
207 + )?;
208 +
209 + connection.grab_button(
210 + false,
211 + root,
212 + EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE,
213 + GrabMode::SYNC,
214 + GrabMode::ASYNC,
215 + x11rb::NONE,
216 + x11rb::NONE,
217 + ButtonIndex::M3,
218 + grab_mask.into(),
219 + )?;
220 + }
180 221
181 let monitors = detect_monitors(&connection, &screen, root)?; 222 let monitors = detect_monitors(&connection, &screen, root)?;
182 223
@@ -196,9 +237,9 @@ impl WindowManager {
196 &config, 237 &config,
197 display, 238 display,
198 &font, 239 &font,
199 - monitor.x as i16, 240 + monitor.screen_x as i16,
200 - monitor.y as i16, 241 + monitor.screen_y as i16,
201 - monitor.width as u16, 242 + monitor.screen_width as u16,
202 )?; 243 )?;
203 bars.push(bar); 244 bars.push(bar);
204 } 245 }
@@ -212,9 +253,9 @@ impl WindowManager {
212 screen_number, 253 screen_number,
213 display, 254 display,
214 &font, 255 &font,
215 - (monitor.x + config.gap_outer_horizontal as i32) as i16, 256 + (monitor.screen_x + config.gap_outer_horizontal as i32) as i16,
216 - (monitor.y as f32 + bar_height + config.gap_outer_vertical as f32) as i16, 257 + (monitor.screen_y as f32 + bar_height + config.gap_outer_vertical as f32) as i16,
217 - monitor.width.saturating_sub(2 * config.gap_outer_horizontal) as u16, 258 + monitor.screen_width.saturating_sub(2 * config.gap_outer_horizontal as i32) as u16,
218 config.scheme_occupied, 259 config.scheme_occupied,
219 config.scheme_selected, 260 config.scheme_selected,
220 )?; 261 )?;
@@ -244,14 +285,13 @@ impl WindowManager {
244 root, 285 root,
245 screen, 286 screen,
246 windows: Vec::new(), 287 windows: Vec::new(),
288 + clients: HashMap::new(),
247 layout: Box::new(TilingLayout), 289 layout: Box::new(TilingLayout),
248 - window_tags: std::collections::HashMap::new(), 290 + window_geometry_cache: HashMap::new(),
249 - window_monitor: std::collections::HashMap::new(),
250 - window_geometry_cache: std::collections::HashMap::new(),
251 gaps_enabled, 291 gaps_enabled,
252 floating_windows: HashSet::new(), 292 floating_windows: HashSet::new(),
253 fullscreen_windows: HashSet::new(), 293 fullscreen_windows: HashSet::new(),
254 - floating_geometry_before_fullscreen: std::collections::HashMap::new(), 294 + floating_geometry_before_fullscreen: HashMap::new(),
255 bars, 295 bars,
256 tab_bars, 296 tab_bars,
257 show_bar: true, 297 show_bar: true,
@@ -280,18 +320,27 @@ impl WindowManager {
280 } 320 }
281 321
282 pub fn show_migration_overlay(&mut self) { 322 pub fn show_migration_overlay(&mut self) {
283 - let message = "Your config.lua uses legacy syntax or has errors.\n\n\ 323 + let message = "We are on version 0.8.0 now.\n\n\
284 - You are now running with default configuration.\n\n\ 324 + Your config file has been deprecated once again.\n\
285 - Press Mod+Shift+/ to see default keybinds\n\ 325 + Backup your current config, and run oxwm --init to generate a new one with correct values.\n\n\
326 + Please reach out to Tony, or check out the\n\
327 + documentation for help with migration.\n\n\
328 + We appreciate you testing oxwm!\n\n\
329 + Press Mod+Shift+/ to see keybinds\n\
286 Press Mod+Shift+R to reload after fixing your config"; 330 Press Mod+Shift+R to reload after fixing your config";
287 331
288 - let screen_width = self.screen.width_in_pixels; 332 + let monitor = &self.monitors[self.selected_monitor];
289 - let screen_height = self.screen.height_in_pixels; 333 + let monitor_x = monitor.screen_x as i16;
334 + let monitor_y = monitor.screen_y as i16;
335 + let screen_width = monitor.screen_width as u16;
336 + let screen_height = monitor.screen_height as u16;
290 337
291 if let Err(e) = self.overlay.show_error( 338 if let Err(e) = self.overlay.show_error(
292 &self.connection, 339 &self.connection,
293 &self.font, 340 &self.font,
294 message, 341 message,
342 + monitor_x,
343 + monitor_y,
295 screen_width, 344 screen_width,
296 screen_height, 345 screen_height,
297 ) { 346 ) {
@@ -349,10 +398,8 @@ impl WindowManager {
349 } 398 }
350 399
351 if attrs.map_state == MapState::VIEWABLE { 400 if attrs.map_state == MapState::VIEWABLE {
352 - let tag = self.get_saved_tag(window, net_client_info)?; 401 + let _tag = self.get_saved_tag(window, net_client_info)?;
353 self.windows.push(window); 402 self.windows.push(window);
354 - self.window_tags.insert(window, tag);
355 - self.window_monitor.insert(window, self.selected_monitor);
356 continue; 403 continue;
357 } 404 }
358 405
@@ -374,17 +421,15 @@ impl WindowManager {
374 .is_ok_and(|prop| !prop.value.is_empty()); 421 .is_ok_and(|prop| !prop.value.is_empty());
375 422
376 if has_wm_class { 423 if has_wm_class {
377 - let tag = self.get_saved_tag(window, net_client_info)?; 424 + let _tag = self.get_saved_tag(window, net_client_info)?;
378 self.connection.map_window(window)?; 425 self.connection.map_window(window)?;
379 self.windows.push(window); 426 self.windows.push(window);
380 - self.window_tags.insert(window, tag);
381 - self.window_monitor.insert(window, self.selected_monitor);
382 } 427 }
383 } 428 }
384 } 429 }
385 430
386 if let Some(&first) = self.windows.first() { 431 if let Some(&first) = self.windows.first() {
387 - self.set_focus(first)?; 432 + self.focus(Some(first))?;
388 } 433 }
389 434
390 self.apply_layout()?; 435 self.apply_layout()?;
@@ -418,7 +463,7 @@ impl WindowManager {
418 Ok(self 463 Ok(self
419 .monitors 464 .monitors
420 .get(self.selected_monitor) 465 .get(self.selected_monitor)
421 - .map(|m| m.selected_tags) 466 + .map(|m| m.tagset[m.selected_tags_index])
422 .unwrap_or(tag_mask(0))) 467 .unwrap_or(tag_mask(0)))
423 } 468 }
424 469
@@ -496,350 +541,71 @@ impl WindowManager {
496 } 541 }
497 542
498 fn toggle_floating(&mut self) -> WmResult<()> { 543 fn toggle_floating(&mut self) -> WmResult<()> {
499 - if let Some(focused) = self 544 + let focused = self
500 .monitors 545 .monitors
501 .get(self.selected_monitor) 546 .get(self.selected_monitor)
502 - .and_then(|m| m.focused_window) 547 + .and_then(|m| m.selected_client);
503 - {
504 - if self.floating_windows.contains(&focused) {
505 - self.floating_windows.remove(&focused);
506 -
507 - let selected_tags = self
508 - .monitors
509 - .get(self.selected_monitor)
510 - .map(|m| m.selected_tags)
511 - .unwrap_or(tag_mask(0));
512 -
513 - self.window_tags.insert(focused, selected_tags);
514 - self.window_monitor.insert(focused, self.selected_monitor);
515 - if let Err(error) = self.save_client_tag(focused, selected_tags) {
516 - eprintln!("Failed to save client tag: {:?}", error);
517 - }
518 -
519 - self.apply_layout()?;
520 - } else {
521 - let float_width = (self.screen.width_in_pixels / 2) as u32;
522 - let float_height = (self.screen.height_in_pixels / 2) as u32;
523 548
524 - let border_width = self.config.border_width; 549 + if focused.is_none() {
525 - 550 + return Ok(());
526 - let center_width = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32; 551 + }
527 - let center_height = 552 + let focused = focused.unwrap();
528 - ((self.screen.height_in_pixels - float_height as u16) / 2) as i32;
529 -
530 - self.connection.configure_window(
531 - focused,
532 - &ConfigureWindowAux::new()
533 - .x(center_width)
534 - .y(center_height)
535 - .width(float_width)
536 - .height(float_height)
537 - .border_width(border_width)
538 - .stack_mode(StackMode::ABOVE),
539 - )?;
540 553
541 - self.floating_windows.insert(focused); 554 + if let Some(client) = self.clients.get(&focused) {
542 - self.apply_layout()?; 555 + if client.is_fullscreen {
543 - self.connection.flush()?; 556 + return Ok(());
544 } 557 }
545 } 558 }
546 - Ok(())
547 - }
548 -
549 - fn collect_visible_floating_geometries(&mut self) -> Vec<(Window, CachedGeometry)> {
550 - let focused_window = self.monitors.get(self.selected_monitor)
551 - .and_then(|monitor| monitor.focused_window)
552 - .unwrap_or(0);
553 - let selected_monitor_index = self.selected_monitor;
554 -
555 - let candidate_windows: Vec<Window> = self.windows.iter()
556 - .filter(|&&window| {
557 - window != focused_window
558 - && self.floating_windows.contains(&window)
559 - && self.is_window_visible(window)
560 - && self.window_monitor.get(&window).copied().unwrap_or(0) == selected_monitor_index
561 - })
562 - .copied()
563 - .collect();
564 -
565 - candidate_windows.into_iter()
566 - .filter_map(|window| {
567 - self.get_or_query_geometry(window).ok().map(|geometry| (window, geometry))
568 - })
569 - .collect()
570 - }
571 559
572 - fn calculate_smart_move_position( 560 + let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) {
573 - &self, 561 + (client.is_fixed, client.x_position as i32, client.y_position as i32, client.width as u32, client.height as u32)
574 - current_x: i32,
575 - current_y: i32,
576 - current_width: i32,
577 - current_height: i32,
578 - direction: i32,
579 - monitor: &Monitor,
580 - other_geometries: &[(Window, CachedGeometry)],
581 - ) -> (i32, i32) {
582 - let (gap_inner_horizontal, gap_inner_vertical, gap_outer_horizontal, gap_outer_vertical) = if self.gaps_enabled {
583 - (
584 - self.config.gap_inner_horizontal as i32,
585 - self.config.gap_inner_vertical as i32,
586 - self.config.gap_outer_horizontal as i32,
587 - self.config.gap_outer_vertical as i32,
588 - )
589 } else { 562 } else {
590 - (0, 0, 0, 0) 563 + return Ok(());
591 }; 564 };
592 565
593 - match direction { 566 + let was_floating = self.floating_windows.contains(&focused);
594 - 0 => {
595 - let mut target_position = i32::MIN;
596 - let current_top = current_y;
597 - let mut new_y_position = current_y - (monitor.height as i32 / SMART_MOVE_STEP_RATIO_VERTICAL);
598 -
599 - for (_other_window, other_geometry) in other_geometries {
600 - let other_x = other_geometry.x_position as i32;
601 - let other_y = other_geometry.y_position as i32;
602 - let other_width = other_geometry.width as i32;
603 - let other_height = other_geometry.height as i32;
604 -
605 - if current_x + current_width < other_x || current_x > other_x + other_width {
606 - continue;
607 - }
608 -
609 - let other_bottom = other_y + other_height + gap_inner_vertical;
610 - if current_top > other_bottom && new_y_position < other_bottom {
611 - target_position = target_position.max(other_bottom);
612 - }
613 - }
614 -
615 - if target_position != i32::MIN {
616 - new_y_position = target_position;
617 - }
618 - new_y_position = new_y_position.max(monitor.y as i32 + gap_outer_vertical);
619 - (current_x, new_y_position)
620 - }
621 - 1 => {
622 - let mut target_position = i32::MAX;
623 - let current_bottom = current_y + current_height;
624 - let mut new_y_position = current_y + (monitor.height as i32 / SMART_MOVE_STEP_RATIO_VERTICAL);
625 -
626 - for (_other_window, other_geometry) in other_geometries {
627 - let other_x = other_geometry.x_position as i32;
628 - let other_y = other_geometry.y_position as i32;
629 - let other_width = other_geometry.width as i32;
630 -
631 - if current_x + current_width < other_x || current_x > other_x + other_width {
632 - continue;
633 - }
634 -
635 - let other_top = other_y - gap_inner_vertical;
636 - if current_bottom < other_top && (new_y_position + current_height) > other_top {
637 - target_position = target_position.min(other_top - current_height);
638 - }
639 - }
640 -
641 - if target_position != i32::MAX {
642 - new_y_position = target_position;
643 - }
644 - new_y_position = new_y_position.min(monitor.y as i32 + monitor.height as i32 - current_height - gap_outer_vertical);
645 - (current_x, new_y_position)
646 - }
647 - 2 => {
648 - let mut target_position = i32::MIN;
649 - let current_left = current_x;
650 - let mut new_x_position = current_x - (monitor.width as i32 / SMART_MOVE_STEP_RATIO_HORIZONTAL);
651 567
652 - for (_other_window, other_geometry) in other_geometries { 568 + if was_floating {
653 - let other_x = other_geometry.x_position as i32; 569 + self.floating_windows.remove(&focused);
654 - let other_y = other_geometry.y_position as i32; 570 + if let Some(client) = self.clients.get_mut(&focused) {
655 - let other_width = other_geometry.width as i32; 571 + client.is_floating = false;
656 - let other_height = other_geometry.height as i32;
657 -
658 - if current_y + current_height < other_y || current_y > other_y + other_height {
659 - continue;
660 - }
661 -
662 - let other_right = other_x + other_width + gap_inner_horizontal;
663 - if current_left > other_right && new_x_position < other_right {
664 - target_position = target_position.max(other_right);
665 - }
666 - }
667 -
668 - if target_position != i32::MIN {
669 - new_x_position = target_position;
670 - }
671 - new_x_position = new_x_position.max(monitor.x as i32 + gap_outer_horizontal);
672 - (new_x_position, current_y)
673 } 572 }
674 - 3 => { 573 + } else {
675 - let mut target_position = i32::MAX; 574 + self.floating_windows.insert(focused);
676 - let current_right = current_x + current_width; 575 + if let Some(client) = self.clients.get_mut(&focused) {
677 - let mut new_x_position = current_x + (monitor.width as i32 / SMART_MOVE_STEP_RATIO_HORIZONTAL); 576 + client.is_floating = is_fixed || !client.is_floating;
678 -
679 - for (_other_window, other_geometry) in other_geometries {
680 - let other_x = other_geometry.x_position as i32;
681 - let other_y = other_geometry.y_position as i32;
682 - let other_height = other_geometry.height as i32;
683 -
684 - if current_y + current_height < other_y || current_y > other_y + other_height {
685 - continue;
686 - }
687 -
688 - let other_left = other_x - gap_inner_horizontal;
689 - if current_right < other_left && (new_x_position + current_width) > other_left {
690 - target_position = target_position.min(other_left - current_width);
691 - }
692 - }
693 -
694 - if target_position != i32::MAX {
695 - new_x_position = target_position;
696 - }
697 - new_x_position = new_x_position.min(monitor.x as i32 + monitor.width as i32 - current_width - gap_outer_horizontal);
698 - (new_x_position, current_y)
699 } 577 }
700 - _ => (current_x, current_y),
701 - }
702 - }
703 -
704 - fn smart_move_window(&mut self, direction: i32) -> WmResult<()> {
705 - let focused = match self
706 - .monitors
707 - .get(self.selected_monitor)
708 - .and_then(|monitor| monitor.focused_window)
709 - {
710 - Some(window) => window,
711 - None => return Ok(()),
712 - };
713 -
714 - if !self.floating_windows.contains(&focused) {
715 - let float_width = (self.screen.width_in_pixels as f32 * DEFAULT_FLOAT_WIDTH_RATIO) as u32;
716 - let float_height = (self.screen.height_in_pixels as f32 * DEFAULT_FLOAT_HEIGHT_RATIO) as u32;
717 - let border_width = self.config.border_width;
718 - let center_x_position = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32;
719 - let center_y_position = ((self.screen.height_in_pixels - float_height as u16) / 2) as i32;
720 578
721 self.connection.configure_window( 579 self.connection.configure_window(
722 focused, 580 focused,
723 &ConfigureWindowAux::new() 581 &ConfigureWindowAux::new()
724 - .x(center_x_position) 582 + .x(x)
725 - .y(center_y_position) 583 + .y(y)
726 - .width(float_width) 584 + .width(w)
727 - .height(float_height) 585 + .height(h)
728 - .border_width(border_width)
729 .stack_mode(StackMode::ABOVE), 586 .stack_mode(StackMode::ABOVE),
730 )?; 587 )?;
731 - self.floating_windows.insert(focused);
732 } 588 }
733 589
734 - let current_geometry = self.get_or_query_geometry(focused)?; 590 + self.apply_layout()?;
735 - let current_x = current_geometry.x_position as i32;
736 - let current_y = current_geometry.y_position as i32;
737 - let current_width = current_geometry.width as i32;
738 - let current_height = current_geometry.height as i32;
739 -
740 - let other_geometries = self.collect_visible_floating_geometries();
741 -
742 - let monitor = match self.monitors.get(self.selected_monitor) {
743 - Some(monitor) => monitor,
744 - None => return Ok(()),
745 - };
746 -
747 - let (new_x_position, new_y_position) = self.calculate_smart_move_position(
748 - current_x,
749 - current_y,
750 - current_width,
751 - current_height,
752 - direction,
753 - monitor,
754 - &other_geometries,
755 - );
756 -
757 - self.connection.configure_window(
758 - focused,
759 - &ConfigureWindowAux::new()
760 - .x(new_x_position)
761 - .y(new_y_position)
762 - .stack_mode(StackMode::ABOVE),
763 - )?;
764 -
765 - self.update_geometry_cache(focused, CachedGeometry {
766 - x_position: new_x_position as i16,
767 - y_position: new_y_position as i16,
768 - width: current_width as u16,
769 - height: current_height as u16,
770 - border_width: current_geometry.border_width,
771 - });
772 -
773 - self.connection.flush()?;
774 Ok(()) 591 Ok(())
775 } 592 }
776 593
777 - fn exchange_client(&mut self, direction: i32) -> WmResult<()> { 594 + fn set_master_factor(&mut self, delta: f32) -> WmResult<()> {
778 - let focused = match self 595 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
779 - .monitors 596 + let new_mfact = (monitor.master_factor + delta).max(0.05).min(0.95);
780 - .get(self.selected_monitor) 597 + monitor.master_factor = new_mfact;
781 - .and_then(|m| m.focused_window) 598 + self.apply_layout()?;
782 - {
783 - Some(win) => win,
784 - None => return Ok(()),
785 - };
786 -
787 - if self.floating_windows.contains(&focused) {
788 - return Ok(());
789 - }
790 -
791 - let visible = self.visible_windows();
792 - if visible.len() < 2 {
793 - return Ok(());
794 } 599 }
600 + Ok(())
601 + }
795 602
796 - let current_idx = match visible.iter().position(|&w| w == focused) { 603 + fn inc_num_master(&mut self, delta: i32) -> WmResult<()> {
797 - Some(idx) => idx, 604 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
798 - None => return Ok(()), 605 + let new_nmaster = (monitor.num_master + delta).max(0);
799 - }; 606 + monitor.num_master = new_nmaster;
800 -
801 - let target_idx = match direction {
802 - 0 | 2 => {
803 - // UP or LEFT - previous in stack
804 - if current_idx == 0 {
805 - visible.len() - 1
806 - } else {
807 - current_idx - 1
808 - }
809 - }
810 - 1 | 3 => {
811 - // DOWN or RIGHT - next in stack
812 - (current_idx + 1) % visible.len()
813 - }
814 - _ => return Ok(()),
815 - };
816 -
817 - let target = visible[target_idx];
818 -
819 - let focused_pos = self.windows.iter().position(|&w| w == focused);
820 - let target_pos = self.windows.iter().position(|&w| w == target);
821 -
822 - if let (Some(f_pos), Some(t_pos)) = (focused_pos, target_pos) {
823 - self.windows.swap(f_pos, t_pos);
824 -
825 self.apply_layout()?; 607 self.apply_layout()?;
826 -
827 - self.set_focus(focused)?;
828 -
829 - if let Ok(geometry) = self.connection.get_geometry(focused)?.reply() {
830 - self.connection.warp_pointer(
831 - x11rb::NONE,
832 - focused,
833 - 0,
834 - 0,
835 - 0,
836 - 0,
837 - geometry.width as i16 / 2,
838 - geometry.height as i16 / 2,
839 - )?;
840 - }
841 } 608 }
842 -
843 Ok(()) 609 Ok(())
844 } 610 }
845 611
@@ -905,9 +671,9 @@ impl WindowManager {
905 for (monitor_index, monitor) in self.monitors.iter().enumerate() { 671 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
906 if let Some(bar) = self.bars.get_mut(monitor_index) { 672 if let Some(bar) = self.bars.get_mut(monitor_index) {
907 let mut occupied_tags: TagMask = 0; 673 let mut occupied_tags: TagMask = 0;
908 - for (&window, &tags) in &self.window_tags { 674 + for client in self.clients.values() {
909 - if self.window_monitor.get(&window).copied().unwrap_or(0) == monitor_index { 675 + if client.monitor_index == monitor_index {
910 - occupied_tags |= tags; 676 + occupied_tags |= client.tags;
911 } 677 }
912 } 678 }
913 679
@@ -917,7 +683,7 @@ impl WindowManager {
917 &self.connection, 683 &self.connection,
918 &self.font, 684 &self.font,
919 self.display, 685 self.display,
920 - monitor.selected_tags, 686 + monitor.tagset[monitor.selected_tags_index],
921 occupied_tags, 687 occupied_tags,
922 draw_blocks, 688 draw_blocks,
923 &layout_symbol, 689 &layout_symbol,
@@ -931,27 +697,26 @@ impl WindowManager {
931 fn update_tab_bars(&mut self) -> WmResult<()> { 697 fn update_tab_bars(&mut self) -> WmResult<()> {
932 for (monitor_index, monitor) in self.monitors.iter().enumerate() { 698 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
933 if let Some(tab_bar) = self.tab_bars.get_mut(monitor_index) { 699 if let Some(tab_bar) = self.tab_bars.get_mut(monitor_index) {
934 - let visible_windows: Vec<Window> = self 700 + let visible_windows: Vec<(Window, String)> = self
935 .windows 701 .windows
936 .iter() 702 .iter()
937 - .filter(|&&window| { 703 + .filter_map(|&window| {
938 - let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); 704 + if let Some(client) = self.clients.get(&window) {
939 - if window_monitor_index != monitor_index 705 + if client.monitor_index != monitor_index
940 - || self.floating_windows.contains(&window) 706 + || self.floating_windows.contains(&window)
941 - || self.fullscreen_windows.contains(&window) 707 + || self.fullscreen_windows.contains(&window)
942 - { 708 + {
943 - return false; 709 + return None;
944 - } 710 + }
945 - if let Some(&tags) = self.window_tags.get(&window) { 711 + if (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0 {
946 - (tags & monitor.selected_tags) != 0 712 + return Some((window, client.name.clone()));
947 - } else { 713 + }
948 - false
949 } 714 }
715 + None
950 }) 716 })
951 - .copied()
952 .collect(); 717 .collect();
953 718
954 - let focused_window = monitor.focused_window; 719 + let focused_window = monitor.selected_client;
955 720
956 tab_bar.draw( 721 tab_bar.draw(
957 &self.connection, 722 &self.connection,
@@ -966,7 +731,7 @@ impl WindowManager {
966 731
967 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { 732 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> {
968 match action { 733 match action {
969 - KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, 734 + KeyAction::Spawn => handlers::handle_spawn_action(action, arg, self.selected_monitor)?,
970 KeyAction::SpawnTerminal => { 735 KeyAction::SpawnTerminal => {
971 use std::process::Command; 736 use std::process::Command;
972 let terminal = &self.config.terminal; 737 let terminal = &self.config.terminal;
@@ -978,13 +743,14 @@ impl WindowManager {
978 if let Some(focused) = self 743 if let Some(focused) = self
979 .monitors 744 .monitors
980 .get(self.selected_monitor) 745 .get(self.selected_monitor)
981 - .and_then(|m| m.focused_window) 746 + .and_then(|m| m.selected_client)
982 { 747 {
983 self.kill_client(focused)?; 748 self.kill_client(focused)?;
984 } 749 }
985 } 750 }
986 KeyAction::ToggleFullScreen => { 751 KeyAction::ToggleFullScreen => {
987 self.fullscreen()?; 752 self.fullscreen()?;
753 + self.restack()?;
988 } 754 }
989 KeyAction::ChangeLayout => { 755 KeyAction::ChangeLayout => {
990 if let Arg::Str(layout_name) = arg { 756 if let Arg::Str(layout_name) = arg {
@@ -996,6 +762,7 @@ impl WindowManager {
996 } 762 }
997 self.apply_layout()?; 763 self.apply_layout()?;
998 self.update_bar()?; 764 self.update_bar()?;
765 + self.restack()?;
999 } 766 }
1000 Err(e) => eprintln!("Failed to change layout: {}", e), 767 Err(e) => eprintln!("Failed to change layout: {}", e),
1001 } 768 }
@@ -1012,39 +779,24 @@ impl WindowManager {
1012 } 779 }
1013 self.apply_layout()?; 780 self.apply_layout()?;
1014 self.update_bar()?; 781 self.update_bar()?;
782 + self.restack()?;
1015 } 783 }
1016 Err(e) => eprintln!("Failed to cycle layout: {}", e), 784 Err(e) => eprintln!("Failed to cycle layout: {}", e),
1017 } 785 }
1018 } 786 }
1019 KeyAction::ToggleFloating => { 787 KeyAction::ToggleFloating => {
1020 self.toggle_floating()?; 788 self.toggle_floating()?;
1021 - } 789 + self.restack()?;
1022 -
1023 - KeyAction::SmartMoveWin => {
1024 - if let Arg::Int(direction) = arg {
1025 - self.smart_move_window(*direction)?;
1026 - }
1027 - }
1028 -
1029 - KeyAction::ExchangeClient => {
1030 - if let Arg::Int(direction) = arg {
1031 - self.exchange_client(*direction)?;
1032 - }
1033 } 790 }
1034 791
1035 KeyAction::FocusStack => { 792 KeyAction::FocusStack => {
1036 if let Arg::Int(direction) = arg { 793 if let Arg::Int(direction) = arg {
1037 - self.cycle_focus(*direction)?; 794 + self.focusstack(*direction)?;
1038 - }
1039 - }
1040 - KeyAction::FocusDirection => {
1041 - if let Arg::Int(direction) = arg {
1042 - self.focus_direction(*direction)?;
1043 } 795 }
1044 } 796 }
1045 - KeyAction::SwapDirection => { 797 + KeyAction::MoveStack => {
1046 if let Arg::Int(direction) = arg { 798 if let Arg::Int(direction) = arg {
1047 - self.swap_direction(*direction)?; 799 + self.move_stack(*direction)?;
1048 } 800 }
1049 } 801 }
1050 KeyAction::Quit | KeyAction::Restart => { 802 KeyAction::Quit | KeyAction::Restart => {
@@ -1064,100 +816,108 @@ impl WindowManager {
1064 self.view_tag(*tag_index as usize)?; 816 self.view_tag(*tag_index as usize)?;
1065 } 817 }
1066 } 818 }
819 + KeyAction::ToggleView => {
820 + if let Arg::Int(tag_index) = arg {
821 + self.toggleview(*tag_index as usize)?;
822 + }
823 + }
1067 KeyAction::MoveToTag => { 824 KeyAction::MoveToTag => {
1068 if let Arg::Int(tag_index) = arg { 825 if let Arg::Int(tag_index) = arg {
1069 self.move_to_tag(*tag_index as usize)?; 826 self.move_to_tag(*tag_index as usize)?;
1070 } 827 }
1071 } 828 }
829 + KeyAction::ToggleTag => {
830 + if let Arg::Int(tag_index) = arg {
831 + self.toggletag(*tag_index as usize)?;
832 + }
833 + }
1072 KeyAction::ToggleGaps => { 834 KeyAction::ToggleGaps => {
1073 self.gaps_enabled = !self.gaps_enabled; 835 self.gaps_enabled = !self.gaps_enabled;
1074 self.apply_layout()?; 836 self.apply_layout()?;
837 + self.restack()?;
1075 } 838 }
1076 KeyAction::FocusMonitor => { 839 KeyAction::FocusMonitor => {
1077 if let Arg::Int(direction) = arg { 840 if let Arg::Int(direction) = arg {
1078 self.focus_monitor(*direction)?; 841 self.focus_monitor(*direction)?;
1079 } 842 }
1080 } 843 }
844 + KeyAction::TagMonitor => {
845 + if let Arg::Int(direction) = arg {
846 + self.send_window_to_adjacent_monitor(*direction)?;
847 + }
848 + }
1081 KeyAction::ShowKeybindOverlay => { 849 KeyAction::ShowKeybindOverlay => {
1082 let monitor = &self.monitors[self.selected_monitor]; 850 let monitor = &self.monitors[self.selected_monitor];
1083 self.keybind_overlay.toggle( 851 self.keybind_overlay.toggle(
1084 &self.connection, 852 &self.connection,
1085 &self.font, 853 &self.font,
1086 &self.config.keybindings, 854 &self.config.keybindings,
1087 - monitor.width as u16, 855 + monitor.screen_width as u16,
1088 - monitor.height as u16, 856 + monitor.screen_height as u16,
1089 )?; 857 )?;
1090 } 858 }
859 + KeyAction::SetMasterFactor => {
860 + if let Arg::Int(delta) = arg {
861 + self.set_master_factor(*delta as f32 / 100.0)?;
862 + }
863 + }
864 + KeyAction::IncNumMaster => {
865 + if let Arg::Int(delta) = arg {
866 + self.inc_num_master(*delta)?;
867 + }
868 + }
1091 KeyAction::None => {} 869 KeyAction::None => {}
1092 } 870 }
1093 Ok(()) 871 Ok(())
1094 } 872 }
1095 873
1096 - fn focus_monitor(&mut self, direction: i32) -> WmResult<()> {
1097 - if self.monitors.is_empty() {
1098 - return Ok(());
1099 - }
1100 -
1101 - let new_monitor = if direction > 0 {
1102 - (self.selected_monitor + 1) % self.monitors.len()
1103 - } else {
1104 - (self.selected_monitor + self.monitors.len() - 1) % self.monitors.len()
1105 - };
1106 -
1107 - if new_monitor == self.selected_monitor {
1108 - return Ok(());
1109 - }
1110 -
1111 - self.selected_monitor = new_monitor;
1112 -
1113 - self.update_bar()?;
1114 -
1115 - let visible = self.visible_windows_on_monitor(new_monitor);
1116 - if let Some(&win) = visible.first() {
1117 - self.set_focus(win)?;
1118 - }
1119 -
1120 - Ok(())
1121 - }
1122 874
1123 fn is_window_visible(&self, window: Window) -> bool { 875 fn is_window_visible(&self, window: Window) -> bool {
1124 - let window_mon = self.window_monitor.get(&window).copied().unwrap_or(0); 876 + if let Some(client) = self.clients.get(&window) {
1125 - 877 + let monitor = self.monitors.get(client.monitor_index);
1126 - if let Some(&tags) = self.window_tags.get(&window) { 878 + let selected_tags = monitor.map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0);
1127 - let monitor = self.monitors.get(window_mon); 879 + (client.tags & selected_tags) != 0
1128 - let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0);
1129 - (tags & selected_tags) != 0
1130 } else { 880 } else {
1131 false 881 false
1132 } 882 }
1133 } 883 }
1134 884
1135 fn visible_windows(&self) -> Vec<Window> { 885 fn visible_windows(&self) -> Vec<Window> {
1136 - self.windows 886 + let mut result = Vec::new();
1137 - .iter() 887 + for monitor in &self.monitors {
1138 - .filter(|&&w| self.is_window_visible(w)) 888 + let mut current = monitor.clients_head;
1139 - .copied() 889 + while let Some(window) = current {
1140 - .collect() 890 + if let Some(client) = self.clients.get(&window) {
891 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
892 + if visible_tags != 0 {
893 + result.push(window);
894 + }
895 + current = client.next;
896 + } else {
897 + break;
898 + }
899 + }
900 + }
901 + result
1141 } 902 }
1142 903
1143 fn visible_windows_on_monitor(&self, monitor_index: usize) -> Vec<Window> { 904 fn visible_windows_on_monitor(&self, monitor_index: usize) -> Vec<Window> {
1144 - self.windows 905 + let mut result = Vec::new();
1145 - .iter() 906 + if let Some(monitor) = self.monitors.get(monitor_index) {
1146 - .filter(|&&w| { 907 + let mut current = monitor.clients_head;
1147 - let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0); 908 + while let Some(window) = current {
1148 - if window_mon != monitor_index { 909 + if let Some(client) = self.clients.get(&window) {
1149 - return false; 910 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
1150 - } 911 + if visible_tags != 0 {
1151 - if let Some(&tags) = self.window_tags.get(&w) { 912 + result.push(window);
1152 - let monitor = self.monitors.get(monitor_index); 913 + }
1153 - let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0); 914 + current = client.next;
1154 - (tags & selected_tags) != 0
1155 } else { 915 } else {
1156 - false 916 + break;
1157 } 917 }
1158 - }) 918 + }
1159 - .copied() 919 + }
1160 - .collect() 920 + result
1161 } 921 }
1162 922
1163 fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<usize> { 923 fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<usize> {
@@ -1166,53 +926,203 @@ impl WindowManager {
1166 .position(|mon| mon.contains_point(x, y)) 926 .position(|mon| mon.contains_point(x, y))
1167 } 927 }
1168 928
1169 - // Dwm's g-loaded approach to handling the spam alternating crash. 929 + fn get_monitor_for_rect(&self, x: i32, y: i32, w: i32, h: i32) -> usize {
1170 - fn update_window_visibility(&self) -> WmResult<()> { 930 + let mut best_monitor = self.selected_monitor;
1171 - for &window in &self.windows { 931 + let mut max_area = 0;
1172 - if !self.is_window_visible(window) { 932 +
1173 - if let Ok(geom) = self.connection.get_geometry(window)?.reply() { 933 + for (idx, monitor) in self.monitors.iter().enumerate() {
1174 - self.connection.configure_window( 934 + let intersect_width = 0.max((x + w).min(monitor.window_area_x + monitor.window_area_width) - x.max(monitor.window_area_x));
1175 - window, 935 + let intersect_height = 0.max((y + h).min(monitor.window_area_y + monitor.window_area_height) - y.max(monitor.window_area_y));
1176 - &ConfigureWindowAux::new() 936 + let area = intersect_width * intersect_height;
1177 - .x(-(geom.width as i32 * 2)) 937 +
1178 - .y(geom.y as i32), 938 + if area > max_area {
1179 - )?; 939 + max_area = area;
1180 - } 940 + best_monitor = idx;
1181 } 941 }
1182 } 942 }
1183 - self.connection.flush()?; 943 +
1184 - Ok(()) 944 + best_monitor
1185 } 945 }
1186 946
1187 - pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> { 947 + fn move_window_to_monitor(&mut self, window: Window, target_monitor_index: usize) -> WmResult<()> {
1188 - if tag_index >= self.config.tags.len() { 948 + let current_monitor_index = self.clients
1189 - return Ok(()); 949 + .get(&window)
1190 - } 950 + .map(|c| c.monitor_index);
1191 951
1192 - if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { 952 + if let Some(current_idx) = current_monitor_index {
1193 - monitor.selected_tags = tag_mask(tag_index); 953 + if current_idx == target_monitor_index {
954 + return Ok(());
955 + }
1194 } 956 }
1195 957
1196 - self.save_selected_tags()?; 958 + self.unfocus(window)?;
1197 - self.update_window_visibility()?; 959 + self.detach(window);
1198 - self.apply_layout()?; 960 + self.detach_stack(window);
1199 - self.update_bar()?;
1200 961
1201 - let visible = self.visible_windows_on_monitor(self.selected_monitor); 962 + if let Some(client) = self.clients.get_mut(&window) {
1202 - if let Some(&win) = visible.first() { 963 + client.monitor_index = target_monitor_index;
1203 - self.set_focus(win)?; 964 + if let Some(target_monitor) = self.monitors.get(target_monitor_index) {
965 + client.tags = target_monitor.tagset[target_monitor.selected_tags_index];
966 + }
1204 } 967 }
1205 968
969 + self.attach_aside(window, target_monitor_index);
970 + self.attach_stack(window, target_monitor_index);
971 +
972 + self.focus(None)?;
973 + self.apply_layout()?;
974 +
1206 Ok(()) 975 Ok(())
1207 } 976 }
1208 977
1209 - fn save_selected_tags(&self) -> WmResult<()> { 978 + fn get_adjacent_monitor(&self, direction: i32) -> Option<usize> {
1210 - let net_current_desktop = self.atoms.net_current_desktop; 979 + if self.monitors.len() <= 1 {
980 + return None;
981 + }
982 +
983 + if direction > 0 {
984 + if self.selected_monitor + 1 < self.monitors.len() {
985 + Some(self.selected_monitor + 1)
986 + } else {
987 + Some(0)
988 + }
989 + } else {
990 + if self.selected_monitor == 0 {
991 + Some(self.monitors.len() - 1)
992 + } else {
993 + Some(self.selected_monitor - 1)
994 + }
995 + }
996 + }
997 +
998 + fn is_visible(&self, window: Window) -> bool {
999 + let Some(client) = self.clients.get(&window) else {
1000 + return false;
1001 + };
1002 +
1003 + let Some(monitor) = self.monitors.get(client.monitor_index) else {
1004 + return false;
1005 + };
1006 +
1007 + (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0
1008 + }
1009 +
1010 + fn showhide(&mut self, window: Option<Window>) -> WmResult<()> {
1011 + let Some(window) = window else {
1012 + return Ok(());
1013 + };
1014 +
1015 + let Some(client) = self.clients.get(&window).cloned() else {
1016 + return Ok(());
1017 + };
1018 +
1019 + let monitor = match self.monitors.get(client.monitor_index) {
1020 + Some(m) => m,
1021 + None => return Ok(()),
1022 + };
1023 +
1024 + let is_visible = (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0;
1025 +
1026 + if is_visible {
1027 + self.connection.configure_window(
1028 + window,
1029 + &ConfigureWindowAux::new()
1030 + .x(client.x_position as i32)
1031 + .y(client.y_position as i32),
1032 + )?;
1033 +
1034 + let is_floating = client.is_floating;
1035 + let is_fullscreen = client.is_fullscreen;
1036 + let has_no_layout = self.layout.name() == LayoutType::Normie.as_str();
1037 +
1038 + if (has_no_layout || is_floating) && !is_fullscreen {
1039 + self.connection.configure_window(
1040 + window,
1041 + &ConfigureWindowAux::new()
1042 + .x(client.x_position as i32)
1043 + .y(client.y_position as i32)
1044 + .width(client.width as u32)
1045 + .height(client.height as u32),
1046 + )?;
1047 + }
1048 +
1049 + self.showhide(client.stack_next)?;
1050 + } else {
1051 + self.showhide(client.stack_next)?;
1052 +
1053 + let width = client.width_with_border() as i32;
1054 + self.connection.configure_window(
1055 + window,
1056 + &ConfigureWindowAux::new()
1057 + .x(width * -2)
1058 + .y(client.y_position as i32),
1059 + )?;
1060 + }
1061 +
1062 + Ok(())
1063 + }
1064 +
1065 + pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> {
1066 + if tag_index >= self.config.tags.len() {
1067 + return Ok(());
1068 + }
1069 +
1070 + let monitor = match self.monitors.get_mut(self.selected_monitor) {
1071 + Some(m) => m,
1072 + None => return Ok(()),
1073 + };
1074 +
1075 + let new_tagset = tag_mask(tag_index);
1076 +
1077 + if new_tagset == monitor.tagset[monitor.selected_tags_index] {
1078 + return Ok(());
1079 + }
1080 +
1081 + monitor.selected_tags_index ^= 1;
1082 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1083 +
1084 + self.save_selected_tags()?;
1085 + self.focus(None)?;
1086 + self.apply_layout()?;
1087 + self.update_bar()?;
1088 +
1089 + Ok(())
1090 + }
1091 +
1092 + pub fn toggleview(&mut self, tag_index: usize) -> WmResult<()> {
1093 + if tag_index >= self.config.tags.len() {
1094 + return Ok(());
1095 + }
1096 +
1097 + let monitor = match self.monitors.get_mut(self.selected_monitor) {
1098 + Some(m) => m,
1099 + None => return Ok(()),
1100 + };
1101 +
1102 + let mask = tag_mask(tag_index);
1103 + let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask;
1104 +
1105 + if new_tagset == 0 {
1106 + return Ok(());
1107 + }
1108 +
1109 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1110 +
1111 + self.save_selected_tags()?;
1112 + self.focus(None)?;
1113 + self.apply_layout()?;
1114 + self.update_bar()?;
1115 +
1116 + Ok(())
1117 + }
1118 +
1119 + fn save_selected_tags(&self) -> WmResult<()> {
1120 + let net_current_desktop = self.atoms.net_current_desktop;
1211 1121
1212 let selected_tags = self 1122 let selected_tags = self
1213 .monitors 1123 .monitors
1214 .get(self.selected_monitor) 1124 .get(self.selected_monitor)
1215 - .map(|m| m.selected_tags) 1125 + .map(|m| m.tagset[m.selected_tags_index])
1216 .unwrap_or(tag_mask(0)); 1126 .unwrap_or(tag_mask(0));
1217 let desktop = selected_tags.trailing_zeros(); 1127 let desktop = selected_tags.trailing_zeros();
1218 1128
@@ -1236,23 +1146,66 @@ impl WindowManager {
1236 return Ok(()); 1146 return Ok(());
1237 } 1147 }
1238 1148
1239 - if let Some(focused) = self 1149 + let focused = match self
1240 .monitors 1150 .monitors
1241 .get(self.selected_monitor) 1151 .get(self.selected_monitor)
1242 - .and_then(|m| m.focused_window) 1152 + .and_then(|m| m.selected_client)
1243 { 1153 {
1244 - let mask = tag_mask(tag_index); 1154 + Some(win) => win,
1245 - self.window_tags.insert(focused, mask); 1155 + None => return Ok(()),
1156 + };
1246 1157
1247 - if let Err(error) = self.save_client_tag(focused, mask) { 1158 + let mask = tag_mask(tag_index);
1248 - eprintln!("Failed to save client tag: {:?}", error);
1249 - }
1250 1159
1251 - self.update_window_visibility()?; 1160 + if let Some(client) = self.clients.get_mut(&focused) {
1252 - self.apply_layout()?; 1161 + client.tags = mask;
1253 - self.update_bar()?; 1162 + }
1163 +
1164 + if let Err(error) = self.save_client_tag(focused, mask) {
1165 + eprintln!("Failed to save client tag: {:?}", error);
1166 + }
1167 +
1168 + self.focus(None)?;
1169 + self.apply_layout()?;
1170 + self.update_bar()?;
1171 +
1172 + Ok(())
1173 + }
1174 +
1175 + pub fn toggletag(&mut self, tag_index: usize) -> WmResult<()> {
1176 + if tag_index >= self.config.tags.len() {
1177 + return Ok(());
1178 + }
1179 +
1180 + let focused = match self
1181 + .monitors
1182 + .get(self.selected_monitor)
1183 + .and_then(|m| m.selected_client)
1184 + {
1185 + Some(win) => win,
1186 + None => return Ok(()),
1187 + };
1188 +
1189 + let mask = tag_mask(tag_index);
1190 + let current_tags = self.clients.get(&focused).map(|c| c.tags).unwrap_or(0);
1191 + let new_tags = current_tags ^ mask;
1192 +
1193 + if new_tags == 0 {
1194 + return Ok(());
1195 + }
1196 +
1197 + if let Some(client) = self.clients.get_mut(&focused) {
1198 + client.tags = new_tags;
1199 + }
1200 +
1201 + if let Err(error) = self.save_client_tag(focused, new_tags) {
1202 + eprintln!("Failed to save client tag: {:?}", error);
1254 } 1203 }
1255 1204
1205 + self.focus(None)?;
1206 + self.apply_layout()?;
1207 + self.update_bar()?;
1208 +
1256 Ok(()) 1209 Ok(())
1257 } 1210 }
1258 1211
@@ -1266,7 +1219,7 @@ impl WindowManager {
1266 let current = self 1219 let current = self
1267 .monitors 1220 .monitors
1268 .get(self.selected_monitor) 1221 .get(self.selected_monitor)
1269 - .and_then(|m| m.focused_window); 1222 + .and_then(|m| m.selected_client);
1270 1223
1271 let next_window = if let Some(current) = current { 1224 let next_window = if let Some(current) = current {
1272 if let Some(current_index) = visible.iter().position(|&w| w == current) { 1225 if let Some(current_index) = visible.iter().position(|&w| w == current) {
@@ -1291,7 +1244,7 @@ impl WindowManager {
1291 )?; 1244 )?;
1292 } 1245 }
1293 1246
1294 - self.set_focus(next_window)?; 1247 + self.focus(Some(next_window))?;
1295 1248
1296 if is_tabbed { 1249 if is_tabbed {
1297 self.update_tab_bars()?; 1250 self.update_tab_bars()?;
@@ -1300,104 +1253,6 @@ impl WindowManager {
1300 Ok(()) 1253 Ok(())
1301 } 1254 }
1302 1255
1303 - fn find_directional_window_candidate(&mut self, focused_window: Window, direction: i32) -> Option<Window> {
1304 - let visible_windows = self.visible_windows();
1305 - if visible_windows.len() < 2 {
1306 - return None;
1307 - }
1308 -
1309 - let focused_geometry = self.get_or_query_geometry(focused_window).ok()?;
1310 - let focused_center_x = focused_geometry.x_position + (focused_geometry.width as i16 / 2);
1311 - let focused_center_y = focused_geometry.y_position + (focused_geometry.height as i16 / 2);
1312 -
1313 - let mut candidates = Vec::new();
1314 -
1315 - for &window in &visible_windows {
1316 - if window == focused_window {
1317 - continue;
1318 - }
1319 -
1320 - let geometry = match self.get_or_query_geometry(window) {
1321 - Ok(geometry) => geometry,
1322 - Err(_) => continue,
1323 - };
1324 -
1325 - let center_x = geometry.x_position + (geometry.width as i16 / 2);
1326 - let center_y = geometry.y_position + (geometry.height as i16 / 2);
1327 -
1328 - let is_valid_direction = match direction {
1329 - 0 => center_y < focused_center_y,
1330 - 1 => center_y > focused_center_y,
1331 - 2 => center_x < focused_center_x,
1332 - 3 => center_x > focused_center_x,
1333 - _ => false,
1334 - };
1335 -
1336 - if is_valid_direction {
1337 - let delta_x = (center_x - focused_center_x) as i32;
1338 - let delta_y = (center_y - focused_center_y) as i32;
1339 - let distance_squared = delta_x * delta_x + delta_y * delta_y;
1340 - candidates.push((window, distance_squared));
1341 - }
1342 - }
1343 -
1344 - candidates.iter().min_by_key(|&(_window, distance)| distance).map(|&(window, _distance)| window)
1345 - }
1346 -
1347 - pub fn focus_direction(&mut self, direction: i32) -> WmResult<()> {
1348 - let focused_window = match self
1349 - .monitors
1350 - .get(self.selected_monitor)
1351 - .and_then(|monitor| monitor.focused_window)
1352 - {
1353 - Some(window) => window,
1354 - None => return Ok(()),
1355 - };
1356 -
1357 - if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) {
1358 - self.set_focus(target_window)?;
1359 - }
1360 -
1361 - Ok(())
1362 - }
1363 -
1364 - pub fn swap_direction(&mut self, direction: i32) -> WmResult<()> {
1365 - let focused_window = match self
1366 - .monitors
1367 - .get(self.selected_monitor)
1368 - .and_then(|monitor| monitor.focused_window)
1369 - {
1370 - Some(window) => window,
1371 - None => return Ok(()),
1372 - };
1373 -
1374 - if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) {
1375 - let focused_position = self.windows.iter().position(|&window| window == focused_window);
1376 - let target_position = self.windows.iter().position(|&window| window == target_window);
1377 -
1378 - if let (Some(focused_index), Some(target_index)) = (focused_position, target_position) {
1379 - self.windows.swap(focused_index, target_index);
1380 - self.apply_layout()?;
1381 - self.set_focus(focused_window)?;
1382 -
1383 - if let Ok(geometry) = self.get_or_query_geometry(focused_window) {
1384 - self.connection.warp_pointer(
1385 - x11rb::NONE,
1386 - focused_window,
1387 - 0,
1388 - 0,
1389 - 0,
1390 - 0,
1391 - geometry.width as i16 / 2,
1392 - geometry.height as i16 / 2,
1393 - )?;
1394 - }
1395 - }
1396 - }
1397 -
1398 - Ok(())
1399 - }
1400 -
1401 fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> { 1256 fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> {
1402 use std::collections::HashMap; 1257 use std::collections::HashMap;
1403 use x11rb::protocol::xproto::Keycode; 1258 use x11rb::protocol::xproto::Keycode;
@@ -1431,6 +1286,13 @@ impl WindowManager {
1431 1286
1432 let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new(); 1287 let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new();
1433 1288
1289 + let ignore_modifiers = [
1290 + 0,
1291 + u16::from(ModMask::LOCK),
1292 + u16::from(ModMask::M2),
1293 + u16::from(ModMask::LOCK | ModMask::M2),
1294 + ];
1295 +
1434 for &candidate_index in candidates { 1296 for &candidate_index in candidates {
1435 let binding = &self.config.keybindings[candidate_index]; 1297 let binding = &self.config.keybindings[candidate_index];
1436 if keys_pressed < binding.keys.len() { 1298 if keys_pressed < binding.keys.len() {
@@ -1439,17 +1301,20 @@ impl WindowManager {
1439 1301
1440 if let Some(keycodes) = keysym_to_keycode.get(&next_key.keysym) { 1302 if let Some(keycodes) = keysym_to_keycode.get(&next_key.keysym) {
1441 if let Some(&keycode) = keycodes.first() { 1303 if let Some(&keycode) = keycodes.first() {
1442 - let key_tuple = (modifier_mask, keycode); 1304 + for &ignore_mask in &ignore_modifiers {
1443 - 1305 + let grab_mask = modifier_mask | ignore_mask;
1444 - if grabbed_keys.insert(key_tuple) { 1306 + let key_tuple = (grab_mask, keycode);
1445 - self.connection.grab_key( 1307 +
1446 - false, 1308 + if grabbed_keys.insert(key_tuple) {
1447 - self.root, 1309 + self.connection.grab_key(
1448 - modifier_mask.into(), 1310 + false,
1449 - keycode, 1311 + self.root,
1450 - GrabMode::ASYNC, 1312 + grab_mask.into(),
1451 - GrabMode::ASYNC, 1313 + keycode,
1452 - )?; 1314 + GrabMode::ASYNC,
1315 + GrabMode::ASYNC,
1316 + )?;
1317 + }
1453 } 1318 }
1454 } 1319 }
1455 } 1320 }
@@ -1458,14 +1323,16 @@ impl WindowManager {
1458 1323
1459 if let Some(keycodes) = keysym_to_keycode.get(&keyboard::keysyms::XK_ESCAPE) { 1324 if let Some(keycodes) = keysym_to_keycode.get(&keyboard::keysyms::XK_ESCAPE) {
1460 if let Some(&keycode) = keycodes.first() { 1325 if let Some(&keycode) = keycodes.first() {
1461 - self.connection.grab_key( 1326 + for &ignore_mask in &ignore_modifiers {
1462 - false, 1327 + self.connection.grab_key(
1463 - self.root, 1328 + false,
1464 - ModMask::from(0u16), 1329 + self.root,
1465 - keycode, 1330 + ModMask::from(ignore_mask),
1466 - GrabMode::ASYNC, 1331 + keycode,
1467 - GrabMode::ASYNC, 1332 + GrabMode::ASYNC,
1468 - )?; 1333 + GrabMode::ASYNC,
1334 + )?;
1335 + }
1469 } 1336 }
1470 } 1337 }
1471 1338
@@ -1482,12 +1349,9 @@ impl WindowManager {
1482 } 1349 }
1483 1350
1484 fn kill_client(&self, window: Window) -> WmResult<()> { 1351 fn kill_client(&self, window: Window) -> WmResult<()> {
1485 - // Try to send WM_DELETE_WINDOW message first (graceful close)
1486 if self.send_event(window, self.atoms.wm_delete_window)? { 1352 if self.send_event(window, self.atoms.wm_delete_window)? {
1487 - // Window supports WM_DELETE_WINDOW, it will close gracefully
1488 self.connection.flush()?; 1353 self.connection.flush()?;
1489 } else { 1354 } else {
1490 - // Window doesn't support WM_DELETE_WINDOW, forcefully kill it
1491 eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window); 1355 eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window);
1492 self.connection.kill_client(window)?; 1356 self.connection.kill_client(window)?;
1493 self.connection.flush()?; 1357 self.connection.flush()?;
@@ -1496,7 +1360,6 @@ impl WindowManager {
1496 } 1360 }
1497 1361
1498 fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> { 1362 fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> {
1499 - // Check if the window supports this protocol
1500 let protocols_reply = self.connection.get_property( 1363 let protocols_reply = self.connection.get_property(
1501 false, 1364 false,
1502 window, 1365 window,
@@ -1521,7 +1384,6 @@ impl WindowManager {
1521 return Ok(false); 1384 return Ok(false);
1522 } 1385 }
1523 1386
1524 - // Send a ClientMessage event
1525 let event = x11rb::protocol::xproto::ClientMessageEvent { 1387 let event = x11rb::protocol::xproto::ClientMessageEvent {
1526 response_type: x11rb::protocol::xproto::CLIENT_MESSAGE_EVENT, 1388 response_type: x11rb::protocol::xproto::CLIENT_MESSAGE_EVENT,
1527 format: 32, 1389 format: 32,
@@ -1541,6 +1403,120 @@ impl WindowManager {
1541 Ok(true) 1403 Ok(true)
1542 } 1404 }
1543 1405
1406 + fn set_urgent(&mut self, window: Window, urgent: bool) -> WmResult<()> {
1407 + if let Some(client) = self.clients.get_mut(&window) {
1408 + client.is_urgent = urgent;
1409 + }
1410 +
1411 + let hints_reply = self.connection.get_property(
1412 + false,
1413 + window,
1414 + AtomEnum::WM_HINTS,
1415 + AtomEnum::WM_HINTS,
1416 + 0,
1417 + 9,
1418 + )?.reply();
1419 +
1420 + if let Ok(hints) = hints_reply {
1421 + if hints.value.len() >= 4 {
1422 + let mut flags = u32::from_ne_bytes([
1423 + hints.value[0],
1424 + hints.value[1],
1425 + hints.value[2],
1426 + hints.value[3],
1427 + ]);
1428 +
1429 + if urgent {
1430 + flags |= 256;
1431 + } else {
1432 + flags &= !256;
1433 + }
1434 +
1435 + let mut new_hints = hints.value.clone();
1436 + new_hints[0..4].copy_from_slice(&flags.to_ne_bytes());
1437 +
1438 + self.connection.change_property(
1439 + PropMode::REPLACE,
1440 + window,
1441 + AtomEnum::WM_HINTS,
1442 + AtomEnum::WM_HINTS,
1443 + 32,
1444 + new_hints.len() as u32 / 4,
1445 + &new_hints,
1446 + )?;
1447 + }
1448 + }
1449 +
1450 + Ok(())
1451 + }
1452 +
1453 + fn get_window_state(&self, window: Window) -> WmResult<i32> {
1454 + let reply = self.connection.get_property(
1455 + false,
1456 + window,
1457 + self.atoms.wm_state,
1458 + self.atoms.wm_state,
1459 + 0,
1460 + 2,
1461 + )?.reply();
1462 +
1463 + match reply {
1464 + Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => {
1465 + let state = u32::from_ne_bytes([
1466 + prop.value[0],
1467 + prop.value[1],
1468 + prop.value[2],
1469 + prop.value[3],
1470 + ]);
1471 + Ok(state as i32)
1472 + }
1473 + _ => Ok(-1),
1474 + }
1475 + }
1476 +
1477 + fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> {
1478 + let reply = self.connection.get_property(
1479 + false,
1480 + window,
1481 + property,
1482 + AtomEnum::ATOM,
1483 + 0,
1484 + 1,
1485 + )?.reply();
1486 +
1487 + match reply {
1488 + Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => {
1489 + let atom = u32::from_ne_bytes([
1490 + prop.value[0],
1491 + prop.value[1],
1492 + prop.value[2],
1493 + prop.value[3],
1494 + ]);
1495 + Ok(Some(atom))
1496 + }
1497 + _ => Ok(None),
1498 + }
1499 + }
1500 +
1501 + fn get_window_text_property(&self, window: Window, atom: Atom) -> WmResult<Option<String>> {
1502 + let reply = self.connection.get_property(
1503 + false,
1504 + window,
1505 + atom,
1506 + AtomEnum::ANY,
1507 + 0,
1508 + 1024,
1509 + )?.reply();
1510 +
1511 + match reply {
1512 + Ok(prop) if !prop.value.is_empty() => {
1513 + let text = String::from_utf8_lossy(&prop.value).to_string();
1514 + Ok(Some(text.trim_end_matches('\0').to_string()))
1515 + }
1516 + _ => Ok(None),
1517 + }
1518 + }
1519 +
1544 fn fullscreen(&mut self) -> WmResult<()> { 1520 fn fullscreen(&mut self) -> WmResult<()> {
1545 if self.show_bar { 1521 if self.show_bar {
1546 let windows: Vec<Window> = self.windows.iter() 1522 let windows: Vec<Window> = self.windows.iter()
@@ -1571,7 +1547,9 @@ impl WindowManager {
1571 .collect(); 1547 .collect();
1572 1548
1573 for window in floating_windows { 1549 for window in floating_windows {
1574 - let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); 1550 + let monitor_idx = self.clients.get(&window)
1551 + .map(|c| c.monitor_index)
1552 + .unwrap_or(self.selected_monitor);
1575 let monitor = &self.monitors[monitor_idx]; 1553 let monitor = &self.monitors[monitor_idx];
1576 1554
1577 let (outer_gap_h, outer_gap_v) = if self.gaps_enabled { 1555 let (outer_gap_h, outer_gap_v) = if self.gaps_enabled {
@@ -1583,18 +1561,18 @@ impl WindowManager {
1583 (0, 0) 1561 (0, 0)
1584 }; 1562 };
1585 1563
1586 - let window_x = monitor.x + outer_gap_h as i32; 1564 + let window_x = monitor.screen_x + outer_gap_h as i32;
1587 - let window_y = monitor.y + outer_gap_v as i32; 1565 + let window_y = monitor.screen_y + outer_gap_v as i32;
1588 - let window_width = monitor.width.saturating_sub(2 * outer_gap_h).saturating_sub(2 * border_width); 1566 + let window_width = monitor.screen_width.saturating_sub(2 * outer_gap_h as i32).saturating_sub(2 * border_width as i32);
1589 - let window_height = monitor.height.saturating_sub(2 * outer_gap_v).saturating_sub(2 * border_width); 1567 + let window_height = monitor.screen_height.saturating_sub(2 * outer_gap_v as i32).saturating_sub(2 * border_width as i32);
1590 1568
1591 self.connection.configure_window( 1569 self.connection.configure_window(
1592 window, 1570 window,
1593 &x11rb::protocol::xproto::ConfigureWindowAux::new() 1571 &x11rb::protocol::xproto::ConfigureWindowAux::new()
1594 .x(window_x) 1572 .x(window_x)
1595 .y(window_y) 1573 .y(window_y)
1596 - .width(window_width) 1574 + .width(window_width as u32)
1597 - .height(window_height), 1575 + .height(window_height as u32),
1598 )?; 1576 )?;
1599 } 1577 }
1600 self.connection.flush()?; 1578 self.connection.flush()?;
@@ -1654,6 +1632,11 @@ impl WindowManager {
1654 } 1632 }
1655 1633
1656 fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> { 1634 fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> {
1635 + let monitor_idx = self.clients.get(&window)
1636 + .map(|c| c.monitor_index)
1637 + .unwrap_or(self.selected_monitor);
1638 + let monitor = &self.monitors[monitor_idx];
1639 +
1657 if fullscreen && !self.fullscreen_windows.contains(&window) { 1640 if fullscreen && !self.fullscreen_windows.contains(&window) {
1658 let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec(); 1641 let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec();
1659 self.connection.change_property( 1642 self.connection.change_property(
@@ -1666,30 +1649,28 @@ impl WindowManager {
1666 &bytes, 1649 &bytes,
1667 )?; 1650 )?;
1668 1651
1669 - self.fullscreen_windows.insert(window); 1652 + if let Some(client) = self.clients.get_mut(&window) {
1670 - 1653 + client.is_fullscreen = true;
1671 - let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); 1654 + client.old_state = client.is_floating;
1672 - let monitor = &self.monitors[monitor_idx]; 1655 + client.old_border_width = client.border_width;
1673 - 1656 + client.border_width = 0;
1674 - if self.show_bar { 1657 + client.is_floating = true;
1675 - if let Some(bar) = self.bars.get(monitor_idx) {
1676 - self.connection.unmap_window(bar.window())?;
1677 - }
1678 } 1658 }
1679 1659
1660 + self.fullscreen_windows.insert(window);
1661 +
1680 self.connection.configure_window( 1662 self.connection.configure_window(
1681 window, 1663 window,
1682 &x11rb::protocol::xproto::ConfigureWindowAux::new() 1664 &x11rb::protocol::xproto::ConfigureWindowAux::new()
1683 .border_width(0) 1665 .border_width(0)
1684 - .x(monitor.x) 1666 + .x(monitor.screen_x)
1685 - .y(monitor.y) 1667 + .y(monitor.screen_y)
1686 - .width(monitor.width as u32) 1668 + .width(monitor.screen_width as u32)
1687 - .height(monitor.height as u32) 1669 + .height(monitor.screen_height as u32)
1688 .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), 1670 .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE),
1689 )?; 1671 )?;
1690 1672
1691 self.connection.flush()?; 1673 self.connection.flush()?;
1692 - self.update_bar()?;
1693 } else if !fullscreen && self.fullscreen_windows.contains(&window) { 1674 } else if !fullscreen && self.fullscreen_windows.contains(&window) {
1694 self.connection.change_property( 1675 self.connection.change_property(
1695 PropMode::REPLACE, 1676 PropMode::REPLACE,
@@ -1703,17 +1684,26 @@ impl WindowManager {
1703 1684
1704 self.fullscreen_windows.remove(&window); 1685 self.fullscreen_windows.remove(&window);
1705 1686
1706 - self.connection.configure_window( 1687 + if let Some(client) = self.clients.get_mut(&window) {
1707 - window, 1688 + client.is_fullscreen = false;
1708 - &x11rb::protocol::xproto::ConfigureWindowAux::new() 1689 + client.is_floating = client.old_state;
1709 - .border_width(self.config.border_width), 1690 + client.border_width = client.old_border_width;
1710 - )?;
1711 1691
1712 - let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); 1692 + let x = client.old_x_position;
1713 - if self.show_bar { 1693 + let y = client.old_y_position;
1714 - if let Some(bar) = self.bars.get(monitor_idx) { 1694 + let w = client.old_width;
1715 - self.connection.map_window(bar.window())?; 1695 + let h = client.old_height;
1716 - } 1696 + let bw = client.border_width;
1697 +
1698 + self.connection.configure_window(
1699 + window,
1700 + &x11rb::protocol::xproto::ConfigureWindowAux::new()
1701 + .x(x as i32)
1702 + .y(y as i32)
1703 + .width(w as u32)
1704 + .height(h as u32)
1705 + .border_width(bw as u32),
1706 + )?;
1717 } 1707 }
1718 1708
1719 self.apply_layout()?; 1709 self.apply_layout()?;
@@ -1736,8 +1726,8 @@ impl WindowManager {
1736 Ok(()) 1726 Ok(())
1737 } 1727 }
1738 1728
1739 - fn is_transient_window(&self, window: Window) -> bool { 1729 + fn get_transient_parent(&self, window: Window) -> Option<Window> {
1740 - let transient_for = self.connection 1730 + self.connection
1741 .get_property( 1731 .get_property(
1742 false, 1732 false,
1743 window, 1733 window,
@@ -1748,29 +1738,737 @@ impl WindowManager {
1748 ) 1738 )
1749 .ok() 1739 .ok()
1750 .and_then(|cookie| cookie.reply().ok()) 1740 .and_then(|cookie| cookie.reply().ok())
1751 - .filter(|reply| !reply.value.is_empty()); 1741 + .filter(|reply| !reply.value.is_empty())
1742 + .and_then(|reply| {
1743 + if reply.value.len() >= 4 {
1744 + let parent_window = u32::from_ne_bytes([
1745 + reply.value[0],
1746 + reply.value[1],
1747 + reply.value[2],
1748 + reply.value[3],
1749 + ]);
1750 + Some(parent_window)
1751 + } else {
1752 + None
1753 + }
1754 + })
1755 + }
1756 +
1757 + fn is_dialog_window(&self, window: Window) -> bool {
1758 + let window_type_property = self.connection
1759 + .get_property(
1760 + false,
1761 + window,
1762 + self.atoms.net_wm_window_type,
1763 + AtomEnum::ATOM,
1764 + 0,
1765 + 32,
1766 + )
1767 + .ok()
1768 + .and_then(|cookie| cookie.reply().ok());
1769 +
1770 + if let Some(reply) = window_type_property {
1771 + let atoms: Vec<Atom> = reply
1772 + .value
1773 + .chunks_exact(4)
1774 + .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]))
1775 + .collect();
1776 +
1777 + atoms.contains(&self.atoms.net_wm_window_type_dialog)
1778 + } else {
1779 + false
1780 + }
1781 + }
1782 +
1783 + fn get_window_class(&self, window: Window) -> Option<String> {
1784 + self.connection
1785 + .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)
1786 + .ok()
1787 + .and_then(|cookie| cookie.reply().ok())
1788 + .and_then(|reply| {
1789 + if reply.value.is_empty() {
1790 + None
1791 + } else {
1792 + std::str::from_utf8(&reply.value).ok().map(|s| {
1793 + s.split('\0').nth(1).unwrap_or(s.split('\0').next().unwrap_or("")).to_string()
1794 + })
1795 + }
1796 + })
1797 + }
1798 +
1799 + fn get_window_class_instance(&self, window: Window) -> (String, String) {
1800 + let reply = self.connection
1801 + .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)
1802 + .ok()
1803 + .and_then(|cookie| cookie.reply().ok());
1804 +
1805 + if let Some(reply) = reply {
1806 + if !reply.value.is_empty() {
1807 + if let Ok(text) = std::str::from_utf8(&reply.value) {
1808 + let parts: Vec<&str> = text.split('\0').collect();
1809 + let instance = parts.get(0).unwrap_or(&"").to_string();
1810 + let class = parts.get(1).unwrap_or(&"").to_string();
1811 + return (instance, class);
1812 + }
1813 + }
1814 + }
1815 +
1816 + (String::new(), String::new())
1817 + }
1818 +
1819 + fn apply_rules(&mut self, window: Window) -> WmResult<()> {
1820 + let (instance, class) = self.get_window_class_instance(window);
1821 + let title = self.clients.get(&window).map(|c| c.name.clone()).unwrap_or_default();
1822 +
1823 + let mut rule_tags: Option<u32> = None;
1824 + let mut rule_floating: Option<bool> = None;
1825 + let mut rule_monitor: Option<usize> = None;
1826 +
1827 + for rule in &self.config.window_rules {
1828 + if rule.matches(&class, &instance, &title) {
1829 + if rule.tags.is_some() {
1830 + rule_tags = rule.tags;
1831 + }
1832 + if rule.is_floating.is_some() {
1833 + rule_floating = rule.is_floating;
1834 + }
1835 + if rule.monitor.is_some() {
1836 + rule_monitor = rule.monitor;
1837 + }
1838 + }
1839 + }
1840 +
1841 + if let Some(client) = self.clients.get_mut(&window) {
1842 + if let Some(is_floating) = rule_floating {
1843 + client.is_floating = is_floating;
1844 + if is_floating {
1845 + self.floating_windows.insert(window);
1846 + } else {
1847 + self.floating_windows.remove(&window);
1848 + }
1849 + }
1850 +
1851 + if let Some(monitor_index) = rule_monitor {
1852 + if monitor_index < self.monitors.len() {
1853 + client.monitor_index = monitor_index;
1854 + }
1855 + }
1856 +
1857 + let tags = rule_tags.unwrap_or_else(|| {
1858 + self.monitors
1859 + .get(client.monitor_index)
1860 + .map(|m| m.tagset[m.selected_tags_index])
1861 + .unwrap_or(tag_mask(0))
1862 + });
1863 +
1864 + client.tags = tags;
1865 + }
1866 +
1867 + Ok(())
1868 + }
1869 +
1870 + fn manage_window(&mut self, window: Window) -> WmResult<()> {
1871 + let geometry = self.connection.get_geometry(window)?.reply()?;
1872 + let mut window_x = geometry.x as i32;
1873 + let mut window_y = geometry.y as i32;
1874 + let window_width = geometry.width as u32;
1875 + let window_height = geometry.height as u32;
1876 +
1877 + let transient_parent = self.get_transient_parent(window);
1878 + let (window_tags, monitor_index) = if let Some(parent) = transient_parent {
1879 + if let Some(parent_client) = self.clients.get(&parent) {
1880 + (parent_client.tags, parent_client.monitor_index)
1881 + } else {
1882 + let tags = self.monitors
1883 + .get(self.selected_monitor)
1884 + .map(|m| m.tagset[m.selected_tags_index])
1885 + .unwrap_or(tag_mask(0));
1886 + (tags, self.selected_monitor)
1887 + }
1888 + } else {
1889 + let selected_tags = self.monitors
1890 + .get(self.selected_monitor)
1891 + .map(|m| m.tagset[m.selected_tags_index])
1892 + .unwrap_or(tag_mask(0));
1893 + (selected_tags, self.selected_monitor)
1894 + };
1895 +
1896 + let monitor = self.monitors[monitor_index].clone();
1897 + let border_width = self.config.border_width;
1898 +
1899 + let mut client = Client::new(window, monitor_index, window_tags);
1900 + client.x_position = window_x as i16;
1901 + client.y_position = window_y as i16;
1902 + client.width = window_width as u16;
1903 + client.height = window_height as u16;
1904 + client.old_x_position = window_x as i16;
1905 + client.old_y_position = window_y as i16;
1906 + client.old_width = window_width as u16;
1907 + client.old_height = window_height as u16;
1908 + client.border_width = border_width as u16;
1909 + client.old_border_width = border_width as u16;
1910 +
1911 + if window_x + (window_width as i32) + (2 * border_width as i32) > monitor.screen_x + monitor.screen_width as i32 {
1912 + window_x = monitor.screen_x + monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32);
1913 + }
1914 + if window_y + (window_height as i32) + (2 * border_width as i32) > monitor.screen_y + monitor.screen_height as i32 {
1915 + window_y = monitor.screen_y + monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32);
1916 + }
1917 + window_x = window_x.max(monitor.screen_x);
1918 + window_y = window_y.max(monitor.screen_y);
1919 +
1920 + let is_transient = transient_parent.is_some();
1921 + let is_dialog = self.is_dialog_window(window);
1922 +
1923 + let class_name = self.get_window_class(window).unwrap_or_default();
1924 + eprintln!("MapRequest 0x{:x}: class='{}' size={}x{} pos=({},{}) transient={} dialog={}",
1925 + window, class_name, window_width, window_height, window_x, window_y, is_transient, is_dialog);
1926 +
1927 + let off_screen_x = window_x + (2 * self.screen.width_in_pixels as i32);
1928 +
1929 + self.connection.configure_window(
1930 + window,
1931 + &ConfigureWindowAux::new()
1932 + .x(off_screen_x)
1933 + .y(window_y)
1934 + .width(window_width)
1935 + .height(window_height)
1936 + .border_width(border_width)
1937 + )?;
1938 +
1939 + self.connection.change_window_attributes(
1940 + window,
1941 + &ChangeWindowAttributesAux::new().event_mask(
1942 + EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE
1943 + ),
1944 + )?;
1945 +
1946 + client.is_floating = is_transient || is_dialog;
1947 +
1948 + self.clients.insert(window, client);
1949 + self.update_size_hints(window)?;
1950 + self.update_window_title(window)?;
1951 + self.apply_rules(window)?;
1952 +
1953 + let updated_monitor_index = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(monitor_index);
1954 + let updated_monitor = self.monitors.get(updated_monitor_index).cloned().unwrap_or(monitor.clone());
1955 + let is_rule_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false);
1956 +
1957 + self.attach_aside(window, updated_monitor_index);
1958 + self.attach_stack(window, updated_monitor_index);
1959 +
1960 + self.windows.push(window);
1961 +
1962 + if is_transient || is_dialog {
1963 + self.floating_windows.insert(window);
1964 +
1965 + let (center_x, center_y) = if let Some(parent) = transient_parent {
1966 + if let Ok(parent_geom) = self.connection.get_geometry(parent)?.reply() {
1967 + let parent_center_x = parent_geom.x as i32 + (parent_geom.width as i32 / 2);
1968 + let parent_center_y = parent_geom.y as i32 + (parent_geom.height as i32 / 2);
1969 + (parent_center_x, parent_center_y)
1970 + } else {
1971 + let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2);
1972 + let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2);
1973 + (monitor_center_x, monitor_center_y)
1974 + }
1975 + } else {
1976 + let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2);
1977 + let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2);
1978 + (monitor_center_x, monitor_center_y)
1979 + };
1980 +
1981 + let positioned_x = center_x - (window_width as i32 / 2);
1982 + let positioned_y = center_y - (window_height as i32 / 2);
1983 +
1984 + let clamped_x = positioned_x
1985 + .max(monitor.screen_x)
1986 + .min(monitor.screen_x + monitor.screen_width as i32 - window_width as i32);
1987 + let clamped_y = positioned_y
1988 + .max(monitor.screen_y)
1989 + .min(monitor.screen_y + monitor.screen_height as i32 - window_height as i32);
1990 +
1991 + self.update_geometry_cache(window, CachedGeometry {
1992 + x_position: clamped_x as i16,
1993 + y_position: clamped_y as i16,
1994 + width: window_width as u16,
1995 + height: window_height as u16,
1996 + border_width: border_width as u16,
1997 + });
1998 +
1999 + self.connection.configure_window(
2000 + window,
2001 + &ConfigureWindowAux::new()
2002 + .x(clamped_x)
2003 + .y(clamped_y)
2004 + .width(window_width)
2005 + .height(window_height)
2006 + .border_width(border_width)
2007 + .stack_mode(StackMode::ABOVE),
2008 + )?;
2009 + } else if is_rule_floating && !is_transient && !is_dialog {
2010 + let mut adjusted_x = window_x;
2011 + let mut adjusted_y = window_y;
2012 +
2013 + if adjusted_x + (window_width as i32) + (2 * border_width as i32) > updated_monitor.screen_x + updated_monitor.screen_width as i32 {
2014 + adjusted_x = updated_monitor.screen_x + updated_monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32);
2015 + }
2016 + if adjusted_y + (window_height as i32) + (2 * border_width as i32) > updated_monitor.screen_y + updated_monitor.screen_height as i32 {
2017 + adjusted_y = updated_monitor.screen_y + updated_monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32);
2018 + }
2019 + adjusted_x = adjusted_x.max(updated_monitor.screen_x);
2020 + adjusted_y = adjusted_y.max(updated_monitor.screen_y);
2021 +
2022 + if let Some(client) = self.clients.get_mut(&window) {
2023 + client.x_position = adjusted_x as i16;
2024 + client.y_position = adjusted_y as i16;
2025 + client.width = window_width as u16;
2026 + client.height = window_height as u16;
2027 + }
2028 +
2029 + self.update_geometry_cache(window, CachedGeometry {
2030 + x_position: adjusted_x as i16,
2031 + y_position: adjusted_y as i16,
2032 + width: window_width as u16,
2033 + height: window_height as u16,
2034 + border_width: border_width as u16,
2035 + });
2036 +
2037 + self.connection.configure_window(
2038 + window,
2039 + &ConfigureWindowAux::new()
2040 + .x(adjusted_x)
2041 + .y(adjusted_y)
2042 + .width(window_width)
2043 + .height(window_height)
2044 + .border_width(border_width)
2045 + .stack_mode(StackMode::ABOVE),
2046 + )?;
2047 + }
2048 +
2049 + self.set_wm_state(window, 1)?;
2050 + if let Err(error) = self.save_client_tag(window, window_tags) {
2051 + eprintln!("Failed to save client tag for new window: {:?}", error);
2052 + }
2053 +
2054 + self.apply_layout()?;
2055 + self.connection.map_window(window)?;
2056 + self.update_bar()?;
2057 + self.focus(Some(window))?;
2058 +
2059 + if self.layout.name() == "tabbed" {
2060 + self.update_tab_bars()?;
2061 + }
2062 +
2063 + Ok(())
2064 + }
2065 +
2066 + pub fn set_focus(&mut self, window: Window) -> WmResult<()> {
2067 + let old_focused = self.previous_focused;
2068 +
2069 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
2070 + monitor.selected_client = Some(window);
2071 + }
2072 +
2073 + self.connection
2074 + .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?;
2075 + self.connection.flush()?;
2076 +
2077 + self.update_focus_visuals(old_focused, window)?;
2078 + self.previous_focused = Some(window);
2079 +
2080 + if self.layout.name() == "tabbed" {
2081 + self.update_tab_bars()?;
2082 + }
2083 +
2084 + Ok(())
2085 + }
2086 +
2087 + fn unfocus(&self, window: Window) -> WmResult<()> {
2088 + if !self.windows.contains(&window) {
2089 + return Ok(());
2090 + }
2091 +
2092 + self.connection.change_window_attributes(
2093 + window,
2094 + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused),
2095 + )?;
2096 +
2097 + self.connection.grab_button(
2098 + false,
2099 + window,
2100 + EventMask::BUTTON_PRESS.into(),
2101 + GrabMode::SYNC,
2102 + GrabMode::SYNC,
2103 + x11rb::NONE,
2104 + x11rb::NONE,
2105 + ButtonIndex::ANY,
2106 + ModMask::ANY,
2107 + )?;
2108 +
2109 + Ok(())
2110 + }
2111 +
2112 + fn focus(&mut self, window: Option<Window>) -> WmResult<()> {
2113 + let monitor = self.monitors.get_mut(self.selected_monitor).unwrap();
2114 + let old_selected = monitor.selected_client;
2115 +
2116 + if let Some(old_win) = old_selected {
2117 + if old_selected != window {
2118 + self.unfocus(old_win)?;
2119 + }
2120 + }
2121 +
2122 + let mut win = window;
2123 + if win.is_none() || !self.is_visible(win.unwrap()) {
2124 + let mut current = self.monitors.get(self.selected_monitor)
2125 + .and_then(|m| m.stack_head);
2126 +
2127 + while let Some(w) = current {
2128 + if self.is_visible(w) {
2129 + win = Some(w);
2130 + break;
2131 + }
2132 + current = self.clients.get(&w).and_then(|c| c.stack_next);
2133 + }
2134 + }
2135 +
2136 + if let Some(win) = win {
2137 + if !self.windows.contains(&win) {
2138 + return Ok(());
2139 + }
2140 +
2141 + let monitor_idx = self.clients.get(&win)
2142 + .map(|c| c.monitor_index)
2143 + .unwrap_or(self.selected_monitor);
2144 + if monitor_idx != self.selected_monitor {
2145 + self.selected_monitor = monitor_idx;
2146 + }
2147 +
2148 + self.detach_stack(win);
2149 + self.attach_stack(win, monitor_idx);
2150 +
2151 + self.connection.change_window_attributes(
2152 + win,
2153 + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused),
2154 + )?;
2155 +
2156 + self.connection.ungrab_button(ButtonIndex::ANY, win, ModMask::ANY)?;
2157 +
2158 + self.connection.set_input_focus(
2159 + InputFocus::POINTER_ROOT,
2160 + win,
2161 + x11rb::CURRENT_TIME,
2162 + )?;
2163 +
2164 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
2165 + monitor.selected_client = Some(win);
2166 + }
2167 +
2168 + self.previous_focused = Some(win);
2169 + } else {
2170 + self.connection.set_input_focus(
2171 + InputFocus::POINTER_ROOT,
2172 + self.root,
2173 + x11rb::CURRENT_TIME,
2174 + )?;
2175 +
2176 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
2177 + monitor.selected_client = None;
2178 + }
2179 + }
2180 +
2181 + self.restack()?;
2182 + self.connection.flush()?;
2183 +
2184 + Ok(())
2185 + }
2186 +
2187 + fn restack(&mut self) -> WmResult<()> {
2188 + let monitor = match self.monitors.get(self.selected_monitor) {
2189 + Some(m) => m,
2190 + None => return Ok(()),
2191 + };
2192 +
2193 + let mut windows_to_restack: Vec<Window> = Vec::new();
2194 +
2195 + if let Some(selected) = monitor.selected_client {
2196 + if self.floating_windows.contains(&selected) {
2197 + windows_to_restack.push(selected);
2198 + }
2199 + }
2200 +
2201 + let mut current = monitor.stack_head;
2202 + while let Some(win) = current {
2203 + if self.windows.contains(&win) && self.floating_windows.contains(&win) {
2204 + if Some(win) != monitor.selected_client {
2205 + windows_to_restack.push(win);
2206 + }
2207 + }
2208 + current = self.clients.get(&win).and_then(|c| c.stack_next);
2209 + }
2210 +
2211 + current = monitor.stack_head;
2212 + while let Some(win) = current {
2213 + if self.windows.contains(&win) && !self.floating_windows.contains(&win) {
2214 + windows_to_restack.push(win);
2215 + }
2216 + current = self.clients.get(&win).and_then(|c| c.stack_next);
2217 + }
2218 +
2219 + for (i, &win) in windows_to_restack.iter().enumerate() {
2220 + if i == 0 {
2221 + self.connection.configure_window(
2222 + win,
2223 + &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
2224 + )?;
2225 + } else {
2226 + self.connection.configure_window(
2227 + win,
2228 + &ConfigureWindowAux::new()
2229 + .sibling(windows_to_restack[i - 1])
2230 + .stack_mode(StackMode::BELOW),
2231 + )?;
2232 + }
2233 + }
2234 +
2235 + Ok(())
2236 + }
2237 +
2238 + fn focusstack(&mut self, direction: i32) -> WmResult<()> {
2239 + let monitor = match self.monitors.get(self.selected_monitor) {
2240 + Some(m) => m,
2241 + None => return Ok(()),
2242 + };
2243 +
2244 + let selected = match monitor.selected_client {
2245 + Some(win) => win,
2246 + None => return Ok(()),
2247 + };
2248 +
2249 + let selected_tags = monitor.tagset[monitor.selected_tags_index];
2250 +
2251 + let mut stack_windows: Vec<Window> = Vec::new();
2252 + let mut current = monitor.clients_head;
2253 + while let Some(win) = current {
2254 + if let Some(client) = self.clients.get(&win) {
2255 + if client.tags & selected_tags != 0 && !client.is_floating {
2256 + stack_windows.push(win);
2257 + }
2258 + current = client.next;
2259 + } else {
2260 + break;
2261 + }
2262 + }
2263 +
2264 + if stack_windows.is_empty() {
2265 + return Ok(());
2266 + }
2267 +
2268 + let current_idx = stack_windows.iter().position(|&w| w == selected);
2269 +
2270 + let next_window = if let Some(idx) = current_idx {
2271 + if direction > 0 {
2272 + if idx + 1 < stack_windows.len() {
2273 + stack_windows[idx + 1]
2274 + } else {
2275 + stack_windows[0]
2276 + }
2277 + } else {
2278 + if idx > 0 {
2279 + stack_windows[idx - 1]
2280 + } else {
2281 + stack_windows[stack_windows.len() - 1]
2282 + }
2283 + }
2284 + } else {
2285 + return Ok(());
2286 + };
2287 +
2288 + self.focus(Some(next_window))?;
2289 + self.update_tab_bars()?;
2290 +
2291 + Ok(())
2292 + }
2293 +
2294 + pub fn move_stack(&mut self, direction: i32) -> WmResult<()> {
2295 + let monitor_index = self.selected_monitor;
2296 + let monitor = match self.monitors.get(monitor_index) {
2297 + Some(m) => m.clone(),
2298 + None => return Ok(()),
2299 + };
2300 +
2301 + let selected = match monitor.selected_client {
2302 + Some(win) => win,
2303 + None => return Ok(()),
2304 + };
2305 +
2306 + let selected_client = match self.clients.get(&selected) {
2307 + Some(c) => c,
2308 + None => return Ok(()),
2309 + };
2310 +
2311 + let target = if direction > 0 {
2312 + let next = self.next_tiled(selected_client.next, &monitor);
2313 + if next.is_some() {
2314 + next
2315 + } else {
2316 + self.next_tiled(monitor.clients_head, &monitor)
2317 + }
2318 + } else {
2319 + let mut previous = None;
2320 + let mut current = monitor.clients_head;
2321 + while let Some(window) = current {
2322 + if window == selected {
2323 + break;
2324 + }
2325 + if let Some(client) = self.clients.get(&window) {
2326 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
2327 + if visible_tags != 0 && !client.is_floating {
2328 + previous = Some(window);
2329 + }
2330 + current = client.next;
2331 + } else {
2332 + break;
2333 + }
2334 + }
2335 + if previous.is_none() {
2336 + let mut last = None;
2337 + let mut current = monitor.clients_head;
2338 + while let Some(window) = current {
2339 + if let Some(client) = self.clients.get(&window) {
2340 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
2341 + if visible_tags != 0 && !client.is_floating {
2342 + last = Some(window);
2343 + }
2344 + current = client.next;
2345 + } else {
2346 + break;
2347 + }
2348 + }
2349 + last
2350 + } else {
2351 + previous
2352 + }
2353 + };
2354 +
2355 + let target = match target {
2356 + Some(t) if t != selected => t,
2357 + _ => return Ok(()),
2358 + };
2359 +
2360 + let mut prev_selected = None;
2361 + let mut prev_target = None;
2362 + let mut current = monitor.clients_head;
2363 +
2364 + while let Some(window) = current {
2365 + if let Some(client) = self.clients.get(&window) {
2366 + if client.next == Some(selected) {
2367 + prev_selected = Some(window);
2368 + }
2369 + if client.next == Some(target) {
2370 + prev_target = Some(window);
2371 + }
2372 + current = client.next;
2373 + } else {
2374 + break;
2375 + }
2376 + }
2377 +
2378 + let selected_next = self.clients.get(&selected).and_then(|c| c.next);
2379 + let target_next = self.clients.get(&target).and_then(|c| c.next);
2380 +
2381 + let temp = if selected_next == Some(target) {
2382 + Some(selected)
2383 + } else {
2384 + selected_next
2385 + };
2386 +
2387 + if let Some(client) = self.clients.get_mut(&selected) {
2388 + client.next = if target_next == Some(selected) {
2389 + Some(target)
2390 + } else {
2391 + target_next
2392 + };
2393 + }
2394 +
2395 + if let Some(client) = self.clients.get_mut(&target) {
2396 + client.next = temp;
2397 + }
2398 +
2399 + if let Some(prev) = prev_selected {
2400 + if prev != target {
2401 + if let Some(client) = self.clients.get_mut(&prev) {
2402 + client.next = Some(target);
2403 + }
2404 + }
2405 + }
2406 +
2407 + if let Some(prev) = prev_target {
2408 + if prev != selected {
2409 + if let Some(client) = self.clients.get_mut(&prev) {
2410 + client.next = Some(selected);
2411 + }
2412 + }
2413 + }
2414 +
2415 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
2416 + if monitor.clients_head == Some(selected) {
2417 + monitor.clients_head = Some(target);
2418 + } else if monitor.clients_head == Some(target) {
2419 + monitor.clients_head = Some(selected);
2420 + }
2421 + }
1752 2422
1753 - transient_for.is_some() 2423 + self.apply_layout()?;
2424 + Ok(())
1754 } 2425 }
1755 2426
1756 - pub fn set_focus(&mut self, window: Window) -> WmResult<()> { 2427 + pub fn focus_monitor(&mut self, direction: i32) -> WmResult<()> {
1757 - let old_focused = self.previous_focused; 2428 + if self.monitors.len() <= 1 {
2429 + return Ok(());
2430 + }
1758 2431
1759 - if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { 2432 + let target_monitor = match self.get_adjacent_monitor(direction) {
1760 - monitor.focused_window = Some(window); 2433 + Some(idx) if idx != self.selected_monitor => idx,
2434 + _ => return Ok(()),
2435 + };
2436 +
2437 + let old_selected = self.monitors
2438 + .get(self.selected_monitor)
2439 + .and_then(|m| m.selected_client);
2440 +
2441 + if let Some(win) = old_selected {
2442 + self.unfocus(win)?;
1761 } 2443 }
1762 2444
1763 - self.connection 2445 + self.selected_monitor = target_monitor;
1764 - .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?; 2446 + self.focus(None)?;
1765 - self.connection.flush()?;
1766 2447
1767 - self.update_focus_visuals(old_focused, window)?; 2448 + Ok(())
1768 - self.previous_focused = Some(window); 2449 + }
1769 2450
1770 - if self.layout.name() == "tabbed" { 2451 + pub fn send_window_to_adjacent_monitor(&mut self, direction: i32) -> WmResult<()> {
1771 - self.update_tab_bars()?; 2452 + if self.monitors.len() <= 1 {
2453 + return Ok(());
1772 } 2454 }
1773 2455
2456 + let selected_window = self.monitors
2457 + .get(self.selected_monitor)
2458 + .and_then(|m| m.selected_client);
2459 +
2460 + let window = match selected_window {
2461 + Some(win) => win,
2462 + None => return Ok(()),
2463 + };
2464 +
2465 + let target_monitor = match self.get_adjacent_monitor(direction) {
2466 + Some(idx) => idx,
2467 + None => return Ok(()),
2468 + };
2469 +
2470 + self.move_window_to_monitor(window, target_monitor)?;
2471 +
1774 Ok(()) 2472 Ok(())
1775 } 2473 }
1776 2474
@@ -1807,63 +2505,146 @@ impl WindowManager {
1807 Ok(()) 2505 Ok(())
1808 } 2506 }
1809 2507
1810 - fn move_mouse(&mut self, window: Window) -> WmResult<()> { 2508 + fn drag_window(&mut self, window: Window) -> WmResult<()> {
1811 - self.floating_windows.insert(window); 2509 + let is_fullscreen = self.clients
2510 + .get(&window)
2511 + .map(|c| c.is_fullscreen)
2512 + .unwrap_or(false);
1812 2513
1813 - let geometry = self.connection.get_geometry(window)?.reply()?; 2514 + if is_fullscreen {
2515 + return Ok(());
2516 + }
1814 2517
1815 - self.connection 2518 + let client_info = self.clients.get(&window).map(|c| {
1816 - .grab_pointer( 2519 + (c.x_position, c.y_position, c.width, c.height, c.is_floating, c.monitor_index)
1817 - false, 2520 + });
1818 - self.root, 2521 +
1819 - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE).into(), 2522 + let Some((orig_x, orig_y, width, height, was_floating, monitor_idx)) = client_info else {
1820 - GrabMode::ASYNC, 2523 + return Ok(());
1821 - GrabMode::ASYNC, 2524 + };
1822 - x11rb::NONE, 2525 +
1823 - x11rb::NONE, 2526 + let monitor = self.monitors.get(monitor_idx).cloned();
1824 - x11rb::CURRENT_TIME, 2527 + let Some(monitor) = monitor else {
1825 - )? 2528 + return Ok(());
1826 - .reply()?; 2529 + };
2530 +
2531 + let snap = 32;
2532 + let is_normie = self.layout.name() == "normie";
2533 +
2534 + if !was_floating && !is_normie {
2535 + self.toggle_floating()?;
2536 + }
2537 +
2538 + self.connection.grab_pointer(
2539 + false,
2540 + self.root,
2541 + (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE |
2542 + EventMask::BUTTON_PRESS).into(),
2543 + GrabMode::ASYNC,
2544 + GrabMode::ASYNC,
2545 + x11rb::NONE,
2546 + x11rb::NONE,
2547 + x11rb::CURRENT_TIME,
2548 + )?.reply()?;
1827 2549
1828 let pointer = self.connection.query_pointer(self.root)?.reply()?; 2550 let pointer = self.connection.query_pointer(self.root)?.reply()?;
1829 - let (start_x, start_y) = (pointer.root_x, pointer.root_y); 2551 + let (start_x, start_y) = (pointer.root_x as i32, pointer.root_y as i32);
1830 2552
1831 - self.connection.configure_window( 2553 + let mut last_time = 0u32;
1832 - window,
1833 - &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
1834 - )?;
1835 2554
1836 loop { 2555 loop {
1837 let event = self.connection.wait_for_event()?; 2556 let event = self.connection.wait_for_event()?;
1838 match event { 2557 match event {
2558 + Event::ConfigureRequest(_) | Event::MapRequest(_) | Event::Expose(_) => {}
1839 Event::MotionNotify(e) => { 2559 Event::MotionNotify(e) => {
1840 - let new_x = geometry.x + (e.root_x - start_x); 2560 + if e.time.wrapping_sub(last_time) <= 16 {
1841 - let new_y = geometry.y + (e.root_y - start_y); 2561 + continue;
1842 - self.connection.configure_window( 2562 + }
1843 - window, 2563 + last_time = e.time;
1844 - &ConfigureWindowAux::new().x(new_x as i32).y(new_y as i32), 2564 +
1845 - )?; 2565 + let mut new_x = orig_x as i32 + (e.root_x as i32 - start_x);
1846 - self.connection.flush()?; 2566 + let mut new_y = orig_y as i32 + (e.root_y as i32 - start_y);
2567 +
2568 + if (monitor.window_area_x - new_x).abs() < snap {
2569 + new_x = monitor.window_area_x;
2570 + } else if ((monitor.window_area_x + monitor.window_area_width) - (new_x + width as i32)).abs() < snap {
2571 + new_x = monitor.window_area_x + monitor.window_area_width - width as i32;
2572 + }
2573 +
2574 + if (monitor.window_area_y - new_y).abs() < snap {
2575 + new_y = monitor.window_area_y;
2576 + } else if ((monitor.window_area_y + monitor.window_area_height) - (new_y + height as i32)).abs() < snap {
2577 + new_y = monitor.window_area_y + monitor.window_area_height - height as i32;
2578 + }
2579 +
2580 + let should_resize = is_normie || self.clients
2581 + .get(&window)
2582 + .map(|c| c.is_floating)
2583 + .unwrap_or(false);
2584 +
2585 + if should_resize {
2586 + if let Some(client) = self.clients.get_mut(&window) {
2587 + client.x_position = new_x as i16;
2588 + client.y_position = new_y as i16;
2589 + }
2590 +
2591 + self.connection.configure_window(
2592 + window,
2593 + &ConfigureWindowAux::new()
2594 + .x(new_x)
2595 + .y(new_y),
2596 + )?;
2597 + self.connection.flush()?;
2598 + }
1847 } 2599 }
1848 Event::ButtonRelease(_) => break, 2600 Event::ButtonRelease(_) => break,
1849 _ => {} 2601 _ => {}
1850 } 2602 }
1851 } 2603 }
1852 2604
1853 - self.connection 2605 + self.connection.ungrab_pointer(x11rb::CURRENT_TIME)?.check()?;
1854 - .ungrab_pointer(x11rb::CURRENT_TIME)? 2606 +
1855 - .check()?; 2607 + let final_client = self.clients.get(&window).map(|c| {
1856 - self.connection 2608 + (c.x_position, c.y_position, c.width, c.height)
1857 - .allow_events(Allow::REPLAY_POINTER, x11rb::CURRENT_TIME)? 2609 + });
1858 - .check()?; 2610 +
2611 + if let Some((x, y, w, h)) = final_client {
2612 + let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32);
2613 + if new_monitor != monitor_idx {
2614 + self.move_window_to_monitor(window, new_monitor)?;
2615 + self.selected_monitor = new_monitor;
2616 + self.focus(None)?;
2617 + }
2618 + }
1859 2619
1860 Ok(()) 2620 Ok(())
1861 } 2621 }
1862 2622
1863 - fn resize_mouse(&mut self, window: Window) -> WmResult<()> { 2623 + fn resize_window_with_mouse(&mut self, window: Window) -> WmResult<()> {
1864 - self.floating_windows.insert(window); 2624 + let is_fullscreen = self.clients
2625 + .get(&window)
2626 + .map(|c| c.is_fullscreen)
2627 + .unwrap_or(false);
1865 2628
1866 - let geometry = self.connection.get_geometry(window)?.reply()?; 2629 + if is_fullscreen {
2630 + return Ok(());
2631 + }
2632 +
2633 + let client_info = self.clients.get(&window).map(|c| {
2634 + (c.x_position, c.y_position, c.width, c.height, c.border_width, c.is_floating, c.monitor_index)
2635 + });
2636 +
2637 + let Some((orig_x, orig_y, orig_width, orig_height, border_width, was_floating, monitor_idx)) = client_info else {
2638 + return Ok(());
2639 + };
2640 +
2641 + let monitor = self.monitors.get(monitor_idx).cloned();
2642 + let Some(monitor) = monitor else {
2643 + return Ok(());
2644 + };
2645 +
2646 + let snap = 32;
2647 + let is_normie = self.layout.name() == "normie";
1867 2648
1868 self.connection.warp_pointer( 2649 self.connection.warp_pointer(
1869 x11rb::NONE, 2650 x11rb::NONE,
@@ -1872,54 +2653,115 @@ impl WindowManager {
1872 0, 2653 0,
1873 0, 2654 0,
1874 0, 2655 0,
1875 - geometry.width as i16, 2656 + (orig_width + border_width - 1) as i16,
1876 - geometry.height as i16, 2657 + (orig_height + border_width - 1) as i16,
1877 )?; 2658 )?;
1878 2659
1879 - self.connection 2660 + self.connection.grab_pointer(
1880 - .grab_pointer( 2661 + false,
1881 - false, 2662 + self.root,
1882 - self.root, 2663 + (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE |
1883 - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE).into(), 2664 + EventMask::BUTTON_PRESS).into(),
1884 - GrabMode::ASYNC, 2665 + GrabMode::ASYNC,
1885 - GrabMode::ASYNC, 2666 + GrabMode::ASYNC,
1886 - x11rb::NONE, 2667 + x11rb::NONE,
1887 - x11rb::NONE, 2668 + x11rb::NONE,
1888 - x11rb::CURRENT_TIME, 2669 + x11rb::CURRENT_TIME,
1889 - )? 2670 + )?.reply()?;
1890 - .reply()?;
1891 2671
1892 - self.connection.configure_window( 2672 + let mut last_time = 0u32;
1893 - window,
1894 - &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
1895 - )?;
1896 2673
1897 loop { 2674 loop {
1898 let event = self.connection.wait_for_event()?; 2675 let event = self.connection.wait_for_event()?;
1899 match event { 2676 match event {
2677 + Event::ConfigureRequest(_) | Event::MapRequest(_) | Event::Expose(_) => {}
1900 Event::MotionNotify(e) => { 2678 Event::MotionNotify(e) => {
1901 - let new_width = (e.root_x - geometry.x).max(1) as u32; 2679 + if e.time.wrapping_sub(last_time) <= 16 {
1902 - let new_height = (e.root_y - geometry.y).max(1) as u32; 2680 + continue;
2681 + }
2682 + last_time = e.time;
2683 +
2684 + let new_width = ((e.root_x as i32 - orig_x as i32 - 2 * border_width as i32 + 1).max(1)) as u32;
2685 + let new_height = ((e.root_y as i32 - orig_y as i32 - 2 * border_width as i32 + 1).max(1)) as u32;
2686 +
2687 + let in_monitor_bounds =
2688 + monitor.window_area_x + new_width as i32 >= monitor.window_area_x &&
2689 + monitor.window_area_x + new_width as i32 <= monitor.window_area_x + monitor.window_area_width &&
2690 + monitor.window_area_y + new_height as i32 >= monitor.window_area_y &&
2691 + monitor.window_area_y + new_height as i32 <= monitor.window_area_y + monitor.window_area_height;
2692 +
2693 + if in_monitor_bounds {
2694 + if !was_floating && !is_normie &&
2695 + ((new_width as i32 - orig_width as i32).abs() > snap ||
2696 + (new_height as i32 - orig_height as i32).abs() > snap) {
2697 + self.toggle_floating()?;
2698 + }
2699 + }
1903 2700
1904 - self.connection.configure_window( 2701 + let should_resize = is_normie || self.clients
1905 - window, 2702 + .get(&window)
1906 - &ConfigureWindowAux::new() 2703 + .map(|c| c.is_floating)
1907 - .width(new_width) 2704 + .unwrap_or(false);
1908 - .height(new_height), 2705 +
1909 - )?; 2706 + if should_resize {
1910 - self.connection.flush()?; 2707 + if let Some(client) = self.clients.get(&window) {
2708 + let (hint_width, hint_height) = self.apply_size_hints(
2709 + client,
2710 + new_width as i32,
2711 + new_height as i32,
2712 + );
2713 +
2714 + if let Some(client_mut) = self.clients.get_mut(&window) {
2715 + client_mut.width = hint_width as u16;
2716 + client_mut.height = hint_height as u16;
2717 + }
2718 +
2719 + self.connection.configure_window(
2720 + window,
2721 + &ConfigureWindowAux::new()
2722 + .width(hint_width as u32)
2723 + .height(hint_height as u32),
2724 + )?;
2725 + self.connection.flush()?;
2726 + }
2727 + }
1911 } 2728 }
1912 Event::ButtonRelease(_) => break, 2729 Event::ButtonRelease(_) => break,
1913 _ => {} 2730 _ => {}
1914 } 2731 }
1915 } 2732 }
1916 2733
1917 - self.connection 2734 + let final_client = self.clients.get(&window).map(|c| {
1918 - .ungrab_pointer(x11rb::CURRENT_TIME)? 2735 + (c.width, c.border_width)
1919 - .check()?; 2736 + });
1920 - self.connection 2737 +
1921 - .allow_events(Allow::REPLAY_POINTER, x11rb::CURRENT_TIME)? 2738 + if let Some((w, bw)) = final_client {
1922 - .check()?; 2739 + self.connection.warp_pointer(
2740 + x11rb::NONE,
2741 + window,
2742 + 0,
2743 + 0,
2744 + 0,
2745 + 0,
2746 + (w + bw - 1) as i16,
2747 + (w + bw - 1) as i16,
2748 + )?;
2749 + }
2750 +
2751 + self.connection.ungrab_pointer(x11rb::CURRENT_TIME)?.check()?;
2752 +
2753 + let final_client_pos = self.clients.get(&window).map(|c| {
2754 + (c.x_position, c.y_position, c.width, c.height)
2755 + });
2756 +
2757 + if let Some((x, y, w, h)) = final_client_pos {
2758 + let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32);
2759 + if new_monitor != monitor_idx {
2760 + self.move_window_to_monitor(window, new_monitor)?;
2761 + self.selected_monitor = new_monitor;
2762 + self.focus(None)?;
2763 + }
2764 + }
1923 2765
1924 Ok(()) 2766 Ok(())
1925 } 2767 }
@@ -2000,88 +2842,8 @@ impl WindowManager {
2000 return Ok(None); 2842 return Ok(None);
2001 } 2843 }
2002 2844
2003 - if self.windows.contains(&event.window) { 2845 + if !self.windows.contains(&event.window) {
2004 - return Ok(None); 2846 + self.manage_window(event.window)?;
2005 - }
2006 -
2007 - self.connection.map_window(event.window)?;
2008 - self.connection.change_window_attributes(
2009 - event.window,
2010 - &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE),
2011 - )?;
2012 -
2013 - let selected_tags = self
2014 - .monitors
2015 - .get(self.selected_monitor)
2016 - .map(|m| m.selected_tags)
2017 - .unwrap_or(tag_mask(0));
2018 -
2019 - self.windows.push(event.window);
2020 - self.window_tags.insert(event.window, selected_tags);
2021 - self.window_monitor
2022 - .insert(event.window, self.selected_monitor);
2023 - self.set_wm_state(event.window, 1)?;
2024 - if let Err(error) = self.save_client_tag(event.window, selected_tags) {
2025 - eprintln!("Failed to save client tag for new window: {:?}", error);
2026 - }
2027 -
2028 - let is_transient = self.is_transient_window(event.window);
2029 - if is_transient {
2030 - self.floating_windows.insert(event.window);
2031 - }
2032 -
2033 - let is_normie_layout = self.layout.name() == "normie";
2034 - if is_normie_layout && !is_transient {
2035 - let mut pointer_x: i32 = 0;
2036 - let mut pointer_y: i32 = 0;
2037 - let mut root_return: x11::xlib::Window = 0;
2038 - let mut child_return: x11::xlib::Window = 0;
2039 - let mut win_x: i32 = 0;
2040 - let mut win_y: i32 = 0;
2041 - let mut mask_return: u32 = 0;
2042 -
2043 - let pointer_queried = unsafe {
2044 - x11::xlib::XQueryPointer(
2045 - self.display,
2046 - self.root as x11::xlib::Window,
2047 - &mut root_return,
2048 - &mut child_return,
2049 - &mut pointer_x,
2050 - &mut pointer_y,
2051 - &mut win_x,
2052 - &mut win_y,
2053 - &mut mask_return,
2054 - ) != 0
2055 - };
2056 -
2057 - if pointer_queried {
2058 - let window_width = (self.screen.width_in_pixels as f32 * 0.6) as u32;
2059 - let window_height = (self.screen.height_in_pixels as f32 * 0.6) as u32;
2060 -
2061 - let spawn_x = pointer_x - (window_width as i32 / 2);
2062 - let spawn_y = pointer_y - (window_height as i32 / 2);
2063 -
2064 - self.connection.configure_window(
2065 - event.window,
2066 - &ConfigureWindowAux::new()
2067 - .x(spawn_x)
2068 - .y(spawn_y)
2069 - .width(window_width)
2070 - .height(window_height)
2071 - .border_width(self.config.border_width)
2072 - .stack_mode(StackMode::ABOVE),
2073 - )?;
2074 -
2075 - self.floating_windows.insert(event.window);
2076 - }
2077 - }
2078 -
2079 - self.apply_layout()?;
2080 - self.update_bar()?;
2081 - self.set_focus(event.window)?;
2082 -
2083 - if self.layout.name() == "tabbed" {
2084 - self.update_tab_bars()?;
2085 } 2847 }
2086 } 2848 }
2087 Event::UnmapNotify(event) => { 2849 Event::UnmapNotify(event) => {
@@ -2094,12 +2856,65 @@ impl WindowManager {
2094 self.remove_window(event.window)?; 2856 self.remove_window(event.window)?;
2095 } 2857 }
2096 } 2858 }
2859 + Event::PropertyNotify(event) => {
2860 + if event.state == x11rb::protocol::xproto::Property::DELETE {
2861 + return Ok(None);
2862 + }
2863 +
2864 + if !self.clients.contains_key(&event.window) {
2865 + return Ok(None);
2866 + }
2867 +
2868 + if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() {
2869 + let is_floating = self.clients
2870 + .get(&event.window)
2871 + .map(|c| c.is_floating)
2872 + .unwrap_or(false);
2873 +
2874 + if !is_floating {
2875 + if let Some(transient_parent) = self.get_transient_parent(event.window) {
2876 + if self.clients.contains_key(&transient_parent) {
2877 + if let Some(client) = self.clients.get_mut(&event.window) {
2878 + client.is_floating = true;
2879 + }
2880 + self.floating_windows.insert(event.window);
2881 + self.apply_layout()?;
2882 + }
2883 + }
2884 + }
2885 + } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() {
2886 + if let Some(client) = self.clients.get_mut(&event.window) {
2887 + client.hints_valid = false;
2888 + }
2889 + } else if event.atom == AtomEnum::WM_HINTS.into() {
2890 + self.update_window_hints(event.window)?;
2891 + self.update_bar()?;
2892 + }
2893 +
2894 + if event.atom == self.atoms.wm_name || event.atom == self.atoms.net_wm_name {
2895 + let _ = self.update_window_title(event.window);
2896 + if self.layout.name() == "tabbed" {
2897 + self.update_tab_bars()?;
2898 + }
2899 + }
2900 +
2901 + if event.atom == self.atoms.net_wm_window_type {
2902 + self.update_window_type(event.window)?;
2903 + }
2904 + }
2097 Event::EnterNotify(event) => { 2905 Event::EnterNotify(event) => {
2098 if event.mode != x11rb::protocol::xproto::NotifyMode::NORMAL { 2906 if event.mode != x11rb::protocol::xproto::NotifyMode::NORMAL {
2099 return Ok(None); 2907 return Ok(None);
2100 } 2908 }
2101 if self.windows.contains(&event.event) { 2909 if self.windows.contains(&event.event) {
2102 - self.set_focus(event.event)?; 2910 + if let Some(client) = self.clients.get(&event.event) {
2911 + if client.monitor_index != self.selected_monitor {
2912 + self.selected_monitor = client.monitor_index;
2913 + self.update_bar()?;
2914 + }
2915 + }
2916 + self.focus(Some(event.event))?;
2917 + self.update_tab_bars()?;
2103 } 2918 }
2104 } 2919 }
2105 Event::MotionNotify(event) => { 2920 Event::MotionNotify(event) => {
@@ -2116,7 +2931,8 @@ impl WindowManager {
2116 2931
2117 let visible = self.visible_windows_on_monitor(monitor_index); 2932 let visible = self.visible_windows_on_monitor(monitor_index);
2118 if let Some(&win) = visible.first() { 2933 if let Some(&win) = visible.first() {
2119 - self.set_focus(win)?; 2934 + self.focus(Some(win))?;
2935 + self.update_tab_bars()?;
2120 } 2936 }
2121 } 2937 }
2122 } 2938 }
@@ -2150,12 +2966,17 @@ impl WindowManager {
2150 Err(err) => { 2966 Err(err) => {
2151 eprintln!("Config reload error: {}", err); 2967 eprintln!("Config reload error: {}", err);
2152 self.error_message = Some(err.clone()); 2968 self.error_message = Some(err.clone());
2153 - let screen_width = self.screen.width_in_pixels; 2969 + let monitor = &self.monitors[self.selected_monitor];
2154 - let screen_height = self.screen.height_in_pixels; 2970 + let monitor_x = monitor.screen_x as i16;
2971 + let monitor_y = monitor.screen_y as i16;
2972 + let screen_width = monitor.screen_width as u16;
2973 + let screen_height = monitor.screen_height as u16;
2155 match self.overlay.show_error( 2974 match self.overlay.show_error(
2156 &self.connection, 2975 &self.connection,
2157 &self.font, 2976 &self.font,
2158 &err, 2977 &err,
2978 + monitor_x,
2979 + monitor_y,
2159 screen_width, 2980 screen_width,
2160 screen_height, 2981 screen_height,
2161 ) { 2982 ) {
@@ -2217,25 +3038,24 @@ impl WindowManager {
2217 self.selected_monitor = monitor_index; 3038 self.selected_monitor = monitor_index;
2218 } 3039 }
2219 3040
2220 - let visible_windows: Vec<Window> = self 3041 + let visible_windows: Vec<(Window, String)> = self
2221 .windows 3042 .windows
2222 .iter() 3043 .iter()
2223 - .filter(|&&window| { 3044 + .filter_map(|&window| {
2224 - let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); 3045 + if let Some(client) = self.clients.get(&window) {
2225 - if window_monitor_index != monitor_index 3046 + if client.monitor_index != monitor_index
2226 - || self.floating_windows.contains(&window) 3047 + || self.floating_windows.contains(&window)
2227 - || self.fullscreen_windows.contains(&window) 3048 + || self.fullscreen_windows.contains(&window)
2228 - { 3049 + {
2229 - return false; 3050 + return None;
2230 - } 3051 + }
2231 - let monitor_tags = self.monitors.get(monitor_index).map(|m| m.selected_tags).unwrap_or(0); 3052 + let monitor_tags = self.monitors.get(monitor_index).map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0);
2232 - if let Some(&tags) = self.window_tags.get(&window) { 3053 + if (client.tags & monitor_tags) != 0 {
2233 - (tags & monitor_tags) != 0 3054 + return Some((window, client.name.clone()));
2234 - } else { 3055 + }
2235 - false
2236 } 3056 }
3057 + None
2237 }) 3058 })
2238 - .copied()
2239 .collect(); 3059 .collect();
2240 3060
2241 if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) { 3061 if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) {
@@ -2243,16 +3063,17 @@ impl WindowManager {
2243 clicked_window, 3063 clicked_window,
2244 &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), 3064 &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
2245 )?; 3065 )?;
2246 - self.set_focus(clicked_window)?; 3066 + self.focus(Some(clicked_window))?;
2247 self.update_tab_bars()?; 3067 self.update_tab_bars()?;
2248 } 3068 }
2249 } else if event.child != x11rb::NONE { 3069 } else if event.child != x11rb::NONE {
2250 - self.set_focus(event.child)?; 3070 + self.focus(Some(event.child))?;
3071 + self.update_tab_bars()?;
2251 3072
2252 if event.detail == ButtonIndex::M1.into() { 3073 if event.detail == ButtonIndex::M1.into() {
2253 - self.move_mouse(event.child)?; 3074 + self.drag_window(event.child)?;
2254 } else if event.detail == ButtonIndex::M3.into() { 3075 } else if event.detail == ButtonIndex::M3.into() {
2255 - self.resize_mouse(event.child)?; 3076 + self.resize_window_with_mouse(event.child)?;
2256 } 3077 }
2257 } 3078 }
2258 } 3079 }
@@ -2264,15 +3085,137 @@ impl WindowManager {
2264 self.update_bar()?; 3085 self.update_bar()?;
2265 break; 3086 break;
2266 } 3087 }
2267 - } 3088 + }
2268 - for _tab_bar in &self.tab_bars { 3089 + for _tab_bar in &self.tab_bars {
2269 - if event.window == _tab_bar.window() { 3090 + if event.window == _tab_bar.window() {
2270 - self.update_tab_bars()?; 3091 + self.update_tab_bars()?;
2271 - break; 3092 + break;
3093 + }
3094 + }
3095 + }
3096 + Event::ConfigureRequest(event) => {
3097 + if self.windows.contains(&event.window) {
3098 + let monitor_index = self.clients.get(&event.window)
3099 + .map(|c| c.monitor_index)
3100 + .unwrap_or(self.selected_monitor);
3101 + let monitor = &self.monitors[monitor_index];
3102 + let is_floating = self.floating_windows.contains(&event.window);
3103 + let is_tiling_layout = self.layout.name() != "normie";
3104 +
3105 + if is_floating || !is_tiling_layout {
3106 + let cached_geom = self.window_geometry_cache.get(&event.window);
3107 + let border_width = self.config.border_width as u16;
3108 +
3109 + let mut config = ConfigureWindowAux::new();
3110 + let value_mask = event.value_mask;
3111 +
3112 + if value_mask.contains(ConfigWindow::BORDER_WIDTH) {
3113 + config = config.border_width(event.border_width as u32);
3114 + }
3115 +
3116 + if value_mask.contains(ConfigWindow::X) {
3117 + let mut x = event.x as i32;
3118 + x = x.max(monitor.screen_x);
3119 + if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 {
3120 + x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32;
3121 + }
3122 + config = config.x(x);
3123 + }
3124 +
3125 + if value_mask.contains(ConfigWindow::Y) {
3126 + let mut y = event.y as i32;
3127 + y = y.max(monitor.screen_y);
3128 + if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 {
3129 + y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32;
3130 + }
3131 + config = config.y(y);
3132 + }
3133 +
3134 + if value_mask.contains(ConfigWindow::WIDTH) {
3135 + config = config.width(event.width as u32);
3136 + }
3137 +
3138 + if value_mask.contains(ConfigWindow::HEIGHT) {
3139 + config = config.height(event.height as u32);
3140 + }
3141 +
3142 + if value_mask.contains(ConfigWindow::SIBLING) {
3143 + config = config.sibling(event.sibling);
3144 + }
3145 +
3146 + if value_mask.contains(ConfigWindow::STACK_MODE) {
3147 + config = config.stack_mode(event.stack_mode);
3148 + }
3149 +
3150 + self.connection.configure_window(event.window, &config)?;
3151 +
3152 + let final_x = if value_mask.contains(ConfigWindow::X) {
3153 + let mut x = event.x as i32;
3154 + x = x.max(monitor.screen_x);
3155 + if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 {
3156 + x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32;
3157 + }
3158 + x as i16
3159 + } else {
3160 + cached_geom.map(|g| g.x_position).unwrap_or(0)
3161 + };
3162 +
3163 + let final_y = if value_mask.contains(ConfigWindow::Y) {
3164 + let mut y = event.y as i32;
3165 + y = y.max(monitor.screen_y);
3166 + if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 {
3167 + y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32;
3168 + }
3169 + y as i16
3170 + } else {
3171 + cached_geom.map(|g| g.y_position).unwrap_or(0)
3172 + };
3173 +
3174 + let final_width = if value_mask.contains(ConfigWindow::WIDTH) { event.width } else { cached_geom.map(|g| g.width).unwrap_or(1) };
3175 + let final_height = if value_mask.contains(ConfigWindow::HEIGHT) { event.height } else { cached_geom.map(|g| g.height).unwrap_or(1) };
3176 +
3177 + self.update_geometry_cache(event.window, CachedGeometry {
3178 + x_position: final_x,
3179 + y_position: final_y,
3180 + width: final_width,
3181 + height: final_height,
3182 + border_width: if value_mask.contains(ConfigWindow::BORDER_WIDTH) { event.border_width } else { border_width },
3183 + });
3184 +
3185 + if is_floating {
3186 + let new_monitor = self.get_monitor_for_rect(final_x as i32, final_y as i32, final_width as i32, final_height as i32);
3187 +
3188 + if new_monitor != monitor_index {
3189 + self.move_window_to_monitor(event.window, new_monitor)?;
3190 + }
3191 + }
3192 + } else {
3193 + self.send_configure_notify(event.window)?;
3194 + }
3195 + } else {
3196 + let mut config = ConfigureWindowAux::new()
3197 + .x(event.x as i32)
3198 + .y(event.y as i32)
3199 + .width(event.width as u32)
3200 + .height(event.height as u32)
3201 + .border_width(event.border_width as u32);
3202 +
3203 + if event.value_mask.contains(ConfigWindow::SIBLING) {
3204 + config = config.sibling(event.sibling);
3205 + }
3206 +
3207 + if event.value_mask.contains(ConfigWindow::STACK_MODE) {
3208 + config = config.stack_mode(event.stack_mode);
2272 } 3209 }
3210 +
3211 + self.connection.configure_window(event.window, &config)?;
2273 } 3212 }
2274 } 3213 }
2275 Event::ClientMessage(event) => { 3214 Event::ClientMessage(event) => {
3215 + if !self.clients.contains_key(&event.window) {
3216 + return Ok(None);
3217 + }
3218 +
2276 if event.type_ == self.atoms.net_wm_state { 3219 if event.type_ == self.atoms.net_wm_state {
2277 if let Some(data) = event.data.as_data32().get(1) { 3220 if let Some(data) = event.data.as_data32().get(1) {
2278 if *data == self.atoms.net_wm_state_fullscreen { 3221 if *data == self.atoms.net_wm_state_fullscreen {
@@ -2286,6 +3229,46 @@ impl WindowManager {
2286 self.set_window_fullscreen(event.window, fullscreen)?; 3229 self.set_window_fullscreen(event.window, fullscreen)?;
2287 } 3230 }
2288 } 3231 }
3232 + } else if event.type_ == self.atoms.net_active_window {
3233 + let selected_window = self.monitors
3234 + .get(self.selected_monitor)
3235 + .and_then(|m| m.selected_client);
3236 +
3237 + let is_urgent = self.clients
3238 + .get(&event.window)
3239 + .map(|c| c.is_urgent)
3240 + .unwrap_or(false);
3241 +
3242 + if Some(event.window) != selected_window && !is_urgent {
3243 + self.set_urgent(event.window, true)?;
3244 + }
3245 + }
3246 + }
3247 + Event::FocusIn(event) => {
3248 + let selected_window = self.monitors
3249 + .get(self.selected_monitor)
3250 + .and_then(|m| m.selected_client);
3251 +
3252 + if let Some(sel_win) = selected_window {
3253 + if event.event != sel_win {
3254 + self.set_focus(sel_win)?;
3255 + }
3256 + }
3257 + }
3258 + Event::MappingNotify(event) => {
3259 + if event.request == x11rb::protocol::xproto::Mapping::KEYBOARD {
3260 + keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?;
3261 + }
3262 + }
3263 + Event::ConfigureNotify(event) => {
3264 + if event.window == self.root {
3265 + let old_width = self.screen.width_in_pixels;
3266 + let old_height = self.screen.height_in_pixels;
3267 +
3268 + if event.width != old_width || event.height != old_height {
3269 + self.screen = self.connection.setup().roots[self.screen_number].clone();
3270 + self.apply_layout()?;
3271 + }
2289 } 3272 }
2290 } 3273 }
2291 _ => {} 3274 _ => {}
@@ -2294,12 +3277,11 @@ impl WindowManager {
2294 } 3277 }
2295 3278
2296 fn apply_layout(&mut self) -> WmResult<()> { 3279 fn apply_layout(&mut self) -> WmResult<()> {
2297 - if self.layout.name() == LayoutType::Normie.as_str() { 3280 + let is_normie = self.layout.name() == LayoutType::Normie.as_str();
2298 - return Ok(());
2299 - }
2300 3281
2301 - let monitor_count = self.monitors.len(); 3282 + if !is_normie {
2302 - for monitor_index in 0..monitor_count { 3283 + let monitor_count = self.monitors.len();
3284 + for monitor_index in 0..monitor_count {
2303 let monitor = &self.monitors[monitor_index]; 3285 let monitor = &self.monitors[monitor_index];
2304 let border_width = self.config.border_width; 3286 let border_width = self.config.border_width;
2305 3287
@@ -2319,31 +3301,21 @@ impl WindowManager {
2319 } 3301 }
2320 }; 3302 };
2321 3303
2322 - let monitor_selected_tags = monitor.selected_tags; 3304 + let monitor_x = monitor.screen_x;
2323 - let monitor_x = monitor.x; 3305 + let monitor_y = monitor.screen_y;
2324 - let monitor_y = monitor.y; 3306 + let monitor_width = monitor.screen_width;
2325 - let monitor_width = monitor.width; 3307 + let monitor_height = monitor.screen_height;
2326 - let monitor_height = monitor.height; 3308 +
2327 - 3309 + let mut visible: Vec<Window> = Vec::new();
2328 - let visible: Vec<Window> = self 3310 + let mut current = self.next_tiled(monitor.clients_head, monitor);
2329 - .windows 3311 + while let Some(window) = current {
2330 - .iter() 3312 + visible.push(window);
2331 - .filter(|&&window| { 3313 + if let Some(client) = self.clients.get(&window) {
2332 - let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); 3314 + current = self.next_tiled(client.next, monitor);
2333 - if window_monitor_index != monitor_index 3315 + } else {
2334 - || self.floating_windows.contains(&window) 3316 + break;
2335 - || self.fullscreen_windows.contains(&window) 3317 + }
2336 - { 3318 + }
2337 - return false;
2338 - }
2339 - if let Some(&tags) = self.window_tags.get(&window) {
2340 - (tags & monitor_selected_tags) != 0
2341 - } else {
2342 - false
2343 - }
2344 - })
2345 - .copied()
2346 - .collect();
2347 3319
2348 let bar_height = if self.show_bar { 3320 let bar_height = if self.show_bar {
2349 self.bars 3321 self.bars
@@ -2353,19 +3325,47 @@ impl WindowManager {
2353 } else { 3325 } else {
2354 0 3326 0
2355 }; 3327 };
2356 - let usable_height = monitor_height.saturating_sub(bar_height); 3328 + let usable_height = monitor_height.saturating_sub(bar_height as i32);
2357 - 3329 + let master_factor = monitor.master_factor;
2358 - let geometries = self 3330 + let num_master = monitor.num_master;
2359 - .layout 3331 + let smartgaps_enabled = self.config.smartgaps_enabled;
2360 - .arrange(&visible, monitor_width, usable_height, &gaps); 3332 +
3333 + let geometries = self.layout.arrange(
3334 + &visible,
3335 + monitor_width as u32,
3336 + usable_height as u32,
3337 + &gaps,
3338 + master_factor,
3339 + num_master,
3340 + smartgaps_enabled,
3341 + );
2361 3342
2362 for (window, geometry) in visible.iter().zip(geometries.iter()) { 3343 for (window, geometry) in visible.iter().zip(geometries.iter()) {
2363 - let adjusted_width = geometry.width.saturating_sub(2 * border_width); 3344 + let mut adjusted_width = geometry.width.saturating_sub(2 * border_width);
2364 - let adjusted_height = geometry.height.saturating_sub(2 * border_width); 3345 + let mut adjusted_height = geometry.height.saturating_sub(2 * border_width);
3346 +
3347 + if let Some(client) = self.clients.get(window) {
3348 + if !client.is_floating {
3349 + let (hint_width, hint_height) = self.apply_size_hints(
3350 + client,
3351 + adjusted_width as i32,
3352 + adjusted_height as i32,
3353 + );
3354 + adjusted_width = hint_width as u32;
3355 + adjusted_height = hint_height as u32;
3356 + }
3357 + }
2365 3358
2366 let adjusted_x = geometry.x_coordinate + monitor_x; 3359 let adjusted_x = geometry.x_coordinate + monitor_x;
2367 let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32; 3360 let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32;
2368 3361
3362 + if let Some(client) = self.clients.get_mut(window) {
3363 + client.x_position = adjusted_x as i16;
3364 + client.y_position = adjusted_y as i16;
3365 + client.width = adjusted_width as u16;
3366 + client.height = adjusted_height as u16;
3367 + }
3368 +
2369 self.connection.configure_window( 3369 self.connection.configure_window(
2370 *window, 3370 *window,
2371 &ConfigureWindowAux::new() 3371 &ConfigureWindowAux::new()
@@ -2384,6 +3384,12 @@ impl WindowManager {
2384 border_width: border_width as u16, 3384 border_width: border_width as u16,
2385 }); 3385 });
2386 } 3386 }
3387 + }
3388 + }
3389 +
3390 + for monitor_index in 0..self.monitors.len() {
3391 + let stack_head = self.monitors[monitor_index].stack_head;
3392 + self.showhide(stack_head)?;
2387 } 3393 }
2388 3394
2389 self.connection.flush()?; 3395 self.connection.flush()?;
@@ -2413,9 +3419,9 @@ impl WindowManager {
2413 0.0 3419 0.0
2414 }; 3420 };
2415 3421
2416 - let tab_bar_x = (monitor.x + outer_horizontal as i32) as i16; 3422 + let tab_bar_x = (monitor.screen_x + outer_horizontal as i32) as i16;
2417 - let tab_bar_y = (monitor.y as f32 + bar_height + outer_vertical as f32) as i16; 3423 + let tab_bar_y = (monitor.screen_y as f32 + bar_height + outer_vertical as f32) as i16;
2418 - let tab_bar_width = monitor.width.saturating_sub(2 * outer_horizontal) as u16; 3424 + let tab_bar_width = monitor.screen_width.saturating_sub(2 * outer_horizontal as i32) as u16;
2419 3425
2420 if let Err(e) = self.tab_bars[monitor_index].reposition( 3426 if let Err(e) = self.tab_bars[monitor_index].reposition(
2421 &self.connection, 3427 &self.connection,
@@ -2434,16 +3440,15 @@ impl WindowManager {
2434 .windows 3440 .windows
2435 .iter() 3441 .iter()
2436 .any(|&window| { 3442 .any(|&window| {
2437 - let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); 3443 + if let Some(client) = self.clients.get(&window) {
2438 - if window_monitor_index != monitor_index 3444 + if client.monitor_index != monitor_index
2439 - || self.floating_windows.contains(&window) 3445 + || self.floating_windows.contains(&window)
2440 - || self.fullscreen_windows.contains(&window) 3446 + || self.fullscreen_windows.contains(&window)
2441 - { 3447 + {
2442 - return false; 3448 + return false;
2443 - } 3449 + }
2444 - if let Some(monitor) = self.monitors.get(monitor_index) { 3450 + if let Some(monitor) = self.monitors.get(monitor_index) {
2445 - if let Some(&tags) = self.window_tags.get(&window) { 3451 + return (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0;
2446 - return (tags & monitor.selected_tags) != 0;
2447 } 3452 }
2448 } 3453 }
2449 false 3454 false
@@ -2498,26 +3503,484 @@ impl WindowManager {
2498 Ok(cached) 3503 Ok(cached)
2499 } 3504 }
2500 3505
3506 + fn send_configure_notify(&mut self, window: Window) -> WmResult<()> {
3507 + let geometry = self.get_or_query_geometry(window)?;
3508 +
3509 + let event = x11rb::protocol::xproto::ConfigureNotifyEvent {
3510 + response_type: x11rb::protocol::xproto::CONFIGURE_NOTIFY_EVENT,
3511 + sequence: 0,
3512 + event: window,
3513 + window,
3514 + above_sibling: x11rb::NONE,
3515 + x: geometry.x_position,
3516 + y: geometry.y_position,
3517 + width: geometry.width,
3518 + height: geometry.height,
3519 + border_width: geometry.border_width,
3520 + override_redirect: false,
3521 + };
3522 +
3523 + self.connection.send_event(
3524 + false,
3525 + window,
3526 + x11rb::protocol::xproto::EventMask::STRUCTURE_NOTIFY,
3527 + event,
3528 + )?;
3529 +
3530 + Ok(())
3531 + }
3532 +
3533 + fn update_size_hints(&mut self, window: Window) -> WmResult<()> {
3534 + let size_hints = self.connection
3535 + .get_property(
3536 + false,
3537 + window,
3538 + x11rb::protocol::xproto::AtomEnum::WM_NORMAL_HINTS,
3539 + x11rb::protocol::xproto::AtomEnum::WM_SIZE_HINTS,
3540 + 0,
3541 + 18,
3542 + )?
3543 + .reply()?;
3544 +
3545 + if size_hints.value.is_empty() {
3546 + if let Some(client) = self.clients.get_mut(&window) {
3547 + client.hints_valid = false;
3548 + }
3549 + return Ok(());
3550 + }
3551 +
3552 + if size_hints.value.len() < 18 * 4 {
3553 + if let Some(client) = self.clients.get_mut(&window) {
3554 + client.hints_valid = false;
3555 + }
3556 + return Ok(());
3557 + }
3558 +
3559 + let read_u32 = |offset: usize| -> u32 {
3560 + let bytes = &size_hints.value[offset * 4..(offset + 1) * 4];
3561 + u32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])
3562 + };
3563 +
3564 + let flags = read_u32(0);
3565 +
3566 + const P_SIZE: u32 = 1 << 3;
3567 + const P_MIN_SIZE: u32 = 1 << 4;
3568 + const P_MAX_SIZE: u32 = 1 << 5;
3569 + const P_RESIZE_INC: u32 = 1 << 6;
3570 + const P_ASPECT: u32 = 1 << 7;
3571 + const P_BASE_SIZE: u32 = 1 << 8;
3572 +
3573 + if let Some(client) = self.clients.get_mut(&window) {
3574 + if flags & P_BASE_SIZE != 0 {
3575 + client.base_width = read_u32(8) as i32;
3576 + client.base_height = read_u32(9) as i32;
3577 + } else if flags & P_MIN_SIZE != 0 {
3578 + client.base_width = read_u32(5) as i32;
3579 + client.base_height = read_u32(6) as i32;
3580 + } else {
3581 + client.base_width = 0;
3582 + client.base_height = 0;
3583 + }
3584 +
3585 + if flags & P_RESIZE_INC != 0 {
3586 + client.increment_width = read_u32(10) as i32;
3587 + client.increment_height = read_u32(11) as i32;
3588 + } else {
3589 + client.increment_width = 0;
3590 + client.increment_height = 0;
3591 + }
3592 +
3593 + if flags & P_MAX_SIZE != 0 {
3594 + client.max_width = read_u32(7) as i32;
3595 + client.max_height = read_u32(8) as i32;
3596 + } else {
3597 + client.max_width = 0;
3598 + client.max_height = 0;
3599 + }
3600 +
3601 + if flags & P_MIN_SIZE != 0 {
3602 + client.min_width = read_u32(5) as i32;
3603 + client.min_height = read_u32(6) as i32;
3604 + } else if flags & P_SIZE != 0 {
3605 + client.min_width = read_u32(3) as i32;
3606 + client.min_height = read_u32(4) as i32;
3607 + } else {
3608 + client.min_width = 0;
3609 + client.min_height = 0;
3610 + }
3611 +
3612 + if flags & P_ASPECT != 0 {
3613 + client.min_aspect = (read_u32(12) as f32) / (read_u32(13) as f32).max(1.0);
3614 + client.max_aspect = (read_u32(14) as f32) / (read_u32(15) as f32).max(1.0);
3615 + } else {
3616 + client.min_aspect = 0.0;
3617 + client.max_aspect = 0.0;
3618 + }
3619 +
3620 + client.is_fixed = client.max_width > 0
3621 + && client.max_height > 0
3622 + && client.max_width == client.min_width
3623 + && client.max_height == client.min_height;
3624 +
3625 + client.hints_valid = true;
3626 + }
3627 + Ok(())
3628 + }
3629 +
3630 + fn update_window_title(&mut self, window: Window) -> WmResult<()> {
3631 + let net_name = self.connection
3632 + .get_property(
3633 + false,
3634 + window,
3635 + self.atoms.net_wm_name,
3636 + self.atoms.utf8_string,
3637 + 0,
3638 + 256,
3639 + )
3640 + .ok()
3641 + .and_then(|cookie| cookie.reply().ok());
3642 +
3643 + if let Some(name) = net_name {
3644 + if !name.value.is_empty() {
3645 + if let Ok(title) = String::from_utf8(name.value.clone()) {
3646 + if let Some(client) = self.clients.get_mut(&window) {
3647 + client.name = title;
3648 + return Ok(());
3649 + }
3650 + }
3651 + }
3652 + }
3653 +
3654 + let wm_name = self.connection
3655 + .get_property(
3656 + false,
3657 + window,
3658 + self.atoms.wm_name,
3659 + x11rb::protocol::xproto::AtomEnum::STRING,
3660 + 0,
3661 + 256,
3662 + )?
3663 + .reply()?;
3664 +
3665 + if !wm_name.value.is_empty() {
3666 + if let Ok(title) = String::from_utf8(wm_name.value.clone()) {
3667 + if let Some(client) = self.clients.get_mut(&window) {
3668 + client.name = title;
3669 + }
3670 + }
3671 + }
3672 +
3673 + Ok(())
3674 + }
3675 +
3676 + fn update_window_hints(&mut self, window: Window) -> WmResult<()> {
3677 + let hints_reply = self.connection.get_property(
3678 + false,
3679 + window,
3680 + AtomEnum::WM_HINTS,
3681 + AtomEnum::WM_HINTS,
3682 + 0,
3683 + 9,
3684 + )?.reply();
3685 +
3686 + if let Ok(hints) = hints_reply {
3687 + if hints.value.len() >= 4 {
3688 + let flags = u32::from_ne_bytes([
3689 + hints.value[0],
3690 + hints.value[1],
3691 + hints.value[2],
3692 + hints.value[3],
3693 + ]);
3694 +
3695 + let selected_window = self.monitors
3696 + .get(self.selected_monitor)
3697 + .and_then(|m| m.selected_client);
3698 +
3699 + if Some(window) == selected_window && (flags & 256) != 0 {
3700 + let new_flags = flags & !256;
3701 + let mut new_hints = hints.value.clone();
3702 + new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes());
3703 +
3704 + self.connection.change_property(
3705 + x11rb::protocol::xproto::PropMode::REPLACE,
3706 + window,
3707 + AtomEnum::WM_HINTS,
3708 + AtomEnum::WM_HINTS,
3709 + 32,
3710 + 9,
3711 + &new_hints,
3712 + )?;
3713 + } else {
3714 + if let Some(client) = self.clients.get_mut(&window) {
3715 + client.is_urgent = (flags & 256) != 0;
3716 + }
3717 + }
3718 +
3719 + if hints.value.len() >= 8 && (flags & 1) != 0 {
3720 + let input = i32::from_ne_bytes([
3721 + hints.value[4],
3722 + hints.value[5],
3723 + hints.value[6],
3724 + hints.value[7],
3725 + ]);
3726 +
3727 + if let Some(client) = self.clients.get_mut(&window) {
3728 + client.never_focus = input == 0;
3729 + }
3730 + } else {
3731 + if let Some(client) = self.clients.get_mut(&window) {
3732 + client.never_focus = false;
3733 + }
3734 + }
3735 + }
3736 + }
3737 +
3738 + Ok(())
3739 + }
3740 +
3741 + fn update_window_type(&mut self, window: Window) -> WmResult<()> {
3742 + if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) {
3743 + if state_atom == self.atoms.net_wm_state_fullscreen {
3744 + self.set_window_fullscreen(window, true)?;
3745 + }
3746 + }
3747 +
3748 + if let Ok(Some(type_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_window_type) {
3749 + if type_atom == self.atoms.net_wm_window_type_dialog {
3750 + if let Some(client) = self.clients.get_mut(&window) {
3751 + client.is_floating = true;
3752 + }
3753 + self.floating_windows.insert(window);
3754 + }
3755 + }
3756 +
3757 + Ok(())
3758 + }
3759 +
3760 + fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) {
3761 + if !client.hints_valid {
3762 + return (width.max(1), height.max(1));
3763 + }
3764 +
3765 + if client.min_width > 0 {
3766 + width = width.max(client.min_width);
3767 + }
3768 + if client.min_height > 0 {
3769 + height = height.max(client.min_height);
3770 + }
3771 +
3772 + if client.max_width > 0 {
3773 + width = width.min(client.max_width);
3774 + }
3775 + if client.max_height > 0 {
3776 + height = height.min(client.max_height);
3777 + }
3778 +
3779 + if client.increment_width > 0 {
3780 + width -= client.base_width;
3781 + width -= width % client.increment_width;
3782 + width += client.base_width;
3783 + }
3784 + if client.increment_height > 0 {
3785 + height -= client.base_height;
3786 + height -= height % client.increment_height;
3787 + height += client.base_height;
3788 + }
3789 +
3790 + if client.min_aspect > 0.0 || client.max_aspect > 0.0 {
3791 + let actual_aspect = width as f32 / height as f32;
3792 +
3793 + if client.max_aspect > 0.0 && actual_aspect > client.max_aspect {
3794 + width = (height as f32 * client.max_aspect) as i32;
3795 + } else if client.min_aspect > 0.0 && actual_aspect < client.min_aspect {
3796 + height = (width as f32 / client.min_aspect) as i32;
3797 + }
3798 + }
3799 +
3800 + (width.max(1), height.max(1))
3801 + }
3802 +
3803 + fn next_tiled(&self, start: Option<Window>, monitor: &Monitor) -> Option<Window> {
3804 + let mut current = start;
3805 + while let Some(window) = current {
3806 + if let Some(client) = self.clients.get(&window) {
3807 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
3808 + if visible_tags != 0 && !client.is_floating {
3809 + return Some(window);
3810 + }
3811 + current = client.next;
3812 + } else {
3813 + break;
3814 + }
3815 + }
3816 + None
3817 + }
3818 +
3819 + fn next_tagged(&self, start: Option<Window>, tags: u32) -> Option<Window> {
3820 + let mut current = start;
3821 + while let Some(window) = current {
3822 + if let Some(client) = self.clients.get(&window) {
3823 + let visible_on_tags = (client.tags & tags) != 0;
3824 + if !client.is_floating && visible_on_tags {
3825 + return Some(window);
3826 + }
3827 + current = client.next;
3828 + } else {
3829 + break;
3830 + }
3831 + }
3832 + None
3833 + }
3834 +
3835 + fn attach(&mut self, window: Window, monitor_index: usize) {
3836 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3837 + if let Some(client) = self.clients.get_mut(&window) {
3838 + client.next = monitor.clients_head;
3839 + monitor.clients_head = Some(window);
3840 + }
3841 + }
3842 + }
3843 +
3844 + fn attach_aside(&mut self, window: Window, monitor_index: usize) {
3845 + let monitor = match self.monitors.get(monitor_index) {
3846 + Some(m) => m,
3847 + None => return,
3848 + };
3849 +
3850 + let new_window_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(0);
3851 + let first_tagged = self.next_tagged(monitor.clients_head, new_window_tags);
3852 +
3853 + if first_tagged.is_none() {
3854 + self.attach(window, monitor_index);
3855 + return;
3856 + }
3857 +
3858 + if let Some(insert_after_window) = first_tagged {
3859 + if let Some(after_client) = self.clients.get(&insert_after_window) {
3860 + let old_next = after_client.next;
3861 + if let Some(new_client) = self.clients.get_mut(&window) {
3862 + new_client.next = old_next;
3863 + }
3864 + if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) {
3865 + after_client_mut.next = Some(window);
3866 + }
3867 + }
3868 + }
3869 + }
3870 +
3871 + fn detach(&mut self, window: Window) {
3872 + let monitor_index = self.clients.get(&window).map(|c| c.monitor_index);
3873 + if let Some(monitor_index) = monitor_index {
3874 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3875 + if monitor.clients_head == Some(window) {
3876 + if let Some(client) = self.clients.get(&window) {
3877 + monitor.clients_head = client.next;
3878 + }
3879 + } else {
3880 + let mut current = monitor.clients_head;
3881 + while let Some(current_window) = current {
3882 + if let Some(current_client) = self.clients.get(&current_window) {
3883 + if current_client.next == Some(window) {
3884 + let new_next = self.clients.get(&window).and_then(|c| c.next);
3885 + if let Some(current_client_mut) = self.clients.get_mut(&current_window) {
3886 + current_client_mut.next = new_next;
3887 + }
3888 + break;
3889 + }
3890 + current = current_client.next;
3891 + } else {
3892 + break;
3893 + }
3894 + }
3895 + }
3896 + }
3897 + }
3898 + }
3899 +
3900 + fn attach_stack(&mut self, window: Window, monitor_index: usize) {
3901 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3902 + if let Some(client) = self.clients.get_mut(&window) {
3903 + client.stack_next = monitor.stack_head;
3904 + monitor.stack_head = Some(window);
3905 + }
3906 + }
3907 + }
3908 +
3909 + fn detach_stack(&mut self, window: Window) {
3910 + let monitor_index = self.clients.get(&window).map(|c| c.monitor_index);
3911 + if let Some(monitor_index) = monitor_index {
3912 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3913 + if monitor.stack_head == Some(window) {
3914 + if let Some(client) = self.clients.get(&window) {
3915 + monitor.stack_head = client.stack_next;
3916 + }
3917 + let should_update_selected = monitor.selected_client == Some(window);
3918 + let mut new_selected: Option<Window> = None;
3919 + if should_update_selected {
3920 + let mut stack_current = monitor.stack_head;
3921 + while let Some(stack_window) = stack_current {
3922 + if let Some(stack_client) = self.clients.get(&stack_window) {
3923 + if self.is_window_visible(stack_window) {
3924 + new_selected = Some(stack_window);
3925 + break;
3926 + }
3927 + stack_current = stack_client.stack_next;
3928 + } else {
3929 + break;
3930 + }
3931 + }
3932 + }
3933 + if should_update_selected {
3934 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3935 + monitor.selected_client = new_selected;
3936 + }
3937 + }
3938 + } else {
3939 + let mut current = monitor.stack_head;
3940 + while let Some(current_window) = current {
3941 + if let Some(current_client) = self.clients.get(&current_window) {
3942 + if current_client.stack_next == Some(window) {
3943 + let new_stack_next = self.clients.get(&window).and_then(|c| c.stack_next);
3944 + if let Some(current_client_mut) = self.clients.get_mut(&current_window) {
3945 + current_client_mut.stack_next = new_stack_next;
3946 + }
3947 + break;
3948 + }
3949 + current = current_client.stack_next;
3950 + } else {
3951 + break;
3952 + }
3953 + }
3954 + }
3955 + }
3956 + }
3957 + }
3958 +
2501 fn remove_window(&mut self, window: Window) -> WmResult<()> { 3959 fn remove_window(&mut self, window: Window) -> WmResult<()> {
2502 let initial_count = self.windows.len(); 3960 let initial_count = self.windows.len();
2503 3961
3962 + let focused = self
3963 + .monitors
3964 + .get(self.selected_monitor)
3965 + .and_then(|m| m.selected_client);
3966 +
3967 + if self.clients.contains_key(&window) {
3968 + self.detach(window);
3969 + self.detach_stack(window);
3970 + self.clients.remove(&window);
3971 + }
3972 +
2504 self.windows.retain(|&w| w != window); 3973 self.windows.retain(|&w| w != window);
2505 - self.window_tags.remove(&window);
2506 - self.window_monitor.remove(&window);
2507 self.window_geometry_cache.remove(&window); 3974 self.window_geometry_cache.remove(&window);
2508 self.floating_windows.remove(&window); 3975 self.floating_windows.remove(&window);
2509 3976
2510 if self.windows.len() < initial_count { 3977 if self.windows.len() < initial_count {
2511 - let focused = self
2512 - .monitors
2513 - .get(self.selected_monitor)
2514 - .and_then(|m| m.focused_window);
2515 if focused == Some(window) { 3978 if focused == Some(window) {
2516 let visible = self.visible_windows_on_monitor(self.selected_monitor); 3979 let visible = self.visible_windows_on_monitor(self.selected_monitor);
2517 if let Some(&new_win) = visible.last() { 3980 if let Some(&new_win) = visible.last() {
2518 - self.set_focus(new_win)?; 3981 + self.focus(Some(new_win))?;
2519 } else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { 3982 } else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
2520 - monitor.focused_window = None; 3983 + monitor.selected_client = None;
2521 } 3984 }
2522 } 3985 }
2523 3986
+109 −106 templates/config.lua
@@ -25,6 +25,9 @@ local modkey = "Mod4"
25 local terminal = "alacritty" 25 local terminal = "alacritty"
26 26
27 -- Color palette - customize these to match your theme 27 -- Color palette - customize these to match your theme
28 +-- Alternatively you can import other files in here, such as
29 +-- local colors = require("colors.lua") and make colors.lua a file
30 +-- in the ~/.config/oxwm directory
28 local colors = { 31 local colors = {
29 fg = "#bbbbbb", 32 fg = "#bbbbbb",
30 red = "#f7768e", 33 red = "#f7768e",
@@ -55,28 +58,24 @@ local blocks = {
55 underline = true, 58 underline = true,
56 }), 59 }),
57 oxwm.bar.block.static({ 60 oxwm.bar.block.static({
58 - format = "{}",
59 text = " │ ", 61 text = " │ ",
60 interval = 999999999, 62 interval = 999999999,
61 color = colors.lavender, 63 color = colors.lavender,
62 underline = false, 64 underline = false,
63 }), 65 }),
64 oxwm.bar.block.shell({ 66 oxwm.bar.block.shell({
65 - format = "Kernel: {}",
66 command = "uname -r", 67 command = "uname -r",
67 interval = 999999999, 68 interval = 999999999,
68 color = colors.red, 69 color = colors.red,
69 underline = true, 70 underline = true,
70 }), 71 }),
71 oxwm.bar.block.static({ 72 oxwm.bar.block.static({
72 - format = "{}",
73 text = " │ ", 73 text = " │ ",
74 interval = 999999999, 74 interval = 999999999,
75 color = colors.lavender, 75 color = colors.lavender,
76 underline = false, 76 underline = false,
77 }), 77 }),
78 oxwm.bar.block.datetime({ 78 oxwm.bar.block.datetime({
79 - format = "{}",
80 date_format = "%a, %b %d - %-I:%M %P", 79 date_format = "%a, %b %d - %-I:%M %P",
81 interval = 1, 80 interval = 1,
82 color = colors.cyan, 81 color = colors.cyan,
@@ -114,14 +113,40 @@ oxwm.set_layout_symbol("tabbed", "[=]")
114 -- Appearance 113 -- Appearance
115 ------------------------------------------------------------------------------- 114 -------------------------------------------------------------------------------
116 -- Border configuration 115 -- Border configuration
117 -oxwm.border.set_width(2) -- Width in pixels
118 -oxwm.border.set_focused_color(colors.blue) -- Color of focused window border
119 -oxwm.border.set_unfocused_color(colors.grey) -- Color of unfocused window borders
120 116
121 --- Gap configuration (space between windows and screen edges) 117 +-- Width in pixels
122 -oxwm.gaps.set_enabled(true) -- Enable or disable gaps 118 +oxwm.border.set_width(2)
123 -oxwm.gaps.set_inner(5, 5) -- Inner gaps (horizontal, vertical) in pixels 119 +-- Color of focused window border
124 -oxwm.gaps.set_outer(5, 5) -- Outer gaps (horizontal, vertical) in pixels 120 +oxwm.border.set_focused_color(colors.blue)
121 +-- Color of unfocused window borders
122 +oxwm.border.set_unfocused_color(colors.grey)
123 +
124 +-- Smart Enabled = No border if 1 window
125 +oxwm.gaps.set_smart(enabled)
126 +-- Inner gaps (horizontal, vertical) in pixels
127 +oxwm.gaps.set_inner(5, 5)
128 +-- Outer gaps (horizontal, vertical) in pixels
129 +oxwm.gaps.set_outer(5, 5)
130 +
131 +-------------------------------------------------------------------------------
132 +-- Window Rules
133 +-------------------------------------------------------------------------------
134 +-- Rules allow you to automatically configure windows based on their properties
135 +-- You can match windows by class, instance, title, or role
136 +-- Available properties: floating, tag, fullscreen, etc.
137 +--
138 +-- Common use cases:
139 +-- - Force floating for certain applications (dialogs, utilities)
140 +-- - Send specific applications to specific workspaces
141 +-- - Configure window behavior based on title or class
142 +
143 +-- Examples (uncomment to use):
144 +oxwm.rule.add({ instance = "gimp", floating = true })
145 +-- oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
146 +-- oxwm.rule.add({ instance = "mpv", floating = true })
147 +
148 +-- To find window properties, use xprop and click on the window
149 +-- WM_CLASS(STRING) shows both instance and class (instance, class)
125 150
126 ------------------------------------------------------------------------------- 151 -------------------------------------------------------------------------------
127 -- Status Bar Configuration 152 -- Status Bar Configuration
@@ -134,9 +159,13 @@ oxwm.bar.set_blocks(blocks)
134 159
135 -- Bar color schemes (for workspace tag display) 160 -- Bar color schemes (for workspace tag display)
136 -- Parameters: foreground, background, border 161 -- Parameters: foreground, background, border
137 -oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444") -- Unoccupied tags 162 +
138 -oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan) -- Occupied tags 163 +-- Unoccupied tags
139 -oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) -- Currently selected tag 164 +oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444")
165 +-- Occupied tags
166 +oxwm.bar.set_scheme_occupied(colors.cyan, colors.bg, colors.cyan)
167 +-- Currently selected tag
168 +oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
140 169
141 ------------------------------------------------------------------------------- 170 -------------------------------------------------------------------------------
142 -- Keybindings 171 -- Keybindings
@@ -150,39 +179,59 @@ oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) -- Currently
150 -- Common keys: Return, Space, Tab, Escape, Backspace, Delete, Left, Right, Up, Down 179 -- Common keys: Return, Space, Tab, Escape, Backspace, Delete, Left, Right, Up, Down
151 180
152 -- Basic window management 181 -- Basic window management
153 -oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal()) -- Spawn terminal 182 +
154 -oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) -- Application launcher 183 +oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal())
155 -oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) -- Screenshot selection 184 +-- Launch Dmenu
156 -oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) -- Close focused window 185 +oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
186 +-- Copy screenshot to clipboard
187 +oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
188 +oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
157 189
158 -- Keybind overlay - Shows important keybindings on screen 190 -- Keybind overlay - Shows important keybindings on screen
159 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds()) 191 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
160 192
161 -- Window state toggles 193 -- Window state toggles
162 -oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen()) -- Toggle fullscreen 194 +oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen())
163 -oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating()) -- Toggle floating mode 195 +oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating())
164 196
165 -- Layout management 197 -- Layout management
166 -oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie")) -- Set floating layout 198 +oxwm.key.bind({ modkey }, "F", oxwm.layout.set("normie"))
167 -oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling")) -- Set tiling layout 199 +oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling"))
168 -oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle()) -- Cycle through layouts 200 +-- Cycle through layouts
201 +oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
202 +
203 +-- Master area controls (tiling layout)
204 +
205 +-- Decrease/Increase master area width
206 +oxwm.key.bind({ modkey }, "H", oxwm.set_master_factor(-5))
207 +oxwm.key.bind({ modkey }, "L", oxwm.set_master_factor(5))
208 +-- Increment/Decrement number of master windows
209 +oxwm.key.bind({ modkey }, "I", oxwm.inc_num_master(1))
210 +oxwm.key.bind({ modkey }, "P", oxwm.inc_num_master(-1))
169 211
170 -- Gaps toggle 212 -- Gaps toggle
171 -oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) -- Toggle gaps on/off 213 +oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
172 214
173 -- Window manager controls 215 -- Window manager controls
174 -oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) -- Quit OXWM 216 +oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
175 -oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) -- Restart OXWM (reloads config) 217 +oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
176 218
177 --- Focus movement (vim keys) 219 +-- Focus movement [1 for up in the stack, -1 for down]
178 -oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left")) -- Focus window to the left 220 +oxwm.key.bind({ modkey }, "J", oxwm.client.focus_stack(1))
179 -oxwm.key.bind({ modkey }, "J", oxwm.client.focus_direction("down")) -- Focus window below 221 +oxwm.key.bind({ modkey }, "K", oxwm.client.focus_stack(-1))
180 -oxwm.key.bind({ modkey }, "K", oxwm.client.focus_direction("up")) -- Focus window above 222 +
181 -oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right")) -- Focus window to the right 223 +-- Window movement (swap position in stack)
224 +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1))
225 +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1))
182 226
183 -- Multi-monitor support 227 -- Multi-monitor support
184 -oxwm.key.bind({ modkey }, "Comma", oxwm.focus_monitor(-1)) -- Focus previous monitor 228 +
185 -oxwm.key.bind({ modkey }, "Period", oxwm.focus_monitor(1)) -- Focus next monitor 229 +-- Focus next/previous Monitors
230 +oxwm.key.bind({ modkey }, "Comma", oxwm.monitor.focus(-1))
231 +oxwm.key.bind({ modkey }, "Period", oxwm.monitor.focus(1))
232 +-- Move window to next/previous Monitors
233 +oxwm.key.bind({ modkey, "Shift" }, "Comma", oxwm.monitor.tag(-1))
234 +oxwm.key.bind({ modkey, "Shift" }, "Period", oxwm.monitor.tag(1))
186 235
187 -- Workspace (tag) navigation 236 -- Workspace (tag) navigation
188 -- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0) 237 -- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0)
@@ -207,11 +256,29 @@ oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
207 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7)) 256 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
208 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8)) 257 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
209 258
210 --- Swap windows in direction (vim keys with Shift) 259 +-- Combo view (view multiple tags at once) {argos_nothing}
211 -oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left")) -- Swap with window to the left 260 +-- Example: Mod+Ctrl+2 while on tag 1 will show BOTH tags 1 and 2
212 -oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down")) -- Swap with window below 261 +oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(0))
213 -oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up")) -- Swap with window above 262 +oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(1))
214 -oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right")) -- Swap with window to the right 263 +oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(2))
264 +oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(3))
265 +oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(4))
266 +oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(5))
267 +oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(6))
268 +oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(7))
269 +oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(8))
270 +
271 +-- Multi tag (window on multiple tags)
272 +-- Example: Mod+Ctrl+Shift+2 puts focused window on BOTH current tag and tag 2
273 +oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(0))
274 +oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(1))
275 +oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(2))
276 +oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(3))
277 +oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(4))
278 +oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(5))
279 +oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
280 +oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
281 +oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
215 282
216 ------------------------------------------------------------------------------- 283 -------------------------------------------------------------------------------
217 -- Advanced: Keychords 284 -- Advanced: Keychords
@@ -224,77 +291,13 @@ oxwm.key.chord({
224 { {}, "T" } 291 { {}, "T" }
225 }, oxwm.spawn_terminal()) 292 }, oxwm.spawn_terminal())
226 293
227 --------------------------------------------------------------------------------
228 --- Status Bar Blocks
229 --------------------------------------------------------------------------------
230 --- Add informational blocks to the status bar using block constructors
231 --- Each block is created with oxwm.bar.block.<type>() and configured with a table:
232 --- format: Display format with {} placeholders
233 --- interval: Seconds between updates
234 --- color: Text color (from color palette)
235 --- underline: Whether to underline the block
236 ---
237 --- Available block types:
238 --- ram(config) - Memory usage
239 --- datetime(config) - Date and time (requires date_format field)
240 --- shell(config) - Shell command output (requires command field)
241 --- static(config) - Static text (requires text field)
242 --- battery(config) - Battery status (requires charging, discharging, full fields)
243 -
244 -oxwm.bar.set_blocks({
245 - oxwm.bar.block.ram({
246 - format = "Ram: {used}/{total} GB",
247 - interval = 5,
248 - color = colors.light_blue,
249 - underline = true,
250 - }),
251 - oxwm.bar.block.static({
252 - format = "{}",
253 - text = " │ ",
254 - interval = 999999999,
255 - color = colors.lavender,
256 - underline = false,
257 - }),
258 - oxwm.bar.block.shell({
259 - format = "Kernel: {}",
260 - command = "uname -r",
261 - interval = 999999999,
262 - color = colors.red,
263 - underline = true,
264 - }),
265 - oxwm.bar.block.static({
266 - format = "{}",
267 - text = " │ ",
268 - interval = 999999999,
269 - color = colors.lavender,
270 - underline = false,
271 - }),
272 - oxwm.bar.block.datetime({
273 - format = "{}",
274 - date_format = "%a, %b %d - %-I:%M %P",
275 - interval = 1,
276 - color = colors.cyan,
277 - underline = true,
278 - }),
279 - -- Uncomment to add battery status (useful for laptops)
280 - -- oxwm.bar.block.battery({
281 - -- format = "Bat: {}%",
282 - -- charging = "⚡ Bat: {}%",
283 - -- discharging = "🔋 Bat: {}%",
284 - -- full = "✓ Bat: {}%",
285 - -- interval = 30,
286 - -- color = colors.green,
287 - -- underline = true,
288 - -- }),
289 -})
290 -
291 ------------------------------------------------------------------------------- 294 -------------------------------------------------------------------------------
292 -- Autostart 295 -- Autostart
293 ------------------------------------------------------------------------------- 296 -------------------------------------------------------------------------------
294 -- Commands to run once when OXWM starts 297 -- Commands to run once when OXWM starts
295 -- Uncomment and modify these examples, or add your own 298 -- Uncomment and modify these examples, or add your own
296 299
297 --- oxwm.autostart("picom") -- Compositor for transparency and effects 300 +-- oxwm.autostart("picom")
298 --- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg") -- Set wallpaper 301 +-- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg")
299 --- oxwm.autostart("dunst") -- Notification daemon 302 +-- oxwm.autostart("dunst")
300 --- oxwm.autostart("nm-applet") -- Network manager applet 303 +-- oxwm.autostart("nm-applet")
+45 −18 templates/oxwm.lua
@@ -42,6 +42,14 @@ function oxwm.set_tags(tags) end
42 ---@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]") 42 ---@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]")
43 function oxwm.set_layout_symbol(name, symbol) end 43 function oxwm.set_layout_symbol(name, symbol) end
44 44
45 +---Window rule module
46 +---@class oxwm.rule
47 +oxwm.rule = {}
48 +
49 +---Add a window rule
50 +---@param rule {class: string?, instance: string?, title: string?, role: string?, floating: boolean?, tag: integer?, fullscreen: boolean?} Rule configuration
51 +function oxwm.rule.add(rule) end
52 +
45 ---Quit the window manager 53 ---Quit the window manager
46 ---@return table Action table for keybinding 54 ---@return table Action table for keybinding
47 function oxwm.quit() end 55 function oxwm.quit() end
@@ -62,10 +70,15 @@ function oxwm.toggle_gaps() end
62 ---@return table Action table for keybinding 70 ---@return table Action table for keybinding
63 function oxwm.show_keybinds() end 71 function oxwm.show_keybinds() end
64 72
65 ----Focus monitor by index 73 +---Set master area factor (adjust master window width in tiling layout)
66 ----@param index integer Monitor index (-1 for previous, 1 for next) 74 +---@param delta integer Delta to adjust by (negative to decrease, positive to increase)
67 ---@return table Action table for keybinding 75 ---@return table Action table for keybinding
68 -function oxwm.focus_monitor(index) end 76 +function oxwm.set_master_factor(delta) end
77 +
78 +---Increment/decrement number of master windows
79 +---@param delta integer Delta to adjust by (negative to decrease, positive to increase)
80 +---@return table Action table for keybinding
81 +function oxwm.inc_num_master(delta) end
69 82
70 ---Keybinding module 83 ---Keybinding module
71 ---@class oxwm.key 84 ---@class oxwm.key
@@ -106,6 +119,10 @@ function oxwm.gaps.set_inner(horizontal, vertical) end
106 ---@param vertical integer Vertical outer gap in pixels 119 ---@param vertical integer Vertical outer gap in pixels
107 function oxwm.gaps.set_outer(horizontal, vertical) end 120 function oxwm.gaps.set_outer(horizontal, vertical) end
108 121
122 +---Set smart gaps (disable outer gaps when only one window visible)
123 +---@param enabled boolean Enable or disable smart gaps
124 +function oxwm.gaps.set_smart(enabled) end
125 +
109 ---Border configuration module 126 ---Border configuration module
110 ---@class oxwm.border 127 ---@class oxwm.border
111 oxwm.border = {} 128 oxwm.border = {}
@@ -138,29 +155,29 @@ function oxwm.client.toggle_fullscreen() end
138 ---@return table Action table for keybinding 155 ---@return table Action table for keybinding
139 function oxwm.client.toggle_floating() end 156 function oxwm.client.toggle_floating() end
140 157
141 ----Focus window in direction 158 +---Focus stack (next/previous window)
142 ----@param direction "up"|"down"|"left"|"right" Direction to focus 159 +---@param dir integer Direction (1 for next, -1 for previous)
143 ---@return table Action table for keybinding 160 ---@return table Action table for keybinding
144 -function oxwm.client.focus_direction(direction) end 161 +function oxwm.client.focus_stack(dir) end
145 162
146 ----Swap window in direction 163 +---Move stack (next/previous window)
147 ----@param direction "up"|"down"|"left"|"right" Direction to swap 164 +---@param dir integer Direction (1 for next, -1 for previous)
148 ---@return table Action table for keybinding 165 ---@return table Action table for keybinding
149 -function oxwm.client.swap_direction(direction) end 166 +function oxwm.client.move_stack(dir) end
150 167
151 ----Smart move window (move or swap) 168 +---Monitor management module
152 ----@param direction "up"|"down"|"left"|"right" Direction to move 169 +---@class oxwm.monitor
153 ----@return table Action table for keybinding 170 +oxwm.monitor = {}
154 -function oxwm.client.smart_move(direction) end
155 171
156 ----Focus stack (next/previous window) 172 +---Focus monitor
157 ----@param dir integer Direction (1 for next, -1 for previous) 173 +---@param dir integer Direction (-1 for previous, 1 for next)
158 ---@return table Action table for keybinding 174 ---@return table Action table for keybinding
159 -function oxwm.client.focus_stack(dir) end 175 +function oxwm.monitor.focus(dir) end
160 176
161 ----Exchange client positions 177 +---Send focused window to monitor
178 +---@param dir integer Direction (-1 for previous, 1 for next)
162 ---@return table Action table for keybinding 179 ---@return table Action table for keybinding
163 -function oxwm.client.exchange() end 180 +function oxwm.monitor.tag(dir) end
164 181
165 ---Layout management module 182 ---Layout management module
166 ---@class oxwm.layout 183 ---@class oxwm.layout
@@ -189,6 +206,16 @@ function oxwm.tag.view(index) end
189 ---@return table Action table for keybinding 206 ---@return table Action table for keybinding
190 function oxwm.tag.move_to(index) end 207 function oxwm.tag.move_to(index) end
191 208
209 +---Toggle viewing a tag (allows viewing multiple tags at once)
210 +---@param index integer Tag index (0-based)
211 +---@return table Action table for keybinding
212 +function oxwm.tag.toggleview(index) end
213 +
214 +---Toggle tag on focused window (allows window to appear on multiple tags)
215 +---@param index integer Tag index (0-based)
216 +---@return table Action table for keybinding
217 +function oxwm.tag.toggletag(index) end
218 +
192 ---Status bar configuration module 219 ---Status bar configuration module
193 ---@class oxwm.bar 220 ---@class oxwm.bar
194 oxwm.bar = {} 221 oxwm.bar = {}