From f7ac9654d1f4b827d17173b57a7d3d6ab2a4ec09 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 30 Mar 2022 22:11:29 +0200 Subject: [PATCH] input: Move windows between workspaces --- src/input/mod.rs | 9 ++++++++- src/shell/layout/floating/mod.rs | 4 ++++ src/shell/layout/mod.rs | 2 +- src/shell/layout/tiling/mod.rs | 6 ++++++ src/shell/mod.rs | 13 +++++++++++++ src/shell/workspace.rs | 8 ++++++-- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 02875cf0..44bfe045 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -294,7 +294,14 @@ impl Common { .add(&handle); return FilterResult::Intercept(()); } - Action::MoveToWorkspace(num) => { /* TODO */ } + Action::MoveToWorkspace(num) => { + let current_output = active_output(seat, &self); + self.shell.move_current_window( + seat, + ¤t_output, + *num, + ); + } Action::Focus(focus) => match focus { _ => { /* TODO */ } }, diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index 6f20fccb..08806b90 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -54,6 +54,10 @@ impl Layout for FloatingLayout { // TODO make sure all windows are still visible on any output or move them } + fn unmap_window(&mut self, space: &mut Space, window: &Window) { + space.unmap_window(window) + } + fn maximize_request(&mut self, space: &mut Space, window: &Window, output: &Output) { let layers = layer_map_for_output(&output); let geometry = layers.non_exclusive_zone(); diff --git a/src/shell/layout/mod.rs b/src/shell/layout/mod.rs index 81e075f6..5e565e67 100644 --- a/src/shell/layout/mod.rs +++ b/src/shell/layout/mod.rs @@ -32,7 +32,7 @@ pub trait Layout { focus_stack: Box + 'a>, ); //working around object safety.. fn refresh(&mut self, space: &mut Space); - //fn unmap_window(&mut self, space: &mut Space, window: &Window); + fn unmap_window(&mut self, space: &mut Space, window: &Window); fn update_orientation<'a>( &mut self, diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 089cb86d..91d20a31 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -200,6 +200,12 @@ impl Layout for TilingLayout { } } + fn unmap_window(&mut self, space: &mut Space, window: &Window) { + self.unmap_window(&window); + space.unmap_window(&window); + self.refresh(space); + } + fn resize_request( &mut self, _space: &mut Space, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 435e5f7f..abdf1479 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -237,6 +237,19 @@ impl Shell { }; } + pub fn move_current_window(&mut self, seat: &Seat, output: &Output, idx: u8) { + let workspace = self.active_space_mut(output); + if idx == workspace.idx { + return; + } + + let maybe_window = workspace.focus_stack(seat).last(); + if let Some(window) = maybe_window { + workspace.unmap_window(&window); + self.spaces[idx as usize].map_window(&window, seat); + } + } + #[cfg(feature = "debug")] pub fn mode(&self) -> &Mode { &self.mode diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 85f5e19b..76022436 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -48,7 +48,7 @@ impl<'a> FocusStackMut<'a> { type FocusStackData = RefCell<(HashMap>, IndexSet)>; pub struct Workspace { - idx: u8, + pub(super) idx: u8, pub space: Space, pub(super) layout: Box, pub(super) pending_windows: Vec<(Window, Seat)>, @@ -89,7 +89,7 @@ impl Workspace { self.pending_windows.push((window, seat.clone())); } - pub(super) fn map_window<'a>(&mut self, window: &Window, seat: &Seat) { + pub(super) fn map_window(&mut self, window: &Window, seat: &Seat) { seat.user_data() .insert_if_missing(|| FocusStackData::new((HashMap::new(), IndexSet::new()))); let focus_stack = FocusStackMut(RefMut::map( @@ -103,6 +103,10 @@ impl Workspace { .map_window(&mut self.space, window, seat, focus_stack.iter()) } + pub(super) fn unmap_window(&mut self, window: &Window) { + self.layout.unmap_window(&mut self.space, window) + } + pub fn refresh(&mut self) { self.layout.refresh(&mut self.space); self.space.refresh();