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 <yalterz@gmail.com>
This commit is contained in:
FluxTape
2024-03-19 14:27:52 +00:00
committed by GitHub
parent c3327d36da
commit 23ac3d7323
9 changed files with 150 additions and 2 deletions
+21
View File
@@ -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<W: LayoutElement> {
/// Configurable properties of the layout.
pub options: Rc<Options>,
/// 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<R> => {
Tile = TileRenderElement<R>,
@@ -225,6 +240,7 @@ impl<W: LayoutElement> Workspace<W> {
view_offset_adj: None,
activate_prev_column_on_removal: None,
options,
id: WorkspaceId::next(),
}
}
@@ -240,9 +256,14 @@ impl<W: LayoutElement> Workspace<W> {
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);