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

@ -400,8 +400,7 @@ fn create_workspace_from_pinned(
} else {
TilingState::FloatingOnly
},
// TODO Set id for persistent workspaces
None,
pinned.id.clone(),
)
.unwrap();
state.add_workspace_state(&workspace_handle, WState::Pinned);

View file

@ -72,8 +72,7 @@ const FULLSCREEN_ANIMATION_DURATION: Duration = Duration::from_millis(200);
// For stable workspace id, generate random 24-bit integer, as a hex string
// Must be compared with existing workspaces work uniqueness.
// TODO: Assign an id to any workspace that is pinned
pub fn random_id() -> String {
pub fn random_workspace_id() -> String {
let id = rand::random_range(0..(2 << 24));
format!("{:x}", id)
}
@ -106,6 +105,7 @@ pub struct Workspace {
pub tiling_enabled: bool,
pub fullscreen: Option<FullscreenSurface>,
pub pinned: bool,
pub id: Option<String>,
pub handle: WorkspaceHandle,
pub focus_stack: FocusStacks,
@ -362,6 +362,7 @@ impl Workspace {
minimized_windows: Vec::new(),
fullscreen: None,
pinned: false,
id: None,
handle,
focus_stack: FocusStacks::default(),
screencopy: ScreencopySessions::default(),
@ -393,6 +394,7 @@ impl Workspace {
minimized_windows: Vec::new(),
fullscreen: None,
pinned: true,
id: pinned.id.clone(),
handle,
focus_stack: FocusStacks::default(),
screencopy: ScreencopySessions::default(),
@ -410,6 +412,7 @@ impl Workspace {
}
pub fn to_pinned(&self) -> Option<PinnedWorkspace> {
debug_assert!(self.id.is_some());
let output = self.explicit_output().clone();
if self.pinned {
Some(PinnedWorkspace {
@ -418,6 +421,7 @@ impl Workspace {
edid: output.edid,
},
tiling_enabled: self.tiling_enabled,
id: self.id.clone(),
})
} else {
None