diff --git a/src/input/actions.rs b/src/input/actions.rs index 90b99653c..09cb2b452 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -873,26 +873,22 @@ impl State { } Action::Minimize => { - let Some(focused_output) = seat.focused_output() else { - return; - }; let mut shell = self.common.shell.write(); - let workspace = shell.active_space_mut(&focused_output).unwrap(); - let focus_stack = workspace.focus_stack.get(seat); - if let Some(surface) = focus_stack.last().and_then(FocusTarget::wl_surface) { - shell.minimize_request(&surface); + if let Some(focused_window) = seat + .get_keyboard() + .unwrap() + .current_focus() + .and_then(|f| f.active_window()) + { + shell.minimize_request(&focused_window); } } Action::Maximize => { - let Some(focused_output) = seat.focused_output() else { - return; - }; let mut shell = self.common.shell.write(); - let workspace = shell.active_space(&focused_output).unwrap(); - let focus_stack = workspace.focus_stack.get(seat); - let focused_window = focus_stack.last().cloned(); - if let Some(FocusTarget::Window(window)) = focused_window { + if let Some(KeyboardFocusTarget::Element(window)) = + seat.get_keyboard().unwrap().current_focus() + { shell.maximize_toggle(&window, seat, &self.common.event_loop_handle); } } @@ -902,22 +898,18 @@ impl State { return; }; let mut shell = self.common.shell.write(); - let workspace = shell.active_space(&focused_output).unwrap(); - let focus_stack = workspace.focus_stack.get(seat); - let focused_window = focus_stack.last().cloned(); - match focused_window { - Some(FocusTarget::Window(window)) => { - let output = workspace.output.clone(); + match seat.get_keyboard().unwrap().current_focus() { + Some(KeyboardFocusTarget::Element(window)) => { if let Some(target) = shell.fullscreen_request( &window.active_window(), - output, + focused_output, &self.common.event_loop_handle, ) { std::mem::drop(shell); Shell::set_focus(self, Some(&target), seat, Some(serial), true); } } - Some(FocusTarget::Fullscreen(surface)) => { + Some(KeyboardFocusTarget::Fullscreen(surface)) => { if let Some(target) = shell.unfullscreen_request(&surface, &self.common.event_loop_handle) { diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index 2e30d1339..6924fee66 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -220,6 +220,14 @@ impl KeyboardFocusTarget { } } + pub fn active_window(&self) -> Option { + match self { + KeyboardFocusTarget::Element(mapped) => Some(mapped.active_window()), + KeyboardFocusTarget::Fullscreen(surface) => Some(surface.clone()), + _ => None, + } + } + pub fn is_xwm(&self, xwm: XwmId) -> bool { match self { KeyboardFocusTarget::Element(mapped) => { diff --git a/src/shell/seats.rs b/src/shell/seats.rs index c1f6dbae2..f58b88028 100644 --- a/src/shell/seats.rs +++ b/src/shell/seats.rs @@ -262,8 +262,7 @@ impl SeatExt for Seat { } /// 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::()