workspace: Add toggle_stacking/toggle_stacking_focused

This commit is contained in:
Victoria Brekenfeld 2023-12-07 19:36:03 +00:00 committed by Victoria Brekenfeld
parent 677f686afd
commit 0147c328f9
2 changed files with 30 additions and 2 deletions

View file

@ -1821,8 +1821,9 @@ impl State {
Action::ToggleStacking => {
let output = seat.active_output();
let workspace = self.common.shell.active_space_mut(&output);
let focus_stack = workspace.focus_stack.get_mut(seat);
workspace.tiling_layer.toggle_stacking(seat, focus_stack);
if let Some(new_focus) = workspace.toggle_stacking_focused(seat) {
Common::set_focus(self, Some(&new_focus), seat, Some(serial));
}
}
Action::ToggleTiling => {
let output = seat.active_output();

View file

@ -777,6 +777,33 @@ impl Workspace {
}
}
pub fn toggle_stacking(&mut self, window: &CosmicMapped) -> Option<KeyboardFocusTarget> {
if self.tiling_layer.mapped().any(|(_, m, _)| m == window) {
self.tiling_layer.toggle_stacking(window)
} else if self.floating_layer.mapped().any(|w| w == window) {
self.floating_layer.toggle_stacking(window)
} else {
None
}
}
pub fn toggle_stacking_focused(&mut self, seat: &Seat<State>) -> Option<KeyboardFocusTarget> {
let maybe_window = self.focus_stack.get(seat).iter().next().cloned();
if let Some(window) = maybe_window {
if self.tiling_layer.mapped().any(|(_, m, _)| m == &window) {
self.tiling_layer
.toggle_stacking_focused(seat, self.focus_stack.get_mut(seat))
} else if self.floating_layer.mapped().any(|w| w == &window) {
self.floating_layer
.toggle_stacking_focused(seat, self.focus_stack.get_mut(seat))
} else {
None
}
} else {
None
}
}
pub fn mapped(&self) -> impl Iterator<Item = &CosmicMapped> {
self.floating_layer
.mapped()