From 23ac3d73232f307186212293713d6801d37cff2a Mon Sep 17 00:00:00 2001 From: FluxTape Date: Tue, 19 Mar 2024 14:27:52 +0000 Subject: Workspace back and forth (#253) * implement workspace back and forth * Make our own ID counter instead of SerialCounter, use a newtype * Rename FocusWorkspaceBackAndForth to FocusWorkspacePrevious * Add focus-workspace-previous to tests * Don't special case in switch_workspace_previous * Minor clean up * Add switch_workspace_auto_back_and_forth to tests * Skip animation on switch_workspace_previous * Preserve previous_workspace_id on workspace movement * Make Workspace::id private with a getter Reduce the chance it gets overwritten. * Add test for workspace ID uniqueness * Update previous workspace ID upon moving workspace across monitors --------- Co-authored-by: Ivan Molodetskikh --- src/utils/id.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/utils/id.rs (limited to 'src/utils/id.rs') diff --git a/src/utils/id.rs b/src/utils/id.rs new file mode 100644 index 00000000..3f8a2a7d --- /dev/null +++ b/src/utils/id.rs @@ -0,0 +1,27 @@ +use std::sync::atomic::{AtomicU32, Ordering}; + +/// Counter that returns unique IDs. +/// +/// Under the hood it uses a `u32` that will eventually wrap around. When incrementing it once a +/// second, it will wrap around after about 136 years. +pub struct IdCounter { + value: AtomicU32, +} + +impl IdCounter { + pub const fn new() -> Self { + Self { + value: AtomicU32::new(0), + } + } + + pub fn next(&self) -> u32 { + self.value.fetch_add(1, Ordering::SeqCst) + } +} + +impl Default for IdCounter { + fn default() -> Self { + Self::new() + } +} -- cgit