protocols/workspace: Set ext workspace id for pinned workspace

The `id` is defined to be sent only once, on creation of the handle or
later. And only for workspaces that are "likely to be stable across
multiple sessions".

Set we add an `id` initially for pinned workspaces, and add one when the
workspace is pinned.

The `id` is not supposed to be human readable, so we just use a random
value.
This commit is contained in:
Ian Douglas Scott 2025-06-19 07:55:11 -07:00 committed by Victoria Brekenfeld
parent f2813f0500
commit e54f4b4963
6 changed files with 45 additions and 11 deletions

View file

@ -51,6 +51,7 @@ pub struct WorkspaceDataInner {
capabilities: Option<ext_workspace_handle_v1::WorkspaceCapabilities>,
coordinates: Vec<u32>,
states: Option<ext_workspace_handle_v1::State>,
ext_id: Option<String>,
pub(super) cosmic_v2_handle: Option<Weak<ZcosmicWorkspaceHandleV2>>,
}
@ -404,9 +405,6 @@ where
},
) {
mngr.workspace(&handle);
if let Some(id) = workspace.ext_id.clone() {
handle.id(id);
}
workspace.ext_instances.push(handle);
workspace.ext_instances.last_mut().unwrap()
} else {
@ -492,8 +490,12 @@ where
handle_state.states = Some(states);
changed = true;
}
// TODO ext_workspace_handle_v1::id
// TODO send id if pinned
if handle_state.ext_id.is_none() {
if let Some(id) = workspace.ext_id.clone() {
instance.id(id);
}
}
if let Some(cosmic_v2_handle) = handle_state
.cosmic_v2_handle

View file

@ -356,7 +356,6 @@ where
&mut self,
group: &WorkspaceGroupHandle,
tiling: zcosmic_workspace_handle_v2::TilingState,
// TODO way to add id to workspace that doesn't have it
ext_id: Option<String>,
) -> Option<WorkspaceHandle> {
if let Some(group) = self.0.groups.iter_mut().find(|g| g.id == group.id) {
@ -597,6 +596,25 @@ where
workspace.tiling = state;
}
}
pub fn set_id(
&mut self,
workspace: &WorkspaceHandle,
id: &str,
) -> Result<(), WorkspaceIdAlreadySetError> {
if let Some(workspace) = self
.0
.groups
.iter_mut()
.find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id))
{
if workspace.ext_id.is_some() {
return Err(WorkspaceIdAlreadySetError);
}
workspace.ext_id = Some(id.to_owned());
}
Ok(())
}
}
impl<'a, D> Drop for WorkspaceUpdateGuard<'a, D>
@ -608,6 +626,9 @@ where
}
}
#[derive(Clone, Copy, Debug)]
pub struct WorkspaceIdAlreadySetError;
macro_rules! delegate_workspace {
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [