From feeb139b052fdcf35a3b631c8e46745bd86284f7 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Thu, 2 May 2024 23:34:21 -0500 Subject: [PATCH] Don't focus windows on inactive tags --- src/api.rs | 4 ++-- src/api/window.rs | 21 +++------------------ src/focus.rs | 14 ++++++++++++-- src/handlers.rs | 19 +++++-------------- src/handlers/xdg_shell.rs | 12 +++++------- src/handlers/xwayland.rs | 23 +++++------------------ 6 files changed, 32 insertions(+), 61 deletions(-) diff --git a/src/api.rs b/src/api.rs index 85af2b6..607781d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -753,7 +753,7 @@ impl tag_service_server::TagService for TagService { state.pinnacle.fixup_xwayland_window_layering(); state.pinnacle.request_layout(&output); - state.update_focus(&output); + state.update_keyboard_focus(&output); state.schedule_render(&output); }) .await @@ -784,7 +784,7 @@ impl tag_service_server::TagService for TagService { state.pinnacle.fixup_xwayland_window_layering(); state.pinnacle.request_layout(&output); - state.update_focus(&output); + state.update_keyboard_focus(&output); state.schedule_render(&output); }) .await diff --git a/src/api/window.rs b/src/api/window.rs index ecc2e96..df92c0b 100644 --- a/src/api/window.rs +++ b/src/api/window.rs @@ -21,10 +21,7 @@ use smithay::{ use tonic::{Request, Response, Status}; use tracing::{error, warn}; -use crate::{ - focus::keyboard::KeyboardFocusTarget, output::OutputName, state::WithState, tag::TagId, - window::window_state::WindowId, -}; +use crate::{output::OutputName, state::WithState, tag::TagId, window::window_state::WindowId}; use super::{run_unary, run_unary_no_response, StateFnSender}; @@ -313,13 +310,7 @@ impl window_service_server::WindowService for WindowService { window.set_activate(true); output.with_state_mut(|state| state.focus_stack.set_focus(window.clone())); state.pinnacle.output_focus_stack.set_focus(output.clone()); - if let Some(keyboard) = state.pinnacle.seat.get_keyboard() { - keyboard.set_focus( - state, - Some(KeyboardFocusTarget::Window(window)), - SERIAL_COUNTER.next_serial(), - ); - } + state.update_keyboard_focus(&output); } SetOrToggle::Unset => { if state.pinnacle.focused_window(&output) == Some(window) { @@ -339,13 +330,7 @@ impl window_service_server::WindowService for WindowService { window.set_activate(true); output.with_state_mut(|state| state.focus_stack.set_focus(window.clone())); state.pinnacle.output_focus_stack.set_focus(output.clone()); - if let Some(keyboard) = state.pinnacle.seat.get_keyboard() { - keyboard.set_focus( - state, - Some(KeyboardFocusTarget::Window(window)), - SERIAL_COUNTER.next_serial(), - ); - } + state.update_keyboard_focus(&output); } } SetOrToggle::Unspecified => unreachable!(), diff --git a/src/focus.rs b/src/focus.rs index 2ce0ec1..5a24ad5 100644 --- a/src/focus.rs +++ b/src/focus.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use smithay::{output::Output, utils::SERIAL_COUNTER}; +use smithay::{desktop::space::SpaceElement, output::Output, utils::SERIAL_COUNTER}; use tracing::warn; use crate::{ @@ -13,12 +13,22 @@ pub mod pointer; impl State { /// Update the keyboard focus. - pub fn update_focus(&mut self, output: &Output) { + pub fn update_keyboard_focus(&mut self, output: &Output) { let current_focus = self.pinnacle.focused_window(output); if let Some(win) = ¤t_focus { assert!(!win.is_x11_override_redirect()); + let wins = output.with_state(|state| state.focus_stack.stack.clone()); + + for win in wins.iter() { + win.set_activate(false); + if let Some(toplevel) = win.toplevel() { + toplevel.send_configure(); + } + } + + win.set_activate(true); if let Some(toplevel) = win.toplevel() { toplevel.send_configure(); } diff --git a/src/handlers.rs b/src/handlers.rs index 55e7ea9..9b8dbcc 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -31,7 +31,7 @@ use smithay::{ Client, Resource, }, }, - utils::{Logical, Point, Rectangle, SERIAL_COUNTER}, + utils::{Logical, Point, Rectangle}, wayland::{ buffer::BufferHandler, compositor::{ @@ -190,20 +190,11 @@ impl CompositorHandler for State { Some(Duration::ZERO), surface_primary_scanout_output, ); - } - self.pinnacle.loop_handle.insert_idle(move |state| { - state - .pinnacle - .seat - .get_keyboard() - .expect("Seat had no keyboard") // FIXME: actually handle error - .set_focus( - state, - Some(KeyboardFocusTarget::Window(new_window)), - SERIAL_COUNTER.next_serial(), - ); - }); + self.pinnacle.loop_handle.insert_idle(move |state| { + state.update_keyboard_focus(&focused_output); + }); + } } else if new_window.toplevel().is_some() { new_window.on_commit(); self.pinnacle.ensure_initial_configure(surface); diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index a7c0817..8e9b451 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -13,7 +13,7 @@ use smithay::{ Resource, }, }, - utils::{Serial, SERIAL_COUNTER}, + utils::Serial, wayland::{ seat::WaylandFocus, shell::xdg::{ @@ -76,23 +76,21 @@ impl XdgShellHandler for State { if let Some(output) = window.output(&self.pinnacle) { self.pinnacle.request_layout(&output); + let focus = self .pinnacle .focused_window(&output) .map(KeyboardFocusTarget::Window); + if let Some(KeyboardFocusTarget::Window(window)) = &focus { tracing::debug!("Focusing on prev win"); - // TODO: self.pinnacle.raise_window(window.clone(), true); if let Some(toplevel) = window.toplevel() { toplevel.send_configure(); } } - self.pinnacle - .seat - .get_keyboard() - .expect("Seat had no keyboard") - .set_focus(self, focus, SERIAL_COUNTER.next_serial()); + + self.update_keyboard_focus(&output); self.schedule_render(&output); } diff --git a/src/handlers/xwayland.rs b/src/handlers/xwayland.rs index 3dccffd..935ff3d 100644 --- a/src/handlers/xwayland.rs +++ b/src/handlers/xwayland.rs @@ -114,20 +114,11 @@ impl XwmHandler for State { if let Some(output) = window.output(&self.pinnacle) { output.with_state_mut(|state| state.focus_stack.set_focus(window.clone())); self.pinnacle.request_layout(&output); - } - self.pinnacle.loop_handle.insert_idle(move |state| { - state - .pinnacle - .seat - .get_keyboard() - .expect("Seat had no keyboard") // FIXME: actually handle error - .set_focus( - state, - Some(KeyboardFocusTarget::Window(window)), - SERIAL_COUNTER.next_serial(), - ); - }); + self.pinnacle.loop_handle.insert_idle(move |state| { + state.update_keyboard_focus(&output); + }); + } } fn mapped_override_redirect_window(&mut self, _xwm: XwmId, surface: X11Surface) { @@ -470,11 +461,7 @@ impl State { } } - self.pinnacle - .seat - .get_keyboard() - .expect("Seat had no keyboard") - .set_focus(self, focus, SERIAL_COUNTER.next_serial()); + self.update_keyboard_focus(&output); self.schedule_render(&output); }