Skip to content

Commit e09fcec

Browse files
committed
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 #453.
1 parent 1285767 commit e09fcec

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

src/input/actions.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -873,26 +873,22 @@ impl State {
873873
}
874874

875875
Action::Minimize => {
876-
let Some(focused_output) = seat.focused_output() else {
877-
return;
878-
};
879876
let mut shell = self.common.shell.write();
880-
let workspace = shell.active_space_mut(&focused_output).unwrap();
881-
let focus_stack = workspace.focus_stack.get(seat);
882-
if let Some(surface) = focus_stack.last().and_then(FocusTarget::wl_surface) {
883-
shell.minimize_request(&surface);
877+
if let Some(focused_window) = seat
878+
.get_keyboard()
879+
.unwrap()
880+
.current_focus()
881+
.and_then(|f| f.active_window())
882+
{
883+
shell.minimize_request(&focused_window);
884884
}
885885
}
886886

887887
Action::Maximize => {
888-
let Some(focused_output) = seat.focused_output() else {
889-
return;
890-
};
891888
let mut shell = self.common.shell.write();
892-
let workspace = shell.active_space(&focused_output).unwrap();
893-
let focus_stack = workspace.focus_stack.get(seat);
894-
let focused_window = focus_stack.last().cloned();
895-
if let Some(FocusTarget::Window(window)) = focused_window {
889+
if let Some(KeyboardFocusTarget::Element(window)) =
890+
seat.get_keyboard().unwrap().current_focus()
891+
{
896892
shell.maximize_toggle(&window, seat, &self.common.event_loop_handle);
897893
}
898894
}
@@ -902,22 +898,18 @@ impl State {
902898
return;
903899
};
904900
let mut shell = self.common.shell.write();
905-
let workspace = shell.active_space(&focused_output).unwrap();
906-
let focus_stack = workspace.focus_stack.get(seat);
907-
let focused_window = focus_stack.last().cloned();
908-
match focused_window {
909-
Some(FocusTarget::Window(window)) => {
910-
let output = workspace.output.clone();
901+
match seat.get_keyboard().unwrap().current_focus() {
902+
Some(KeyboardFocusTarget::Element(window)) => {
911903
if let Some(target) = shell.fullscreen_request(
912904
&window.active_window(),
913-
output,
905+
focused_output,
914906
&self.common.event_loop_handle,
915907
) {
916908
std::mem::drop(shell);
917909
Shell::set_focus(self, Some(&target), seat, Some(serial), true);
918910
}
919911
}
920-
Some(FocusTarget::Fullscreen(surface)) => {
912+
Some(KeyboardFocusTarget::Fullscreen(surface)) => {
921913
if let Some(target) =
922914
shell.unfullscreen_request(&surface, &self.common.event_loop_handle)
923915
{

src/shell/focus/target.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ impl KeyboardFocusTarget {
220220
}
221221
}
222222

223+
pub fn active_window(&self) -> Option<CosmicSurface> {
224+
match self {
225+
KeyboardFocusTarget::Element(mapped) => Some(mapped.active_window()),
226+
KeyboardFocusTarget::Fullscreen(surface) => Some(surface.clone()),
227+
_ => None,
228+
}
229+
}
230+
223231
fn x11_surface(&self) -> Option<X11Surface> {
224232
match self {
225233
KeyboardFocusTarget::Element(mapped) => mapped.active_window().x11_surface().cloned(),

src/shell/seats.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ impl SeatExt for Seat<State> {
268268
}
269269

270270
/// Returns the output that contains the cursor associated with a seat. Note that the window which has keyboard focus
271-
/// may be on a different output. Currently, to get the focused output, first get the keyboard focus target and pass
272-
/// it to get_focused_output in the shell.
271+
/// may be on a different output. Currently, to get the focused output, use [`Self::focused_output`].
273272
fn active_output(&self) -> Output {
274273
self.user_data()
275274
.get::<ActiveOutput>()

0 commit comments

Comments
 (0)