| @@ -25,6 +25,10 @@ struct AtomCache { |
| 25 |
net_current_desktop: Atom, |
25 |
net_current_desktop: Atom, |
| 26 |
net_client_info: Atom, |
26 |
net_client_info: Atom, |
| 27 |
wm_state: Atom, |
27 |
wm_state: Atom, |
|
|
28 |
+ wm_protocols: Atom, |
|
|
29 |
+ wm_delete_window: Atom, |
|
|
30 |
+ net_wm_state: Atom, |
|
|
31 |
+ net_wm_state_fullscreen: Atom, |
| 28 |
} |
32 |
} |
| 29 |
|
33 |
|
| 30 |
impl AtomCache { |
34 |
impl AtomCache { |
| @@ -41,10 +45,34 @@ impl AtomCache { |
| 41 |
|
45 |
|
| 42 |
let wm_state = connection.intern_atom(false, b"WM_STATE")?.reply()?.atom; |
46 |
let wm_state = connection.intern_atom(false, b"WM_STATE")?.reply()?.atom; |
| 43 |
|
47 |
|
|
|
48 |
+ let wm_protocols = connection |
|
|
49 |
+ .intern_atom(false, b"WM_PROTOCOLS")? |
|
|
50 |
+ .reply()? |
|
|
51 |
+ .atom; |
|
|
52 |
+ |
|
|
53 |
+ let wm_delete_window = connection |
|
|
54 |
+ .intern_atom(false, b"WM_DELETE_WINDOW")? |
|
|
55 |
+ .reply()? |
|
|
56 |
+ .atom; |
|
|
57 |
+ |
|
|
58 |
+ let net_wm_state = connection |
|
|
59 |
+ .intern_atom(false, b"_NET_WM_STATE")? |
|
|
60 |
+ .reply()? |
|
|
61 |
+ .atom; |
|
|
62 |
+ |
|
|
63 |
+ let net_wm_state_fullscreen = connection |
|
|
64 |
+ .intern_atom(false, b"_NET_WM_STATE_FULLSCREEN")? |
|
|
65 |
+ .reply()? |
|
|
66 |
+ .atom; |
|
|
67 |
+ |
| 44 |
Ok(Self { |
68 |
Ok(Self { |
| 45 |
net_current_desktop, |
69 |
net_current_desktop, |
| 46 |
net_client_info, |
70 |
net_client_info, |
| 47 |
wm_state, |
71 |
wm_state, |
|
|
72 |
+ wm_protocols, |
|
|
73 |
+ wm_delete_window, |
|
|
74 |
+ net_wm_state, |
|
|
75 |
+ net_wm_state_fullscreen, |
| 48 |
}) |
76 |
}) |
| 49 |
} |
77 |
} |
| 50 |
} |
78 |
} |
| @@ -62,6 +90,7 @@ pub struct WindowManager { |
| 62 |
window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>, |
90 |
window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>, |
| 63 |
gaps_enabled: bool, |
91 |
gaps_enabled: bool, |
| 64 |
floating_windows: HashSet<Window>, |
92 |
floating_windows: HashSet<Window>, |
|
|
93 |
+ fullscreen_windows: HashSet<Window>, |
| 65 |
bars: Vec<Bar>, |
94 |
bars: Vec<Bar>, |
| 66 |
monitors: Vec<Monitor>, |
95 |
monitors: Vec<Monitor>, |
| 67 |
selected_monitor: usize, |
96 |
selected_monitor: usize, |
| @@ -185,6 +214,7 @@ impl WindowManager { |
| 185 |
window_geometries: std::collections::HashMap::new(), |
214 |
window_geometries: std::collections::HashMap::new(), |
| 186 |
gaps_enabled, |
215 |
gaps_enabled, |
| 187 |
floating_windows: HashSet::new(), |
216 |
floating_windows: HashSet::new(), |
|
|
217 |
+ fullscreen_windows: HashSet::new(), |
| 188 |
bars, |
218 |
bars, |
| 189 |
monitors, |
219 |
monitors, |
| 190 |
selected_monitor: 0, |
220 |
selected_monitor: 0, |
| @@ -932,18 +962,43 @@ impl WindowManager { |
| 932 |
.get(self.selected_monitor) |
962 |
.get(self.selected_monitor) |
| 933 |
.and_then(|m| m.focused_window) |
963 |
.and_then(|m| m.focused_window) |
| 934 |
{ |
964 |
{ |
| 935 |
- match self.connection.kill_client(focused) { |
965 |
+ self.kill_client(focused)?; |
| 936 |
- Ok(_) => { |
|
|
| 937 |
- self.connection.flush()?; |
|
|
| 938 |
- } |
|
|
| 939 |
- Err(e) => { |
|
|
| 940 |
- eprintln!("Failed to kill window {}: {}", focused, e); |
|
|
| 941 |
- } |
|
|
| 942 |
- } |
|
|
| 943 |
} |
966 |
} |
| 944 |
} |
967 |
} |
| 945 |
KeyAction::ToggleFullScreen => { |
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 |
KeyAction::ChangeLayout => { |
1003 |
KeyAction::ChangeLayout => { |
| 949 |
if let Arg::Str(layout_name) = arg { |
1004 |
if let Arg::Str(layout_name) = arg { |
| @@ -1463,6 +1518,147 @@ impl WindowManager { |
| 1463 |
Ok(()) |
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 |
pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
1662 |
pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
| 1467 |
let old_focused = self.previous_focused; |
1663 |
let old_focused = self.previous_focused; |
| 1468 |
|
1664 |
|
| @@ -1707,7 +1903,7 @@ impl WindowManager { |
| 1707 |
self.connection.map_window(event.window)?; |
1903 |
self.connection.map_window(event.window)?; |
| 1708 |
self.connection.change_window_attributes( |
1904 |
self.connection.change_window_attributes( |
| 1709 |
event.window, |
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 |
let selected_tags = self |
1909 |
let selected_tags = self |
| @@ -1723,10 +1919,37 @@ impl WindowManager { |
| 1723 |
self.set_wm_state(event.window, 1)?; |
1919 |
self.set_wm_state(event.window, 1)?; |
| 1724 |
let _ = self.save_client_tag(event.window, selected_tags); |
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 |
self.apply_layout()?; |
1927 |
self.apply_layout()?; |
| 1727 |
self.update_bar()?; |
1928 |
self.update_bar()?; |
| 1728 |
self.set_focus(event.window)?; |
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 |
Event::UnmapNotify(event) => { |
1953 |
Event::UnmapNotify(event) => { |
| 1731 |
if self.windows.contains(&event.window) && self.is_window_visible(event.window) { |
1954 |
if self.windows.contains(&event.window) && self.is_window_visible(event.window) { |
| 1732 |
self.remove_window(event.window)?; |
1955 |
self.remove_window(event.window)?; |
| @@ -1964,6 +2187,7 @@ impl WindowManager { |
| 1964 |
self.window_monitor.remove(&window); |
2187 |
self.window_monitor.remove(&window); |
| 1965 |
self.window_geometries.remove(&window); |
2188 |
self.window_geometries.remove(&window); |
| 1966 |
self.floating_windows.remove(&window); |
2189 |
self.floating_windows.remove(&window); |
|
|
2190 |
+ self.fullscreen_windows.remove(&window); |
| 1967 |
|
2191 |
|
| 1968 |
if self.windows.len() < initial_count { |
2192 |
if self.windows.len() < initial_count { |
| 1969 |
let focused = self |
2193 |
let focused = self |