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/layout/workspace.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/layout/workspace.rs') diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 2c18b40e..e2a95ad4 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -18,6 +18,7 @@ use crate::animation::Animation; use crate::niri_render_elements; use crate::render_helpers::renderer::NiriRenderer; use crate::swipe_tracker::SwipeTracker; +use crate::utils::id::IdCounter; use crate::utils::output_size; /// Amount of touchpad movement to scroll the view for the width of one working area. @@ -76,11 +77,25 @@ pub struct Workspace { /// Configurable properties of the layout. pub options: Rc, + + /// Unique ID of this workspace. + id: WorkspaceId, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct OutputId(String); +static WORKSPACE_ID_COUNTER: IdCounter = IdCounter::new(); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct WorkspaceId(u32); + +impl WorkspaceId { + fn next() -> WorkspaceId { + WorkspaceId(WORKSPACE_ID_COUNTER.next()) + } +} + niri_render_elements! { WorkspaceRenderElement => { Tile = TileRenderElement, @@ -225,6 +240,7 @@ impl Workspace { view_offset_adj: None, activate_prev_column_on_removal: None, options, + id: WorkspaceId::next(), } } @@ -240,9 +256,14 @@ impl Workspace { view_offset_adj: None, activate_prev_column_on_removal: None, options, + id: WorkspaceId::next(), } } + pub fn id(&self) -> WorkspaceId { + self.id + } + pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) { if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj { anim.set_current_time(current_time); -- cgit