From 7e3d3a9bae541d0a70c375567b9c9b280c60252e Mon Sep 17 00:00:00 2001 From: tcmal Date: Mon, 15 Jul 2024 19:25:03 +0100 Subject: Handle fullscreen requests sent by clients --- src/main.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 7c6c7bd..122f735 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,8 +29,8 @@ use nix::{ unistd::Pid, }; use xcb::{ - x::{self, PropertyNotifyEvent}, - Connection as RawConnection, Event, Extension, + x::{self, ClientMessageEvent, PropertyNotifyEvent}, + Connection as RawConnection, Event, Extension, Xid, }; pub mod clients; @@ -101,12 +101,13 @@ impl<'a> WM<'a> { Event::X(x::Event::MapRequest(e)) => self.handle_map_request(&e)?, Event::X(x::Event::UnmapNotify(e)) => self.handle_unmap_notify(&e), - // // See focus.rs + // See focus.rs Event::X(x::Event::EnterNotify(e)) => self.handle_enter_notify(&e), Event::X(x::Event::FocusIn(e)) => self.handle_focus_in(&e), - // // See below + // See below Event::X(x::Event::PropertyNotify(e)) => self.handle_property_notify(&e), + Event::X(x::Event::ClientMessage(e)) => self.handle_client_message(&e), _ => {} } } @@ -127,10 +128,48 @@ impl<'a> WM<'a> { if x::ATOM_WM_HINTS == e.atom() { let focused = self.clients.is_focused(e.window()); if let Some(c) = self.clients.find_client_mut(e.window()) { - c.sync_properties(&self.conn, focused); + c.sync_hints(&self.conn, focused); } } } + + /// Handle some common client requests set out by the EWMH spec + fn handle_client_message(&mut self, e: &ClientMessageEvent) { + let Some((mon, pos)) = self.clients.find_client_pos(e.window()) else { + return; + }; + + if e.format() != 32 { + return; + } + + if dbg!(e.r#type()) == dbg!(self.conn.atoms.net_wm_state) { + let x::ClientMessageData::Data32(data) = e.data() else { + unreachable!(); + }; + + if !(data[1] == self.conn.atoms.net_wm_fullscreen.resource_id() + || data[2] == self.conn.atoms.net_wm_fullscreen.resource_id()) + { + return; + } + + let mon_geom = self.clients.mon_geometry(mon); + let c = self.clients.client_mut(mon, pos).unwrap(); + let fullscreen = match data[0] { + 1 => true, + 2 => !c.fullscreen(), + _ => false, + }; + + if fullscreen { + c.set_fullscreen(&self.conn, &mon_geom); + } else { + c.set_tiled(&self.conn); + } + self.clients.rearrange(&self.conn); + } + } } /// Cleanup this process' children and set some flags. -- cgit v1.2.3