add ScrollerGrouped

This commit is contained in:
Peter Fajdiga
2023-12-09 17:03:19 +01:00
parent c65361853c
commit 7314c0ee24
5 changed files with 109 additions and 10 deletions

View File

@@ -267,6 +267,13 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="kcfg_scrollingGrouped">
<property name="text">
<string>Prevent needlessly obscuring columns</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -14,6 +14,7 @@ type Config = {
skipSwitcher: boolean,
scrollingLazy: boolean,
scrollingCentered: boolean,
scrollingGrouped: boolean,
tiledKeepBelow: boolean,
floatingKeepAbove: boolean,
windowRules: string,

View File

@@ -127,6 +127,11 @@ const configDef = [
"type": "Bool",
"default": false
},
{
"name": "scrollingGrouped",
"type": "Bool",
"default": false
},
{
"name": "tiledKeepBelow",
"type": "Bool",

View File

@@ -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;
}
}
}

View File

@@ -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);