From 7314c0ee24368effe504eafa1fe6e617503698a7 Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Sat, 9 Dec 2023 17:03:19 +0100 Subject: [PATCH] add ScrollerGrouped --- package/contents/ui/config.ui | 7 +++ src/config/config.ts | 1 + src/config/definition.ts | 5 +++ src/layout/ScrollerGrouped.ts | 83 +++++++++++++++++++++++++++++++++++ src/world/World.ts | 23 +++++----- 5 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 src/layout/ScrollerGrouped.ts diff --git a/package/contents/ui/config.ui b/package/contents/ui/config.ui index d1db0ca..1cb9ba2 100644 --- a/package/contents/ui/config.ui +++ b/package/contents/ui/config.ui @@ -267,6 +267,13 @@ + + + + Prevent needlessly obscuring columns + + + diff --git a/src/config/config.ts b/src/config/config.ts index fbefa0f..7d5497e 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -14,6 +14,7 @@ type Config = { skipSwitcher: boolean, scrollingLazy: boolean, scrollingCentered: boolean, + scrollingGrouped: boolean, tiledKeepBelow: boolean, floatingKeepAbove: boolean, windowRules: string, diff --git a/src/config/definition.ts b/src/config/definition.ts index eed4ed9..303d2c4 100644 --- a/src/config/definition.ts +++ b/src/config/definition.ts @@ -127,6 +127,11 @@ const configDef = [ "type": "Bool", "default": false }, + { + "name": "scrollingGrouped", + "type": "Bool", + "default": false + }, { "name": "tiledKeepBelow", "type": "Bool", diff --git a/src/layout/ScrollerGrouped.ts b/src/layout/ScrollerGrouped.ts new file mode 100644 index 0000000..8398420 --- /dev/null +++ b/src/layout/ScrollerGrouped.ts @@ -0,0 +1,83 @@ +class ScrollerGrouped { + private readonly layoutConfig: LayoutConfig; + + constructor(layoutConfig: LayoutConfig) { + this.layoutConfig = layoutConfig; + } + + public focusColumn(desktop: Desktop, column: Column) { + const columnRange = new ScrollerGrouped.ColumnRange(column); + const visibleRange = desktop.getCurrentVisibleRange(); + columnRange.addNeighbors(visibleRange, this.layoutConfig.gapsInnerHorizontal, true); + columnRange.addNeighbors(visibleRange, this.layoutConfig.gapsInnerHorizontal, false); + desktop.scrollCenterRange(columnRange); + } +} + +namespace ScrollerGrouped { + import Range = Desktop.Range; + + export class ColumnRange { + private left: Column; + private right: Column; + private width: number; + + constructor(initialColumn: Column) { + this.left = initialColumn; + this.right = initialColumn; + this.width = initialColumn.getWidth(); + } + + public addNeighbors(visibleRange: Range, gap: number, requireVisible: boolean) { + const grid = this.left.grid; + + let leftColumn: Column|null = this.left; + while (true) { + leftColumn = grid.getPrevColumn(leftColumn); + if ( + leftColumn === null || + requireVisible && !leftColumn.isVisible(visibleRange, true) || + this.width + gap + leftColumn.getWidth() > visibleRange.getWidth() + ) { + break; + } + this.addLeft(leftColumn, gap); + } + + let rightColumn: Column|null = this.right; + while (true) { + rightColumn = grid.getNextColumn(rightColumn); + if ( + rightColumn === null || + requireVisible && !rightColumn.isVisible(visibleRange, true) || + this.width + gap + rightColumn.getWidth() > visibleRange.getWidth() + ) { + break; + } + this.addRight(rightColumn, gap); + } + } + + public addLeft(column: Column, gap: number) { + this.left = column; + this.width += column.getWidth() + gap; + } + + public addRight(column: Column, gap: number) { + this.right = column; + this.width += column.getWidth() + gap; + } + + public getLeft() { + return this.left.getLeft(); + } + + public getRight() { + return this.right.getRight(); + } + + public getWidth() { + return this.width; + } + } +} diff --git a/src/world/World.ts b/src/world/World.ts index 20305c1..caf2bc9 100644 --- a/src/world/World.ts +++ b/src/world/World.ts @@ -21,6 +21,17 @@ class World { this.pinManager = new PinManager(); + const layoutConfig = { + gapsInnerHorizontal: config.gapsInnerHorizontal, + gapsInnerVertical: config.gapsInnerVertical, + stackColumnsByDefault: config.stackColumnsByDefault, + resizeNeighborColumn: config.resizeNeighborColumn, + reMaximize: config.reMaximize, + skipSwitcher: config.skipSwitcher, + tiledKeepBelow: config.tiledKeepBelow, + maximizedKeepAbove: config.floatingKeepAbove, + }; + this.desktopManager = new DesktopManager( this.pinManager, { @@ -31,18 +42,10 @@ class World { overscroll: config.overscroll, scroller: config.scrollingLazy ? new ScrollerLazy() : config.scrollingCentered ? new ScrollerCentered() : + config.scrollingGrouped ? new ScrollerGrouped(layoutConfig) : console.assert(false), }, - { - gapsInnerHorizontal: config.gapsInnerHorizontal, - gapsInnerVertical: config.gapsInnerVertical, - stackColumnsByDefault: config.stackColumnsByDefault, - resizeNeighborColumn: config.resizeNeighborColumn, - reMaximize: config.reMaximize, - skipSwitcher: config.skipSwitcher, - tiledKeepBelow: config.tiledKeepBelow, - maximizedKeepAbove: config.floatingKeepAbove, - }, + layoutConfig, workspace.currentActivity, ); this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager);