diff options
author | tcmal <me@aria.rip> | 2024-08-28 21:34:33 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-30 15:02:54 +0100 |
commit | bcc817382addf2d60b5ba0f76c25bd44fe8c828c (patch) | |
tree | 313aa59a8a413592dcc760ee2fb77c39fde125cc /src/clients | |
parent | afff36ca723f5297d26144dd70a18250653bfb3e (diff) |
Fix issues when currently focused window is killed
Diffstat (limited to 'src/clients')
-rw-r--r-- | src/clients/mod.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 47eb094..dcce37a 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -16,7 +16,7 @@ use xcb::{ GetWindowAttributes, InputFocus, MapRequestEvent, PropMode, SetInputFocus, UnmapNotifyEvent, Window, }, - xinerama, Extension, + xinerama, BaseEvent, Extension, }; pub use client::*; @@ -118,10 +118,19 @@ impl WM<'_> { /// When a window is unmapped, update its state. pub(crate) fn handle_unmap_notify(&mut self, e: &UnmapNotifyEvent) { - if let Some(c) = self.clients.find_client_mut(e.window()) { - let cookie = c.set_withdrawn(&self.conn, true); - // The above may fail if the window has already been destroyed - just discard the error here. - let _ = self.conn.check_request(cookie); + if !e.is_from_send_event() { + if let Some(c) = self.clients.find_client_mut(e.window()) { + let cookie = c.set_withdrawn(&self.conn, true); + // The above may fail if the window has already been destroyed - just discard the error here. + let _ = self.conn.check_request(cookie); + } + if self + .clients + .focused() + .is_some_and(|c| c.window() == e.window()) + { + self.clients.unfocus_destroyed(); + } } } } @@ -263,6 +272,13 @@ impl ClientState { old.set_border(conn, conn.colours.border_normal()); buttons::grab(conn, old.window(), false); } + self.focused_client = None; + } + + /// Unfocus the currently focused window, if it exists, without doing any of the X11 parts. + /// This is used when a focused window is destroyed or unmapped + pub fn unfocus_destroyed(&mut self) { + self.focused_client = None; } /// Go to the next or previous window in the current monitor, looping around if needed |