diff options
-rw-r--r-- | src/clients/mod.rs | 26 | ||||
-rw-r--r-- | src/conn_info/mod.rs | 1 |
2 files changed, 21 insertions, 6 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 diff --git a/src/conn_info/mod.rs b/src/conn_info/mod.rs index a0b2b50..f85cdc0 100644 --- a/src/conn_info/mod.rs +++ b/src/conn_info/mod.rs @@ -150,7 +150,6 @@ impl<'a> Connection<'a> { x::Cw::EventMask( x::EventMask::SUBSTRUCTURE_REDIRECT | x::EventMask::SUBSTRUCTURE_NOTIFY - | x::EventMask::STRUCTURE_NOTIFY | x::EventMask::BUTTON_PRESS | x::EventMask::ENTER_WINDOW | x::EventMask::FOCUS_CHANGE |