Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d0e83ca2f | ||
|
|
b8650a2e1f | ||
|
|
19f275325d | ||
|
|
9a5a28db82 | ||
|
|
6c698c9c82 | ||
|
|
973956ed5e | ||
|
|
f05ae6686d | ||
|
|
3a47fef028 | ||
|
|
ccf0626795 | ||
|
|
9ba3bc6b0b | ||
|
|
99c6a39ac5 | ||
|
|
85d7bbe777 | ||
|
|
6f69252001 | ||
|
|
60bee26e29 | ||
|
|
7d4eab03b9 | ||
|
|
7070e59044 | ||
|
|
7f5745b2cf | ||
|
|
c7752bf20a | ||
|
|
8149100aac | ||
|
|
99bf71f0b9 | ||
|
|
2b882768d9 | ||
|
|
bb42e4d3ad | ||
|
|
c7effc8913 | ||
|
|
2c433867f3 | ||
|
|
e995555074 | ||
|
|
6a1e018df1 | ||
|
|
872a67e6e1 | ||
|
|
5a57ba76d8 | ||
|
|
55c6932338 | ||
|
|
b1d6193e48 | ||
|
|
456bbf30b4 | ||
|
|
24c1fa0a38 | ||
|
|
ac7566d2cf | ||
|
|
195f4e6d30 | ||
|
|
e8f2a50420 | ||
|
|
9910bc7041 | ||
|
|
1b592c5b4b | ||
|
|
75384d9fb4 | ||
|
|
dba92d3826 | ||
|
|
dbb95e0470 | ||
|
|
056149440d | ||
|
|
33be23c6dc | ||
|
|
e31669e499 | ||
|
|
caf2b5a146 | ||
|
|
b7f1876a84 | ||
|
|
f108c4a45e | ||
|
|
0aa5d8c3fa | ||
|
|
1674d14453 | ||
|
|
ca8b78ef04 | ||
|
|
877767cea3 | ||
|
|
f1a18b8276 | ||
|
|
8725bc84e0 | ||
|
|
8c23535e86 | ||
|
|
c0e7234fec | ||
|
|
03acbe1280 | ||
|
|
7ef0c60cb8 | ||
|
|
7e1517bbcb | ||
|
|
a23acd056b | ||
|
|
e908f7fe8a | ||
|
|
ba63c1d4e7 | ||
|
|
bf060cef17 | ||
|
|
0f21f94d02 | ||
|
|
6dd356dc53 | ||
|
|
c99cad96c3 | ||
|
|
b4fe71f91b | ||
|
|
099b9f5d6a | ||
|
|
92f6942eef | ||
|
|
9621c2a75b | ||
|
|
36bc1be8c0 | ||
|
|
68b659744c | ||
|
|
c715289282 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,4 +2,6 @@
|
||||
/package/contents/config/main.xml
|
||||
/karousel*.tar.gz
|
||||
run-ts-tmp.js
|
||||
|
||||
/node_modules
|
||||
/.idea
|
||||
|
||||
19
Makefile
19
Makefile
@@ -1,15 +1,26 @@
|
||||
VERSION = $(shell grep '"Version":' ./package/metadata.json | grep -o '[0-9\.]*')
|
||||
TESTS := true
|
||||
CHECKS := true
|
||||
|
||||
.PHONY: *
|
||||
|
||||
build: tests
|
||||
build: lint test
|
||||
tsc -p ./src/main --outFile ./package/contents/code/main.js
|
||||
mkdir -p ./package/contents/config
|
||||
./run-ts.sh ./src/generators/config > ./package/contents/config/main.xml
|
||||
|
||||
tests:
|
||||
ifeq (${TESTS}, true)
|
||||
npm-install:
|
||||
npm install
|
||||
|
||||
lint: npm-install
|
||||
ifeq (${CHECKS}, true)
|
||||
npx eslint ./src
|
||||
endif
|
||||
|
||||
lint-fix: npm-install
|
||||
npx eslint ./src --fix
|
||||
|
||||
test:
|
||||
ifeq (${CHECKS}, true)
|
||||
./run-ts.sh ./src/tests
|
||||
endif
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ First install the _org.kde.notification_ QML module (_qml-module-org-kde-notific
|
||||
|
||||
Then download the [latest release](https://github.com/peterfajdiga/karousel/releases/latest) and extract it into _~/.local/share/kwin/scripts/_.
|
||||
|
||||
Or clone the repo and run `make install` (requires node and tsc).
|
||||
Or clone the repo and run `make install` (requires npm, node, and tsc).
|
||||
|
||||
## Key bindings
|
||||
The key bindings can be configured in KDE System Settings among KWin's own keyboard shortcuts.
|
||||
|
||||
15
eslint.config.mjs
Normal file
15
eslint.config.mjs
Normal file
@@ -0,0 +1,15 @@
|
||||
// @ts-check
|
||||
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
extends: [tseslint.configs.stylistic],
|
||||
rules: {
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"semi": "error",
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"indent": ["error", 4],
|
||||
},
|
||||
}
|
||||
);
|
||||
1466
package-lock.json
generated
Normal file
1466
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
package.json
Normal file
6
package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"eslint": "^9.24.0",
|
||||
"typescript-eslint": "^8.30.1"
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="kcfg_cursorFollowsFocus">
|
||||
<property name="text">
|
||||
<string>Cursor follows focus (experimental)</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>When a window gains focus, move the cursor to it</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="kcfg_stackColumnsByDefault">
|
||||
<property name="text">
|
||||
@@ -101,6 +111,35 @@
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<widget class="QGroupBox">
|
||||
<property name="title">
|
||||
<string>Touchpad scrolling (Wayland only)</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="kcfg_gestureScroll">
|
||||
<property name="text">
|
||||
<string>Enable scrolling with touchpad gestures
|
||||
(please don't forget to disable KDE's workspace switching gestures)</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Scroll with a three-finger horizontal swipe gesture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<widget class="QCheckBox" name="kcfg_gestureScrollInvert">
|
||||
<property name="text">
|
||||
<string>Invert scroll direction (Natural scrolling)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<widget class="QGroupBox">
|
||||
<property name="title">
|
||||
@@ -110,14 +149,14 @@
|
||||
<item>
|
||||
<widget class="QRadioButton" name="kcfg_tiledKeepBelow">
|
||||
<property name="text">
|
||||
<string>Keep tiled windows below</string>
|
||||
<string>Set "Keep Below" for tiled windows</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="kcfg_floatingKeepAbove">
|
||||
<property name="text">
|
||||
<string>Keep floating windows above</string>
|
||||
<string>Set "Keep Above" for floating windows</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -343,6 +382,36 @@
|
||||
</item>
|
||||
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_gestureScrollStep">
|
||||
<property name="text">
|
||||
<string>Touchpad gesture scrolling speed:</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The amount to scroll per edge-to-edge gesture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QSpinBox" name="kcfg_gestureScrollStep">
|
||||
<property name="suffix">
|
||||
<string> px</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1920</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="10" column="0">
|
||||
<widget class="QLabel" name="label_presetWidths">
|
||||
<property name="text">
|
||||
<string>Preset widths:</string>
|
||||
@@ -352,7 +421,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<item row="10" column="1">
|
||||
<widget class="QLineEdit" name="kcfg_presetWidths">
|
||||
<property name="toolTip">
|
||||
<string>Comma-separated list of widths. Supported units: "px" and "%".</string>
|
||||
@@ -360,14 +429,14 @@
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="10" column="0">
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="label_offScreenOpacity">
|
||||
<property name="text">
|
||||
<string>Obscured window opacity:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<item row="11" column="1">
|
||||
<widget class="QSpinBox" name="kcfg_offScreenOpacity">
|
||||
<property name="suffix">
|
||||
<string> %</string>
|
||||
@@ -380,6 +449,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
@@ -388,6 +458,27 @@
|
||||
<string>Window Rules</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_desktops">
|
||||
<property name="text">
|
||||
<string>Tiled desktops:</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="kcfg_tiledDesktops">
|
||||
<property name="toolTip">
|
||||
<string>Regex string to match desktops by desktop name"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="kcfg_windowRules">
|
||||
<property name="tabChangesFocus">
|
||||
|
||||
@@ -16,6 +16,16 @@ Item {
|
||||
qmlBase.karouselInstance.destroy();
|
||||
}
|
||||
|
||||
Notification {
|
||||
id: notificationInvalidTiledDesktops
|
||||
componentName: "plasma_workspace"
|
||||
eventId: "notification"
|
||||
title: "Karousel"
|
||||
text: "Your Tiled Desktops regex is malformed, please review your Karousel configuration"
|
||||
flags: Notification.Persistent
|
||||
urgency: Notification.HighUrgency
|
||||
}
|
||||
|
||||
Notification {
|
||||
id: notificationInvalidWindowRules
|
||||
componentName: "plasma_workspace"
|
||||
@@ -35,4 +45,29 @@ Item {
|
||||
flags: Notification.Persistent
|
||||
urgency: Notification.HighUrgency
|
||||
}
|
||||
|
||||
SwipeGestureHandler {
|
||||
direction: SwipeGestureHandler.Direction.Left
|
||||
fingerCount: 3
|
||||
onActivated: qmlBase.karouselInstance.gestureScrollFinish()
|
||||
onCancelled: qmlBase.karouselInstance.gestureScrollFinish()
|
||||
onProgressChanged: qmlBase.karouselInstance.gestureScroll(-progress)
|
||||
}
|
||||
|
||||
SwipeGestureHandler {
|
||||
direction: SwipeGestureHandler.Direction.Right
|
||||
fingerCount: 3
|
||||
onActivated: qmlBase.karouselInstance.gestureScrollFinish()
|
||||
onCancelled: qmlBase.karouselInstance.gestureScrollFinish()
|
||||
onProgressChanged: qmlBase.karouselInstance.gestureScroll(progress)
|
||||
}
|
||||
|
||||
DBusCall {
|
||||
id: moveCursorToFocus
|
||||
|
||||
service: "org.kde.kglobalaccel"
|
||||
path: "/component/kwin"
|
||||
method: "invokeShortcut"
|
||||
arguments: ["MoveMouseToFocus"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"Name": "Peter Fajdiga"
|
||||
}],
|
||||
"Id": "karousel",
|
||||
"Version": "0.12",
|
||||
"Version": "0.16",
|
||||
"License": "GPLv3",
|
||||
"Website": "https://github.com/peterfajdiga/karousel",
|
||||
"BugReportUrl": "https://github.com/peterfajdiga/karousel/issues"
|
||||
|
||||
2
src/extern/global.d.ts
vendored
2
src/extern/global.d.ts
vendored
@@ -2,5 +2,7 @@ declare const Qt: Qt;
|
||||
declare const KWin: KWin;
|
||||
declare const Workspace: Workspace;
|
||||
declare const qmlBase: QmlObject;
|
||||
declare const notificationInvalidTiledDesktops: Notification;
|
||||
declare const notificationInvalidWindowRules: Notification;
|
||||
declare const notificationInvalidPresetWidths: Notification;
|
||||
declare const moveCursorToFocus: DBusCall;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
type DocsKeyBinding = {
|
||||
interface DocsKeyBinding {
|
||||
description: string;
|
||||
keySequence: string;
|
||||
};
|
||||
}
|
||||
|
||||
function formatDescription(item: {description: string, comment?: string}) {
|
||||
const suffix = item.comment === undefined ? "" : ` (${item.comment})`;
|
||||
@@ -15,9 +15,9 @@ function printCols(...columns: (string[] | string)[]) {
|
||||
}
|
||||
|
||||
let nRows = Math.min(...columns.filter(
|
||||
(column: string[] | string) => column instanceof Array
|
||||
(column: string[] | string) => column instanceof Array,
|
||||
).map(
|
||||
(column: string[] | string) => column.length
|
||||
(column: string[] | string) => column.length,
|
||||
));
|
||||
if (nRows === Infinity) {
|
||||
// we only have single string columns
|
||||
@@ -28,12 +28,12 @@ function printCols(...columns: (string[] | string)[]) {
|
||||
(column: string[] | string) => {
|
||||
if (column instanceof Array) {
|
||||
return Math.max(...column.map(
|
||||
(cell: string) => cell.length
|
||||
))
|
||||
(cell: string) => cell.length,
|
||||
));
|
||||
} else {
|
||||
return column.length;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function getCell(col: number, row: number) {
|
||||
|
||||
@@ -13,8 +13,8 @@ class ContextualResizer {
|
||||
return;
|
||||
}
|
||||
|
||||
let leftVisibleColumn = grid.getLeftmostVisibleColumn(visibleRange, true);
|
||||
let rightVisibleColumn = grid.getRightmostVisibleColumn(visibleRange, true);
|
||||
const leftVisibleColumn = grid.getLeftmostVisibleColumn(visibleRange);
|
||||
const rightVisibleColumn = grid.getRightmostVisibleColumn(visibleRange);
|
||||
if (leftVisibleColumn === null || rightVisibleColumn === null) {
|
||||
console.assert(false); // should at least see self
|
||||
return;
|
||||
@@ -31,7 +31,7 @@ class ContextualResizer {
|
||||
...this.presetWidths.getWidths(minWidth, maxWidth),
|
||||
],
|
||||
width => width - column.getWidth(),
|
||||
)
|
||||
);
|
||||
if (newWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -50,8 +50,8 @@ class ContextualResizer {
|
||||
return;
|
||||
}
|
||||
|
||||
const leftVisibleColumn = grid.getLeftmostVisibleColumn(visibleRange, true);
|
||||
const rightVisibleColumn = grid.getRightmostVisibleColumn(visibleRange, true);
|
||||
const leftVisibleColumn = grid.getLeftmostVisibleColumn(visibleRange);
|
||||
const rightVisibleColumn = grid.getRightmostVisibleColumn(visibleRange);
|
||||
if (leftVisibleColumn === null || rightVisibleColumn === null) {
|
||||
console.assert(false); // should at least see self
|
||||
return;
|
||||
@@ -78,7 +78,7 @@ class ContextualResizer {
|
||||
...this.presetWidths.getWidths(minWidth, maxWidth),
|
||||
],
|
||||
width => column.getWidth() - width,
|
||||
)
|
||||
);
|
||||
if (newWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -86,4 +86,22 @@ class ContextualResizer {
|
||||
column.setWidth(newWidth, true);
|
||||
desktop.scrollCenterVisible(column);
|
||||
}
|
||||
|
||||
public maximizeWidth(column: Column) {
|
||||
const grid = column.grid;
|
||||
const desktop = grid.desktop;
|
||||
const presetWidths = this.presetWidths.getWidths(column.getMinWidth(), column.getMaxWidth());
|
||||
const maxWidth = presetWidths[presetWidths.length-1];
|
||||
column.setWidth(maxWidth, true);
|
||||
desktop.scrollCenterVisible(column);
|
||||
}
|
||||
|
||||
public minimizeWidth(column: Column) {
|
||||
const grid = column.grid;
|
||||
const desktop = grid.desktop;
|
||||
const presetWidths = this.presetWidths.getWidths(column.getMinWidth(), column.getMaxWidth());
|
||||
const minWidth = presetWidths[0];
|
||||
column.setWidth(minWidth, true);
|
||||
desktop.scrollCenterVisible(column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,16 @@ class RawResizer {
|
||||
}
|
||||
column.setWidth(newWidth, true);
|
||||
}
|
||||
|
||||
public maximizeWidth(column: Column) {
|
||||
const presetWidths = this.presetWidths.getWidths(column.getMinWidth(), column.getMaxWidth());
|
||||
const maxWidth = presetWidths[presetWidths.length-1];
|
||||
column.setWidth(maxWidth, true);
|
||||
}
|
||||
|
||||
public minimizeWidth(column: Column) {
|
||||
const presetWidths = this.presetWidths.getWidths(column.getMinWidth(), column.getMaxWidth());
|
||||
const minWidth = presetWidths[0];
|
||||
column.setWidth(minWidth, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ class CenterClamper {
|
||||
}
|
||||
const lastColumn = desktop.grid.getLastColumn()!;
|
||||
|
||||
let minScroll = Math.round((firstColumn.getWidth() - desktop.tilingArea.width) / 2);
|
||||
let maxScroll = Math.round(desktop.grid.getWidth() - (desktop.tilingArea.width + lastColumn.getWidth()) / 2);
|
||||
const minScroll = Math.round((firstColumn.getWidth() - desktop.tilingArea.width) / 2);
|
||||
const maxScroll = Math.round(desktop.grid.getWidth() - (desktop.tilingArea.width + lastColumn.getWidth()) / 2);
|
||||
return clamp(x, minScroll, maxScroll);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class EdgeClamper {
|
||||
public clampScrollX(desktop: Desktop, x: number) {
|
||||
let minScroll = 0;
|
||||
let maxScroll = desktop.grid.getWidth() - desktop.tilingArea.width;
|
||||
const minScroll = 0;
|
||||
const maxScroll = desktop.grid.getWidth() - desktop.tilingArea.width;
|
||||
if (maxScroll < 0) {
|
||||
return Math.round(maxScroll / 2);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
type Config = {
|
||||
interface Config {
|
||||
gapsOuterTop: number;
|
||||
gapsOuterBottom: number;
|
||||
gapsOuterLeft: number;
|
||||
@@ -11,6 +11,7 @@ type Config = {
|
||||
presetWidths: string;
|
||||
offScreenOpacity: number;
|
||||
untileOnDrag: boolean;
|
||||
cursorFollowsFocus: boolean;
|
||||
stackColumnsByDefault: boolean;
|
||||
resizeNeighborColumn: boolean;
|
||||
reMaximize: boolean;
|
||||
@@ -18,7 +19,11 @@ type Config = {
|
||||
scrollingLazy: boolean;
|
||||
scrollingCentered: boolean;
|
||||
scrollingGrouped: boolean;
|
||||
gestureScroll: boolean;
|
||||
gestureScrollInvert: boolean;
|
||||
gestureScrollStep: number;
|
||||
tiledKeepBelow: boolean;
|
||||
floatingKeepAbove: boolean;
|
||||
windowRules: string;
|
||||
};
|
||||
tiledDesktops: string;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ const defaultWindowRules = `[
|
||||
"class": "(org\\\\.kde\\\\.)?yakuake",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "wl-copy|wl-paste",
|
||||
"caption": "wl-clipboard",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "steam",
|
||||
"caption": "Steam Big Picture Mode",
|
||||
@@ -114,6 +119,11 @@ const configDef = [
|
||||
type: "Bool",
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
name: "cursorFollowsFocus",
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "stackColumnsByDefault",
|
||||
type: "Bool",
|
||||
@@ -149,6 +159,21 @@ const configDef = [
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "gestureScroll",
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "gestureScrollInvert",
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "gestureScrollStep",
|
||||
type: "UInt",
|
||||
default: 1920,
|
||||
},
|
||||
{
|
||||
name: "tiledKeepBelow",
|
||||
type: "Bool",
|
||||
@@ -168,5 +193,10 @@ const configDef = [
|
||||
name: "windowRules",
|
||||
type: "String",
|
||||
default: defaultWindowRules,
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "tiledDesktops",
|
||||
type: "String",
|
||||
default: ".*",
|
||||
},
|
||||
];
|
||||
|
||||
3
src/lib/extern/dbuscall.ts
vendored
Normal file
3
src/lib/extern/dbuscall.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
interface DBusCall extends QmlObject {
|
||||
call(): void;
|
||||
}
|
||||
25
src/lib/extern/kwin.ts
vendored
25
src/lib/extern/kwin.ts
vendored
@@ -1,10 +1,10 @@
|
||||
type KWin = {
|
||||
interface KWin {
|
||||
__brand: "KWin";
|
||||
|
||||
readConfig(key: string, defaultValue: any): any;
|
||||
};
|
||||
}
|
||||
|
||||
type Workspace = {
|
||||
interface Workspace {
|
||||
__brand: "Workspace";
|
||||
|
||||
readonly activities: string[];
|
||||
@@ -28,7 +28,7 @@ type Workspace = {
|
||||
readonly virtualScreenSizeChanged: QSignal<[]>;
|
||||
|
||||
clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop): QmlRect;
|
||||
};
|
||||
}
|
||||
|
||||
const enum ClientAreaOption {
|
||||
PlacementArea,
|
||||
@@ -48,10 +48,10 @@ const enum MaximizedMode {
|
||||
Maximized,
|
||||
}
|
||||
|
||||
type Tile = { __brand: "Tile" };
|
||||
type Output = { __brand: "Output" };
|
||||
interface Tile { __brand: "Tile" }
|
||||
interface Output { __brand: "Output" }
|
||||
|
||||
type KwinClient = {
|
||||
interface KwinClient {
|
||||
__brand: "KwinClient";
|
||||
|
||||
readonly caption: string;
|
||||
@@ -96,15 +96,16 @@ type KwinClient = {
|
||||
readonly frameGeometryChanged: QSignal<[oldGeometry: QmlRect]>;
|
||||
|
||||
setMaximize(vertically: boolean, horizontally: boolean): void;
|
||||
};
|
||||
}
|
||||
|
||||
type KwinDesktop = {
|
||||
interface KwinDesktop {
|
||||
__brand: "KwinDesktop";
|
||||
|
||||
readonly id: string;
|
||||
};
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
type ShortcutHandler = QmlObject & {
|
||||
interface ShortcutHandler extends QmlObject {
|
||||
readonly activated: QSignal<[]>;
|
||||
destroy(): void;
|
||||
};
|
||||
}
|
||||
|
||||
4
src/lib/extern/notification.ts
vendored
4
src/lib/extern/notification.ts
vendored
@@ -1,3 +1,3 @@
|
||||
type Notification = QmlObject & {
|
||||
interface Notification extends QmlObject {
|
||||
sendEvent(): void;
|
||||
};
|
||||
}
|
||||
|
||||
34
src/lib/extern/qt.ts
vendored
34
src/lib/extern/qt.ts
vendored
@@ -1,56 +1,52 @@
|
||||
type Console = {
|
||||
interface Console {
|
||||
__brand: "Console";
|
||||
|
||||
log(...args: any[]): void;
|
||||
assert(assertion: boolean, message?: string): void;
|
||||
};
|
||||
}
|
||||
|
||||
type Qt = {
|
||||
interface Qt {
|
||||
__brand: "Qt";
|
||||
|
||||
rect(x: number, y: number, width: number, height: number): QmlRect;
|
||||
createQmlObject(qml: string, parent: QmlObject): QmlObject;
|
||||
};
|
||||
}
|
||||
|
||||
type QmlObject = { __brand: "QmlObject" };
|
||||
interface QmlObject { __brand: "QmlObject" }
|
||||
|
||||
type QmlPoint = {
|
||||
interface QmlPoint {
|
||||
__brand: "QmlPoint";
|
||||
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
}
|
||||
|
||||
type QmlRect = {
|
||||
interface QmlRect {
|
||||
__brand: "QmlRect";
|
||||
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
readonly top: number;
|
||||
readonly bottom: number; // top + height
|
||||
readonly left: number;
|
||||
readonly right: number; // left + width
|
||||
};
|
||||
}
|
||||
|
||||
type QmlSize = {
|
||||
interface QmlSize {
|
||||
__brand: "QmlSize";
|
||||
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}
|
||||
|
||||
type QSignal<T extends unknown[]> = {
|
||||
interface QSignal<T extends unknown[]> {
|
||||
__brand: "QSignal";
|
||||
|
||||
connect(handler: (...args: [...T]) => void): void;
|
||||
disconnect(handler: (...args: [...T]) => void): void;
|
||||
};
|
||||
}
|
||||
|
||||
type QmlTimer = QmlObject & {
|
||||
interface QmlTimer extends QmlObject {
|
||||
interval: number;
|
||||
readonly triggered: QSignal<[]>;
|
||||
restart(): void;
|
||||
destroy(): void;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ class Actions {
|
||||
if (leftColumn === null) {
|
||||
return;
|
||||
}
|
||||
leftColumn.focus();
|
||||
}
|
||||
leftColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly focusRight = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const rightColumn = grid.getRightColumn(column);
|
||||
if (rightColumn === null) {
|
||||
return;
|
||||
}
|
||||
rightColumn.focus();
|
||||
}
|
||||
rightColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly focusUp = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const aboveWindow = column.getAboveWindow(window);
|
||||
@@ -25,7 +25,7 @@ class Actions {
|
||||
return;
|
||||
}
|
||||
aboveWindow.focus();
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focusDown = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const belowWindow = column.getBelowWindow(window);
|
||||
@@ -33,7 +33,7 @@ class Actions {
|
||||
return;
|
||||
}
|
||||
belowWindow.focus();
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focusNext = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const belowWindow = column.getBelowWindow(window);
|
||||
@@ -46,7 +46,7 @@ class Actions {
|
||||
}
|
||||
rightColumn.getFirstWindow().focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focusPrevious = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const aboveWindow = column.getAboveWindow(window);
|
||||
@@ -59,25 +59,33 @@ class Actions {
|
||||
}
|
||||
leftColumn.getLastWindow().focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focusStart = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
if (firstColumn === null) {
|
||||
return;
|
||||
}
|
||||
firstColumn.focus();
|
||||
}
|
||||
firstColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly focusEnd = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
if (lastColumn === null) {
|
||||
return;
|
||||
}
|
||||
lastColumn.focus();
|
||||
}
|
||||
lastColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly windowMoveLeft = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
@@ -86,40 +94,40 @@ class Actions {
|
||||
if (leftColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(leftColumn, true);
|
||||
window.moveToColumn(leftColumn, true, FocusPassing.Type.None);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
} else {
|
||||
// move from shared column into own column
|
||||
const newColumn = new Column(grid, grid.getLeftColumn(column));
|
||||
window.moveToColumn(newColumn, true);
|
||||
window.moveToColumn(newColumn, true, FocusPassing.Type.None);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly windowMoveRight = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid, bottom: boolean = true) => {
|
||||
public readonly windowMoveRight = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid, bottom = true) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
// move from own column into existing column
|
||||
const rightColumn = grid.getRightColumn(column);
|
||||
if (rightColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(rightColumn, bottom);
|
||||
window.moveToColumn(rightColumn, bottom, FocusPassing.Type.None);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
} else {
|
||||
// move from shared column into own column
|
||||
const newColumn = new Column(grid, column);
|
||||
window.moveToColumn(newColumn, true);
|
||||
window.moveToColumn(newColumn, true, FocusPassing.Type.None);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// TODO (optimization): only arrange moved windows
|
||||
public readonly windowMoveUp = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
column.moveWindowUp(window);
|
||||
}
|
||||
};
|
||||
|
||||
// TODO (optimization): only arrange moved windows
|
||||
public readonly windowMoveDown = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
column.moveWindowDown(window);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly windowMoveNext = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const canMoveDown = window !== column.getLastWindow();
|
||||
@@ -128,7 +136,7 @@ class Actions {
|
||||
} else {
|
||||
this.windowMoveRight(cm, dm, window, column, grid, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly windowMovePrevious = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const canMoveUp = window !== column.getFirstWindow();
|
||||
@@ -137,67 +145,79 @@ class Actions {
|
||||
} else {
|
||||
this.windowMoveLeft(cm, dm, window, column, grid);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly windowMoveStart = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const newColumn = new Column(grid, null);
|
||||
window.moveToColumn(newColumn, true);
|
||||
}
|
||||
window.moveToColumn(newColumn, true, FocusPassing.Type.None);
|
||||
};
|
||||
|
||||
public readonly windowMoveEnd = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const newColumn = new Column(grid, grid.getLastColumn());
|
||||
window.moveToColumn(newColumn, true);
|
||||
}
|
||||
window.moveToColumn(newColumn, true, FocusPassing.Type.None);
|
||||
};
|
||||
|
||||
public readonly windowToggleFloating = (cm: ClientManager, dm: DesktopManager) => {
|
||||
if (Workspace.activeWindow === null) {
|
||||
return;
|
||||
}
|
||||
cm.toggleFloatingClient(Workspace.activeWindow);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnMoveLeft = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
grid.moveColumnLeft(column);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnMoveRight = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
grid.moveColumnRight(column);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnMoveStart = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
grid.moveColumn(column, null);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnMoveEnd = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
grid.moveColumn(column, grid.getLastColumn());
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnToggleStacked = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
column.toggleStacked();
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnWidthIncrease = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
this.config.columnResizer.increaseWidth(column);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnWidthDecrease = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
this.config.columnResizer.decreaseWidth(column);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnWidthMaximize = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
this.config.columnResizer.maximizeWidth(column);
|
||||
};
|
||||
|
||||
|
||||
public readonly columnWidthMinimize = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
this.config.columnResizer.minimizeWidth(column);
|
||||
};
|
||||
|
||||
public readonly cyclePresetWidths = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const nextWidth = this.config.presetWidths.next(column.getWidth(), column.getMinWidth(), column.getMaxWidth());
|
||||
column.setWidth(nextWidth, true);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly cyclePresetWidthsReverse = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const nextWidth = this.config.presetWidths.prev(column.getWidth(), column.getMinWidth(), column.getMaxWidth());
|
||||
column.setWidth(nextWidth, true);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnsWidthEqualize = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const visibleRange = desktop.getCurrentVisibleRange();
|
||||
const visibleColumns = Array.from(desktop.grid.getVisibleColumns(visibleRange, true));
|
||||
const visibleColumns = Array.from(desktop.grid.getVisibleColumns(visibleRange));
|
||||
|
||||
const availableSpace = desktop.tilingArea.width;
|
||||
const gapsWidth = desktop.grid.config.gapsInnerHorizontal * (visibleColumns.length-1);
|
||||
@@ -211,7 +231,7 @@ class Actions {
|
||||
visibleColumns[0],
|
||||
visibleColumns[visibleColumns.length - 1],
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnsSqueezeLeft = (cm: ClientManager, dm: DesktopManager, window: Window, focusedColumn: Column, grid: Grid) => {
|
||||
const visibleRange = grid.desktop.getCurrentVisibleRange();
|
||||
@@ -219,7 +239,7 @@ class Actions {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentVisibleColumns = Array.from(grid.getVisibleColumns(visibleRange, true));
|
||||
const currentVisibleColumns = Array.from(grid.getVisibleColumns(visibleRange));
|
||||
console.assert(currentVisibleColumns.includes(focusedColumn), "should at least contain the focused column");
|
||||
|
||||
const targetColumn = grid.getLeftColumn(currentVisibleColumns[0]);
|
||||
@@ -238,7 +258,7 @@ class Actions {
|
||||
break; // don't scroll past the currently focused column
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnsSqueezeRight = (cm: ClientManager, dm: DesktopManager, window: Window, focusedColumn: Column, grid: Grid) => {
|
||||
const visibleRange = grid.desktop.getCurrentVisibleRange();
|
||||
@@ -246,7 +266,7 @@ class Actions {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentVisibleColumns = Array.from(grid.getVisibleColumns(visibleRange, true));
|
||||
const currentVisibleColumns = Array.from(grid.getVisibleColumns(visibleRange));
|
||||
console.assert(currentVisibleColumns.includes(focusedColumn), "should at least contain the focused column");
|
||||
|
||||
const targetColumn = grid.getRightColumn(currentVisibleColumns[currentVisibleColumns.length-1]);
|
||||
@@ -265,7 +285,7 @@ class Actions {
|
||||
break; // don't scroll past the currently focused column
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly squeezeColumns = (columns: Column[]) => {
|
||||
const firstColumn = columns[0];
|
||||
@@ -286,37 +306,48 @@ class Actions {
|
||||
columns.forEach((column, index) => column.setWidth(widths[index], true));
|
||||
desktop.scrollCenterRange(Range.fromRanges(firstColumn, lastColumn));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollLeft = (cm: ClientManager, dm: DesktopManager) => {
|
||||
this.gridScroll(dm, -this.config.manualScrollStep);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollRight = (cm: ClientManager, dm: DesktopManager) => {
|
||||
this.gridScroll(dm, this.config.manualScrollStep);
|
||||
}
|
||||
};
|
||||
|
||||
private readonly gridScroll = (desktopManager: DesktopManager, amount: number) => {
|
||||
desktopManager.getCurrentDesktop().adjustScroll(amount, false);
|
||||
}
|
||||
const desktop = desktopManager.getCurrentDesktop();
|
||||
if (desktop !== undefined) {
|
||||
desktop.adjustScroll(amount, false);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollStart = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
if (firstColumn === null) {
|
||||
return;
|
||||
}
|
||||
grid.desktop.scrollToColumn(firstColumn, false);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollEnd = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
if (lastColumn === null) {
|
||||
return;
|
||||
}
|
||||
grid.desktop.scrollToColumn(lastColumn, false);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollFocused = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const scrollAmount = Range.minus(column, grid.desktop.getCurrentVisibleRange());
|
||||
@@ -325,11 +356,15 @@ class Actions {
|
||||
} else {
|
||||
grid.desktop.scrollToColumn(column, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollLeftColumn = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange());
|
||||
if (column === null) {
|
||||
return;
|
||||
}
|
||||
@@ -340,11 +375,15 @@ class Actions {
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(leftColumn, false);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollRightColumn = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange());
|
||||
if (column === null) {
|
||||
return;
|
||||
}
|
||||
@@ -355,19 +394,23 @@ class Actions {
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(rightColumn, false);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly screenSwitch = (cm: ClientManager, dm: DesktopManager) => {
|
||||
dm.selectScreen(Workspace.activeScreen);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focus = (columnIndex: number, cm: ClientManager, dm: DesktopManager) => {
|
||||
const grid = dm.getCurrentDesktop().grid;
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
targetColumn.focus();
|
||||
targetColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly windowMoveToColumn = (columnIndex: number, cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
@@ -375,7 +418,7 @@ class Actions {
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(targetColumn, true);
|
||||
window.moveToColumn(targetColumn, true, FocusPassing.Type.None);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
};
|
||||
|
||||
@@ -396,7 +439,11 @@ class Actions {
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = dm.getDesktopInCurrentActivity(kwinDesktop).grid;
|
||||
const newDesktop = dm.getDesktopInCurrentActivity(kwinDesktop);
|
||||
if (newDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = newDesktop.grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
@@ -408,7 +455,11 @@ class Actions {
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = dm.getDesktopInCurrentActivity(kwinDesktop).grid;
|
||||
const newDesktop = dm.getDesktopInCurrentActivity(kwinDesktop);
|
||||
if (newDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = newDesktop.grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
@@ -417,17 +468,19 @@ class Actions {
|
||||
}
|
||||
|
||||
namespace Actions {
|
||||
export type Config = {
|
||||
export interface Config {
|
||||
manualScrollStep: number;
|
||||
presetWidths: {
|
||||
next: (currentWidth: number, minWidth: number, maxWidth: number) => number;
|
||||
prev: (currentWidth: number, minWidth: number, maxWidth: number) => number
|
||||
};
|
||||
};
|
||||
columnResizer: ColumnResizer;
|
||||
};
|
||||
}
|
||||
|
||||
export type ColumnResizer = {
|
||||
export interface ColumnResizer {
|
||||
increaseWidth(column: Column): void;
|
||||
decreaseWidth(column: Column): void;
|
||||
};
|
||||
maximizeWidth(column: Column): void;
|
||||
minimizeWidth(column: Column): void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,16 @@ function getKeyBindings(world: World, actions: Actions): KeyBinding[] {
|
||||
defaultKeySequence: "Meta+Ctrl+-",
|
||||
action: () => world.doIfTiledFocused(actions.columnWidthDecrease),
|
||||
},
|
||||
{
|
||||
name: "column-width-maximize",
|
||||
description: "Increase column width to maximum",
|
||||
action: () => world.doIfTiledFocused(actions.columnWidthMaximize),
|
||||
},
|
||||
{
|
||||
name: "column-width-minimize",
|
||||
description: "Decrease column width to minimum",
|
||||
action: () => world.doIfTiledFocused(actions.columnWidthMinimize),
|
||||
},
|
||||
{
|
||||
name: "cycle-preset-widths",
|
||||
description: "Cycle through preset column widths",
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
type KeyBinding = {
|
||||
interface KeyBinding {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultKeySequence?: string;
|
||||
action: () => void;
|
||||
};
|
||||
}
|
||||
|
||||
type NumKeyBinding = {
|
||||
interface NumKeyBinding {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultModifiers: string;
|
||||
fKeys: boolean;
|
||||
action: (i: number) => void;
|
||||
};
|
||||
}
|
||||
|
||||
function catchWrap(f: () => void) {
|
||||
return () => {
|
||||
|
||||
@@ -21,7 +21,7 @@ class Column {
|
||||
if (targetGrid === this.grid) {
|
||||
this.grid.moveColumn(this, leftColumn);
|
||||
} else {
|
||||
this.grid.onColumnRemoved(this, this.isFocused());
|
||||
this.grid.onColumnRemoved(this, this.isFocused() ? FocusPassing.Type.Immediate : FocusPassing.Type.None);
|
||||
this.grid = targetGrid;
|
||||
targetGrid.onColumnAdded(this, leftColumn);
|
||||
for (const window of this.windows.iterator()) {
|
||||
@@ -79,7 +79,7 @@ class Column {
|
||||
public getMinWidth() {
|
||||
let maxMinWidth = Column.minWidth;
|
||||
for (const window of this.windows.iterator()) {
|
||||
const minWidth = window.client.kwinClient.minSize.width;
|
||||
const minWidth = window.client.kwinClient.minSize.width.ceil();
|
||||
if (minWidth > maxMinWidth) {
|
||||
maxMinWidth = minWidth;
|
||||
}
|
||||
@@ -195,12 +195,8 @@ class Column {
|
||||
return this.focusTaker;
|
||||
}
|
||||
|
||||
public focus() {
|
||||
const window = this.getFocusTaker() ?? this.windows.getFirst();
|
||||
if (window === null) {
|
||||
return;
|
||||
}
|
||||
window.focus();
|
||||
public getWindowToFocus() {
|
||||
return this.getFocusTaker() ?? this.windows.getFirst()!;
|
||||
}
|
||||
|
||||
public isFocused() {
|
||||
@@ -273,7 +269,7 @@ class Column {
|
||||
this.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
|
||||
public onWindowRemoved(window: Window, passFocus: boolean) {
|
||||
public onWindowRemoved(window: Window, passFocus: FocusPassing.Type) {
|
||||
const lastWindow = this.windows.length() === 1;
|
||||
const windowToFocus = this.getAboveWindow(window) ?? this.getBelowWindow(window);
|
||||
|
||||
@@ -288,8 +284,15 @@ class Column {
|
||||
this.destroy(passFocus);
|
||||
} else {
|
||||
this.resizeWindows();
|
||||
if (passFocus && windowToFocus !== null) {
|
||||
windowToFocus.focus();
|
||||
if (windowToFocus !== null) {
|
||||
switch (passFocus) {
|
||||
case FocusPassing.Type.Immediate:
|
||||
windowToFocus.focus();
|
||||
break;
|
||||
case FocusPassing.Type.OnUnfocus:
|
||||
this.grid.focusPasser.request(windowToFocus.client.kwinClient);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,18 +300,18 @@ class Column {
|
||||
}
|
||||
|
||||
public onWindowFocused(window: Window) {
|
||||
this.grid.onColumnFocused(this);
|
||||
this.grid.onColumnFocused(this, window);
|
||||
this.focusTaker = window;
|
||||
}
|
||||
|
||||
public restoreToTiled() {
|
||||
public restoreToTiled(focusedWindow: Window) {
|
||||
const lastFocusedWindow = this.getFocusTaker();
|
||||
if (lastFocusedWindow !== null) {
|
||||
if (lastFocusedWindow !== null && lastFocusedWindow !== focusedWindow) {
|
||||
lastFocusedWindow.restoreToTiled();
|
||||
}
|
||||
}
|
||||
|
||||
private destroy(passFocus: boolean) {
|
||||
private destroy(passFocus: FocusPassing.Type) {
|
||||
this.grid.onColumnRemoved(this, passFocus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Desktop {
|
||||
public readonly grid: Grid;
|
||||
private scrollX: number;
|
||||
private gestureScrollXInitial: number | null;
|
||||
private dirty: boolean;
|
||||
private dirtyScroll: boolean;
|
||||
private dirtyPins: boolean;
|
||||
@@ -13,12 +14,14 @@ class Desktop {
|
||||
private readonly config: Desktop.Config,
|
||||
private readonly getScreen: () => Output,
|
||||
layoutConfig: LayoutConfig,
|
||||
focusPasser: FocusPassing.Passer,
|
||||
) {
|
||||
this.scrollX = 0;
|
||||
this.gestureScrollXInitial = null;
|
||||
this.dirty = true;
|
||||
this.dirtyScroll = true;
|
||||
this.dirtyPins = true;
|
||||
this.grid = new Grid(this, layoutConfig);
|
||||
this.grid = new Grid(this, layoutConfig, focusPasser);
|
||||
this.clientArea = Desktop.getClientArea(this.getScreen(), kwinDesktop);
|
||||
this.tilingArea = Desktop.getTilingArea(this.clientArea, kwinDesktop, pinManager, config);
|
||||
}
|
||||
@@ -52,7 +55,7 @@ class Desktop {
|
||||
top,
|
||||
right - left,
|
||||
bottom - top,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public scrollIntoView(range: Range) {
|
||||
@@ -124,6 +127,36 @@ class Desktop {
|
||||
this.setScroll(this.scrollX + dx, force);
|
||||
}
|
||||
|
||||
public gestureScroll(amount: number) {
|
||||
if (!this.config.gestureScroll) {
|
||||
return;
|
||||
}
|
||||
if (this.gestureScrollXInitial === null) {
|
||||
this.gestureScrollXInitial = this.scrollX;
|
||||
}
|
||||
|
||||
if (this.config.gestureScrollInvert) {
|
||||
amount = -amount;
|
||||
}
|
||||
this.setScroll(this.gestureScrollXInitial + this.config.gestureScrollStep * amount, false);
|
||||
}
|
||||
|
||||
public gestureScrollFinish(focusedWindow: Window|null) {
|
||||
const scrolledRight = this.scrollX > this.gestureScrollXInitial!;
|
||||
this.gestureScrollXInitial = null;
|
||||
|
||||
const visibleRange = this.getCurrentVisibleRange();
|
||||
if (focusedWindow !== null && !Range.contains(visibleRange, focusedWindow.column)) {
|
||||
// the focused window is no longer visible, find a new window to focus
|
||||
const focusTargetColumn = scrolledRight ?
|
||||
this.grid.getLeftmostVisibleColumn(visibleRange) :
|
||||
this.grid.getRightmostVisibleColumn(visibleRange);
|
||||
if (focusTargetColumn !== null) {
|
||||
focusTargetColumn.getWindowToFocus().focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public arrange() {
|
||||
// TODO (optimization): only arrange visible windows
|
||||
this.updateArea();
|
||||
@@ -155,14 +188,17 @@ class Desktop {
|
||||
}
|
||||
|
||||
namespace Desktop {
|
||||
export type Config = {
|
||||
export interface Config {
|
||||
marginTop: number;
|
||||
marginBottom: number;
|
||||
marginLeft: number;
|
||||
marginRight: number;
|
||||
gestureScroll: boolean;
|
||||
gestureScrollInvert: boolean;
|
||||
gestureScrollStep: number;
|
||||
scroller: Desktop.Scroller;
|
||||
clamper: Desktop.Clamper;
|
||||
};
|
||||
}
|
||||
|
||||
export class ColumnRange {
|
||||
private left: Column;
|
||||
@@ -236,11 +272,11 @@ namespace Desktop {
|
||||
}
|
||||
}
|
||||
|
||||
export type Scroller = {
|
||||
export interface Scroller {
|
||||
scrollToColumn(desktop: Desktop, column: Column): void;
|
||||
};
|
||||
}
|
||||
|
||||
export type Clamper = {
|
||||
export interface Clamper {
|
||||
clampScrollX(desktop: Desktop, x: number): number;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
class Grid {
|
||||
public readonly desktop: Desktop;
|
||||
public readonly config: LayoutConfig;
|
||||
public readonly focusPasser: FocusPassing.Passer;
|
||||
private readonly columns: LinkedList<Column>;
|
||||
private lastFocusedColumn: Column|null;
|
||||
private width: number;
|
||||
private userResize: boolean; // is any part of the grid being resized by the user
|
||||
private readonly userResizeFinishedDelayer: Delayer;
|
||||
|
||||
constructor(desktop: Desktop, config: LayoutConfig) {
|
||||
constructor(desktop: Desktop, config: LayoutConfig, focusPasser: FocusPassing.Passer) {
|
||||
this.desktop = desktop;
|
||||
this.config = config;
|
||||
this.focusPasser = focusPasser;
|
||||
this.columns = new LinkedList();
|
||||
this.lastFocusedColumn = null;
|
||||
this.width = 0;
|
||||
@@ -104,7 +106,7 @@ class Grid {
|
||||
this.width = x - this.config.gapsInnerHorizontal;
|
||||
}
|
||||
|
||||
public getLeftmostVisibleColumn(visibleRange: Range, fullyVisible: boolean) {
|
||||
public getLeftmostVisibleColumn(visibleRange: Range) {
|
||||
for (const column of this.columns.iterator()) {
|
||||
if (Range.contains(visibleRange, column)) {
|
||||
return column;
|
||||
@@ -113,7 +115,7 @@ class Grid {
|
||||
return null;
|
||||
}
|
||||
|
||||
public getRightmostVisibleColumn(visibleRange: Range, fullyVisible: boolean) {
|
||||
public getRightmostVisibleColumn(visibleRange: Range) {
|
||||
let last = null;
|
||||
for (const column of this.columns.iterator()) {
|
||||
if (Range.contains(visibleRange, column)) {
|
||||
@@ -125,7 +127,7 @@ class Grid {
|
||||
return last;
|
||||
}
|
||||
|
||||
public *getVisibleColumns(visibleRange: Range, fullyVisible: boolean) {
|
||||
public *getVisibleColumns(visibleRange: Range) {
|
||||
for (const column of this.columns.iterator()) {
|
||||
if (Range.contains(visibleRange, column)) {
|
||||
yield column;
|
||||
@@ -156,7 +158,7 @@ class Grid {
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public onColumnRemoved(column: Column, passFocus: boolean) {
|
||||
public onColumnRemoved(column: Column, passFocus: FocusPassing.Type) {
|
||||
const isLastColumn = this.columns.length() === 1;
|
||||
const rightColumn = this.getRightColumn(column);
|
||||
const columnToFocus = isLastColumn ? null : this.getLeftColumn(column) ?? rightColumn;
|
||||
@@ -168,11 +170,17 @@ class Grid {
|
||||
this.columnsSetX(rightColumn);
|
||||
|
||||
this.desktop.onLayoutChanged();
|
||||
if (passFocus && columnToFocus !== null) {
|
||||
columnToFocus.focus();
|
||||
} else {
|
||||
this.desktop.autoAdjustScroll();
|
||||
if (columnToFocus !== null) {
|
||||
switch (passFocus) {
|
||||
case FocusPassing.Type.Immediate:
|
||||
columnToFocus.getWindowToFocus().focus();
|
||||
return;
|
||||
case FocusPassing.Type.OnUnfocus:
|
||||
this.focusPasser.request(columnToFocus.getWindowToFocus().client.kwinClient);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public onColumnWidthChanged(column: Column) {
|
||||
@@ -184,10 +192,10 @@ class Grid {
|
||||
}
|
||||
}
|
||||
|
||||
public onColumnFocused(column: Column) {
|
||||
public onColumnFocused(column: Column, window: Window) {
|
||||
const lastFocusedColumn = this.getLastFocusedColumn();
|
||||
if (lastFocusedColumn !== null && lastFocusedColumn !== column) {
|
||||
lastFocusedColumn.restoreToTiled();
|
||||
if (lastFocusedColumn !== null) {
|
||||
lastFocusedColumn.restoreToTiled(window);
|
||||
}
|
||||
this.lastFocusedColumn = column;
|
||||
this.desktop.scrollToColumn(column, false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
type LayoutConfig = {
|
||||
interface LayoutConfig {
|
||||
gapsInnerHorizontal: number;
|
||||
gapsInnerVertical: number;
|
||||
stackOffsetX: number;
|
||||
@@ -11,4 +11,4 @@ type LayoutConfig = {
|
||||
tiledKeepBelow: boolean;
|
||||
maximizedKeepAbove: boolean;
|
||||
untileOnDrag: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
type Range = {
|
||||
interface Range {
|
||||
getLeft(): number;
|
||||
getRight(): number;
|
||||
getWidth(): number;
|
||||
};
|
||||
}
|
||||
|
||||
namespace Range {
|
||||
export function create(x: number, width: number) {
|
||||
|
||||
@@ -7,7 +7,7 @@ class Window {
|
||||
|
||||
constructor(client: ClientWrapper, column: Column) {
|
||||
this.client = client;
|
||||
this.height = client.kwinClient.frameGeometry.height;
|
||||
this.height = client.kwinClient.frameGeometry.height.round();
|
||||
|
||||
let maximizedMode = this.client.getMaximizedMode();
|
||||
if (maximizedMode === undefined) {
|
||||
@@ -23,11 +23,11 @@ class Window {
|
||||
column.onWindowAdded(this, true);
|
||||
}
|
||||
|
||||
public moveToColumn(targetColumn: Column, bottom: boolean) {
|
||||
public moveToColumn(targetColumn: Column, bottom: boolean, passFocus: FocusPassing.Type) {
|
||||
if (targetColumn === this.column) {
|
||||
return;
|
||||
}
|
||||
this.column.onWindowRemoved(this, this.isFocused() && targetColumn.grid !== this.column.grid);
|
||||
this.column.onWindowRemoved(this, passFocus);
|
||||
this.column = targetColumn;
|
||||
targetColumn.onWindowAdded(this, bottom);
|
||||
}
|
||||
@@ -61,6 +61,11 @@ class Window {
|
||||
|
||||
public focus() {
|
||||
this.client.focus();
|
||||
const kwinClient = this.client.kwinClient;
|
||||
if (!this.isFocused()) {
|
||||
// in some situations focus assignment just doesn't work, let's do it later
|
||||
this.column.grid.focusPasser.request(kwinClient);
|
||||
}
|
||||
}
|
||||
|
||||
public isFocused() {
|
||||
@@ -118,18 +123,18 @@ class Window {
|
||||
|
||||
public onFrameGeometryChanged() {
|
||||
const newGeometry = this.client.kwinClient.frameGeometry;
|
||||
this.column.setWidth(newGeometry.width, true);
|
||||
this.column.setWidth(newGeometry.width.round(), true);
|
||||
this.column.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.column.onWindowRemoved(this, passFocus);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Window {
|
||||
export type State = {
|
||||
export interface State {
|
||||
fullScreen: boolean;
|
||||
maximizedMode: MaximizedMode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
30
src/lib/rules/DesktopFilter.ts
Normal file
30
src/lib/rules/DesktopFilter.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
class DesktopFilter {
|
||||
private readonly desktopRegex: RegExp | null; // null means all desktops
|
||||
|
||||
constructor(desktopsConfig: string) {
|
||||
this.desktopRegex = DesktopFilter.parseDesktopConfig(desktopsConfig);
|
||||
}
|
||||
|
||||
public shouldWorkOnDesktop(kwinDesktop: KwinDesktop): boolean {
|
||||
if (this.desktopRegex === null) {
|
||||
return true; // Work on all desktops
|
||||
}
|
||||
return this.desktopRegex.test(kwinDesktop.name);
|
||||
}
|
||||
|
||||
private static parseDesktopConfig(config: string): RegExp | null {
|
||||
const trimmed = config.trim();
|
||||
|
||||
if (trimmed.length === 0) {
|
||||
return null; // Empty config means work on all desktops
|
||||
}
|
||||
|
||||
try {
|
||||
return new RegExp(`^${trimmed}$`);
|
||||
} catch (e) {
|
||||
notificationInvalidTiledDesktops.sendEvent();
|
||||
log(`Invalid regex pattern in tiledDesktops config: ${trimmed}. Working on all desktops.`);
|
||||
return null; // Invalid regex means work on all desktops as fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
type WindowRule = {
|
||||
interface WindowRule {
|
||||
class: string | undefined;
|
||||
caption: string | undefined;
|
||||
tile: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class WindowRuleEnforcer {
|
||||
const ruleCaption = WindowRuleEnforcer.parseRegex(windowRule.caption);
|
||||
const ruleString = ClientMatcher.getRuleString(
|
||||
WindowRuleEnforcer.wrapParens(ruleClass),
|
||||
WindowRuleEnforcer.wrapParens(ruleCaption)
|
||||
WindowRuleEnforcer.wrapParens(ruleCaption),
|
||||
);
|
||||
|
||||
(windowRule.tile ? tileRegexes : floatRegexes).push(ruleString);
|
||||
|
||||
@@ -17,9 +17,9 @@ class Delayer {
|
||||
}
|
||||
|
||||
function initQmlTimer() {
|
||||
return <QmlTimer>Qt.createQmlObject(
|
||||
return Qt.createQmlObject(
|
||||
`import QtQuick 6.0
|
||||
Timer {}`,
|
||||
qmlBase
|
||||
);
|
||||
qmlBase,
|
||||
) as QmlTimer;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class ShortcutAction {
|
||||
` :
|
||||
"";
|
||||
|
||||
return <ShortcutHandler>Qt.createQmlObject(
|
||||
return Qt.createQmlObject(
|
||||
`import QtQuick 6.0
|
||||
import org.kde.kwin 3.0
|
||||
ShortcutHandler {
|
||||
@@ -24,14 +24,14 @@ ShortcutHandler {
|
||||
text: "Karousel: ${keyBinding.description}";
|
||||
${sequenceLine}}`,
|
||||
qmlBase,
|
||||
);
|
||||
) as ShortcutHandler;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ShortcutAction {
|
||||
export type KeyBinding = {
|
||||
export interface KeyBinding {
|
||||
name: string;
|
||||
description: string;
|
||||
defaultKeySequence?: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ function fillSpace(availableSpace: number, items: { min: number, max: number }[]
|
||||
}
|
||||
}
|
||||
|
||||
type Range = {
|
||||
interface Range {
|
||||
start: number,
|
||||
end: number,
|
||||
n: number,
|
||||
};
|
||||
}
|
||||
|
||||
type Fencepost = {
|
||||
interface Fencepost {
|
||||
value: number,
|
||||
nMin: number,
|
||||
nMax: number,
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
interface Number {
|
||||
round(this: number): number;
|
||||
floor(this: number): number;
|
||||
ceil(this: number): number;
|
||||
}
|
||||
|
||||
Number.prototype.round = function() {
|
||||
return Math.round(this);
|
||||
};
|
||||
|
||||
Number.prototype.floor = function() {
|
||||
return Math.floor(this);
|
||||
};
|
||||
|
||||
Number.prototype.ceil = function() {
|
||||
return Math.ceil(this);
|
||||
};
|
||||
|
||||
interface Function {
|
||||
partial<H extends any[], T extends any[], R>(
|
||||
this: (...args: [...H, ...T]) => R,
|
||||
@@ -7,4 +25,4 @@ interface Function {
|
||||
|
||||
Function.prototype.partial = function<H extends any[], T extends any[]>(...head: H) {
|
||||
return (...tail: T) => this(...head, ...tail);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,3 +18,40 @@ function rectEquals(a: QmlRect, b: QmlRect) {
|
||||
a.width === b.width &&
|
||||
a.height === b.height;
|
||||
}
|
||||
|
||||
function pointEquals(a: QmlPoint, b: QmlPoint) {
|
||||
return a.x === b.x &&
|
||||
a.y === b.y;
|
||||
}
|
||||
|
||||
function rectRight(rect: QmlRect) {
|
||||
return rect.x + rect.width;
|
||||
}
|
||||
|
||||
function rectBottom(rect: QmlRect) {
|
||||
return rect.y + rect.height;
|
||||
}
|
||||
|
||||
function rectContainsPoint(rect: QmlRect, point: QmlPoint) {
|
||||
return rect.x <= point.x &&
|
||||
rectRight(rect) >= point.x &&
|
||||
rect.y <= point.y &&
|
||||
rectBottom(rect) >= point.y;
|
||||
}
|
||||
|
||||
function roundQtRect(rect: QmlRect) {
|
||||
return Qt.rect(
|
||||
rect.x.round(),
|
||||
rect.y.round(),
|
||||
rect.width.round(),
|
||||
rect.height.round(),
|
||||
);
|
||||
}
|
||||
|
||||
function rectRightRound(rect: QmlRect) {
|
||||
return rect.x.round() + rect.width.round();
|
||||
}
|
||||
|
||||
function rectBottomRound(rect: QmlRect) {
|
||||
return rect.y.round() + rect.height.round();
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
function initWorkspaceSignalHandlers(world: World) {
|
||||
function initWorkspaceSignalHandlers(world: World, focusPasser: FocusPassing.Passer) {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(Workspace.windowAdded, (kwinClient: KwinClient) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.addClient(kwinClient)
|
||||
clientManager.addClient(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.windowRemoved, (kwinClient: KwinClient) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.removeClient(kwinClient, true);
|
||||
clientManager.removeClient(kwinClient, FocusPassing.Type.Immediate);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.windowActivated, (kwinClient: KwinClient|null) => {
|
||||
if (kwinClient === null) {
|
||||
return;
|
||||
focusPasser.activate();
|
||||
} else {
|
||||
focusPasser.clearIfDifferent(kwinClient);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.onClientFocused(kwinClient);
|
||||
});
|
||||
}
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.onClientFocused(kwinClient);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.currentDesktopChanged, () => {
|
||||
|
||||
@@ -31,16 +31,16 @@ class ClientManager {
|
||||
console.assert(!this.hasClient(kwinClient));
|
||||
|
||||
let constructState: (client: ClientWrapper) => ClientState.State;
|
||||
let desktop: Desktop | undefined;
|
||||
if (kwinClient.dock) {
|
||||
constructState = () => new ClientState.Docked(this.world, kwinClient);
|
||||
} else if (
|
||||
Clients.canTileEver(kwinClient) &&
|
||||
this.windowRuleEnforcer.shouldTile(kwinClient)
|
||||
this.windowRuleEnforcer.shouldTile(kwinClient) &&
|
||||
(desktop = this.desktopManager.getDesktopForClient(kwinClient)) !== undefined
|
||||
) {
|
||||
Clients.makeTileable(kwinClient);
|
||||
console.assert(Clients.canTileNow(kwinClient));
|
||||
const desktop = this.desktopManager.getDesktopForClient(kwinClient);
|
||||
console.assert(desktop !== undefined);
|
||||
constructState = (client: ClientWrapper) => new ClientState.Tiled(this.world, client, desktop!.grid);
|
||||
} else {
|
||||
constructState = (client: ClientWrapper) => new ClientState.Floating(this.world, client, this.config, false);
|
||||
@@ -55,13 +55,16 @@ class ClientManager {
|
||||
this.clientMap.set(kwinClient, client);
|
||||
}
|
||||
|
||||
public removeClient(kwinClient: KwinClient, passFocus: boolean) {
|
||||
public removeClient(kwinClient: KwinClient, passFocus: FocusPassing.Type) {
|
||||
console.assert(this.hasClient(kwinClient));
|
||||
const client = this.clientMap.get(kwinClient);
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
client.destroy(passFocus && kwinClient === this.lastFocusedClient);
|
||||
if (kwinClient !== this.lastFocusedClient) {
|
||||
passFocus = FocusPassing.Type.None;
|
||||
}
|
||||
client.destroy(passFocus);
|
||||
this.clientMap.delete(kwinClient);
|
||||
}
|
||||
|
||||
@@ -84,9 +87,10 @@ class ClientManager {
|
||||
return;
|
||||
}
|
||||
if (client.stateManager.getState() instanceof ClientState.Tiled) {
|
||||
const passFocus = kwinClient === this.lastFocusedClient ? FocusPassing.Type.Immediate : FocusPassing.Type.None;
|
||||
client.stateManager.setState(
|
||||
() => new ClientState.TiledMinimized(this.world, client),
|
||||
kwinClient === this.lastFocusedClient,
|
||||
passFocus,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -95,14 +99,14 @@ class ClientManager {
|
||||
if (client.stateManager.getState() instanceof ClientState.Tiled) {
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false);
|
||||
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), FocusPassing.Type.None);
|
||||
}
|
||||
|
||||
public floatClient(client: ClientWrapper) {
|
||||
if (client.stateManager.getState() instanceof ClientState.Floating) {
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), FocusPassing.Type.None);
|
||||
}
|
||||
|
||||
public tileKwinClient(kwinClient: KwinClient, grid: Grid) {
|
||||
@@ -131,7 +135,7 @@ class ClientManager {
|
||||
kwinClient.tile = null;
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Pinned(this.world, this.pinManager, this.desktopManager, kwinClient, this.config), false);
|
||||
client.stateManager.setState(() => new ClientState.Pinned(this.world, this.pinManager, this.desktopManager, kwinClient, this.config), FocusPassing.Type.None);
|
||||
this.pinManager.addClient(kwinClient);
|
||||
for (const desktop of this.desktopManager.getDesktopsForClient(kwinClient)) {
|
||||
desktop.onPinsChanged();
|
||||
@@ -144,7 +148,7 @@ class ClientManager {
|
||||
return;
|
||||
}
|
||||
console.assert(client.stateManager.getState() instanceof ClientState.Pinned);
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, false), false);
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, false), FocusPassing.Type.None);
|
||||
this.pinManager.removeClient(kwinClient);
|
||||
for (const desktop of this.desktopManager.getDesktopsForClient(kwinClient)) {
|
||||
desktop.onPinsChanged();
|
||||
@@ -164,9 +168,9 @@ class ClientManager {
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, desktop.grid), false);
|
||||
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, desktop.grid), FocusPassing.Type.None);
|
||||
} else if (clientState instanceof ClientState.Tiled) {
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
|
||||
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), FocusPassing.Type.None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +208,7 @@ class ClientManager {
|
||||
|
||||
private removeAllClients() {
|
||||
for (const kwinClient of Array.from(this.clientMap.keys())) {
|
||||
this.removeClient(kwinClient, false);
|
||||
this.removeClient(kwinClient, FocusPassing.Type.None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +218,7 @@ class ClientManager {
|
||||
}
|
||||
|
||||
namespace ClientManager {
|
||||
export type Config = {
|
||||
export interface Config {
|
||||
floatingKeepAbove: boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class ClientWrapper {
|
||||
}
|
||||
this.signalManager = ClientWrapper.initSignalManager(this);
|
||||
this.rulesSignalManager = rulesSignalManager;
|
||||
this.preferredWidth = kwinClient.frameGeometry.width;
|
||||
this.preferredWidth = kwinClient.frameGeometry.width.round();
|
||||
this.manipulatingGeometry = new Doer();
|
||||
this.lastPlacement = null;
|
||||
this.stateManager = new ClientState.Manager(constructInitialState(this));
|
||||
@@ -49,10 +49,10 @@ class ClientWrapper {
|
||||
if (Clients.isOnOneOfVirtualDesktops(this.kwinClient, kwinDesktops)) {
|
||||
const frame = this.kwinClient.frameGeometry;
|
||||
this.kwinClient.frameGeometry = Qt.rect(
|
||||
frame.x + dx,
|
||||
frame.y + dy,
|
||||
frame.width,
|
||||
frame.height,
|
||||
frame.x.round() + dx,
|
||||
frame.y.round() + dy,
|
||||
frame.width.round(),
|
||||
frame.height.round(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ class ClientWrapper {
|
||||
|
||||
public setMaximize(horizontally: boolean, vertically: boolean) {
|
||||
if (!this.kwinClient.maximizable) {
|
||||
this.maximizedMode = MaximizedMode.Unmaximized;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -141,15 +142,15 @@ class ClientWrapper {
|
||||
if (!Clients.isOnVirtualDesktop(this.kwinClient, Workspace.currentDesktop)) {
|
||||
return;
|
||||
}
|
||||
const frame = this.kwinClient.frameGeometry;
|
||||
if (frame.left < screenSize.left) {
|
||||
frame.x = screenSize.left;
|
||||
} else if (frame.right > screenSize.right) {
|
||||
frame.x = screenSize.right - frame.width;
|
||||
const frame = roundQtRect(this.kwinClient.frameGeometry);
|
||||
if (frame.x < screenSize.x) {
|
||||
frame.x = screenSize.x;
|
||||
} else if (rectRight(frame) > rectRight(screenSize)) {
|
||||
frame.x = rectRight(screenSize) - frame.width;
|
||||
}
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.stateManager.destroy(passFocus);
|
||||
this.signalManager.destroy();
|
||||
if (this.rulesSignalManager !== null) {
|
||||
|
||||
@@ -32,23 +32,23 @@ namespace Clients {
|
||||
|
||||
export function getKwinDesktopApprox(kwinClient: KwinClient) {
|
||||
switch (kwinClient.desktops.length) {
|
||||
case 0:
|
||||
case 0:
|
||||
return Workspace.currentDesktop;
|
||||
case 1:
|
||||
return kwinClient.desktops[0];
|
||||
default:
|
||||
if (kwinClient.desktops.includes(Workspace.currentDesktop)) {
|
||||
return Workspace.currentDesktop;
|
||||
case 1:
|
||||
} else {
|
||||
return kwinClient.desktops[0];
|
||||
default:
|
||||
if (kwinClient.desktops.includes(Workspace.currentDesktop)) {
|
||||
return Workspace.currentDesktop;
|
||||
} else {
|
||||
return kwinClient.desktops[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isFullScreenGeometry(kwinClient: KwinClient) {
|
||||
const fullScreenArea = Workspace.clientArea(ClientAreaOption.FullScreenArea, kwinClient.output, getKwinDesktopApprox(kwinClient));
|
||||
return kwinClient.clientGeometry.width === fullScreenArea.width &&
|
||||
kwinClient.clientGeometry.height === fullScreenArea.height;
|
||||
return kwinClient.clientGeometry.width.round() >= fullScreenArea.width &&
|
||||
kwinClient.clientGeometry.height.round() >= fullScreenArea.height;
|
||||
}
|
||||
|
||||
export function isOnVirtualDesktop(kwinClient: KwinClient, kwinDesktop: KwinDesktop) {
|
||||
|
||||
@@ -7,9 +7,9 @@ class DesktopManager {
|
||||
constructor(
|
||||
private readonly pinManager: PinManager,
|
||||
private readonly config: Desktop.Config,
|
||||
public readonly layoutConfig: LayoutConfig,
|
||||
currentActivity: string,
|
||||
currentDesktop: KwinDesktop,
|
||||
private readonly layoutConfig: LayoutConfig,
|
||||
private readonly focusPasser: FocusPassing.Passer,
|
||||
private readonly desktopFilter: DesktopFilter,
|
||||
) {
|
||||
this.pinManager = pinManager;
|
||||
this.config = config;
|
||||
@@ -18,10 +18,12 @@ class DesktopManager {
|
||||
this.selectedScreen = Workspace.activeScreen;
|
||||
this.kwinActivities = new Set(Workspace.activities);
|
||||
this.kwinDesktops = new Set(Workspace.desktops);
|
||||
this.addDesktop(currentActivity, currentDesktop);
|
||||
}
|
||||
|
||||
public getDesktop(activity: string, kwinDesktop: KwinDesktop) {
|
||||
if (!this.desktopFilter.shouldWorkOnDesktop(kwinDesktop)) {
|
||||
return undefined;
|
||||
}
|
||||
const desktopKey = DesktopManager.getDesktopKey(activity, kwinDesktop);
|
||||
const desktop = this.desktops.get(desktopKey);
|
||||
if (desktop !== undefined) {
|
||||
@@ -54,6 +56,7 @@ class DesktopManager {
|
||||
this.config,
|
||||
() => this.selectedScreen,
|
||||
this.layoutConfig,
|
||||
this.focusPasser,
|
||||
);
|
||||
this.desktops.set(desktopKey, desktop);
|
||||
return desktop;
|
||||
|
||||
51
src/lib/world/FocusPassing.ts
Normal file
51
src/lib/world/FocusPassing.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace FocusPassing {
|
||||
export const enum Type {
|
||||
None,
|
||||
Immediate,
|
||||
OnUnfocus,
|
||||
}
|
||||
|
||||
export class Passer {
|
||||
private currentRequest: Request | null = null;
|
||||
|
||||
public request(target: KwinClient) {
|
||||
this.currentRequest = new Request(target, Date.now());
|
||||
}
|
||||
|
||||
public clear() {
|
||||
this.currentRequest = null;
|
||||
}
|
||||
|
||||
public clearIfDifferent(kwinClient: KwinClient) {
|
||||
if (this.currentRequest !== null && this.currentRequest.target !== kwinClient) {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public activate() {
|
||||
if (this.currentRequest === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.currentRequest.isExpired()) {
|
||||
this.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
Workspace.activeWindow = this.currentRequest.target;
|
||||
}
|
||||
}
|
||||
|
||||
class Request {
|
||||
private static readonly validMs = 200;
|
||||
|
||||
constructor(
|
||||
public readonly target: KwinClient,
|
||||
private readonly time: number,
|
||||
) {}
|
||||
|
||||
public isExpired() {
|
||||
return Date.now() - this.time > Request.validMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class PinManager {
|
||||
}
|
||||
|
||||
public getAvailableSpace(kwinDesktop: KwinDesktop, screen: QmlRect) {
|
||||
const baseLot = new PinManager.Lot(screen.top, screen.bottom, screen.left, screen.right);
|
||||
const baseLot = new PinManager.Lot(screen.y, rectBottom(screen), screen.x, rectRight(screen));
|
||||
let lots = [baseLot];
|
||||
for (const client of this.pinnedClients) {
|
||||
if (!Clients.isOnVirtualDesktop(client, kwinDesktop) || client.minimized) {
|
||||
@@ -23,7 +23,7 @@ class PinManager {
|
||||
|
||||
const newLots: PinManager.Lot[] = [];
|
||||
for (const lot of lots) {
|
||||
lot.split(newLots, client.frameGeometry);
|
||||
lot.split(newLots, roundQtRect(client.frameGeometry));
|
||||
}
|
||||
lots = newLots;
|
||||
}
|
||||
@@ -60,23 +60,23 @@ namespace PinManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (obstacle.top - this.top >= Lot.minHeight) {
|
||||
destLots.push(new Lot(this.top, obstacle.top, this.left, this.right));
|
||||
if (obstacle.y - this.top >= Lot.minHeight) {
|
||||
destLots.push(new Lot(this.top, obstacle.y, this.left, this.right));
|
||||
}
|
||||
if (this.bottom - obstacle.bottom >= Lot.minHeight) {
|
||||
destLots.push(new Lot(obstacle.bottom, this.bottom, this.left, this.right));
|
||||
if (this.bottom - rectBottom(obstacle) >= Lot.minHeight) {
|
||||
destLots.push(new Lot(rectBottom(obstacle), this.bottom, this.left, this.right));
|
||||
}
|
||||
if (obstacle.left - this.left >= Lot.minWidth) {
|
||||
destLots.push(new Lot(this.top, this.bottom, this.left, obstacle.left));
|
||||
if (obstacle.x - this.left >= Lot.minWidth) {
|
||||
destLots.push(new Lot(this.top, this.bottom, this.left, obstacle.x));
|
||||
}
|
||||
if (this.right - obstacle.right >= Lot.minWidth) {
|
||||
destLots.push(new Lot(this.top, this.bottom, obstacle.right, this.right));
|
||||
if (this.right - rectRight(obstacle) >= Lot.minWidth) {
|
||||
destLots.push(new Lot(this.top, this.bottom, rectRight(obstacle), this.right));
|
||||
}
|
||||
}
|
||||
|
||||
private contains(obstacle: QmlRect) {
|
||||
return obstacle.right > this.left && obstacle.left < this.right &&
|
||||
obstacle.bottom > this.top && obstacle.top < this.bottom;
|
||||
return rectRight(obstacle) > this.left && obstacle.x < this.right &&
|
||||
rectBottom(obstacle) > this.top && obstacle.y < this.bottom;
|
||||
}
|
||||
|
||||
public area() {
|
||||
|
||||
@@ -5,9 +5,12 @@ class World {
|
||||
private readonly workspaceSignalManager: SignalManager;
|
||||
private readonly shortcutActions: ShortcutAction[];
|
||||
private readonly screenResizedDelayer: Delayer;
|
||||
private readonly cursorFollowsFocus: boolean;
|
||||
|
||||
constructor(config: Config) {
|
||||
this.workspaceSignalManager = initWorkspaceSignalHandlers(this);
|
||||
const focusPasser = new FocusPassing.Passer();
|
||||
this.workspaceSignalManager = initWorkspaceSignalHandlers(this, focusPasser);
|
||||
this.cursorFollowsFocus = config.cursorFollowsFocus;
|
||||
|
||||
let presetWidths = {
|
||||
next: (currentWidth: number, minWidth: number, maxWidth: number) => currentWidth,
|
||||
@@ -61,10 +64,13 @@ class World {
|
||||
marginRight: config.gapsOuterRight,
|
||||
scroller: World.createScroller(config),
|
||||
clamper: config.scrollingLazy ? new EdgeClamper() : new CenterClamper(),
|
||||
gestureScroll: config.gestureScroll,
|
||||
gestureScrollInvert: config.gestureScrollInvert,
|
||||
gestureScrollStep: config.gestureScrollStep,
|
||||
},
|
||||
layoutConfig,
|
||||
Workspace.currentActivity,
|
||||
Workspace.currentDesktop,
|
||||
focusPasser,
|
||||
new DesktopFilter(config.tiledDesktops),
|
||||
);
|
||||
this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager);
|
||||
this.addExistingClients();
|
||||
@@ -85,15 +91,32 @@ class World {
|
||||
}
|
||||
|
||||
private addExistingClients() {
|
||||
const kwinClients = Workspace.windows;
|
||||
for (let i = 0; i < kwinClients.length; i++) {
|
||||
const kwinClient = kwinClients[i];
|
||||
for (const kwinClient of Workspace.windows) {
|
||||
this.clientManager.addClient(kwinClient);
|
||||
}
|
||||
}
|
||||
|
||||
private update() {
|
||||
this.desktopManager.getCurrentDesktop().arrange();
|
||||
const currentDesktop = this.desktopManager.getCurrentDesktop();
|
||||
if (currentDesktop !== undefined) {
|
||||
currentDesktop.arrange();
|
||||
this.moveCursorToFocus();
|
||||
}
|
||||
}
|
||||
|
||||
private moveCursorToFocus() {
|
||||
if (this.cursorFollowsFocus && Workspace.activeWindow !== null) {
|
||||
// Only move cursor for tiled windows
|
||||
const tiledWindow = this.clientManager.findTiledWindow(Workspace.activeWindow);
|
||||
if (tiledWindow === null) {
|
||||
return;
|
||||
}
|
||||
const cursorAlreadyInFocus = rectContainsPoint(roundQtRect(Workspace.activeWindow.frameGeometry), Workspace.cursorPos);
|
||||
if (cursorAlreadyInFocus) {
|
||||
return;
|
||||
}
|
||||
moveCursorToFocus.call();
|
||||
}
|
||||
}
|
||||
|
||||
public do(f: (clientManager: ClientManager, desktopManager: DesktopManager) => void) {
|
||||
@@ -124,6 +147,26 @@ class World {
|
||||
this.doIfTiled(Workspace.activeWindow, f);
|
||||
}
|
||||
|
||||
public gestureScroll(amount: number) {
|
||||
this.do((clientManager, desktopManager) => {
|
||||
const currentDesktop = desktopManager.getCurrentDesktop();
|
||||
if (currentDesktop !== undefined) {
|
||||
currentDesktop.gestureScroll(amount);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public gestureScrollFinish() {
|
||||
this.do((clientManager, desktopManager) => {
|
||||
const focusedWindow = Workspace.activeWindow === null ? null : clientManager.findTiledWindow(Workspace.activeWindow);
|
||||
const currentDesktop = desktopManager.getCurrentDesktop();
|
||||
if (currentDesktop !== undefined) {
|
||||
console.assert(focusedWindow === null || focusedWindow.column.grid.desktop === currentDesktop);
|
||||
currentDesktop.gestureScrollFinish(focusedWindow);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this.workspaceSignalManager.destroy();
|
||||
for (const shortcutAction of this.shortcutActions) {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ClientState {
|
||||
world.onScreenResized();
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
this.world.onScreenResized();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ClientState {
|
||||
this.signalManager = Floating.initSignalManager(world, client.kwinClient);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ namespace ClientState {
|
||||
const clientRect = client.kwinClient.frameGeometry;
|
||||
const width = client.preferredWidth;
|
||||
client.place(
|
||||
clientRect.x,
|
||||
clientRect.y,
|
||||
clientRect.x.round(),
|
||||
clientRect.y.round(),
|
||||
width,
|
||||
Math.min(clientRect.height, Math.round(placementArea.height / 2)),
|
||||
Math.min(clientRect.height.round(), Math.round(placementArea.height / 2)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace ClientState {
|
||||
this.state = initialState;
|
||||
}
|
||||
|
||||
public setState(constructNewState: () => State, passFocus: boolean) {
|
||||
public setState(constructNewState: () => State, passFocus: FocusPassing.Type) {
|
||||
this.state.destroy(passFocus);
|
||||
this.state = constructNewState();
|
||||
}
|
||||
@@ -15,12 +15,12 @@ namespace ClientState {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.state.destroy(passFocus);
|
||||
}
|
||||
}
|
||||
|
||||
export type State = {
|
||||
destroy(passFocus: boolean): void;
|
||||
};
|
||||
export interface State {
|
||||
destroy(passFocus: FocusPassing.Type): void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ClientState {
|
||||
this.signalManager = Pinned.initSignalManager(world, pinManager, kwinClient);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
this.pinManager.removeClient(this.kwinClient);
|
||||
for (const desktop of this.desktopManager.getDesktopsForClient(this.kwinClient)) {
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ClientState {
|
||||
this.signalManager = Tiled.initSignalManager(world, window, grid.config);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
|
||||
const window = this.window;
|
||||
@@ -54,7 +54,7 @@ namespace ClientState {
|
||||
}
|
||||
Tiled.moveWindowToGrid(window, desktop.grid);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.minimizedChanged, () => {
|
||||
console.assert(kwinClient.minimized);
|
||||
@@ -113,7 +113,7 @@ namespace ClientState {
|
||||
}
|
||||
});
|
||||
|
||||
let externalFrameGeometryChangedRateLimiter = new RateLimiter(4, Tiled.maxExternalFrameGeometryChangedIntervalMs);
|
||||
const externalFrameGeometryChangedRateLimiter = new RateLimiter(4, Tiled.maxExternalFrameGeometryChangedIntervalMs);
|
||||
manager.connect(kwinClient.frameGeometryChanged, (oldGeometry: QmlRect) => {
|
||||
// on Wayland, this fires after `tileChanged`
|
||||
if (kwinClient.tile !== null) {
|
||||
@@ -123,7 +123,12 @@ namespace ClientState {
|
||||
return;
|
||||
}
|
||||
|
||||
const newGeometry = client.kwinClient.frameGeometry;
|
||||
const newGeometry = roundQtRect(client.kwinClient.frameGeometry);
|
||||
if (rectEquals(oldGeometry, newGeometry)) {
|
||||
// no real changes, nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
const oldCenterX = oldGeometry.x + oldGeometry.width/2;
|
||||
const oldCenterY = oldGeometry.y + oldGeometry.height/2;
|
||||
const newCenterX = newGeometry.x + newGeometry.width/2;
|
||||
@@ -142,7 +147,7 @@ namespace ClientState {
|
||||
window.column.onUserResizeWidth(
|
||||
resizeStartWidth,
|
||||
newGeometry.width - resizeStartWidth,
|
||||
newGeometry.left !== oldGeometry.left,
|
||||
newGeometry.x !== oldGeometry.x,
|
||||
resizeNeighbor,
|
||||
);
|
||||
}
|
||||
@@ -193,9 +198,9 @@ namespace ClientState {
|
||||
private static getResizeNeighborColumn(window: Window) {
|
||||
const kwinClient = window.client.kwinClient;
|
||||
const column = window.column;
|
||||
if (Workspace.cursorPos.x > kwinClient.clientGeometry.right) {
|
||||
if (Workspace.cursorPos.x > rectRightRound(kwinClient.clientGeometry)) {
|
||||
return column.grid.getRightColumn(column);
|
||||
} else if (Workspace.cursorPos.x < kwinClient.clientGeometry.left) {
|
||||
} else if (Workspace.cursorPos.x < kwinClient.clientGeometry.x.round()) {
|
||||
return column.grid.getLeftColumn(column);
|
||||
} else {
|
||||
return null;
|
||||
@@ -209,17 +214,26 @@ namespace ClientState {
|
||||
}
|
||||
|
||||
const newColumn = new Column(grid, grid.getLastFocusedColumn() ?? grid.getLastColumn());
|
||||
window.moveToColumn(newColumn, true);
|
||||
const passFocus = window.isFocused() ? FocusPassing.Type.OnUnfocus : FocusPassing.Type.None;
|
||||
window.moveToColumn(newColumn, true, passFocus);
|
||||
}
|
||||
|
||||
private static prepareClientForTiling(client: ClientWrapper, config: LayoutConfig) {
|
||||
if (config.skipSwitcher) {
|
||||
client.kwinClient.skipSwitcher = true;
|
||||
}
|
||||
if (config.tiledKeepBelow) {
|
||||
client.kwinClient.keepBelow = true;
|
||||
|
||||
if (client.kwinClient.fullScreen) {
|
||||
if (config.maximizedKeepAbove) {
|
||||
client.kwinClient.keepAbove = true;
|
||||
}
|
||||
} else {
|
||||
if (config.tiledKeepBelow) {
|
||||
client.kwinClient.keepBelow = true;
|
||||
}
|
||||
client.kwinClient.keepAbove = false;
|
||||
}
|
||||
client.kwinClient.keepAbove = false;
|
||||
|
||||
if (client.kwinClient.tile !== null) {
|
||||
client.setMaximize(false, true); // disable quick tile mode
|
||||
}
|
||||
@@ -245,8 +259,8 @@ namespace ClientState {
|
||||
}
|
||||
|
||||
namespace Tiled {
|
||||
export type WindowState = {
|
||||
export interface WindowState {
|
||||
skipSwitcher: boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace ClientState {
|
||||
this.signalManager = TiledMinimized.initSignalManager(world, client);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests.register("Center focused", 1, () => {
|
||||
tests.register("Center focused", 5, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
@@ -14,8 +14,8 @@ tests.register("Center focused", 1, () => {
|
||||
// center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.centered(config, tilingArea, client2);
|
||||
Assert.fullyVisible(client1.frameGeometry);
|
||||
Assert.fullyVisible(client2.frameGeometry);
|
||||
Assert.fullyVisible(client1.getActualFrameGeometry());
|
||||
Assert.fullyVisible(client2.getActualFrameGeometry());
|
||||
|
||||
// undo center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
@@ -24,14 +24,14 @@ tests.register("Center focused", 1, () => {
|
||||
// center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.centered(config, tilingArea, client2);
|
||||
Assert.fullyVisible(client1.frameGeometry);
|
||||
Assert.fullyVisible(client2.frameGeometry);
|
||||
Assert.fullyVisible(client1.getActualFrameGeometry());
|
||||
Assert.fullyVisible(client2.getActualFrameGeometry());
|
||||
|
||||
// focus client1 (no scrolling should occur)
|
||||
qtMock.fireShortcut("karousel-focus-left");
|
||||
Assert.centered(config, tilingArea, client2, { message: "No scrolling should have occured" });
|
||||
Assert.fullyVisible(client1.frameGeometry);
|
||||
Assert.fullyVisible(client2.frameGeometry);
|
||||
Assert.fullyVisible(client1.getActualFrameGeometry());
|
||||
Assert.fullyVisible(client2.getActualFrameGeometry());
|
||||
|
||||
// center client1
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests.register("columns squeeze side", 1, () => {
|
||||
tests.register("columns squeeze side", 5, () => {
|
||||
const baseTestCases = [
|
||||
{ widths: [500, 500], blocked: [false, false], possible: true },
|
||||
{ widths: [500, 768], blocked: [false, false], possible: true },
|
||||
@@ -46,21 +46,21 @@ tests.register("columns squeeze side", 1, () => {
|
||||
Assert.columnsFillTilingArea(clients, assertOpt);
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
if (testCase.blocked[i]) {
|
||||
Assert.equal(clients[i].frameGeometry.width, testCase.widths[i], assertOpt);
|
||||
Assert.equal(clients[i].getActualFrameGeometry().width, testCase.widths[i], assertOpt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const frames = clients.map(client => client.frameGeometry);
|
||||
const frames = clients.map(client => client.getActualFrameGeometry());
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
const newFrames = clients.map(client => client.frameGeometry);
|
||||
const newFrames = clients.map(client => client.getActualFrameGeometry());
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
Assert.equalRects(frames[i], newFrames[i], assertOpt);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tests.register("columns squeeze side (just scroll)", 1, () => {
|
||||
tests.register("columns squeeze side (just scroll)", 5, () => {
|
||||
const baseTestCases = [
|
||||
{ focus: 0, startVisible: [true, true, false], endVisible: [true, true, false] },
|
||||
{ focus: 1, startVisible: [false, true, true], endVisible: [true, true, false] },
|
||||
@@ -91,12 +91,12 @@ tests.register("columns squeeze side (just scroll)", 1, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
function assertVisible(clients: KwinClient[], visible: boolean[]) {
|
||||
function assertVisible(clients: MockKwinClient[], visible: boolean[]) {
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
if (visible[i]) {
|
||||
Assert.fullyVisible(clients[i].frameGeometry, { message: assertMsg, skip: 1 });
|
||||
Assert.fullyVisible(clients[i].getActualFrameGeometry(), { message: assertMsg, skip: 1 });
|
||||
} else {
|
||||
Assert.notFullyVisible(clients[i].frameGeometry, { message: assertMsg, skip: 1 });
|
||||
Assert.notFullyVisible(clients[i].getActualFrameGeometry(), { message: assertMsg, skip: 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,9 +114,9 @@ tests.register("columns squeeze side (just scroll)", 1, () => {
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
assertVisible(clients, testCase.endVisible);
|
||||
|
||||
const frames = clients.map(client => client.frameGeometry);
|
||||
const frames = clients.map(client => client.getActualFrameGeometry());
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
const newFrames = clients.map(client => client.frameGeometry);
|
||||
const newFrames = clients.map(client => client.getActualFrameGeometry());
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
Assert.equalRects(frames[i], newFrames[i], { message: assertMsg });
|
||||
}
|
||||
|
||||
82
src/tests/flows/cursorFollowsFocus.ts
Normal file
82
src/tests/flows/cursorFollowsFocus.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
tests.register("Drag tiled window, untile", 10, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.cursorFollowsFocus = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [client1, client2] = workspaceMock.createClients(2);
|
||||
const initialCursorPos = new MockQmlPoint(380, 20);
|
||||
Assert.assert(rectContainsPoint(client1.getActualFrameGeometry(), initialCursorPos), { message: "invalid test setup" });
|
||||
workspaceMock.cursorPos = initialCursorPos.clone();
|
||||
|
||||
runOneOf(
|
||||
() => { Workspace.activeWindow = client1; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-1"); },
|
||||
);
|
||||
Assert.assert(rectContainsPoint(client1.getActualFrameGeometry(), Workspace.cursorPos));
|
||||
Assert.assert(!rectContainsPoint(client2.getActualFrameGeometry(), Workspace.cursorPos));
|
||||
Assert.assert(pointEquals(Workspace.cursorPos, initialCursorPos), { message: "Cursor should not have been moved because it was already within the focused client" });
|
||||
|
||||
runOneOf(
|
||||
() => { Workspace.activeWindow = client2; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-2"); },
|
||||
);
|
||||
Assert.assert(!rectContainsPoint(client1.getActualFrameGeometry(), Workspace.cursorPos));
|
||||
Assert.assert(rectContainsPoint(client2.getActualFrameGeometry(), Workspace.cursorPos));
|
||||
|
||||
runOneOf(
|
||||
() => { Workspace.activeWindow = client1; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-1"); },
|
||||
);
|
||||
Assert.assert(rectContainsPoint(client1.getActualFrameGeometry(), Workspace.cursorPos));
|
||||
Assert.assert(!rectContainsPoint(client2.getActualFrameGeometry(), Workspace.cursorPos));
|
||||
const lastCursorPos = workspaceMock.cursorPos.clone();
|
||||
|
||||
Workspace.activeWindow = null;
|
||||
Assert.assert(pointEquals(Workspace.cursorPos, lastCursorPos), { message: "Cursor should not have been moved" });
|
||||
});
|
||||
|
||||
tests.register("Cursor follows focus only on matched desktops", 1, () => {
|
||||
// Test that cursor follow focus only works for windows on matched desktops (tiled windows)
|
||||
const config = getDefaultConfig();
|
||||
config.cursorFollowsFocus = true;
|
||||
config.tiledDesktops = "^Desktop 1$"; // Only work on Desktop 1
|
||||
const { workspaceMock, world } = init(config);
|
||||
|
||||
// Create a client on Desktop 1 (matched desktop) - should be tiled
|
||||
const client1 = new MockKwinClient();
|
||||
client1.desktops = [workspaceMock.desktops[0]]; // Desktop 1
|
||||
workspaceMock.createWindows(client1);
|
||||
|
||||
// Create a client on Desktop 2 (non-matched desktop) - should be floating
|
||||
const client2 = new MockKwinClient();
|
||||
client2.desktops = [workspaceMock.desktops[1]]; // Desktop 2
|
||||
workspaceMock.createWindows(client2);
|
||||
|
||||
// Set initial cursor position outside both windows
|
||||
const initialCursorPos = new MockQmlPoint(10, 10);
|
||||
workspaceMock.cursorPos = initialCursorPos.clone();
|
||||
|
||||
// Test 1: Focus client1 on matched desktop (Desktop 1) - cursor should move
|
||||
workspaceMock.currentDesktop = workspaceMock.desktops[0]; // Switch to Desktop 1
|
||||
Workspace.activeWindow = client1;
|
||||
world.do(() => {});
|
||||
Assert.assert(rectContainsPoint(client1.getActualFrameGeometry(), Workspace.cursorPos),
|
||||
{ message: "Cursor should have moved to tiled window on matched desktop" });
|
||||
|
||||
// Test 2: Switch to non-matched desktop (Desktop 2) and focus client2 - cursor should NOT move
|
||||
workspaceMock.cursorPos = initialCursorPos.clone();
|
||||
workspaceMock.currentDesktop = workspaceMock.desktops[1]; // Switch to Desktop 2
|
||||
Workspace.activeWindow = client2;
|
||||
world.do(() => {});
|
||||
Assert.assert(pointEquals(Workspace.cursorPos, initialCursorPos),
|
||||
{ message: "Cursor should NOT move on non-matched desktop" });
|
||||
|
||||
// Test 3: Even if we focus client1 (tiled) while on Desktop 2, cursor should NOT move
|
||||
// because the current desktop is not matched
|
||||
workspaceMock.cursorPos = initialCursorPos.clone();
|
||||
workspaceMock.currentDesktop = workspaceMock.desktops[1]; // Stay on Desktop 2
|
||||
Workspace.activeWindow = client1;
|
||||
world.do(() => {});
|
||||
Assert.assert(pointEquals(Workspace.cursorPos, initialCursorPos),
|
||||
{ message: "Cursor should NOT move even for tiled window when current desktop is not matched" });
|
||||
});
|
||||
73
src/tests/flows/desktopFiltering.ts
Normal file
73
src/tests/flows/desktopFiltering.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
tests.register("Desktop filtering", 1, () => {
|
||||
// Test 1: Default config should work on all desktops
|
||||
const config1 = getDefaultConfig();
|
||||
const { workspaceMock: wm1, world: world1 } = init(config1);
|
||||
|
||||
const client1 = new MockKwinClient();
|
||||
client1.desktops = [wm1.desktops[0]];
|
||||
wm1.createWindows(client1);
|
||||
|
||||
world1.do((clientManager) => {
|
||||
Assert.tiledClient(clientManager, client1, { message: "Client should be tiled on desktop1 with default config (*)" });
|
||||
});
|
||||
});
|
||||
|
||||
tests.register("Desktop filtering - specific desktop", 1, () => {
|
||||
// Test 2: Specific desktop name - should work only on matching desktop
|
||||
const config2 = getDefaultConfig();
|
||||
config2.tiledDesktops = "^Desktop 1$";
|
||||
const { workspaceMock: wm2, world: world2 } = init(config2);
|
||||
|
||||
const client1 = new MockKwinClient();
|
||||
client1.desktops = [wm2.desktops[0]]; // Desktop 1
|
||||
wm2.createWindows(client1);
|
||||
world2.do((clientManager) => {
|
||||
Assert.tiledClient(clientManager, client1, { message: "Client should be tiled on Desktop 1" });
|
||||
});
|
||||
|
||||
wm2.removeWindow(client1);
|
||||
|
||||
const client2 = new MockKwinClient();
|
||||
client2.desktops = [wm2.desktops[1]]; // Desktop 2
|
||||
wm2.createWindows(client2);
|
||||
world2.do((clientManager) => {
|
||||
Assert.notTiledClient(clientManager, client2, { message: "Client should NOT be tiled on Desktop 2" });
|
||||
});
|
||||
});
|
||||
|
||||
tests.register("Desktop filtering - multiple desktops", 1, () => {
|
||||
// Test 3: Multiple desktop names using regex alternation
|
||||
const config3 = getDefaultConfig();
|
||||
config3.tiledDesktops = "^Desktop [12]$";
|
||||
const { workspaceMock: wm3, world: world3 } = init(config3);
|
||||
|
||||
const client1 = new MockKwinClient();
|
||||
client1.desktops = [wm3.desktops[0]]; // Desktop 1
|
||||
wm3.createWindows(client1);
|
||||
world3.do((clientManager) => {
|
||||
Assert.tiledClient(clientManager, client1, { message: "Client should be tiled on Desktop 1" });
|
||||
});
|
||||
|
||||
wm3.removeWindow(client1);
|
||||
|
||||
const client2 = new MockKwinClient();
|
||||
client2.desktops = [wm3.desktops[1]]; // Desktop 2
|
||||
wm3.createWindows(client2);
|
||||
world3.do((clientManager) => {
|
||||
Assert.tiledClient(clientManager, client2, { message: "Client should be tiled on Desktop 2" });
|
||||
});
|
||||
});
|
||||
|
||||
tests.register("Desktop filtering - windows on multiple desktops", 1, () => {
|
||||
// Test 4: Windows on multiple desktops should not be tiled (fallback to floating)
|
||||
const config4 = getDefaultConfig();
|
||||
config4.tiledDesktops = ".*";
|
||||
const { workspaceMock: wm4, world: world4 } = init(config4);
|
||||
|
||||
const client1 = new MockKwinClient();
|
||||
client1.desktops = [wm4.desktops[0], wm4.desktops[1]]; // Multiple desktops
|
||||
wm4.createWindows(client1);
|
||||
world4.do((clientManager) => {
|
||||
Assert.notTiledClient(clientManager, client1, { message: "Client on multiple desktops should not be tiled" });
|
||||
});
|
||||
});
|
||||
@@ -8,31 +8,31 @@ tests.register("External resize", 1, () => {
|
||||
|
||||
function getTiledFrame(width: number) {
|
||||
return new MockQmlRect(
|
||||
tilingArea.left + Math.round((tilingArea.width - width) / 2),
|
||||
tilingArea.top,
|
||||
tilingArea.x + Math.round((tilingArea.width - width) / 2),
|
||||
tilingArea.y,
|
||||
width,
|
||||
tilingArea.height,
|
||||
);
|
||||
}
|
||||
|
||||
const [client] = workspaceMock.createClientsWithFrames(getClientDesiredFrame(100));
|
||||
Assert.equalRects(client.frameGeometry, getTiledFrame(100), { message: "We should tile the window, respecting its desired width" });
|
||||
Assert.equalRects(client.getActualFrameGeometry(), getTiledFrame(100), { message: "We should tile the window, respecting its desired width" });
|
||||
|
||||
function testExternalResizing() {
|
||||
client.frameGeometry = getClientDesiredFrame(110);
|
||||
Assert.equalRects(client.frameGeometry, getTiledFrame(110), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
Assert.equalRects(client.getActualFrameGeometry(), getTiledFrame(110), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
|
||||
client.frameGeometry = getClientDesiredFrame(120);
|
||||
Assert.equalRects(client.frameGeometry, getTiledFrame(120), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
Assert.equalRects(client.getActualFrameGeometry(), getTiledFrame(120), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
|
||||
client.frameGeometry = getClientDesiredFrame(130);
|
||||
Assert.equalRects(client.frameGeometry, getTiledFrame(130), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
Assert.equalRects(client.getActualFrameGeometry(), getTiledFrame(130), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
|
||||
client.frameGeometry = getClientDesiredFrame(140);
|
||||
Assert.equalRects(client.frameGeometry, getTiledFrame(140), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
Assert.equalRects(client.getActualFrameGeometry(), getTiledFrame(140), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
|
||||
client.frameGeometry = getClientDesiredFrame(200);
|
||||
Assert.equalRects(client.frameGeometry, getClientDesiredFrame(200), { message: "We should give up and let the client have its desired frame" });
|
||||
Assert.equalRects(client.getActualFrameGeometry(), getClientDesiredFrame(200), { message: "We should give up and let the client have its desired frame" });
|
||||
}
|
||||
|
||||
timeControl(addTime => {
|
||||
|
||||
10
src/tests/flows/followWindowToDesktop.ts
Normal file
10
src/tests/flows/followWindowToDesktop.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
tests.register("Move and follow window to desktop", 20, () => {
|
||||
// This tests the Kwin shortcuts for moving windows to adjacent desktops.
|
||||
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [client0, client1] = workspaceMock.createClients(2);
|
||||
client1.moveAndFollowToDesktop(workspaceMock.desktops[1], workspaceMock);
|
||||
Assert.equal(workspaceMock.activeWindow, client1);
|
||||
});
|
||||
@@ -10,7 +10,7 @@ tests.register("Focus and move windows", 1, () => {
|
||||
});
|
||||
Assert.assert(workspaceMock.activeWindow === client3);
|
||||
|
||||
function testLayout(shortcutName: string, grid: KwinClient[][]) {
|
||||
function testLayout(shortcutName: string, grid: MockKwinClient[][]) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
Assert.grid(config, tilingArea, 100, grid, true, [], { skip: 1 });
|
||||
}
|
||||
|
||||
@@ -13,35 +13,35 @@ tests.register("LazyScroller", 20, () => {
|
||||
|
||||
const [client3] = workspaceMock.createClientsWithWidths(300);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.equal(client3.frameGeometry.right, tilingArea.right);
|
||||
Assert.equal(rectRight(client3.getActualFrameGeometry()), rectRight(tilingArea));
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client2,
|
||||
() => qtMock.fireShortcut("karousel-focus-2"),
|
||||
() => qtMock.fireShortcut("karousel-focus-left"),
|
||||
() => { workspaceMock.activeWindow = client2; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-2"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-left"); },
|
||||
);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.equal(client3.frameGeometry.right, tilingArea.right);
|
||||
Assert.equal(rectRight(client3.getActualFrameGeometry()), rectRight(tilingArea));
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client1,
|
||||
() => qtMock.fireShortcut("karousel-focus-1"),
|
||||
() => qtMock.fireShortcut("karousel-focus-left"),
|
||||
() => qtMock.fireShortcut("karousel-focus-start"),
|
||||
() => { workspaceMock.activeWindow = client1; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-1"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-left"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-start"); },
|
||||
);
|
||||
workspaceMock.activeWindow = client1;
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.equal(client1.frameGeometry.left, tilingArea.left);
|
||||
Assert.equal(client1.getActualFrameGeometry().x, tilingArea.x);
|
||||
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.grid(config, tilingArea, 300, [[client1]], true);
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client2,
|
||||
() => qtMock.fireShortcut("karousel-focus-2"),
|
||||
() => qtMock.fireShortcut("karousel-focus-right"),
|
||||
() => { workspaceMock.activeWindow = client2; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-2"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-right"); },
|
||||
);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.equal(client1.frameGeometry.left, tilingArea.left);
|
||||
Assert.equal(client1.getActualFrameGeometry().x, tilingArea.x);
|
||||
});
|
||||
|
||||
@@ -1,214 +1,341 @@
|
||||
tests.register("Maximization", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
{
|
||||
function registerTests(
|
||||
suffix: string,
|
||||
getConfig: () => Config,
|
||||
shouldKeepBelow: (tiled: boolean) => boolean,
|
||||
shouldKeepAbove: (tiled: boolean) => boolean,
|
||||
) {
|
||||
tests.register("Maximization " + suffix, 100, () => {
|
||||
const config = getConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [kwinClient] = workspaceMock.createClientsWithWidths(300);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(kwinClient));
|
||||
});
|
||||
const [kwinClient] = workspaceMock.createClientsWithWidths(300);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(kwinClient));
|
||||
});
|
||||
|
||||
const columnLeftX = tilingArea.left + tilingArea.width/2 - 300/2;
|
||||
const columnTopY = tilingArea.top;
|
||||
const columnHeight = tilingArea.height;
|
||||
Assert.rect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
|
||||
const columnLeftX = tilingArea.x + tilingArea.width/2 - 300/2;
|
||||
const columnTopY = tilingArea.y;
|
||||
const columnHeight = tilingArea.height;
|
||||
Assert.assert(!kwinClient.fullScreen);
|
||||
Assert.equal(kwinClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(kwinClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.rect(kwinClient.getActualFrameGeometry(), columnLeftX, columnTopY, 300, columnHeight);
|
||||
|
||||
kwinClient.fullScreen = true;
|
||||
Assert.equalRects(kwinClient.frameGeometry, screen);
|
||||
kwinClient.fullScreen = true;
|
||||
Assert.assert(kwinClient.fullScreen);
|
||||
Assert.equal(kwinClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(kwinClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), screen);
|
||||
|
||||
kwinClient.fullScreen = false;
|
||||
Assert.rect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
|
||||
kwinClient.fullScreen = false;
|
||||
Assert.assert(!kwinClient.fullScreen);
|
||||
Assert.equal(kwinClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(kwinClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.rect(kwinClient.getActualFrameGeometry(), columnLeftX, columnTopY, 300, columnHeight);
|
||||
|
||||
kwinClient.setMaximize(true, true);
|
||||
Assert.equalRects(kwinClient.frameGeometry, screen);
|
||||
kwinClient.setMaximize(true, true);
|
||||
Assert.assert(!kwinClient.fullScreen);
|
||||
Assert.equal(kwinClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(kwinClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), screen);
|
||||
|
||||
kwinClient.setMaximize(true, false);
|
||||
Assert.rect(kwinClient.frameGeometry, columnLeftX, 0, 300, screen.height);
|
||||
kwinClient.setMaximize(true, false);
|
||||
Assert.assert(!kwinClient.fullScreen);
|
||||
Assert.equal(kwinClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(kwinClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.rect(kwinClient.getActualFrameGeometry(), columnLeftX, 0, 300, screen.height);
|
||||
|
||||
kwinClient.setMaximize(false, false);
|
||||
Assert.rect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
|
||||
});
|
||||
kwinClient.setMaximize(false, false);
|
||||
Assert.assert(!kwinClient.fullScreen);
|
||||
Assert.equal(kwinClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(kwinClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.rect(kwinClient.getActualFrameGeometry(), columnLeftX, columnTopY, 300, columnHeight);
|
||||
});
|
||||
|
||||
tests.register("Maximize with transient", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
tests.register("Maximize with transient " + suffix, 100, () => {
|
||||
const config = getConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const parent = new MockKwinClient(new MockQmlRect(10, 20, 300, 200));
|
||||
const child = new MockKwinClient(new MockQmlRect(14, 24, 50, 50), parent);
|
||||
const parent = new MockKwinClient(new MockQmlRect(10, 20, 300, 200));
|
||||
const child = new MockKwinClient(new MockQmlRect(14, 24, 50, 50), parent);
|
||||
|
||||
workspaceMock.createWindows(parent);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(parent));
|
||||
});
|
||||
workspaceMock.createWindows(parent);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(parent));
|
||||
});
|
||||
|
||||
runOneOf(
|
||||
() => parent.fullScreen = true,
|
||||
() => parent.setMaximize(true, true),
|
||||
);
|
||||
Assert.equalRects(parent.frameGeometry, screen);
|
||||
runOneOf(
|
||||
() => { parent.fullScreen = true; },
|
||||
() => { parent.setMaximize(true, true); },
|
||||
);
|
||||
Assert.equal(parent.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(parent.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(parent.getActualFrameGeometry(), screen);
|
||||
|
||||
workspaceMock.createWindows(child);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(child));
|
||||
});
|
||||
Assert.rect(child.frameGeometry, 14, 24, 50, 50);
|
||||
Assert.equalRects(parent.frameGeometry, screen);
|
||||
});
|
||||
workspaceMock.createWindows(child);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(child));
|
||||
});
|
||||
Assert.assert(!child.fullScreen);
|
||||
Assert.equal(child.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(child.keepAbove, shouldKeepAbove(false));
|
||||
Assert.rect(child.getActualFrameGeometry(), 14, 24, 50, 50);
|
||||
Assert.equal(parent.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(parent.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(parent.getActualFrameGeometry(), screen);
|
||||
});
|
||||
|
||||
tests.register("Re-maximize disabled", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.reMaximize = false;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
{
|
||||
function assertWindowed(config: Config, clients: MockKwinClient[]) {
|
||||
Assert.assert(!clients[0].fullScreen);
|
||||
Assert.equal(clients[0].keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(clients[0].keepAbove, shouldKeepAbove(true));
|
||||
Assert.assert(!clients[1].fullScreen);
|
||||
Assert.equal(clients[1].keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(clients[1].keepAbove, shouldKeepAbove(true));
|
||||
Assert.assert(!clients[2].fullScreen);
|
||||
Assert.equal(clients[2].keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(clients[2].keepAbove, shouldKeepAbove(true));
|
||||
Assert.grid(config, tilingArea, [300, 400], [[clients[0]], [clients[1], clients[2]]], true);
|
||||
}
|
||||
|
||||
const [client1, client2] = workspaceMock.createClientsWithWidths(300, 400);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(client1));
|
||||
Assert.assert(clientManager.hasClient(client2));
|
||||
});
|
||||
function assertFullScreenOrMaximized(clients: MockKwinClient[]) {
|
||||
Assert.assert(!clients[0].fullScreen);
|
||||
Assert.equal(clients[0].keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(clients[0].keepAbove, shouldKeepAbove(true));
|
||||
Assert.assert(!clients[1].fullScreen);
|
||||
Assert.equal(clients[1].keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(clients[1].keepAbove, shouldKeepAbove(true));
|
||||
Assert.equal(clients[2].keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(clients[2].keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(clients[2].getActualFrameGeometry(), screen);
|
||||
}
|
||||
|
||||
const columnsWidth = 300 + 400 + config.gapsInnerHorizontal;
|
||||
const column1LeftX = tilingArea.left + tilingArea.width/2 - columnsWidth/2;
|
||||
const column2LeftX = column1LeftX + 300 + config.gapsInnerHorizontal;
|
||||
const columnTopY = tilingArea.top;
|
||||
const columnHeight = tilingArea.height;
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
|
||||
tests.register("Re-maximize disabled " + suffix, 100, () => {
|
||||
const config = getConfig();
|
||||
config.reMaximize = false;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
runOneOf(
|
||||
() => client2.fullScreen = true,
|
||||
() => client2.setMaximize(true, true),
|
||||
);
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.equalRects(client2.frameGeometry, screen);
|
||||
const clients = workspaceMock.createClientsWithWidths(300, 400, 400);
|
||||
qtMock.fireShortcut("karousel-window-move-left");
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client1,
|
||||
() => qtMock.fireShortcut("karousel-focus-1"),
|
||||
() => qtMock.fireShortcut("karousel-focus-left"),
|
||||
() => qtMock.fireShortcut("karousel-focus-start"),
|
||||
);
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client2,
|
||||
() => qtMock.fireShortcut("karousel-focus-2"),
|
||||
() => qtMock.fireShortcut("karousel-focus-right"),
|
||||
() => qtMock.fireShortcut("karousel-focus-end"),
|
||||
);
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
|
||||
});
|
||||
runOneOf(
|
||||
() => { clients[2].fullScreen = true; },
|
||||
() => { clients[2].setMaximize(true, true); },
|
||||
);
|
||||
assertFullScreenOrMaximized(clients);
|
||||
|
||||
tests.register("Re-maximize enabled", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.reMaximize = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[0]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-1"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-left"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-start"); },
|
||||
);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
const [client1, client2] = workspaceMock.createClientsWithWidths(300, 400);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(client1));
|
||||
Assert.assert(clientManager.hasClient(client2));
|
||||
});
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[2]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-2"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-right"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-end"); },
|
||||
);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
const columnsWidth = 300 + 400 + config.gapsInnerHorizontal;
|
||||
const column1LeftX = tilingArea.left + tilingArea.width/2 - columnsWidth/2;
|
||||
const column2LeftX = column1LeftX + 300 + config.gapsInnerHorizontal;
|
||||
const columnTopY = tilingArea.top;
|
||||
const columnHeight = tilingArea.height;
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
|
||||
runOneOf(
|
||||
() => { clients[2].fullScreen = true; },
|
||||
() => { clients[2].setMaximize(true, true); },
|
||||
);
|
||||
assertFullScreenOrMaximized(clients);
|
||||
|
||||
runOneOf(
|
||||
() => client2.fullScreen = true,
|
||||
() => client2.setMaximize(true, true),
|
||||
);
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.equalRects(client2.frameGeometry, screen);
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[1]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-up"); },
|
||||
);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client1,
|
||||
() => qtMock.fireShortcut("karousel-focus-1"),
|
||||
() => qtMock.fireShortcut("karousel-focus-left"),
|
||||
() => qtMock.fireShortcut("karousel-focus-start"),
|
||||
);
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[2]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-down"); },
|
||||
);
|
||||
assertWindowed(config, clients);
|
||||
});
|
||||
|
||||
runOneOf(
|
||||
() => workspaceMock.activeWindow = client2,
|
||||
() => qtMock.fireShortcut("karousel-focus-2"),
|
||||
() => qtMock.fireShortcut("karousel-focus-right"),
|
||||
() => qtMock.fireShortcut("karousel-focus-end"),
|
||||
);
|
||||
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
|
||||
Assert.equalRects(client2.frameGeometry, screen);
|
||||
});
|
||||
tests.register("Re-maximize enabled " + suffix, 100, () => {
|
||||
const config = getConfig();
|
||||
config.reMaximize = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
tests.register("Start full-screen", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.reMaximize = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
const clients = workspaceMock.createClientsWithWidths(300, 400, 400);
|
||||
qtMock.fireShortcut("karousel-window-move-left");
|
||||
|
||||
const [windowedClient] = workspaceMock.createClientsWithWidths(300);
|
||||
const fullScreenClient = new MockKwinClient(new MockQmlRect(0, 0, 400, 200));
|
||||
fullScreenClient.resourceClass = "full-screen-app";
|
||||
fullScreenClient.fullScreen = true;
|
||||
workspaceMock.createWindows(fullScreenClient);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(windowedClient));
|
||||
Assert.assert(clientManager.hasClient(fullScreenClient));
|
||||
});
|
||||
runOneOf(
|
||||
() => { clients[2].fullScreen = true; },
|
||||
() => { clients[2].setMaximize(true, true); },
|
||||
);
|
||||
assertFullScreenOrMaximized(clients);
|
||||
|
||||
Assert.centered(config, tilingArea, windowedClient);
|
||||
Assert.equalRects(fullScreenClient.frameGeometry, screen);
|
||||
Assert.equal(Workspace.activeWindow, fullScreenClient);
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[0]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-1"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-left"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-start"); },
|
||||
);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
{
|
||||
qtMock.fireShortcut("karousel-focus-left");
|
||||
const opts = { message: "fullScreenClient is not in the grid, so we can't move focus directionally" };
|
||||
Assert.centered(config, tilingArea, windowedClient, opts);
|
||||
Assert.equalRects(fullScreenClient.frameGeometry, screen, opts);
|
||||
Assert.equal(Workspace.activeWindow, fullScreenClient, opts);
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[2]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-2"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-right"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-end"); },
|
||||
);
|
||||
assertFullScreenOrMaximized(clients);
|
||||
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[1]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-up"); },
|
||||
);
|
||||
assertWindowed(config, clients);
|
||||
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = clients[2]; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-down"); },
|
||||
);
|
||||
assertFullScreenOrMaximized(clients);
|
||||
});
|
||||
}
|
||||
|
||||
tests.register("Start full-screen " + suffix, 100, () => {
|
||||
const config = getConfig();
|
||||
config.reMaximize = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [windowedClient] = workspaceMock.createClientsWithWidths(300);
|
||||
const fullScreenClient = new MockKwinClient(new MockQmlRect(0, 0, 400, 200));
|
||||
fullScreenClient.resourceClass = "full-screen-app";
|
||||
fullScreenClient.fullScreen = true;
|
||||
workspaceMock.createWindows(fullScreenClient);
|
||||
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(windowedClient));
|
||||
Assert.assert(clientManager.hasClient(fullScreenClient));
|
||||
});
|
||||
|
||||
Assert.assert(!windowedClient.fullScreen);
|
||||
Assert.equal(windowedClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(windowedClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.centered(config, tilingArea, windowedClient);
|
||||
Assert.assert(fullScreenClient.fullScreen);
|
||||
Assert.equal(fullScreenClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(fullScreenClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(fullScreenClient.getActualFrameGeometry(), screen);
|
||||
Assert.equal(Workspace.activeWindow, fullScreenClient);
|
||||
|
||||
{
|
||||
qtMock.fireShortcut("karousel-focus-left");
|
||||
const opts = { message: "fullScreenClient is not in the grid, so we can't move focus directionally" };
|
||||
Assert.assert(!windowedClient.fullScreen);
|
||||
Assert.equal(windowedClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(windowedClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.centered(config, tilingArea, windowedClient);
|
||||
Assert.assert(fullScreenClient.fullScreen);
|
||||
Assert.equal(fullScreenClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(fullScreenClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(fullScreenClient.getActualFrameGeometry(), screen);
|
||||
Assert.equal(Workspace.activeWindow, fullScreenClient, opts);
|
||||
}
|
||||
|
||||
{
|
||||
qtMock.fireShortcut("karousel-focus-1");
|
||||
const opts = { message: "fullScreenClient is not in grid, so it should stay full-screen" };
|
||||
Assert.assert(!windowedClient.fullScreen);
|
||||
Assert.equal(windowedClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(windowedClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.centered(config, tilingArea, windowedClient);
|
||||
Assert.assert(fullScreenClient.fullScreen);
|
||||
Assert.equal(fullScreenClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(fullScreenClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(fullScreenClient.getActualFrameGeometry(), screen);
|
||||
Assert.equal(Workspace.activeWindow, windowedClient);
|
||||
}
|
||||
});
|
||||
|
||||
tests.register("Start full-screen (force tiling) " + suffix, 100, () => {
|
||||
const config = getConfig();
|
||||
config.reMaximize = true;
|
||||
config.windowRules = '[{ "class": "full-screen-app", "tile": true }]';
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const column1Width = 300;
|
||||
const [windowedClient] = workspaceMock.createClientsWithWidths(column1Width);
|
||||
const fullScreenClient = new MockKwinClient(new MockQmlRect(0, 0, 400, 200));
|
||||
fullScreenClient.resourceClass = "full-screen-app";
|
||||
fullScreenClient.fullScreen = true;
|
||||
workspaceMock.createWindows(fullScreenClient);
|
||||
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(windowedClient));
|
||||
Assert.assert(clientManager.hasClient(fullScreenClient));
|
||||
});
|
||||
Assert.assert(!windowedClient.fullScreen);
|
||||
Assert.equal(windowedClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(windowedClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.grid(config, tilingArea, [column1Width], [[windowedClient]], false);
|
||||
Assert.assert(fullScreenClient.fullScreen);
|
||||
Assert.equal(fullScreenClient.keepBelow, shouldKeepBelow(false));
|
||||
Assert.equal(fullScreenClient.keepAbove, shouldKeepAbove(false));
|
||||
Assert.equalRects(fullScreenClient.getActualFrameGeometry(), screen);
|
||||
Assert.equal(Workspace.activeWindow, fullScreenClient);
|
||||
|
||||
let expectedColumn2Width = 0;
|
||||
let expectedActiveWindow;
|
||||
runOneOf(
|
||||
() => {
|
||||
fullScreenClient.fullScreen = false;
|
||||
expectedColumn2Width = 400;
|
||||
expectedActiveWindow = fullScreenClient;
|
||||
},
|
||||
() => {
|
||||
qtMock.fireShortcut("karousel-focus-left");
|
||||
expectedColumn2Width = tilingArea.width;
|
||||
expectedActiveWindow = windowedClient;
|
||||
},
|
||||
);
|
||||
|
||||
const opts = { message: "fullScreenClient should be restored from full-screen mode to tiled mode" };
|
||||
Assert.assert(!windowedClient.fullScreen);
|
||||
Assert.equal(windowedClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(windowedClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.assert(!fullScreenClient.fullScreen);
|
||||
Assert.equal(fullScreenClient.keepBelow, shouldKeepBelow(true));
|
||||
Assert.equal(fullScreenClient.keepAbove, shouldKeepAbove(true));
|
||||
Assert.grid(config, tilingArea, [column1Width, expectedColumn2Width], [[windowedClient], [fullScreenClient]], false, [], opts);
|
||||
Assert.equal(Workspace.activeWindow, expectedActiveWindow);
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
qtMock.fireShortcut("karousel-focus-1");
|
||||
const opts = { message: "fullScreenClient is not in grid, so it should stay full-screen" };
|
||||
Assert.centered(config, tilingArea, windowedClient, opts);
|
||||
Assert.equalRects(fullScreenClient.frameGeometry, screen, opts);
|
||||
Assert.equal(Workspace.activeWindow, windowedClient);
|
||||
function getConfig(floatingKeepAbove: boolean) {
|
||||
const config = getDefaultConfig();
|
||||
config.tiledKeepBelow = !floatingKeepAbove;
|
||||
config.floatingKeepAbove = floatingKeepAbove;
|
||||
return config;
|
||||
}
|
||||
});
|
||||
|
||||
tests.register("Start full-screen (force tiling)", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.reMaximize = true;
|
||||
config.windowRules = '[{ "class": "full-screen-app", "tile": true }]';
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
registerTests(
|
||||
"(tiled below)",
|
||||
getConfig.partial(false),
|
||||
tiled => tiled,
|
||||
tiled => false,
|
||||
);
|
||||
|
||||
const column1Width = 300;
|
||||
const [windowedClient] = workspaceMock.createClientsWithWidths(column1Width);
|
||||
const fullScreenClient = new MockKwinClient(new MockQmlRect(0, 0, 400, 200));
|
||||
fullScreenClient.resourceClass = "full-screen-app";
|
||||
fullScreenClient.fullScreen = true;
|
||||
workspaceMock.createWindows(fullScreenClient);
|
||||
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(windowedClient));
|
||||
Assert.assert(clientManager.hasClient(fullScreenClient));
|
||||
});
|
||||
Assert.equalRects(fullScreenClient.frameGeometry, screen);
|
||||
Assert.equal(Workspace.activeWindow, fullScreenClient);
|
||||
|
||||
const column2Width = tilingArea.width;
|
||||
const column1LeftX = tilingArea.left;
|
||||
const column2LeftX = column1LeftX + column1Width + gapH;
|
||||
const columnTopY = tilingArea.top;
|
||||
const columnHeight = tilingArea.height;
|
||||
qtMock.fireShortcut("karousel-focus-left");
|
||||
const opts = { message: "fullScreenClient should be restored from full-screen mode to tiled mode" };
|
||||
Assert.rect(windowedClient.frameGeometry, column1LeftX, columnTopY, column1Width, columnHeight, opts);
|
||||
Assert.rect(fullScreenClient.frameGeometry, column2LeftX, columnTopY, column2Width, columnHeight, opts);
|
||||
Assert.equal(Workspace.activeWindow, windowedClient);
|
||||
});
|
||||
registerTests(
|
||||
"(floating above)",
|
||||
getConfig.partial(true),
|
||||
tiled => false,
|
||||
tiled => !tiled,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests.register("Pass focus", 20, () => {
|
||||
tests.register("Pass focus", 100, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
@@ -34,7 +34,4 @@ tests.register("Pass focus", 20, () => {
|
||||
|
||||
removeWindow(client0);
|
||||
Assert.equal(workspaceMock.activeWindow, client6);
|
||||
|
||||
removeWindow(client6);
|
||||
Assert.equal(workspaceMock.activeWindow, null);
|
||||
});
|
||||
|
||||
@@ -22,26 +22,26 @@ tests.register("Pin", 20, () => {
|
||||
Assert.grid(config, tilingArea, 100, [ [pinned], [tiled1], [tiled2] ], true);
|
||||
|
||||
pinned.pin(screenHalfLeft);
|
||||
Assert.equalRects(pinned.frameGeometry, screenHalfLeft);
|
||||
Assert.equalRects(pinned.getActualFrameGeometry(), screenHalfLeft);
|
||||
Assert.grid(config, tilingAreaHalfRight, 100, [ [tiled1], [tiled2] ], true);
|
||||
|
||||
pinned.pin(screenHalfRight);
|
||||
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
|
||||
Assert.equalRects(pinned.getActualFrameGeometry(), screenHalfRight);
|
||||
Assert.grid(config, tilingAreaHalfLeft, 100, [ [tiled1], [tiled2] ], true);
|
||||
|
||||
pinned.unpin();
|
||||
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
|
||||
Assert.equalRects(pinned.getActualFrameGeometry(), screenHalfRight);
|
||||
Assert.grid(config, tilingArea, 100, [ [tiled1], [tiled2] ], true);
|
||||
|
||||
pinned.pin(screenHalfRight);
|
||||
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
|
||||
Assert.equalRects(pinned.getActualFrameGeometry(), screenHalfRight);
|
||||
Assert.grid(config, tilingAreaHalfLeft, 100, [ [tiled1], [tiled2] ], true);
|
||||
|
||||
pinned.minimized = true;
|
||||
Assert.grid(config, tilingArea, 100, [ [tiled1], [tiled2] ], true);
|
||||
|
||||
pinned.minimized = false;
|
||||
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
|
||||
Assert.equalRects(pinned.getActualFrameGeometry(), screenHalfRight);
|
||||
Assert.grid(config, tilingAreaHalfLeft, 100, [ [tiled1], [tiled2] ], true);
|
||||
|
||||
workspaceMock.activeWindow = pinned;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests.register("Preset Widths default", 1, () => {
|
||||
tests.register("Preset Widths default", 5, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
@@ -7,33 +7,48 @@ tests.register("Preset Widths default", 1, () => {
|
||||
|
||||
function getRect(columnWidth: number) {
|
||||
return new MockQmlRect(
|
||||
tilingArea.left + (tilingArea.width - columnWidth) / 2,
|
||||
tilingArea.top,
|
||||
tilingArea.x + (tilingArea.width - columnWidth) / 2,
|
||||
tilingArea.y,
|
||||
columnWidth,
|
||||
tilingArea.height,
|
||||
);
|
||||
}
|
||||
|
||||
const [kwinClient] = workspaceMock.createClientsWithWidths(300);
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(300));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(300));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(halfWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(halfWidth));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(maxWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(maxWidth));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(halfWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(halfWidth));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths-reverse");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(maxWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(maxWidth));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths-reverse");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(halfWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(halfWidth));
|
||||
});
|
||||
|
||||
tests.register("Preset Widths custom", 1, () => {
|
||||
tests.register("Preset Widths custom", 5, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.presetWidths = "500px, 250px, 100px, 50%";
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
@@ -43,39 +58,122 @@ tests.register("Preset Widths custom", 1, () => {
|
||||
|
||||
function getRect(columnWidth: number) {
|
||||
return new MockQmlRect(
|
||||
tilingArea.left + (tilingArea.width - columnWidth) / 2,
|
||||
tilingArea.top,
|
||||
tilingArea.x + (tilingArea.width - columnWidth) / 2,
|
||||
tilingArea.y,
|
||||
columnWidth,
|
||||
tilingArea.height,
|
||||
);
|
||||
}
|
||||
|
||||
const [kwinClient] = workspaceMock.createClientsWithWidths(200);
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(200));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(200));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(250));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(halfWidth));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(500));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(250));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(100));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(halfWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(250));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(500));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(100));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(250));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths-reverse"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(100));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths-reverse");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(100));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(500));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths-reverse"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(halfWidth));
|
||||
});
|
||||
|
||||
tests.register("Preset Widths custom percentages", 5, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.presetWidths = "25%, 50%, 75%, 100%";
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const width100 = tilingArea.width;
|
||||
const width75 = width100*0.75 - config.gapsInnerHorizontal*0.25;
|
||||
const width50 = width100*0.50 - config.gapsInnerHorizontal*0.50;
|
||||
const width25 = width100*0.25 - config.gapsInnerHorizontal*0.75;
|
||||
|
||||
function getRect(columnWidth: number) {
|
||||
return new MockQmlRect(
|
||||
tilingArea.x + (tilingArea.width - columnWidth) / 2,
|
||||
tilingArea.y,
|
||||
columnWidth,
|
||||
tilingArea.height,
|
||||
);
|
||||
}
|
||||
|
||||
const [kwinClient] = workspaceMock.createClientsWithWidths(200);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(200));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width50));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width75));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-increase"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width100));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width25));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths-reverse");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(500));
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width100));
|
||||
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths-reverse");
|
||||
Assert.equalRects(kwinClient.frameGeometry, getRect(halfWidth));
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths-reverse"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width75));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths-reverse"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width50));
|
||||
|
||||
runOneOf(
|
||||
() => qtMock.fireShortcut("karousel-cycle-preset-widths-reverse"),
|
||||
() => qtMock.fireShortcut("karousel-column-width-decrease"),
|
||||
);
|
||||
Assert.equalRects(kwinClient.getActualFrameGeometry(), getRect(width25));
|
||||
});
|
||||
|
||||
tests.register("Preset Widths fill screen uniform", 1, () => {
|
||||
@@ -96,12 +194,12 @@ tests.register("Preset Widths fill screen uniform", 1, () => {
|
||||
qtMock.fireShortcut("karousel-cycle-preset-widths");
|
||||
}
|
||||
|
||||
const left = tilingArea.left;
|
||||
const right = tilingArea.right;
|
||||
const left = tilingArea.x;
|
||||
const right = rectRight(tilingArea);
|
||||
const maxLeftoverPx = nColumns - 1;
|
||||
const eps = Math.ceil(maxLeftoverPx / 2);
|
||||
Assert.between(firstClient!.frameGeometry.left, left, left+eps, { message: `nColumns: ${nColumns}` });
|
||||
Assert.between(lastClient!.frameGeometry.right, right-eps, right, { message: `nColumns: ${nColumns}` });
|
||||
Assert.between(firstClient!.getActualFrameGeometry().x, left, left+eps, { message: `nColumns: ${nColumns}` });
|
||||
Assert.between(rectRight(lastClient!.getActualFrameGeometry()), right-eps, right, { message: `nColumns: ${nColumns}` });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -123,12 +221,12 @@ tests.register("Preset Widths fill screen non-uniform", 1, () => {
|
||||
const halfWidth = maxWidth/2 - config.gapsInnerHorizontal/2;
|
||||
const quarterWidth = halfWidth/2 - config.gapsInnerHorizontal/2;
|
||||
const height = tilingArea.height;
|
||||
const left1 = tilingArea.left;
|
||||
const left1 = tilingArea.x;
|
||||
const left2 = left1 + config.gapsInnerHorizontal + quarterWidth;
|
||||
const left3 = left2 + config.gapsInnerHorizontal + quarterWidth;
|
||||
|
||||
Assert.rect(clientThin1.frameGeometry, left1, tilingArea.top, quarterWidth, height);
|
||||
Assert.rect(clientThin2.frameGeometry, left2, tilingArea.top, quarterWidth, height);
|
||||
Assert.rect(clientWide.frameGeometry, left3, tilingArea.top, halfWidth, height);
|
||||
Assert.equal(clientWide.frameGeometry.right, tilingArea.right);
|
||||
Assert.rect(clientThin1.getActualFrameGeometry(), left1, tilingArea.y, quarterWidth, height);
|
||||
Assert.rect(clientThin2.getActualFrameGeometry(), left2, tilingArea.y, quarterWidth, height);
|
||||
Assert.rect(clientWide.getActualFrameGeometry(), left3, tilingArea.y, halfWidth, height);
|
||||
Assert.equal(rectRight(clientWide.getActualFrameGeometry()), rectRight(tilingArea));
|
||||
});
|
||||
|
||||
@@ -6,9 +6,9 @@ tests.register("User resize", 10, () => {
|
||||
let clientLeft: MockKwinClient, clientRightTop: MockKwinClient, clientRightBottom: MockKwinClient;
|
||||
function assertSizes(leftWidth: number, rightWidth: number, topHeight: number, bottomHeight: number) {
|
||||
const { left, right } = getGridBounds(clientLeft, clientRightTop);
|
||||
Assert.rect(clientLeft.frameGeometry, left, tilingArea.top, leftWidth, tilingArea.height);
|
||||
Assert.rect(clientRightTop.frameGeometry, left+leftWidth+gapH, tilingArea.top, rightWidth, topHeight);
|
||||
Assert.rect(clientRightBottom.frameGeometry, left+leftWidth+gapH, tilingArea.top+topHeight+gapV, rightWidth, bottomHeight);
|
||||
Assert.rect(clientLeft.getActualFrameGeometry(), left, tilingArea.y, leftWidth, tilingArea.height);
|
||||
Assert.rect(clientRightTop.getActualFrameGeometry(), left+leftWidth+gapH, tilingArea.y, rightWidth, topHeight);
|
||||
Assert.rect(clientRightBottom.getActualFrameGeometry(), left+leftWidth+gapH, tilingArea.y+topHeight+gapV, rightWidth, bottomHeight);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -89,9 +89,9 @@ tests.register("User resize", 10, () => {
|
||||
|
||||
function assertSizes(leftWidth: number, rightWidth: number, topHeight: number, bottomHeight: number) {
|
||||
const { left, right } = getGridBounds(clientLeftTop, clientRight);
|
||||
Assert.rect(clientLeftTop.frameGeometry, left, tilingArea.top, leftWidth, topHeight);
|
||||
Assert.rect(clientLeftBottom.frameGeometry, left, tilingArea.top+topHeight+gapV, leftWidth, bottomHeight);
|
||||
Assert.rect(clientRight.frameGeometry, left+leftWidth+gapH, tilingArea.top, rightWidth, tilingArea.height);
|
||||
Assert.rect(clientLeftTop.getActualFrameGeometry(), left, tilingArea.y, leftWidth, topHeight);
|
||||
Assert.rect(clientLeftBottom.getActualFrameGeometry(), left, tilingArea.y+topHeight+gapV, leftWidth, bottomHeight);
|
||||
Assert.rect(clientRight.getActualFrameGeometry(), left+leftWidth+gapH, tilingArea.y, rightWidth, tilingArea.height);
|
||||
}
|
||||
|
||||
workspaceMock.activeWindow = clientLeftBottom;
|
||||
|
||||
41
src/tests/units/rules/DesktopFilter.ts
Normal file
41
src/tests/units/rules/DesktopFilter.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
tests.register("DesktopFilter", 1, () => {
|
||||
const desktop1 = { __brand: "KwinDesktop" as const, id: "1", name: "Desktop 1" };
|
||||
const desktop2 = { __brand: "KwinDesktop" as const, id: "2", name: "Work" };
|
||||
const desktop3 = { __brand: "KwinDesktop" as const, id: "3", name: "Desktop 2" };
|
||||
|
||||
// Test 1: Empty config means all desktops
|
||||
let filter = new DesktopFilter("");
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop1), { message: "Empty config should work on desktop1" });
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop2), { message: "Empty config should work on desktop2" });
|
||||
|
||||
// Test 2: Whitespace only means all desktops
|
||||
filter = new DesktopFilter(" \n \n ");
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop1), { message: "Whitespace only should work on desktop1" });
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop2), { message: "Whitespace only should work on desktop2" });
|
||||
|
||||
// Test 3: Match all regex pattern
|
||||
filter = new DesktopFilter(".*");
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop1), { message: "Regex '.*' should work on desktop1" });
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop2), { message: "Regex '.*' should work on desktop2" });
|
||||
|
||||
// Test 4: Partial match without anchors
|
||||
filter = new DesktopFilter("Work");
|
||||
Assert.assert(!filter.shouldWorkOnDesktop(desktop1), { message: "Should not work on desktop1" });
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop2), { message: "Should work on desktop2 containing 'Work'" });
|
||||
|
||||
// Test 5: Regex alternation for multiple desktops
|
||||
filter = new DesktopFilter("Desktop 1|Work");
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop1), { message: "Should work on desktop1" });
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop2), { message: "Should work on desktop2" });
|
||||
Assert.assert(!filter.shouldWorkOnDesktop(desktop3), { message: "Should not work on desktop3" });
|
||||
|
||||
// Test 6: Regex pattern with character class
|
||||
filter = new DesktopFilter("Desktop [12]");
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop1), { message: "Should work on desktop1" });
|
||||
Assert.assert(!filter.shouldWorkOnDesktop(desktop2), { message: "Should not work on desktop2" });
|
||||
Assert.assert(filter.shouldWorkOnDesktop(desktop3), { message: "Should work on desktop3" });
|
||||
|
||||
// Test 7: Case-sensitive matching
|
||||
filter = new DesktopFilter("work");
|
||||
Assert.assert(!filter.shouldWorkOnDesktop(desktop2), { message: "Should not work on desktop2 (case mismatch)" });
|
||||
});
|
||||
53
src/tests/units/utils/math.ts
Normal file
53
src/tests/units/utils/math.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
tests.register("math", 1, () => {
|
||||
const rect = new MockQmlRect(100, 200, 10, 20);
|
||||
const testCases: {
|
||||
rect: QmlRect,
|
||||
point: QmlPoint,
|
||||
contained: boolean,
|
||||
}[] = [
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(100, 200),
|
||||
contained: true,
|
||||
},
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(110, 220),
|
||||
contained: true,
|
||||
},
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(105, 205),
|
||||
contained: true,
|
||||
},
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(110.01, 205),
|
||||
contained: false,
|
||||
},
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(105, 220.01),
|
||||
contained: false,
|
||||
},
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(16, 205),
|
||||
contained: false,
|
||||
},
|
||||
{
|
||||
rect: rect,
|
||||
point: new MockQmlPoint(105, 16),
|
||||
contained: false,
|
||||
},
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
const result = rectContainsPoint(testCase.rect, testCase.point);
|
||||
Assert.equal(
|
||||
result,
|
||||
testCase.contained,
|
||||
{ message: JSON.stringify(testCase) },
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Assert {
|
||||
type Options = {
|
||||
interface Options {
|
||||
message?: string,
|
||||
skip?: number,
|
||||
}
|
||||
@@ -126,23 +126,61 @@ namespace Assert {
|
||||
export function grid(
|
||||
config: Config,
|
||||
tilingArea: QmlRect,
|
||||
columnWidth: number,
|
||||
grid: KwinClient[][],
|
||||
columnWidths: number[] | number,
|
||||
grid: MockKwinClient[][],
|
||||
centered: boolean,
|
||||
stackedColumns: number[] = [],
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
const nColumns = grid.length;
|
||||
const columnsWidth = nColumns * columnWidth + (nColumns-1) * config.gapsInnerHorizontal;
|
||||
function getGridWidth() {
|
||||
function getColumnsWidth() {
|
||||
if (columnWidths instanceof Array) {
|
||||
let columnsWidth = 0;
|
||||
for (const columnWidth of columnWidths) {
|
||||
columnsWidth += columnWidth;
|
||||
}
|
||||
return columnsWidth;
|
||||
} else {
|
||||
return nColumns * columnWidths;
|
||||
}
|
||||
}
|
||||
|
||||
const gapsWidth = (nColumns-1) * config.gapsInnerHorizontal;
|
||||
return getColumnsWidth() + gapsWidth;
|
||||
}
|
||||
|
||||
function getColumnWidth(column: number) {
|
||||
if (columnWidths instanceof Array) {
|
||||
return columnWidths[column];
|
||||
} else {
|
||||
return columnWidths;
|
||||
}
|
||||
}
|
||||
|
||||
const gridWidth = getGridWidth();
|
||||
const startX = centered ?
|
||||
tilingArea.x + (tilingArea.width - columnsWidth) / 2 :
|
||||
grid[0][0].frameGeometry.x;
|
||||
tilingArea.x + (tilingArea.width - gridWidth) / 2 :
|
||||
grid[0][0].getActualFrameGeometry().x;
|
||||
|
||||
function getColumnX(column: number) {
|
||||
if (columnWidths instanceof Array) {
|
||||
let x = startX;
|
||||
for (let i = 0; i < column; i++) {
|
||||
x += columnWidths[i] + config.gapsInnerHorizontal;
|
||||
}
|
||||
return x;
|
||||
} else {
|
||||
return startX + column * (columnWidths + config.gapsInnerHorizontal);
|
||||
}
|
||||
}
|
||||
|
||||
// assumes uniformly sized windows within columns of uniform width
|
||||
function getRectInGrid(column: number, window: number, nColumns: number, nWindows: number) {
|
||||
const columnWidth = getColumnWidth(column);
|
||||
const windowHeight = (tilingArea.height - config.gapsInnerVertical * (nWindows-1)) / nWindows;
|
||||
return new MockQmlRect(
|
||||
startX + column * (columnWidth + config.gapsInnerHorizontal),
|
||||
getColumnX(column),
|
||||
tilingArea.y + (windowHeight + config.gapsInnerVertical) * window,
|
||||
columnWidth,
|
||||
(tilingArea.height - config.gapsInnerVertical * (nWindows-1)) / nWindows,
|
||||
@@ -150,9 +188,9 @@ namespace Assert {
|
||||
}
|
||||
|
||||
function getRectInGridStacked(column: number, window: number, nColumns: number, nWindows: number) {
|
||||
const columnX = startX + column * (columnWidth + config.gapsInnerHorizontal);
|
||||
const columnWidth = getColumnWidth(column);
|
||||
return new MockQmlRect(
|
||||
columnX + window * config.stackOffsetX,
|
||||
getColumnX(column) + window * config.stackOffsetX,
|
||||
tilingArea.y + window * config.stackOffsetY,
|
||||
columnWidth - (nWindows-1) * config.stackOffsetX,
|
||||
tilingArea.height - (nWindows-1) * config.stackOffsetY,
|
||||
@@ -167,7 +205,7 @@ namespace Assert {
|
||||
for (let iWindow = 0; iWindow < nWindows; iWindow++) {
|
||||
const window = column[iWindow];
|
||||
equalRects(
|
||||
window.frameGeometry,
|
||||
window.getActualFrameGeometry(),
|
||||
getRect(iColumn, iWindow, nColumns, nWindows),
|
||||
{ message: appendMessage(`column ${iColumn}, window ${iWindow}`, message), skip: skip+1 },
|
||||
);
|
||||
@@ -178,13 +216,13 @@ namespace Assert {
|
||||
export function centered(
|
||||
config: Config,
|
||||
tilingArea: QmlRect,
|
||||
client:KwinClient,
|
||||
client:MockKwinClient,
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
grid(
|
||||
config,
|
||||
tilingArea,
|
||||
client.frameGeometry.width,
|
||||
client.getActualFrameGeometry().width,
|
||||
[[client]],
|
||||
true,
|
||||
[],
|
||||
@@ -197,7 +235,7 @@ namespace Assert {
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
assert(
|
||||
rect.left >= tilingArea.left && rect.right <= tilingArea.right,
|
||||
rect.x >= tilingArea.x && rectRight(rect) <= rectRight(tilingArea),
|
||||
{
|
||||
message: appendMessage(`Rect ${rect} not fully visible`, message),
|
||||
skip: skip + 1,
|
||||
@@ -210,7 +248,7 @@ namespace Assert {
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
assert(
|
||||
rect.left < tilingArea.left || rect.right > tilingArea.right,
|
||||
rect.x < tilingArea.x || rectRight(rect) > rectRight(tilingArea),
|
||||
{
|
||||
message: appendMessage(`Rect ${rect} is fully visible, but shouldn't be`, message),
|
||||
skip: skip + 1,
|
||||
@@ -219,18 +257,18 @@ namespace Assert {
|
||||
}
|
||||
|
||||
export function columnsFillTilingArea(
|
||||
columns: KwinClient[],
|
||||
columns: MockKwinClient[],
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
const options = { message: message, skip: skip+1 };
|
||||
let x = tilingArea.left;
|
||||
let x = tilingArea.x;
|
||||
for (const column of columns) {
|
||||
const width = column.frameGeometry.width;
|
||||
fullyVisible(column.frameGeometry, options);
|
||||
rect(column.frameGeometry, x, tilingArea.top, width, tilingArea.height, options);
|
||||
const width = column.getActualFrameGeometry().width;
|
||||
fullyVisible(column.getActualFrameGeometry(), options);
|
||||
rect(column.getActualFrameGeometry(), x, tilingArea.y, width, tilingArea.height, options);
|
||||
x += width + gapH;
|
||||
}
|
||||
equal(columns[columns.length-1].frameGeometry.right, tilingArea.right, options);
|
||||
equal(rectRight(columns[columns.length-1].getActualFrameGeometry()), rectRight(tilingArea), options);
|
||||
}
|
||||
|
||||
export function tiledClient(
|
||||
|
||||
@@ -16,7 +16,7 @@ class TestRunner {
|
||||
}
|
||||
|
||||
namespace TestRunner {
|
||||
export type Test = {
|
||||
export interface Test {
|
||||
name: string,
|
||||
count: number,
|
||||
f: () => void,
|
||||
|
||||
@@ -2,8 +2,10 @@ let Qt: Qt;
|
||||
let KWin: KWin;
|
||||
let Workspace: Workspace;
|
||||
let qmlBase: QmlObject;
|
||||
let notificationInvalidTiledDesktops: Notification;
|
||||
let notificationInvalidWindowRules: Notification;
|
||||
let notificationInvalidPresetWidths: Notification;
|
||||
let moveCursorToFocus: DBusCall;
|
||||
|
||||
let screen: MockQmlRect;
|
||||
let tilingArea: MockQmlRect;
|
||||
@@ -28,14 +30,23 @@ function init(config: Config) {
|
||||
|
||||
Qt = qtMock;
|
||||
Workspace = workspaceMock;
|
||||
moveCursorToFocus = {
|
||||
__brand: "QmlObject",
|
||||
call: () => {
|
||||
Assert.assert(Workspace.activeWindow !== null, { message: "moveCursorToFocus should never be called if there's no focused window" });
|
||||
const frame = (Workspace.activeWindow! as MockKwinClient).getActualFrameGeometry();
|
||||
workspaceMock.cursorPos.x = Math.floor(frame.x + frame.width/2);
|
||||
workspaceMock.cursorPos.y = Math.floor(frame.y + frame.height/2);
|
||||
},
|
||||
};
|
||||
|
||||
const world = new World(config);
|
||||
return { qtMock, workspaceMock, world };
|
||||
}
|
||||
|
||||
function getGridBounds(clientLeft: KwinClient, clientRight: KwinClient) {
|
||||
const columnsWidth = clientRight.frameGeometry.right - clientLeft.frameGeometry.left;
|
||||
const left = tilingArea.left + Math.floor((tilingArea.width - columnsWidth) / 2);
|
||||
function getGridBounds(clientLeft: MockKwinClient, clientRight: MockKwinClient) {
|
||||
const columnsWidth = rectRight(clientRight.getActualFrameGeometry()) - clientLeft.getActualFrameGeometry().x;
|
||||
const left = tilingArea.x + Math.floor((tilingArea.width - columnsWidth) / 2);
|
||||
const right = left + columnsWidth;
|
||||
return { left, right };
|
||||
}
|
||||
@@ -51,3 +62,10 @@ function getClientManager(world: World): ClientManager {
|
||||
world.do((cm, dm) => clientManager = cm);
|
||||
return clientManager!;
|
||||
}
|
||||
|
||||
function activateRandomWindowOnDesktop(desktop: KwinDesktop) {
|
||||
const windows = Workspace.windows.filter(w => w.desktops.includes(desktop));
|
||||
if (windows.length > 0) {
|
||||
Workspace.activeWindow = randomItem(windows);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ class MockKwinClient {
|
||||
private static readonly borderThickness = 10;
|
||||
|
||||
public caption = "App";
|
||||
public minSize: Readonly<QmlSize> = new MockQmlSize(0, 0);
|
||||
public minSize: Readonly<QmlSize> = new MockQmlSize(randomJitter(), randomJitter());
|
||||
public readonly transient: boolean;
|
||||
public move: boolean = false;
|
||||
public resize: boolean = false;
|
||||
public move = false;
|
||||
public resize = false;
|
||||
public readonly fullScreenable: boolean = true;
|
||||
public readonly maximizable: boolean = true;
|
||||
public readonly output: Output = { __brand: "Output" };
|
||||
@@ -18,17 +18,17 @@ class MockKwinClient {
|
||||
public readonly popupWindow: boolean = false;
|
||||
public readonly pid = 1;
|
||||
|
||||
private _maximizedVertically: boolean = false;
|
||||
private _maximizedHorizontally: boolean = false;
|
||||
private _fullScreen: boolean = false;
|
||||
private _maximizedVertically = false;
|
||||
private _maximizedHorizontally = false;
|
||||
private _fullScreen = false;
|
||||
public activities: string[] = [];
|
||||
public skipSwitcher: boolean = false;
|
||||
public keepAbove: boolean = false;
|
||||
public keepBelow: boolean = false;
|
||||
private _minimized: boolean = false;
|
||||
public skipSwitcher = false;
|
||||
public keepAbove = false;
|
||||
public keepBelow = false;
|
||||
private _minimized = false;
|
||||
private _desktops: KwinDesktop[] = [];
|
||||
private _tile: Tile|null = null;
|
||||
public opacity: number = 1.0;
|
||||
public opacity = 1.0;
|
||||
|
||||
public readonly fullScreenChanged = new MockQSignal<[]>();
|
||||
public readonly desktopsChanged = new MockQSignal<[]>();
|
||||
@@ -42,8 +42,8 @@ class MockKwinClient {
|
||||
public readonly frameGeometryChanged = new MockQSignal<[oldGeometry: QmlRect]>();
|
||||
|
||||
private windowedFrameGeometry: MockQmlRect;
|
||||
private windowed: boolean = true;
|
||||
private hasBorder: boolean = true;
|
||||
private windowed = true;
|
||||
private hasBorder = true;
|
||||
|
||||
constructor(
|
||||
private _frameGeometry: MockQmlRect = new MockQmlRect(10, 10, 100, 200),
|
||||
@@ -52,6 +52,7 @@ class MockKwinClient {
|
||||
this.windowedFrameGeometry = _frameGeometry.clone();
|
||||
this.transient = transientFor !== null;
|
||||
this._desktops = [Workspace.currentDesktop];
|
||||
this.activities = [Workspace.currentActivity];
|
||||
}
|
||||
|
||||
setMaximize(vertically: boolean, horizontally: boolean) {
|
||||
@@ -68,7 +69,7 @@ class MockKwinClient {
|
||||
horizontally ? MaximizedMode.Maximized : MaximizedMode.Vertically
|
||||
) : (
|
||||
horizontally ? MaximizedMode.Horizontally : MaximizedMode.Unmaximized
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
this.frameGeometry = new MockQmlRect(
|
||||
@@ -88,7 +89,15 @@ class MockKwinClient {
|
||||
this.frameGeometry.height - 2 * MockKwinClient.borderThickness,
|
||||
);
|
||||
} else {
|
||||
return this.frameGeometry;
|
||||
return runOneOf(
|
||||
() => this.frameGeometry,
|
||||
() => new MockQmlRect(
|
||||
this.frameGeometry.x - 20,
|
||||
this.frameGeometry.y - 20,
|
||||
this.frameGeometry.width + 40,
|
||||
this.frameGeometry.height + 40,
|
||||
), // some full-screen windows that manage their own window decorations can temporarily have a client geometry bigger than the screen
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +116,7 @@ class MockKwinClient {
|
||||
public set fullScreen(fullScreen: boolean) {
|
||||
const oldFullScreen = this._fullScreen;
|
||||
this.hasBorder = !fullScreen;
|
||||
const targetFrameGeometry = fullScreen ? screen : this.windowedFrameGeometry;
|
||||
|
||||
runReorder(
|
||||
() => {
|
||||
@@ -118,42 +128,54 @@ class MockKwinClient {
|
||||
() => {
|
||||
if (oldFullScreen && !fullScreen) {
|
||||
// when switching from full-screen to windowed, Kwin sometimes first adds the frame before changing the frameGeometry to the final value
|
||||
if (rectEquals(this.frameGeometry, this.windowedFrameGeometry)) {
|
||||
if (!rectEquals(this.frameGeometry, screen)) {
|
||||
// already has windowed frame geometry, don't undo that
|
||||
return;
|
||||
}
|
||||
runOneOf(
|
||||
() => this.frameGeometry = new MockQmlRect(
|
||||
0,
|
||||
0,
|
||||
screen.width + 2 * MockKwinClient.borderThickness,
|
||||
screen.height + 2 * MockKwinClient.borderThickness,
|
||||
),
|
||||
() => this.frameGeometry = new MockQmlRect(
|
||||
-MockKwinClient.borderThickness,
|
||||
-MockKwinClient.borderThickness,
|
||||
screen.width + 2 * MockKwinClient.borderThickness,
|
||||
screen.height + 2 * MockKwinClient.borderThickness,
|
||||
),
|
||||
() => {
|
||||
this.frameGeometry = new MockQmlRect(
|
||||
0,
|
||||
0,
|
||||
screen.width + 2 * MockKwinClient.borderThickness,
|
||||
screen.height + 2 * MockKwinClient.borderThickness,
|
||||
);
|
||||
},
|
||||
() => {
|
||||
this.frameGeometry = new MockQmlRect(
|
||||
-MockKwinClient.borderThickness,
|
||||
-MockKwinClient.borderThickness,
|
||||
screen.width + 2 * MockKwinClient.borderThickness,
|
||||
screen.height + 2 * MockKwinClient.borderThickness,
|
||||
);
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
this.windowed = !fullScreen;
|
||||
if (fullScreen) {
|
||||
this.frameGeometry = screen;
|
||||
} else {
|
||||
this.frameGeometry = this.windowedFrameGeometry;
|
||||
}
|
||||
this.frameGeometry = targetFrameGeometry;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public get frameGeometry() {
|
||||
// for assertions
|
||||
public getActualFrameGeometry() {
|
||||
return this._frameGeometry;
|
||||
}
|
||||
|
||||
// for Karousel
|
||||
public get frameGeometry() {
|
||||
return new MockQmlRect(
|
||||
this._frameGeometry.x + randomJitter(),
|
||||
this._frameGeometry.y + randomJitter(),
|
||||
this._frameGeometry.width + randomJitter(),
|
||||
this._frameGeometry.height + randomJitter(),
|
||||
this.frameGeometryChanged.fire.bind(this.frameGeometryChanged),
|
||||
);
|
||||
}
|
||||
|
||||
public set frameGeometry(frameGeometry: MockQmlRect) {
|
||||
const oldFrameGeometry = this._frameGeometry;
|
||||
this._frameGeometry = new MockQmlRect(
|
||||
@@ -189,9 +211,20 @@ class MockKwinClient {
|
||||
this.desktopsChanged.fire();
|
||||
if (Workspace.activeWindow === this && !desktops.includes(Workspace.currentDesktop)) {
|
||||
Workspace.activeWindow = null;
|
||||
runMaybe(() => Workspace.activeWindow = null); // fired again for some reason
|
||||
if (Workspace.activeWindow === null) {
|
||||
activateRandomWindowOnDesktop(Workspace.currentDesktop);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public moveAndFollowToDesktop(desktop: KwinDesktop, workspaceMock: MockWorkspace) {
|
||||
Assert.assert(workspaceMock.activeWindow === this);
|
||||
this._desktops = [desktop];
|
||||
this.desktopsChanged.fire();
|
||||
workspaceMock.currentDesktop = desktop;
|
||||
}
|
||||
|
||||
public get tile() {
|
||||
return this._tile;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class MockQSignal<T extends unknown[]> {
|
||||
public readonly __brand = "QSignal";
|
||||
|
||||
private readonly handlers: Set<(...args: [...T]) => void> = new Set();
|
||||
private readonly handlers = new Set<(...args: [...T]) => void>();
|
||||
|
||||
public connect(handler: (...args: [...T]) => void) {
|
||||
this.handlers.add(handler);
|
||||
|
||||
@@ -5,4 +5,11 @@ class MockQmlPoint {
|
||||
public x: number,
|
||||
public y: number,
|
||||
) {}
|
||||
|
||||
public clone() {
|
||||
return new MockQmlPoint(
|
||||
this.x,
|
||||
this.y,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,22 +49,6 @@ class MockQmlRect {
|
||||
this.onChanged(oldRect);
|
||||
}
|
||||
|
||||
public get top() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public get bottom() {
|
||||
return this.y + this.height;
|
||||
}
|
||||
|
||||
public get left() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public get right() {
|
||||
return this.x + this.width;
|
||||
}
|
||||
|
||||
public set(target: QmlRect) {
|
||||
const oldRect = this.clone();
|
||||
this._x = target.x;
|
||||
|
||||
@@ -3,15 +3,15 @@ class MockWorkspace {
|
||||
|
||||
public activities = ["test-activity"];
|
||||
public desktops: KwinDesktop[] = [
|
||||
{ __brand: "KwinDesktop", id: "desktop1" },
|
||||
{ __brand: "KwinDesktop", id: "desktop2" }
|
||||
{ __brand: "KwinDesktop", id: "desktop1", name: "Desktop 1" },
|
||||
{ __brand: "KwinDesktop", id: "desktop2", name: "Desktop 2" },
|
||||
];
|
||||
public currentDesktop = this.desktops[0];
|
||||
public currentActivity = this.activities[0];
|
||||
public activeScreen: Output = { __brand: "Output" };
|
||||
public readonly windows: MockKwinClient[] = [];
|
||||
public cursorPos = new MockQmlPoint(0, 0);
|
||||
|
||||
private _currentDesktop = this.desktops[0];
|
||||
private _activeWindow: KwinClient|null = null;
|
||||
|
||||
public readonly currentDesktopChanged = new MockQSignal<[]>();
|
||||
@@ -52,13 +52,13 @@ class MockWorkspace {
|
||||
}
|
||||
|
||||
public removeWindow(window: MockKwinClient) {
|
||||
this.activeWindow = null;
|
||||
runReorder(
|
||||
() => this.windows.splice(this.windows.indexOf(window), 1),
|
||||
() => this.windowRemoved.fire(window),
|
||||
);
|
||||
if (window === this.activeWindow) {
|
||||
const windows = this.windows.filter(w => w.desktops.includes(this.currentDesktop));
|
||||
Workspace.activeWindow = windows.length > 0 ? randomItem(windows) : null;
|
||||
if (this.activeWindow === null) {
|
||||
activateRandomWindowOnDesktop(this.currentDesktop);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class MockWorkspace {
|
||||
frame.y += delta.y;
|
||||
}
|
||||
runOneOf(
|
||||
() => window.frameGeometry.set(frame),
|
||||
() => window.getActualFrameGeometry().set(frame),
|
||||
() => window.frameGeometry = frame,
|
||||
);
|
||||
}
|
||||
@@ -88,8 +88,8 @@ class MockWorkspace {
|
||||
const frame = window.getFrameGeometryCopy();
|
||||
if (edgeResize) {
|
||||
this.cursorPos = new MockQmlPoint(
|
||||
leftEdge ? frame.left : frame.right,
|
||||
topEdge ? frame.top : frame.bottom,
|
||||
leftEdge ? frame.x : rectRight(frame),
|
||||
topEdge ? frame.y : rectBottom(frame),
|
||||
);
|
||||
} else {
|
||||
this.cursorPos = new MockQmlPoint(
|
||||
@@ -114,7 +114,7 @@ class MockWorkspace {
|
||||
}
|
||||
}
|
||||
runOneOf(
|
||||
() => window.frameGeometry.set(frame),
|
||||
() => window.getActualFrameGeometry().set(frame),
|
||||
() => window.frameGeometry = frame,
|
||||
);
|
||||
}
|
||||
@@ -123,6 +123,15 @@ class MockWorkspace {
|
||||
window.interactiveMoveResizeFinished.fire();
|
||||
}
|
||||
|
||||
public get currentDesktop() {
|
||||
return this._currentDesktop;
|
||||
}
|
||||
|
||||
public set currentDesktop(currentDesktop: KwinDesktop) {
|
||||
this._currentDesktop = currentDesktop;
|
||||
this.currentDesktopChanged.fire();
|
||||
}
|
||||
|
||||
public get activeWindow() {
|
||||
return this._activeWindow;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ function runMaybe(f: () => void) {
|
||||
}
|
||||
}
|
||||
|
||||
function runOneOf(...fs: (() => void)[]) {
|
||||
function runOneOf<T>(...fs: (() => T)[]) {
|
||||
const index = randomInt(fs.length);
|
||||
runLog.push(`${getStackFrame(1)} - Chose ${index}`);
|
||||
fs[index]();
|
||||
return fs[index]();
|
||||
}
|
||||
|
||||
function runReorder(...fs: (() => void)[]) {
|
||||
@@ -22,6 +22,20 @@ function runReorder(...fs: (() => void)[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function runReorderDebug(order: number[], ...fs: (() => void)[]) {
|
||||
for (const index of order) {
|
||||
fs[index]();
|
||||
}
|
||||
}
|
||||
|
||||
function randomJitter() {
|
||||
if (Math.random() < 0.25) {
|
||||
return (Math.random() - 0.5) * 0.5;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function randomInt(n: number) {
|
||||
return Math.floor(Math.random() * n);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user