tony / oxwm

Add window fullscreen toggle and improve fullscreen handling Browse files
- Added ToggleWindowFullscreen action for explicit per-window fullscreen
- Implemented smart fullscreen behavior: floating windows get per-window fullscreen, tiled windows get monitor fullscreen
- Added proper WM_DELETE_WINDOW support for graceful window closing
- Auto-float transient windows (dialogs, modals)
- Handle client-initiated fullscreen requests via _NET_WM_STATE
- Track fullscreen windows separately from floating windows
- Added _NET_WM_STATE and _NET_WM_STATE_FULLSCREEN atoms
tonybtw committed 2025-11-14 parent ad06fa5 commit 20090b15439bd6c2e10feaa0f3ae699e4ab079ad
Showing 5 changed files with 392 additions and 11 deletions. UnifiedSplit
+154 −0 BUGFIXES.md new file mode 100644
@@ -0,0 +1,154 @@
1 +# Bug Fixes Summary - bugfixes-floating-fullscreen branch
2 +
3 +## Branch Info
4 +- **Location**: `~/repos/oxwm-worktrees/bugfixes-floating-fullscreen`
5 +- **Based on**: `lua-config-test` branch
6 +- **Status**: Ready for testing on bare metal
7 +
8 +## Bugs Fixed
9 +
10 +### ✅ 1. Kill Client Killing All Firefox Instances
11 +**Problem**: Pressing `Mod+Q` killed ALL Firefox windows, not just the focused one.
12 +
13 +**Solution**: Implemented proper EWMH window closing protocol (src/window_manager.rs:1489-1547)
14 +- First tries to send `WM_DELETE_WINDOW` message (graceful close)
15 +- Only forcefully kills window if it doesn't support WM_DELETE_WINDOW
16 +- Matches dwm behavior
17 +
18 +**Test**: Open 2-3 Firefox windows, focus one, press `Mod+Q` → should only close that window
19 +
20 +---
21 +
22 +### ✅ 2. Fullscreen Not Working in Floating Mode
23 +**Problem**: Fullscreen only hid the bar, didn't actually fullscreen windows
24 +
25 +**Solution**: Implemented proper per-window EWMH fullscreen (src/window_manager.rs:1549-1610)
26 +- Added `_NET_WM_STATE` and `_NET_WM_STATE_FULLSCREEN` atoms
27 +- Saves window geometry before fullscreening
28 +- Removes borders and makes window cover entire monitor
29 +- Restores geometry when exiting fullscreen
30 +- Added smart context-aware behavior:
31 + - In normie (floating) layout → fullscreens the focused window
32 + - With explicitly floating window → fullscreens that window
33 + - In tiling layout → hides bar (monitor-level fullscreen)
34 +
35 +**Test**:
36 +1. Switch to normie layout (`Mod+F`)
37 +2. Press `Mod+Shift+F` → window should fullscreen properly
38 +3. In tiling mode, press `Mod+Shift+F` → should hide bar
39 +
40 +---
41 +
42 +### ✅ 3. YouTube Fullscreen (F key) Not Working
43 +**Problem**: Applications couldn't request fullscreen via EWMH protocol
44 +
45 +**Solution**: Implemented ClientMessage event handler (src/window_manager.rs:1909-1930)
46 +- Listens for `_NET_WM_STATE` change requests from clients
47 +- Handles add/remove/toggle fullscreen actions
48 +- Added `PROPERTY_CHANGE` to window event mask
49 +
50 +**Test**:
51 +1. Open Firefox, go to YouTube
52 +2. Press `F` on a video → should properly fullscreen
53 +3. Press `F` or `Esc` to exit → should return to previous size
54 +
55 +---
56 +
57 +### ✅ 4. Modal Windows Not Auto-Floating
58 +**Problem**: Dialogs like Discord loading screens required manual floating
59 +
60 +**Solution**: Implemented transient window detection (src/window_manager.rs:1612-1628, 1900-1903)
61 +- Checks `WM_TRANSIENT_FOR` hint during MapRequest
62 +- Automatically floats transient windows (dialogs, modals, popups)
63 +- Matches dwm behavior
64 +
65 +**Test**: Open Discord → loading modal should automatically float
66 +
67 +---
68 +
69 +### ⏸️ 5. Firefox Cursor Bug (NOT YET FIXED)
70 +**Problem**: Cursor gets "stuck" in one state (e.g., pointer/hand) when hovering over Firefox. The cursor won't update to show different states (arrow, text cursor, etc.) even though clicks/hovers still work functionally. **This is intermittent and hard to reproduce.**
71 +
72 +**Current Status**: Need more info to diagnose
73 +- Only happens in Firefox (so far)
74 +- Random/semi-reproducible
75 +- Not tested if it happens in Xephyr or only bare metal
76 +
77 +**Debug Steps** (when it happens next):
78 +1. Does it happen more in floating or tiling mode?
79 +2. Does switching tags fix it?
80 +3. Does `Mod+Shift+R` (restart WM) fix it?
81 +4. Does it only happen with certain Firefox actions (opening menus, hovering specific elements)?
82 +5. Does moving cursor out of Firefox and back in fix it?
83 +
84 +**Possible Causes**:
85 +- Race condition during cursor changes
86 +- Focus-related timing issue
87 +- Firefox-specific cursor handling
88 +- Event propagation issue
89 +
90 +**Investigation Notes**:
91 +- DWM sets cursor with `CWCursor` flag on root window (dwm.c:1705)
92 +- OXWM already does this correctly
93 +- Event masks look correct (ENTER_WINDOW, STRUCTURE_NOTIFY, PROPERTY_CHANGE)
94 +- Likely needs more investigation with reproducible steps
95 +
96 +---
97 +
98 +## Files Modified
99 +
100 +### Core Changes
101 +- `src/window_manager.rs`:
102 + - Added atoms: `wm_protocols`, `wm_delete_window`, `net_wm_state`, `net_wm_state_fullscreen`
103 + - Added `fullscreen_windows: HashSet<Window>` to track fullscreen state
104 + - Added `kill_client()` - graceful window closing
105 + - Added `send_event()` - send WM protocol messages
106 + - Added `set_window_fullscreen()` - per-window EWMH fullscreen
107 + - Added `is_transient_window()` - detect modal/dialog windows
108 + - Modified `ToggleFullScreen` handler - smart context-aware behavior
109 + - Added `ClientMessage` event handler - handle fullscreen requests
110 + - Modified `MapRequest` handler - auto-float transient windows
111 + - Modified `remove_window()` - clean up fullscreen state
112 +
113 +### Config Support
114 +- `src/config/lua.rs`:
115 + - Added `"ToggleWindowFullscreen"` to string_to_key_action()
116 +
117 +- `src/keyboard/handlers.rs`:
118 + - Added `ToggleWindowFullscreen` enum variant
119 +
120 +- `src/overlay/keybind.rs`:
121 + - Added description for `ToggleWindowFullscreen`
122 +
123 +### Test Config
124 +- `resources/test-config.lua`:
125 + - Uses smart `ToggleFullScreen` (`Mod+Shift+F`)
126 +
127 +---
128 +
129 +## How to Test on Bare Metal
130 +
131 +```bash
132 +cd ~/repos/oxwm-worktrees/bugfixes-floating-fullscreen
133 +cargo build --release
134 +cp target/release/oxwm ~/.local/bin/oxwm # or wherever you install it
135 +```
136 +
137 +Then reload WM with `Mod+Shift+R`
138 +
139 +---
140 +
141 +## Next Steps
142 +
143 +1. **Test all fixes on bare metal** (except cursor bug)
144 +2. **Gather more info on cursor bug** when it happens
145 +3. **If all tests pass**: Merge into `lua-config-test` branch
146 +4. **If issues found**: Iterate on fixes
147 +
148 +---
149 +
150 +## Notes
151 +
152 +- `ToggleWindowFullscreen` action exists but is unused in config (smart `ToggleFullScreen` covers it)
153 +- May want to add `strum` crate to auto-generate enum string parsing (see conversation notes)
154 +- Consider dropping `ron` as dependency eventually
+1 −0 src/config/lua.rs
@@ -369,6 +369,7 @@ fn string_to_key_action(s: &str) -> Result<KeyAction, ConfigError> {
369 369 "ViewTag" => KeyAction::ViewTag,
370 370 "ToggleGaps" => KeyAction::ToggleGaps,
371 371 "ToggleFullScreen" => KeyAction::ToggleFullScreen,
372 + "ToggleWindowFullscreen" => KeyAction::ToggleWindowFullscreen,
372 373 "ToggleFloating" => KeyAction::ToggleFloating,
373 374 "ChangeLayout" => KeyAction::ChangeLayout,
374 375 "CycleLayout" => KeyAction::CycleLayout,
+1 −0 src/keyboard/handlers.rs
@@ -22,6 +22,7 @@ pub enum KeyAction {
22 22 ViewTag,
23 23 ToggleGaps,
24 24 ToggleFullScreen,
25 + ToggleWindowFullscreen,
25 26 ToggleFloating,
26 27 ChangeLayout,
27 28 CycleLayout,
+2 −1 src/overlay/keybind.rs
@@ -209,7 +209,8 @@ impl KeybindOverlay {
209 209 },
210 210 KeyAction::MoveToTag => "Move Window to Workspace".to_string(),
211 211 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(),
212 - KeyAction::ToggleFullScreen => "Toggle Fullscreen".to_string(),
212 + KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(),
213 + KeyAction::ToggleWindowFullscreen => "Toggle Window Fullscreen".to_string(),
213 214 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(),
214 215 KeyAction::ChangeLayout => "Change Layout".to_string(),
215 216 KeyAction::CycleLayout => "Cycle Through Layouts".to_string(),
+234 −10 src/window_manager.rs
@@ -25,6 +25,10 @@ struct AtomCache {
25 25 net_current_desktop: Atom,
26 26 net_client_info: Atom,
27 27 wm_state: Atom,
28 + wm_protocols: Atom,
29 + wm_delete_window: Atom,
30 + net_wm_state: Atom,
31 + net_wm_state_fullscreen: Atom,
28 32 }
29 33
30 34 impl AtomCache {
@@ -41,10 +45,34 @@ impl AtomCache {
41 45
42 46 let wm_state = connection.intern_atom(false, b"WM_STATE")?.reply()?.atom;
43 47
48 + let wm_protocols = connection
49 + .intern_atom(false, b"WM_PROTOCOLS")?
50 + .reply()?
51 + .atom;
52 +
53 + let wm_delete_window = connection
54 + .intern_atom(false, b"WM_DELETE_WINDOW")?
55 + .reply()?
56 + .atom;
57 +
58 + let net_wm_state = connection
59 + .intern_atom(false, b"_NET_WM_STATE")?
60 + .reply()?
61 + .atom;
62 +
63 + let net_wm_state_fullscreen = connection
64 + .intern_atom(false, b"_NET_WM_STATE_FULLSCREEN")?
65 + .reply()?
66 + .atom;
67 +
44 68 Ok(Self {
45 69 net_current_desktop,
46 70 net_client_info,
47 71 wm_state,
72 + wm_protocols,
73 + wm_delete_window,
74 + net_wm_state,
75 + net_wm_state_fullscreen,
48 76 })
49 77 }
50 78 }
@@ -62,6 +90,7 @@ pub struct WindowManager {
62 90 window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>,
63 91 gaps_enabled: bool,
64 92 floating_windows: HashSet<Window>,
93 + fullscreen_windows: HashSet<Window>,
65 94 bars: Vec<Bar>,
66 95 monitors: Vec<Monitor>,
67 96 selected_monitor: usize,
@@ -185,6 +214,7 @@ impl WindowManager {
185 214 window_geometries: std::collections::HashMap::new(),
186 215 gaps_enabled,
187 216 floating_windows: HashSet::new(),
217 + fullscreen_windows: HashSet::new(),
188 218 bars,
189 219 monitors,
190 220 selected_monitor: 0,
@@ -932,18 +962,43 @@ impl WindowManager {
932 962 .get(self.selected_monitor)
933 963 .and_then(|m| m.focused_window)
934 964 {
935 - match self.connection.kill_client(focused) {
936 - Ok(_) => {
937 - self.connection.flush()?;
938 - }
939 - Err(e) => {
940 - eprintln!("Failed to kill window {}: {}", focused, e);
941 - }
942 - }
965 + self.kill_client(focused)?;
943 966 }
944 967 }
945 968 KeyAction::ToggleFullScreen => {
946 - self.toggle_fullscreen()?;
969 + // Smart fullscreen:
970 + // - In normie (floating) layout: always fullscreen the focused window
971 + // - With explicitly floating window: fullscreen that window
972 + // - Otherwise: do monitor-level fullscreen (hide bar)
973 + let is_normie_layout = self.layout.name() == "normie";
974 +
975 + if let Some(focused) = self
976 + .monitors
977 + .get(self.selected_monitor)
978 + .and_then(|m| m.focused_window)
979 + {
980 + if is_normie_layout || self.floating_windows.contains(&focused) {
981 + // In floating layout or window is floating - do per-window fullscreen
982 + let is_fullscreen = self.fullscreen_windows.contains(&focused);
983 + self.set_window_fullscreen(focused, !is_fullscreen)?;
984 + } else {
985 + // Window is tiled - do monitor fullscreen
986 + self.toggle_fullscreen()?;
987 + }
988 + } else {
989 + // No focused window - do monitor fullscreen
990 + self.toggle_fullscreen()?;
991 + }
992 + }
993 + KeyAction::ToggleWindowFullscreen => {
994 + if let Some(focused) = self
995 + .monitors
996 + .get(self.selected_monitor)
997 + .and_then(|m| m.focused_window)
998 + {
999 + let is_fullscreen = self.fullscreen_windows.contains(&focused);
1000 + self.set_window_fullscreen(focused, !is_fullscreen)?;
1001 + }
947 1002 }
948 1003 KeyAction::ChangeLayout => {
949 1004 if let Arg::Str(layout_name) = arg {
@@ -1463,6 +1518,147 @@ impl WindowManager {
1463 1518 Ok(())
1464 1519 }
1465 1520
1521 + fn kill_client(&self, window: Window) -> WmResult<()> {
1522 + // Try to send WM_DELETE_WINDOW message first (graceful close)
1523 + if self.send_event(window, self.atoms.wm_delete_window)? {
1524 + // Window supports WM_DELETE_WINDOW, it will close gracefully
1525 + self.connection.flush()?;
1526 + } else {
1527 + // Window doesn't support WM_DELETE_WINDOW, forcefully kill it
1528 + eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window);
1529 + self.connection.kill_client(window)?;
1530 + self.connection.flush()?;
1531 + }
1532 + Ok(())
1533 + }
1534 +
1535 + fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> {
1536 + // Check if the window supports this protocol
1537 + let protocols_reply = self.connection.get_property(
1538 + false,
1539 + window,
1540 + self.atoms.wm_protocols,
1541 + AtomEnum::ATOM,
1542 + 0,
1543 + 100,
1544 + )?.reply();
1545 +
1546 + let protocols_reply = match protocols_reply {
1547 + Ok(reply) => reply,
1548 + Err(_) => return Ok(false),
1549 + };
1550 +
1551 + let protocols: Vec<Atom> = protocols_reply
1552 + .value
1553 + .chunks_exact(4)
1554 + .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]))
1555 + .collect();
1556 +
1557 + if !protocols.contains(&protocol) {
1558 + return Ok(false);
1559 + }
1560 +
1561 + // Send a ClientMessage event
1562 + let event = x11rb::protocol::xproto::ClientMessageEvent {
1563 + response_type: x11rb::protocol::xproto::CLIENT_MESSAGE_EVENT,
1564 + format: 32,
1565 + sequence: 0,
1566 + window,
1567 + type_: self.atoms.wm_protocols,
1568 + data: x11rb::protocol::xproto::ClientMessageData::from([protocol, x11rb::CURRENT_TIME, 0, 0, 0]),
1569 + };
1570 +
1571 + self.connection.send_event(
1572 + false,
1573 + window,
1574 + EventMask::NO_EVENT,
1575 + event,
1576 + )?;
1577 + self.connection.flush()?;
1578 + Ok(true)
1579 + }
1580 +
1581 + fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> {
1582 + if fullscreen && !self.fullscreen_windows.contains(&window) {
1583 + // Save current geometry before fullscreen
1584 + if let Ok(geom) = self.connection.get_geometry(window)?.reply() {
1585 + self.window_geometries.insert(window, (geom.x, geom.y, geom.width, geom.height));
1586 + }
1587 +
1588 + // Set the _NET_WM_STATE property to fullscreen
1589 + self.connection.change_property(
1590 + PropMode::REPLACE,
1591 + window,
1592 + self.atoms.net_wm_state,
1593 + AtomEnum::ATOM,
1594 + 32,
1595 + 1,
1596 + &self.atoms.net_wm_state_fullscreen.to_ne_bytes(),
1597 + )?;
1598 +
1599 + self.fullscreen_windows.insert(window);
1600 + self.floating_windows.insert(window);
1601 +
1602 + // Get monitor dimensions
1603 + let window_mon = self.window_monitor.get(&window).copied().unwrap_or(self.selected_monitor);
1604 + let monitor = &self.monitors[window_mon];
1605 +
1606 + // Make window fullscreen across the entire monitor
1607 + self.connection.configure_window(
1608 + window,
1609 + &ConfigureWindowAux::new()
1610 + .x(monitor.x)
1611 + .y(monitor.y)
1612 + .width(monitor.width)
1613 + .height(monitor.height)
1614 + .border_width(0)
1615 + .stack_mode(StackMode::ABOVE),
1616 + )?;
1617 +
1618 + self.connection.flush()?;
1619 + } else if !fullscreen && self.fullscreen_windows.contains(&window) {
1620 + // Clear the _NET_WM_STATE property
1621 + self.connection.delete_property(window, self.atoms.net_wm_state)?;
1622 +
1623 + self.fullscreen_windows.remove(&window);
1624 +
1625 + // Restore saved geometry
1626 + if let Some((x, y, width, height)) = self.window_geometries.get(&window) {
1627 + self.connection.configure_window(
1628 + window,
1629 + &ConfigureWindowAux::new()
1630 + .x(*x as i32)
1631 + .y(*y as i32)
1632 + .width(*width as u32)
1633 + .height(*height as u32)
1634 + .border_width(self.config.border_width),
1635 + )?;
1636 + }
1637 +
1638 + self.apply_layout()?;
1639 + self.connection.flush()?;
1640 + }
1641 + Ok(())
1642 + }
1643 +
1644 + fn is_transient_window(&self, window: Window) -> bool {
1645 + // Check if window is transient (e.g., dialog, modal)
1646 + let transient_for = self.connection
1647 + .get_property(
1648 + false,
1649 + window,
1650 + AtomEnum::WM_TRANSIENT_FOR,
1651 + AtomEnum::WINDOW,
1652 + 0,
1653 + 1,
1654 + )
1655 + .ok()
1656 + .and_then(|cookie| cookie.reply().ok())
1657 + .filter(|reply| !reply.value.is_empty());
1658 +
1659 + transient_for.is_some()
1660 + }
1661 +
1466 1662 pub fn set_focus(&mut self, window: Window) -> WmResult<()> {
1467 1663 let old_focused = self.previous_focused;
1468 1664
@@ -1707,7 +1903,7 @@ impl WindowManager {
1707 1903 self.connection.map_window(event.window)?;
1708 1904 self.connection.change_window_attributes(
1709 1905 event.window,
1710 - &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW),
1906 + &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE),
1711 1907 )?;
1712 1908
1713 1909 let selected_tags = self
@@ -1723,10 +1919,37 @@ impl WindowManager {
1723 1919 self.set_wm_state(event.window, 1)?;
1724 1920 let _ = self.save_client_tag(event.window, selected_tags);
1725 1921
1922 + // Auto-float transient windows (e.g., dialogs, modals)
1923 + if self.is_transient_window(event.window) {
1924 + self.floating_windows.insert(event.window);
1925 + }
1926 +
1726 1927 self.apply_layout()?;
1727 1928 self.update_bar()?;
1728 1929 self.set_focus(event.window)?;
1729 1930 }
1931 + Event::ClientMessage(event) => {
1932 + // Handle _NET_WM_STATE fullscreen requests from clients
1933 + if event.type_ == self.atoms.net_wm_state {
1934 + let data = event.data.as_data32();
1935 + let action = data[0]; // 0 = remove, 1 = add, 2 = toggle
1936 + let property1 = data[1];
1937 + let property2 = data[2];
1938 +
1939 + if property1 == self.atoms.net_wm_state_fullscreen || property2 == self.atoms.net_wm_state_fullscreen {
1940 + if self.windows.contains(&event.window) {
1941 + let is_fullscreen = self.fullscreen_windows.contains(&event.window);
1942 + let should_fullscreen = match action {
1943 + 0 => false, // Remove
1944 + 1 => true, // Add
1945 + 2 => !is_fullscreen, // Toggle
1946 + _ => is_fullscreen,
1947 + };
1948 + self.set_window_fullscreen(event.window, should_fullscreen)?;
1949 + }
1950 + }
1951 + }
1952 + }
1730 1953 Event::UnmapNotify(event) => {
1731 1954 if self.windows.contains(&event.window) && self.is_window_visible(event.window) {
1732 1955 self.remove_window(event.window)?;
@@ -1964,6 +2187,7 @@ impl WindowManager {
1964 2187 self.window_monitor.remove(&window);
1965 2188 self.window_geometries.remove(&window);
1966 2189 self.floating_windows.remove(&window);
2190 + self.fullscreen_windows.remove(&window);
1967 2191
1968 2192 if self.windows.len() < initial_count {
1969 2193 let focused = self