From 1a87db1097d9d594c28963c66c627f3c66bcf6de Mon Sep 17 00:00:00 2001 From: tcmal Date: Mon, 15 Jul 2024 19:19:01 +0100 Subject: set fullscreen based on ewm hints --- src/clients/client.rs | 7 ++++--- src/clients/hints.rs | 21 +++++++++++++++++++++ src/clients/mod.rs | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/clients/client.rs b/src/clients/client.rs index 84f787a..c9fa645 100644 --- a/src/clients/client.rs +++ b/src/clients/client.rs @@ -215,9 +215,10 @@ impl Client { }) } - pub fn update_window_type(&mut self, conn: &Connection<'_>) { - // TODO: Fullscreen from net_wm_state - if hints::is_dialog(conn, self.window) { + pub fn update_window_type(&mut self, conn: &Connection<'_>, mon_geom: &MonitorGeometry) { + if hints::is_fullscreen(conn, self.window) { + self.set_fullscreen(conn, mon_geom); + } else if hints::is_dialog(conn, self.window) { self.set_floating(conn); } } diff --git a/src/clients/hints.rs b/src/clients/hints.rs index fdfbead..39003d2 100644 --- a/src/clients/hints.rs +++ b/src/clients/hints.rs @@ -235,3 +235,24 @@ pub fn is_dialog(conn: &Connection, window: Window) -> bool { && hints.format() == 32 && hints.value::()[0] == conn.atoms.net_wm_window_type_dialog } + +/// Check if the given window wants to be fullscreen, using the `NET_WM_STATE` property +pub fn is_fullscreen(conn: &Connection, window: Window) -> bool { + let Ok(hints) = conn.wait_for_reply(conn.send_request(&GetProperty { + window, + delete: false, + property: conn.atoms.net_wm_state, + r#type: x::ATOM_ATOM, + long_offset: 0, + long_length: 9999, + })) else { + return false; + }; + + hints.r#type() == x::ATOM_ATOM + && hints.format() == 32 + && hints + .value::() + .iter() + .any(|a| *a == conn.atoms.net_wm_fullscreen) +} diff --git a/src/clients/mod.rs b/src/clients/mod.rs index c370e04..37a88c0 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -193,7 +193,7 @@ impl ClientState { // TODO: inserting at index 0 is why dwm uses linked lists, maybe this can be improved self.mons[mon].clients.insert(0, Client::new(window)); - let MonitorGeometry { + let mon_geom @ MonitorGeometry { width: mon_width, height: mon_height, .. @@ -213,7 +213,7 @@ impl ClientState { if floating { c.set_floating(conn); } - c.update_window_type(conn); + c.update_window_type(conn, &mon_geom); c.ensure_mapped(conn); c.sync_properties(conn, true); -- cgit v1.2.3