workspace-management: Implement move_to_workspace request

Needed for `cosmic-workspaces`.
This commit is contained in:
Ian Douglas Scott 2023-12-06 15:13:48 -08:00 committed by Victoria Brekenfeld
parent 75990ff056
commit 656996503c
6 changed files with 92 additions and 43 deletions

View file

@ -1,9 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
use smithay::{input::Seat, reexports::wayland_server::DisplayHandle};
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1;
use smithay::{input::Seat, output::Output, reexports::wayland_server::DisplayHandle};
use crate::{
shell::CosmicSurface,
shell::{CosmicSurface, Shell},
utils::prelude::*,
wayland::protocols::{
toplevel_info::ToplevelInfoHandler,
@ -59,6 +60,35 @@ impl ToplevelManagementHandler for State {
fn close(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {
window.close();
}
fn move_to_workspace(
&mut self,
_dh: &DisplayHandle,
window: &<Self as ToplevelInfoHandler>::Window,
workspace: ZcosmicWorkspaceHandleV1,
_output: Output,
) {
let Some(to_handle) = self.common.shell.workspace_state.get_workspace_handle(&workspace) else {
return;
};
let from_workspace = self
.common
.shell
.workspaces
.spaces()
.find(|w| w.windows().any(|w| &w == window));
if let Some(from_workspace) = from_workspace {
let mapped = from_workspace
.mapped()
.find(|m| m.windows().any(|(w, _)| &w == window))
.unwrap()
.clone();
let from_handle = from_workspace.handle;
let _ = Shell::move_window(self, None, &mapped, &from_handle, &to_handle, false, None);
return;
}
}
}
impl ManagementWindow for CosmicSurface {