Update focus on xwayland window destroy

This commit is contained in:
Ottatop 2023-09-10 02:04:36 -05:00
parent f811771fbe
commit f8fcfcd8ce

View file

@ -183,6 +183,10 @@ impl XwmHandler for CalloopData {
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) {
tracing::debug!("UNMAPPED WINDOW");
self.state.focus_state.focus_stack.retain(|win| {
win.wl_surface()
.is_some_and(|surf| Some(surf) != window.wl_surface())
});
let win = self
.state
.space
@ -191,6 +195,22 @@ impl XwmHandler for CalloopData {
.cloned();
if let Some(win) = win {
self.state.space.unmap_elem(&win);
if let Some(output) = win.output(&self.state) {
self.state.update_windows(&output);
let focus = self.state.current_focus(&output).map(FocusTarget::Window);
if let Some(FocusTarget::Window(win)) = &focus {
tracing::debug!("Focusing on prev win");
self.state.space.raise_element(win, true);
if let WindowElement::Wayland(win) = &win {
win.toplevel().send_configure();
}
}
self.state
.seat
.get_keyboard()
.expect("Seat had no keyboard")
.set_focus(&mut self.state, focus, SERIAL_COUNTER.next_serial());
}
}
if !window.is_override_redirect() {
tracing::debug!("set mapped to false");
@ -199,6 +219,10 @@ impl XwmHandler for CalloopData {
}
fn destroyed_window(&mut self, _xwm: XwmId, window: X11Surface) {
self.state.focus_state.focus_stack.retain(|win| {
win.wl_surface()
.is_some_and(|surf| Some(surf) != window.wl_surface())
});
let win = self
.state
.windows
@ -216,6 +240,19 @@ impl XwmHandler for CalloopData {
if let Some(output) = win.output(&self.state) {
self.state.update_windows(&output);
let focus = self.state.current_focus(&output).map(FocusTarget::Window);
if let Some(FocusTarget::Window(win)) = &focus {
tracing::debug!("Focusing on prev win");
self.state.space.raise_element(win, true);
if let WindowElement::Wayland(win) = &win {
win.toplevel().send_configure();
}
}
self.state
.seat
.get_keyboard()
.expect("Seat had no keyboard")
.set_focus(&mut self.state, focus, SERIAL_COUNTER.next_serial());
}
}
tracing::debug!("destroyed x11 window");