workspace: Add explicit toogle_floating_window_focused

`toggle_floating_window` -> `toggle_floating_window_focused`
and added `toggle_floating_window` to deal with explicitly provided
`CosmicMapped`.
This commit is contained in:
Victoria Brekenfeld 2023-12-07 19:34:03 +00:00 committed by Victoria Brekenfeld
parent 1a399b0d04
commit 677f686afd
2 changed files with 20 additions and 12 deletions

View file

@ -1832,7 +1832,7 @@ impl State {
Action::ToggleWindowFloating => { Action::ToggleWindowFloating => {
let output = seat.active_output(); let output = seat.active_output();
let workspace = self.common.shell.active_space_mut(&output); let workspace = self.common.shell.active_space_mut(&output);
workspace.toggle_floating_window(seat); workspace.toggle_floating_window_focused(seat);
} }
Action::Spawn(command) => { Action::Spawn(command) => {
let (token, data) = self let (token, data) = self

View file

@ -753,19 +753,27 @@ impl Workspace {
} }
} }
pub fn toggle_floating_window(&mut self, seat: &Seat<State>) { pub fn toggle_floating_window(&mut self, seat: &Seat<State>, window: &CosmicMapped) {
if self.tiling_enabled { if self.tiling_enabled {
if let Some(window) = self.focus_stack.get(seat).iter().next().cloned() { if window.is_maximized(false) {
if self.tiling_layer.mapped().any(|(_, m, _)| m == &window) { self.unmaximize_request(&window.active_window());
self.tiling_layer.unmap(&window);
self.floating_layer.map(window, None);
} else if self.floating_layer.mapped().any(|w| w == &window) {
let focus_stack = self.focus_stack.get(seat);
self.floating_layer.unmap(&window);
self.tiling_layer
.map(window, Some(focus_stack.iter()), None)
}
} }
if self.tiling_layer.mapped().any(|(_, m, _)| m == window) {
self.tiling_layer.unmap(window);
self.floating_layer.map(window.clone(), None);
} else if self.floating_layer.mapped().any(|w| w == window) {
let focus_stack = self.focus_stack.get(seat);
self.floating_layer.unmap(&window);
self.tiling_layer
.map(window.clone(), Some(focus_stack.iter()), None)
}
}
}
pub fn toggle_floating_window_focused(&mut self, seat: &Seat<State>) {
let maybe_window = self.focus_stack.get(seat).iter().next().cloned();
if let Some(window) = maybe_window {
self.toggle_floating_window(seat, &window);
} }
} }