Use keyboard focus target rather than focus_stack in keybindings

`Action::Close` already used the keyboard focus target, but some other
bindings didn't. Presumably it's most intuitive if all "current window"
key bindings affect the window with keyboard focus.

These used the focus stack on the `focused_output()` (the one with
keyboard focus), so I guess the main impact is when the keyboard target
is a window being dragged? Then the binding will operate on that window,
or have no effect.

This seems related to some of the behaviors discussed in
https://github.com/pop-os/cosmic-comp/issues/453.
This commit is contained in:
Ian Douglas Scott 2025-10-01 13:40:39 -07:00 committed by Ian Douglas Scott
parent 12857672f6
commit e09fcec9f3
3 changed files with 23 additions and 24 deletions

View file

@ -220,6 +220,14 @@ impl KeyboardFocusTarget {
}
}
pub fn active_window(&self) -> Option<CosmicSurface> {
match self {
KeyboardFocusTarget::Element(mapped) => Some(mapped.active_window()),
KeyboardFocusTarget::Fullscreen(surface) => Some(surface.clone()),
_ => None,
}
}
fn x11_surface(&self) -> Option<X11Surface> {
match self {
KeyboardFocusTarget::Element(mapped) => mapped.active_window().x11_surface().cloned(),

View file

@ -268,8 +268,7 @@ impl SeatExt for Seat<State> {
}
/// Returns the output that contains the cursor associated with a seat. Note that the window which has keyboard focus
/// may be on a different output. Currently, to get the focused output, first get the keyboard focus target and pass
/// it to get_focused_output in the shell.
/// may be on a different output. Currently, to get the focused output, use [`Self::focused_output`].
fn active_output(&self) -> Output {
self.user_data()
.get::<ActiveOutput>()