Compare commits
343 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 | ||
|
|
465945429a | ||
|
|
1d7636508b | ||
|
|
47213a71f5 | ||
|
|
75a548977c | ||
|
|
d746b91a88 | ||
|
|
a0d9c49287 | ||
|
|
862cc445bd | ||
|
|
5019a5d702 | ||
|
|
36c7cab137 | ||
|
|
df3c1f4512 | ||
|
|
5f3eaf1eec | ||
|
|
4a680177f6 | ||
|
|
8d807c979b | ||
|
|
c8e37aeb87 | ||
|
|
ad0fe7472c | ||
|
|
a51e45667c | ||
|
|
6615fe6f93 | ||
|
|
6e69139b80 | ||
|
|
97430d5043 | ||
|
|
47f4bbd9b6 | ||
|
|
2d4ad73d16 | ||
|
|
bb4e4f8ebd | ||
|
|
0742975334 | ||
|
|
64457429d0 | ||
|
|
02154f2f5e | ||
|
|
0a2bb4f65d | ||
|
|
6f207e59c4 | ||
|
|
4c987b6c5b | ||
|
|
bca0158df9 | ||
|
|
9feeb0f23e | ||
|
|
0241846ea5 | ||
|
|
3bf3f16f49 | ||
|
|
782a6db56d | ||
|
|
93b6850ffd | ||
|
|
5f0c637d1a | ||
|
|
8829d0b291 | ||
|
|
d37b4bc5d1 | ||
|
|
ead29e5e69 | ||
|
|
ff75d931f6 | ||
|
|
d00d514d30 | ||
|
|
3b919909dc | ||
|
|
0004b6f921 | ||
|
|
24265c56f9 | ||
|
|
dcbc0a474d | ||
|
|
88f170f5c1 | ||
|
|
78ab48ee09 | ||
|
|
b2d81796f8 | ||
|
|
7d27331ce5 | ||
|
|
55e1037a7b | ||
|
|
7820c7d00e | ||
|
|
3d8ca0bc14 | ||
|
|
eaf68b87f9 | ||
|
|
b2dfad6042 | ||
|
|
054808cb38 | ||
|
|
97059fa4f7 | ||
|
|
5e7959c7f4 | ||
|
|
a9c3aa7eae | ||
|
|
3aec148f16 | ||
|
|
c60cfeb521 | ||
|
|
0bbf82d84d | ||
|
|
44c5c43c25 | ||
|
|
98b2d8b882 | ||
|
|
4e78d27620 | ||
|
|
32700d1193 | ||
|
|
817351ec44 | ||
|
|
c2dd832e5c | ||
|
|
2f78f9afb1 | ||
|
|
2cc716f59e | ||
|
|
685323546a | ||
|
|
c8e40185dc | ||
|
|
0b0cb77e9e | ||
|
|
ce4f810372 | ||
|
|
3ccc6dd870 | ||
|
|
92e1c2ffd4 | ||
|
|
3a1c911974 | ||
|
|
e197c3200e | ||
|
|
4fea81423a | ||
|
|
b459ba6d4e | ||
|
|
a16e2edb1e | ||
|
|
fb1047c8ba | ||
|
|
66bc14287d | ||
|
|
86ab4a20f4 | ||
|
|
f467d5a523 | ||
|
|
082d4571d8 | ||
|
|
aa061e586e | ||
|
|
ff5121f1c4 | ||
|
|
984edbec90 | ||
|
|
ea27ce4a03 | ||
|
|
ae0a4e142a | ||
|
|
09b7b44e2c | ||
|
|
fb88300dbe | ||
|
|
9dafb92f47 | ||
|
|
92144e8e83 | ||
|
|
9b54dd543e | ||
|
|
5145b04cb7 | ||
|
|
4372e13869 | ||
|
|
7694bb1f8d | ||
|
|
3615952bd7 | ||
|
|
cba6ecbb3d | ||
|
|
db55af462b | ||
|
|
32f384df75 | ||
|
|
25ac6d4ce8 | ||
|
|
194f774519 | ||
|
|
430f731804 | ||
|
|
2cdf308a72 | ||
|
|
acf4c5c6ae | ||
|
|
703ed2eb40 | ||
|
|
ec5e7002dc | ||
|
|
fe92b1aa13 | ||
|
|
d812fa706f | ||
|
|
0bb9ae9e8d | ||
|
|
315ea6b560 | ||
|
|
a4236534fc | ||
|
|
e95378c0dd | ||
|
|
884dc9977d | ||
|
|
f3cf45e5f3 | ||
|
|
5e7f191e95 | ||
|
|
ec14d5295f | ||
|
|
116372c954 | ||
|
|
7290a0741d | ||
|
|
5bbd0da172 | ||
|
|
fb415042d8 | ||
|
|
ff5ba6b455 | ||
|
|
ef0e840812 | ||
|
|
b0cb9eaba0 | ||
|
|
0eb624d6ff | ||
|
|
6e53bbad2f | ||
|
|
218ab65d61 | ||
|
|
e91c9c825e | ||
|
|
c2931c9fbe | ||
|
|
1c61f22353 | ||
|
|
3ff7688e42 | ||
|
|
f5ca5e71c0 | ||
|
|
3f222f0ef8 | ||
|
|
9a08841bb8 | ||
|
|
2081b9997c | ||
|
|
93fe2a3cfd | ||
|
|
9cee3f2808 | ||
|
|
16618e6ad3 | ||
|
|
90c27bc58b | ||
|
|
79055dcdf3 | ||
|
|
1e328c7b57 | ||
|
|
2be6a04fc4 | ||
|
|
9b21a720be | ||
|
|
fcfed28a0a | ||
|
|
7dce802b70 | ||
|
|
94393393f5 | ||
|
|
1ba128af05 | ||
|
|
8094b64ce7 | ||
|
|
335418e84b | ||
|
|
c675fc63d1 | ||
|
|
9d81262b18 | ||
|
|
5d36f02631 | ||
|
|
977facbed7 | ||
|
|
278a2d9c7b | ||
|
|
8076635719 | ||
|
|
c8f0ed87a4 | ||
|
|
b3f581c386 | ||
|
|
279333dd1d | ||
|
|
dac1d488b7 | ||
|
|
df587fc37b | ||
|
|
987a4c852f | ||
|
|
ebff074a4c | ||
|
|
ef4c509e75 | ||
|
|
d0c1438724 | ||
|
|
d926be2e12 | ||
|
|
b18516646d | ||
|
|
b0405858c5 | ||
|
|
0cb3513532 | ||
|
|
0b2d876074 | ||
|
|
cb1b70d4f0 | ||
|
|
da6b983e4a | ||
|
|
6181057fa8 | ||
|
|
abc8671c6f | ||
|
|
36bf942266 | ||
|
|
d239ac24b3 | ||
|
|
79571146be | ||
|
|
7273196e0c | ||
|
|
212ade5ab6 | ||
|
|
239f8d95cb | ||
|
|
e430a20638 | ||
|
|
0beaebd874 | ||
|
|
6100090db3 | ||
|
|
8d07958962 | ||
|
|
80bafee5ed | ||
|
|
38e72a9504 | ||
|
|
d0c4cee63d | ||
|
|
494192179b | ||
|
|
0dcba7cbc0 | ||
|
|
8312364202 | ||
|
|
6d8dfad4e7 | ||
|
|
0d970a8bec | ||
|
|
12e8d71ef3 | ||
|
|
407b24df08 | ||
|
|
4ecced369a | ||
|
|
e3979d94f7 | ||
|
|
b6a5080d5d | ||
|
|
e974f0ebbd | ||
|
|
23e13436d8 | ||
|
|
aaef587c00 | ||
|
|
8f4c20138e | ||
|
|
a754da9b78 | ||
|
|
b94d3e2304 | ||
|
|
11e1458180 | ||
|
|
e7e68628dd | ||
|
|
edac1a679c | ||
|
|
f711248619 | ||
|
|
502f4bee26 | ||
|
|
35d2096811 | ||
|
|
f682c160db | ||
|
|
ef9cb01755 | ||
|
|
d51b9caec5 | ||
|
|
62bc96f205 | ||
|
|
35802eead7 | ||
|
|
ba886fe5f6 | ||
|
|
30e4e3e273 | ||
|
|
6bcb30b0bd | ||
|
|
747a90f5d7 | ||
|
|
da899171c4 | ||
|
|
109238e645 | ||
|
|
7d1ebcf126 | ||
|
|
07ce0cceb5 | ||
|
|
c7aaa66c5c | ||
|
|
5c77f4f276 | ||
|
|
80608e721f | ||
|
|
54b07ebe56 | ||
|
|
aeba236720 | ||
|
|
1984442ed3 | ||
|
|
2a4c5eac3b | ||
|
|
266beb85ae | ||
|
|
5877e466da | ||
|
|
9a60f94eda | ||
|
|
0f7092a5b6 | ||
|
|
0b3608a530 | ||
|
|
aaeac977e6 | ||
|
|
adc78f11bc | ||
|
|
f1206b18b1 | ||
|
|
c6066c354d | ||
|
|
914202f091 | ||
|
|
b85c86e7db | ||
|
|
fdb4b88333 | ||
|
|
4e3d924366 | ||
|
|
3d3e8cff17 | ||
|
|
a79229da75 | ||
|
|
53d04c1d33 | ||
|
|
a18ff61d9e | ||
|
|
99ffad9223 | ||
|
|
e776df509b | ||
|
|
63de2d4cae | ||
|
|
85d361f16f | ||
|
|
f3b75807be | ||
|
|
88bce26456 | ||
|
|
3a75ddab0f | ||
|
|
ee0aa93308 | ||
|
|
33ca138420 | ||
|
|
79f4aaeef8 | ||
|
|
0aca6e1146 | ||
|
|
28e54434aa | ||
|
|
ee14509228 | ||
|
|
1596edc43f | ||
|
|
b897ab5b9f | ||
|
|
5e6dad8459 | ||
|
|
beeba74442 | ||
|
|
3e14440180 | ||
|
|
36836ad258 | ||
|
|
bebc009cc6 | ||
|
|
a4ba8516dc | ||
|
|
675a70d907 | ||
|
|
3ba66f1c89 | ||
|
|
4556198b2e | ||
|
|
7b8de5955d | ||
|
|
68a687b7d4 |
19
.github/ISSUE_TEMPLATE/1-compatibility-issue.md
vendored
Normal file
19
.github/ISSUE_TEMPLATE/1-compatibility-issue.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Compatibility issue
|
||||
about: Report an issue with a specific application or window
|
||||
title: "[Compatibility]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Karousel version:
|
||||
Plasma version:
|
||||
X11 / Wayland:
|
||||
|
||||
Window class:
|
||||
Window caption (title):
|
||||
Window type:
|
||||
(Get this info [here](https://github.com/peterfajdiga/karousel/wiki/Getting-window-info))
|
||||
|
||||
Description:
|
||||
14
.github/ISSUE_TEMPLATE/2-bug-report.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE/2-bug-report.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
name: Generic bug report
|
||||
about: Report a bug
|
||||
title: "[Bug]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Karousel version:
|
||||
Plasma version:
|
||||
X11 / Wayland:
|
||||
|
||||
Description:
|
||||
22
.github/ISSUE_TEMPLATE/3-feature_request.md
vendored
Normal file
22
.github/ISSUE_TEMPLATE/3-feature_request.md
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Request a feature
|
||||
title: "[Feature]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
||||
These sections are just guidelines, feel free to remove them.
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,7 @@
|
||||
/package/contents/code/main.js
|
||||
/package/contents/config/main.xml
|
||||
/karousel*.tar.gz
|
||||
run-ts-tmp.js
|
||||
|
||||
/node_modules
|
||||
/.idea
|
||||
|
||||
49
Makefile
49
Makefile
@@ -1,32 +1,43 @@
|
||||
VERSION = $(shell grep '"Version":' ./package/metadata.json | grep -o '[0-9\.]*')
|
||||
CHECKS := true
|
||||
|
||||
.PHONY: *
|
||||
|
||||
TSC_SCRIPT_FLAGS = --lib es2020 ./src/extern/qt.d.ts
|
||||
VERSION = $(shell grep '"Version":' ./package/metadata.json | grep -o '[0-9\.]*')
|
||||
|
||||
config:
|
||||
build: lint test
|
||||
tsc -p ./src/main --outFile ./package/contents/code/main.js
|
||||
mkdir -p ./package/contents/config
|
||||
tsc ${TSC_SCRIPT_FLAGS} ./src/config/definition.ts ./generators/config/kcfg.ts --outFile /dev/stdout | node - > ./package/contents/config/main.xml
|
||||
./run-ts.sh ./src/generators/config > ./package/contents/config/main.xml
|
||||
|
||||
build:
|
||||
tsc --outFile ./package/contents/code/main.js
|
||||
npm-install:
|
||||
npm install
|
||||
|
||||
install: build config
|
||||
kpackagetool6 --type=KWin/Script -i ./package || kpackagetool6 --type=KWin/Script -u ./package
|
||||
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
|
||||
|
||||
install: build
|
||||
kpackagetool6 --type=KWin/Script --install=./package || kpackagetool6 --type=KWin/Script --upgrade=./package
|
||||
|
||||
uninstall:
|
||||
kpackagetool6 --type=KWin/Script -r karousel
|
||||
kpackagetool6 --type=KWin/Script --remove=karousel
|
||||
|
||||
package: build config
|
||||
tar -czf ./karousel_${subst .,_,${VERSION}}.tar.gz ./package
|
||||
|
||||
logs:
|
||||
journalctl -t kwin_x11 -g '^qml:|^file://.*karousel' -f
|
||||
package: build
|
||||
tar -czf ./karousel_${subst .,_,${VERSION}}.tar.gz ./package --transform s/package/karousel/
|
||||
|
||||
docs-key-bindings-bbcode:
|
||||
@tsc ${TSC_SCRIPT_FLAGS} ./src/keyBindings/definition.ts ./generators/docs/keyBindings.ts ./generators/docs/keyBindingsBbcode.ts --outFile /dev/stdout | node -
|
||||
@./run-ts.sh ./src/generators/docs/keyBindingsBbcode
|
||||
|
||||
docs-key-bindings-table:
|
||||
@tsc ${TSC_SCRIPT_FLAGS} ./src/keyBindings/definition.ts ./generators/docs/keyBindings.ts ./generators/docs/keyBindingsTable.ts --outFile /dev/stdout | node -
|
||||
docs-key-bindings-markdown:
|
||||
@./run-ts.sh ./src/generators/docs/keyBindingsMarkdown
|
||||
|
||||
docs-key-bindings-fmt:
|
||||
@tsc ${TSC_SCRIPT_FLAGS} ./src/keyBindings/definition.ts ./generators/docs/keyBindings.ts ./generators/docs/keyBindingsFmt.ts --outFile /dev/stdout | node -
|
||||
@./run-ts.sh ./src/generators/docs/keyBindingsFmt
|
||||
|
||||
30
README.md
30
README.md
@@ -1,17 +1,11 @@
|
||||
# Karousel
|
||||
KWin tiling script with scrolling. Works especially well with ultrawide screens.
|
||||
Scrollable tiling Kwin script. Works especially well with ultrawide screens.
|
||||
Use with [this](https://github.com/peterfajdiga/kwin4_effect_geometry_change) for animations.
|
||||
|
||||
https://github.com/peterfajdiga/karousel/assets/22796326/2ab62d18-09c7-45f9-8fda-e5e36b8d7a02
|
||||
|
||||
Karousel works differently from most tiling window managers in that it does not maximize the width
|
||||
of windows, as this can be undesirable with wider screens, where it results in excessively wide
|
||||
windows that require large return sweeps when reading their content.
|
||||
Instead, it leaves the width of windows to the user's control. This additionally prevents
|
||||
unprompted reflow of window content.
|
||||
|
||||
Windows are automatically centered when possible. And when running out of width, windows can be
|
||||
scrolled through horizontally.
|
||||
A scrollable tiling window manager tiles windows, but it does not maximize their widths. Instead, it leaves the width of windows to the user's control.
|
||||
Windows are automatically centered when possible. And when running out of width, windows can be scrolled through horizontally.
|
||||
|
||||
Similar window managers include [PaperWM](https://github.com/paperwm/PaperWM),
|
||||
[Niri](https://github.com/YaLTeR/niri), and
|
||||
@@ -28,6 +22,13 @@ Karousel requires the following QML modules:
|
||||
- Doesn't support windows on all desktops
|
||||
- Doesn't support windows on multiple activities
|
||||
|
||||
## Installation
|
||||
First install the _org.kde.notification_ QML module (_qml-module-org-kde-notifications_ package on Ubuntu).
|
||||
|
||||
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 npm, node, and tsc).
|
||||
|
||||
## Key bindings
|
||||
The key bindings can be configured in KDE System Settings among KWin's own keyboard shortcuts.
|
||||
Here's the default ones:
|
||||
@@ -38,22 +39,30 @@ Here's the default ones:
|
||||
| Meta+D | Move focus right (Clashes with default KDE shortcuts, may require manual remapping) |
|
||||
| Meta+W | Move focus up (Clashes with default KDE shortcuts, may require manual remapping) |
|
||||
| Meta+S | Move focus down (Clashes with default KDE shortcuts, may require manual remapping) |
|
||||
| (unassigned) | Move focus to the next window in grid |
|
||||
| (unassigned) | Move focus to the previous window in grid |
|
||||
| Meta+Home | Move focus to start |
|
||||
| Meta+End | Move focus to end |
|
||||
| Meta+Shift+A | Move window left (Moves window out of and into columns) |
|
||||
| Meta+Shift+D | Move window right (Moves window out of and into columns) |
|
||||
| Meta+Shift+W | Move window up |
|
||||
| Meta+Shift+S | Move window down |
|
||||
| (unassigned) | Move window to the next position in grid |
|
||||
| (unassigned) | Move window to the previous position in grid |
|
||||
| Meta+Shift+Home | Move window to start |
|
||||
| Meta+Shift+End | Move window to end |
|
||||
| Meta+X | Toggle stacked layout for focused column (One window in the column visible, others shaded; not supported on Wayland) |
|
||||
| Meta+X | Toggle stacked layout for focused column (Only the active window visible) |
|
||||
| Meta+Ctrl+Shift+A | Move column left |
|
||||
| Meta+Ctrl+Shift+D | Move column right |
|
||||
| Meta+Ctrl+Shift+Home | Move column to start |
|
||||
| Meta+Ctrl+Shift+End | Move column to end |
|
||||
| Meta+Ctrl++ | Increase column width |
|
||||
| Meta+Ctrl+- | Decrease column width |
|
||||
| Meta+R | Cycle through preset column widths |
|
||||
| Meta+Shift+R | Cycle through preset column widths in reverse |
|
||||
| Meta+Ctrl+X | Equalize widths of visible columns |
|
||||
| Meta+Ctrl+A | Squeeze left column onto the screen (Clashes with default KDE shortcuts, may require manual remapping) |
|
||||
| Meta+Ctrl+D | Squeeze right column onto the screen |
|
||||
| Meta+Alt+Return | Center focused window (Scrolls so that the focused window is centered in the screen) |
|
||||
| Meta+Alt+A | Scroll one column to the left |
|
||||
| Meta+Alt+D | Scroll one column to the right |
|
||||
@@ -61,6 +70,7 @@ Here's the default ones:
|
||||
| Meta+Alt+PgDown | Scroll right |
|
||||
| Meta+Alt+Home | Scroll to start |
|
||||
| Meta+Alt+End | Scroll to end |
|
||||
| Meta+Ctrl+Return | Move Karousel grid to the current screen |
|
||||
| Meta+[N] | Move focus to column N (Clashes with default KDE shortcuts, may require manual remapping) |
|
||||
| Meta+Shift+[N] | Move window to column N (Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!) |
|
||||
| Meta+Ctrl+Shift+[N] | Move column to position N (Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!) |
|
||||
|
||||
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],
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -1,12 +0,0 @@
|
||||
console.log(`[list]`);
|
||||
|
||||
for (const binding of keyBindings) {
|
||||
console.log(` [*] ${binding.defaultKeySequence} — ${binding.description}${formatComment(binding.comment)}`);
|
||||
}
|
||||
|
||||
for (const binding of numKeyBindings) {
|
||||
const numPrefix = binding.fKeys ? "F" : "";
|
||||
console.log(` [*] ${binding.defaultModifiers}+${numPrefix}[N] — ${binding.description}N${formatComment(binding.comment)}`);
|
||||
}
|
||||
|
||||
console.log(`[/list]`);
|
||||
@@ -1,14 +0,0 @@
|
||||
const colLeft = [
|
||||
...keyBindings.map((binding: KeyBinding) => binding.defaultKeySequence),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => {
|
||||
const numPrefix = binding.fKeys ? "F" : "";
|
||||
return `${binding.defaultModifiers}+${numPrefix}[N]`;
|
||||
}),
|
||||
];
|
||||
|
||||
const colRight = [
|
||||
...keyBindings.map((binding: KeyBinding) => `${binding.description}${formatComment(binding.comment)}`),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => `${binding.description}N${formatComment(binding.comment)}`),
|
||||
];
|
||||
|
||||
printCols(colLeft, " ", colRight);
|
||||
@@ -1,18 +0,0 @@
|
||||
const colLeft = [
|
||||
"Shortcut",
|
||||
"---",
|
||||
...keyBindings.map((binding: KeyBinding) => binding.defaultKeySequence),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => {
|
||||
const numPrefix = binding.fKeys ? "F" : "";
|
||||
return `${binding.defaultModifiers}+${numPrefix}[N]`;
|
||||
}),
|
||||
];
|
||||
|
||||
const colRight = [
|
||||
"Action",
|
||||
"---",
|
||||
...keyBindings.map((binding: KeyBinding) => `${binding.description}${formatComment(binding.comment)}`),
|
||||
...numKeyBindings.map((binding: NumKeyBinding) => `${binding.description}N${formatComment(binding.comment)}`),
|
||||
];
|
||||
|
||||
printCols("| ", colLeft, " | ", colRight, " |");
|
||||
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,13 +29,23 @@
|
||||
</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">
|
||||
<string>Stack columns by default</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>New columns start in stacked mode (one window in the column visible, others shaded). Not supported on Wayland.</string>
|
||||
<string>New columns start in stacked mode (only the active window visible)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -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>
|
||||
@@ -280,14 +319,14 @@
|
||||
</item>
|
||||
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_manualScrollStep">
|
||||
<widget class="QLabel" name="label_stackOffsetX">
|
||||
<property name="text">
|
||||
<string>Manual scroll step size:</string>
|
||||
<string>Horizontal offset for stacked columns:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QSpinBox" name="kcfg_manualScrollStep">
|
||||
<widget class="QSpinBox" name="kcfg_stackOffsetX">
|
||||
<property name="suffix">
|
||||
<string> px</string>
|
||||
</property>
|
||||
@@ -301,14 +340,14 @@
|
||||
</item>
|
||||
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_manualResizeStep">
|
||||
<widget class="QLabel" name="label_stackOffsetY">
|
||||
<property name="text">
|
||||
<string>Manual resize step size:</string>
|
||||
<string>Vertical offset for stacked columns:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QSpinBox" name="kcfg_manualResizeStep">
|
||||
<widget class="QSpinBox" name="kcfg_stackOffsetY">
|
||||
<property name="suffix">
|
||||
<string> px</string>
|
||||
</property>
|
||||
@@ -322,13 +361,82 @@
|
||||
</item>
|
||||
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_manualScrollStep">
|
||||
<property name="text">
|
||||
<string>Manual scroll step size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QSpinBox" name="kcfg_manualScrollStep">
|
||||
<property name="suffix">
|
||||
<string> px</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>999</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Widths used for cycling through widths</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="label_offScreenOpacity">
|
||||
<property name="text">
|
||||
<string>Obscured window opacity:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<item row="11" column="1">
|
||||
<widget class="QSpinBox" name="kcfg_offScreenOpacity">
|
||||
<property name="suffix">
|
||||
<string> %</string>
|
||||
@@ -341,6 +449,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
@@ -349,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"
|
||||
@@ -25,4 +35,39 @@ Item {
|
||||
flags: Notification.Persistent
|
||||
urgency: Notification.HighUrgency
|
||||
}
|
||||
|
||||
Notification {
|
||||
id: notificationInvalidPresetWidths
|
||||
componentName: "plasma_workspace"
|
||||
eventId: "notification"
|
||||
title: "Karousel"
|
||||
text: "Your preset widths are malformed, please review your Karousel configuration"
|
||||
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.9.1",
|
||||
"Version": "0.16",
|
||||
"License": "GPLv3",
|
||||
"Website": "https://github.com/peterfajdiga/karousel",
|
||||
"BugReportUrl": "https://github.com/peterfajdiga/karousel/issues"
|
||||
|
||||
8
run-ts.sh
Executable file
8
run-ts.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
JS_FILE='./run-ts-tmp.js'
|
||||
|
||||
tsc -p "$1" --outFile "$JS_FILE"
|
||||
node "$JS_FILE"
|
||||
346
src/Actions.ts
346
src/Actions.ts
@@ -1,346 +0,0 @@
|
||||
namespace Actions {
|
||||
export function getAction(world: World, config: Config, name: string) {
|
||||
switch (name) {
|
||||
case "focus-left": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const prevColumn = grid.getPrevColumn(column);
|
||||
if (prevColumn === null) {
|
||||
return;
|
||||
}
|
||||
prevColumn.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "focus-right": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const nextColumn = grid.getNextColumn(column);
|
||||
if (nextColumn === null) {
|
||||
return;
|
||||
}
|
||||
nextColumn.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "focus-up": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const prevWindow = column.getPrevWindow(window);
|
||||
if (prevWindow === null) {
|
||||
return;
|
||||
}
|
||||
prevWindow.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "focus-down": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const nextWindow = column.getNextWindow(window);
|
||||
if (nextWindow === null) {
|
||||
return;
|
||||
}
|
||||
nextWindow.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "focus-start": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
if (firstColumn === null) {
|
||||
return;
|
||||
}
|
||||
firstColumn.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "focus-end": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
if (lastColumn === null) {
|
||||
return;
|
||||
}
|
||||
lastColumn.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-left": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
// move from own column into existing column
|
||||
const prevColumn = grid.getPrevColumn(column);
|
||||
if (prevColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(prevColumn);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
} else {
|
||||
// move from shared column into own column
|
||||
const newColumn = new Column(grid, grid.getPrevColumn(column));
|
||||
window.moveToColumn(newColumn);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-right": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
// move from own column into existing column
|
||||
const nextColumn = grid.getNextColumn(column);
|
||||
if (nextColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(nextColumn);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
} else {
|
||||
// move from shared column into own column
|
||||
const newColumn = new Column(grid, column);
|
||||
window.moveToColumn(newColumn);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-up": return () => {
|
||||
// TODO (optimization): only arrange moved windows
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveWindowUp(window);
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-down": return () => {
|
||||
// TODO (optimization): only arrange moved windows
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveWindowDown(window);
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-start": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const newColumn = new Column(grid, null);
|
||||
window.moveToColumn(newColumn);
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-end": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const newColumn = new Column(grid, grid.getLastColumn());
|
||||
window.moveToColumn(newColumn);
|
||||
});
|
||||
};
|
||||
|
||||
case "window-toggle-floating": return () => {
|
||||
const kwinClient = Workspace.activeWindow;
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.toggleFloatingClient(kwinClient);
|
||||
});
|
||||
};
|
||||
|
||||
case "column-move-left": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
grid.moveColumnLeft(column);
|
||||
});
|
||||
};
|
||||
|
||||
case "column-move-right": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
grid.moveColumnRight(column);
|
||||
});
|
||||
};
|
||||
|
||||
case "column-move-start": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveAfter(null);
|
||||
});
|
||||
};
|
||||
|
||||
case "column-move-end": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.moveAfter(grid.getLastColumn());
|
||||
});
|
||||
};
|
||||
|
||||
case "column-toggle-stacked": return () => {
|
||||
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
|
||||
column.toggleStacked();
|
||||
});
|
||||
};
|
||||
|
||||
case "column-width-increase": return () => {
|
||||
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
|
||||
config.columnResizer.increaseWidth(column, config.manualResizeStep);
|
||||
});
|
||||
};
|
||||
|
||||
case "column-width-decrease": return () => {
|
||||
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
|
||||
config.columnResizer.decreaseWidth(column, config.manualResizeStep);
|
||||
});
|
||||
};
|
||||
|
||||
case "columns-width-equalize": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.getCurrentDesktop().equalizeVisibleColumnsWidths();
|
||||
});
|
||||
};
|
||||
|
||||
case "grid-scroll-left": return () => {
|
||||
gridScroll(world, -config.manualScrollStep);
|
||||
};
|
||||
|
||||
case "grid-scroll-right": return () => {
|
||||
gridScroll(world, config.manualScrollStep);
|
||||
};
|
||||
|
||||
case "grid-scroll-start": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
if (firstColumn === null) {
|
||||
return;
|
||||
}
|
||||
grid.desktop.scrollToColumn(firstColumn);
|
||||
});
|
||||
};
|
||||
|
||||
case "grid-scroll-end": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
if (lastColumn === null) {
|
||||
return;
|
||||
}
|
||||
grid.desktop.scrollToColumn(lastColumn);
|
||||
});
|
||||
};
|
||||
|
||||
case "grid-scroll-focused": return () => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
grid.desktop.scrollCenterRange(column);
|
||||
})
|
||||
};
|
||||
|
||||
case "grid-scroll-left-column": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
|
||||
if (column === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prevColumn = grid.getPrevColumn(column);
|
||||
if (prevColumn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(prevColumn);
|
||||
});
|
||||
};
|
||||
|
||||
case "grid-scroll-right-column": return () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
|
||||
if (column === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextColumn = grid.getNextColumn(column);
|
||||
if (nextColumn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(nextColumn);
|
||||
});
|
||||
};
|
||||
|
||||
default: throw new Error("unknown action: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
export function getNumAction(world: World, name: string) {
|
||||
switch (name) {
|
||||
case "focus-": return (columnIndex: number) => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
targetColumn.focus();
|
||||
});
|
||||
};
|
||||
|
||||
case "window-move-to-column-": return (columnIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(targetColumn);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
});
|
||||
};
|
||||
|
||||
case "column-move-to-column-": return (columnIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null || targetColumn === column) {
|
||||
return;
|
||||
}
|
||||
if (targetColumn.isAfter(column)) {
|
||||
column.moveAfter(targetColumn);
|
||||
} else {
|
||||
column.moveAfter(grid.getPrevColumn(targetColumn));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
case "column-move-to-desktop-": return (desktopIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
|
||||
const kwinDesktop = Workspace.desktops[desktopIndex];
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
column.moveToGrid(newGrid, newGrid.getLastColumn());
|
||||
});
|
||||
};
|
||||
|
||||
case "tail-move-to-desktop-": return (desktopIndex: number) => {
|
||||
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
|
||||
const kwinDesktop = Workspace.desktops[desktopIndex];
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
oldGrid.evacuateTail(newGrid, column);
|
||||
});
|
||||
};
|
||||
|
||||
default: throw new Error("unknown num action: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
function gridScroll(world: World, amount: number) {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const grid = desktopManager.getCurrentDesktop().grid;
|
||||
grid.desktop.adjustScroll(amount, false);
|
||||
});
|
||||
}
|
||||
|
||||
export type Config = {
|
||||
manualScrollStep: number,
|
||||
manualResizeStep: number,
|
||||
columnResizer: ColumnResizer,
|
||||
};
|
||||
|
||||
export type ColumnResizer = {
|
||||
increaseWidth(column: Column, step: number): void,
|
||||
decreaseWidth(column: Column, step: number): void,
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
class RawResizer {
|
||||
public increaseWidth(column: Column, step: number) {
|
||||
column.adjustWidth(step, true);
|
||||
}
|
||||
|
||||
public decreaseWidth(column: Column, step: number) {
|
||||
column.adjustWidth(-step, true);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
type Config = {
|
||||
gapsOuterTop: number,
|
||||
gapsOuterBottom: number,
|
||||
gapsOuterLeft: number,
|
||||
gapsOuterRight: number,
|
||||
gapsInnerHorizontal: number,
|
||||
gapsInnerVertical: number,
|
||||
manualScrollStep: number,
|
||||
manualResizeStep: number,
|
||||
offScreenOpacity: number,
|
||||
untileOnDrag: boolean,
|
||||
stackColumnsByDefault: boolean,
|
||||
resizeNeighborColumn: boolean,
|
||||
reMaximize: boolean,
|
||||
skipSwitcher: boolean,
|
||||
scrollingLazy: boolean,
|
||||
scrollingCentered: boolean,
|
||||
scrollingGrouped: boolean,
|
||||
tiledKeepBelow: boolean,
|
||||
floatingKeepAbove: boolean,
|
||||
windowRules: string,
|
||||
};
|
||||
10
src/extern/global.d.ts
vendored
10
src/extern/global.d.ts
vendored
@@ -1,6 +1,8 @@
|
||||
declare const Qt: Qt;
|
||||
declare const KWin: KWin;
|
||||
declare const Workspace: Workspace;
|
||||
declare const qmlBase: QmlObject;
|
||||
declare const notificationInvalidTiledDesktops: Notification;
|
||||
declare const notificationInvalidWindowRules: Notification;
|
||||
|
||||
type Notification = {
|
||||
sendEvent(): void;
|
||||
};
|
||||
declare const notificationInvalidPresetWidths: Notification;
|
||||
declare const moveCursorToFocus: DBusCall;
|
||||
|
||||
45
src/extern/qt.d.ts
vendored
45
src/extern/qt.d.ts
vendored
@@ -1,45 +0,0 @@
|
||||
declare const console: {
|
||||
log(...args: any[]);
|
||||
trace();
|
||||
assert(boolean);
|
||||
};
|
||||
|
||||
declare const Qt: {
|
||||
rect(x: number, y: number, width: number, height: number): QmlRect;
|
||||
createQmlObject(qml: string, parent: QmlObject);
|
||||
};
|
||||
|
||||
type QmlObject = unknown;
|
||||
|
||||
type QmlPoint = {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
type QmlRect = {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
top: number;
|
||||
bottom: number; // top + height
|
||||
left: number;
|
||||
right: number; // left + width
|
||||
};
|
||||
|
||||
type QmlSize = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
type QSignal<T extends unknown[]> = {
|
||||
connect(handler: (...args: [...T]) => void): void;
|
||||
disconnect(handler: (...args: [...T]) => void): void;
|
||||
};
|
||||
|
||||
type QmlTimer = {
|
||||
interval: number;
|
||||
readonly triggered: QSignal<[]>;
|
||||
restart(): void;
|
||||
destroy(): void;
|
||||
};
|
||||
8
src/generators/config/tsconfig.json
Normal file
8
src/generators/config/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": [
|
||||
"../../extern/**/*",
|
||||
"../../lib/**/*",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
@@ -1,20 +1,11 @@
|
||||
type KeyBinding = {
|
||||
name: string;
|
||||
interface DocsKeyBinding {
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultKeySequence: string;
|
||||
keySequence: string;
|
||||
}
|
||||
|
||||
type NumKeyBinding = {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultModifiers: string;
|
||||
fKeys: boolean;
|
||||
}
|
||||
|
||||
function formatComment(comment: string | undefined) {
|
||||
return comment === undefined ? "" : ` (${comment})`;
|
||||
function formatDescription(item: {description: string, comment?: string}) {
|
||||
const suffix = item.comment === undefined ? "" : ` (${item.comment})`;
|
||||
return `${applyMacro(item.description, "N")}${suffix}`;
|
||||
}
|
||||
|
||||
function printCols(...columns: (string[] | string)[]) {
|
||||
@@ -24,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
|
||||
@@ -37,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) {
|
||||
@@ -63,3 +54,15 @@ function printCols(...columns: (string[] | string)[]) {
|
||||
console.log(line);
|
||||
}
|
||||
}
|
||||
|
||||
const empty: any = {};
|
||||
const keyBindings: DocsKeyBinding[] = Array.prototype.concat(
|
||||
getKeyBindings(empty, empty).map(binding => ({
|
||||
description: formatDescription(binding),
|
||||
keySequence: binding.defaultKeySequence || "(unassigned)",
|
||||
})),
|
||||
getNumKeyBindings(empty, empty).map(binding => ({
|
||||
description: formatDescription(binding),
|
||||
keySequence: `${binding.defaultModifiers}+${binding.fKeys ? "F" : ""}[N]`,
|
||||
})),
|
||||
);
|
||||
7
src/generators/docs/keyBindingsBbcode/main.ts
Normal file
7
src/generators/docs/keyBindingsBbcode/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
console.log(`[list]`);
|
||||
|
||||
for (const binding of keyBindings) {
|
||||
console.log(` [*] ${binding.keySequence} — ${binding.description}`);
|
||||
}
|
||||
|
||||
console.log(`[/list]`);
|
||||
9
src/generators/docs/keyBindingsBbcode/tsconfig.json
Normal file
9
src/generators/docs/keyBindingsBbcode/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": [
|
||||
"../../../extern/**/*",
|
||||
"../../../lib/**/*",
|
||||
"../keyBindings.ts",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
9
src/generators/docs/keyBindingsFmt/main.ts
Normal file
9
src/generators/docs/keyBindingsFmt/main.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const colLeft = [
|
||||
...keyBindings.map(binding => binding.keySequence),
|
||||
];
|
||||
|
||||
const colRight = [
|
||||
...keyBindings.map(binding => binding.description),
|
||||
];
|
||||
|
||||
printCols(colLeft, " ", colRight);
|
||||
9
src/generators/docs/keyBindingsFmt/tsconfig.json
Normal file
9
src/generators/docs/keyBindingsFmt/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": [
|
||||
"../../../extern/**/*",
|
||||
"../../../lib/**/*",
|
||||
"../keyBindings.ts",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
13
src/generators/docs/keyBindingsMarkdown/main.ts
Normal file
13
src/generators/docs/keyBindingsMarkdown/main.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
const colLeft = [
|
||||
"Shortcut",
|
||||
"---",
|
||||
...keyBindings.map(binding => binding.keySequence),
|
||||
];
|
||||
|
||||
const colRight = [
|
||||
"Action",
|
||||
"---",
|
||||
...keyBindings.map(binding => binding.description),
|
||||
];
|
||||
|
||||
printCols("| ", colLeft, " | ", colRight, " |");
|
||||
9
src/generators/docs/keyBindingsMarkdown/tsconfig.json
Normal file
9
src/generators/docs/keyBindingsMarkdown/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"include": [
|
||||
"../../../extern/**/*",
|
||||
"../../../lib/**/*",
|
||||
"../keyBindings.ts",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
const keyBindings: KeyBinding[] = [
|
||||
{
|
||||
name: "window-toggle-floating",
|
||||
description: "Toggle floating",
|
||||
defaultKeySequence: "Meta+Space",
|
||||
},
|
||||
{
|
||||
name: "focus-left",
|
||||
description: "Move focus left",
|
||||
defaultKeySequence: "Meta+A",
|
||||
},
|
||||
{
|
||||
name: "focus-right",
|
||||
description: "Move focus right",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+D",
|
||||
},
|
||||
{
|
||||
name: "focus-up",
|
||||
description: "Move focus up",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+W",
|
||||
},
|
||||
{
|
||||
name: "focus-down",
|
||||
description: "Move focus down",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+S",
|
||||
},
|
||||
{
|
||||
name: "focus-start",
|
||||
description: "Move focus to start",
|
||||
defaultKeySequence: "Meta+Home",
|
||||
},
|
||||
{
|
||||
name: "focus-end",
|
||||
description: "Move focus to end",
|
||||
defaultKeySequence: "Meta+End",
|
||||
},
|
||||
{
|
||||
name: "window-move-left",
|
||||
description: "Move window left",
|
||||
comment: "Moves window out of and into columns",
|
||||
defaultKeySequence: "Meta+Shift+A",
|
||||
},
|
||||
{
|
||||
name: "window-move-right",
|
||||
description: "Move window right",
|
||||
comment: "Moves window out of and into columns",
|
||||
defaultKeySequence: "Meta+Shift+D",
|
||||
},
|
||||
{
|
||||
name: "window-move-up",
|
||||
description: "Move window up",
|
||||
defaultKeySequence: "Meta+Shift+W",
|
||||
},
|
||||
{
|
||||
name: "window-move-down",
|
||||
description: "Move window down",
|
||||
defaultKeySequence: "Meta+Shift+S",
|
||||
},
|
||||
{
|
||||
name: "window-move-start",
|
||||
description: "Move window to start",
|
||||
defaultKeySequence: "Meta+Shift+Home",
|
||||
},
|
||||
{
|
||||
name: "window-move-end",
|
||||
description: "Move window to end",
|
||||
defaultKeySequence: "Meta+Shift+End",
|
||||
},
|
||||
{
|
||||
name: "column-toggle-stacked",
|
||||
description: "Toggle stacked layout for focused column",
|
||||
comment: "One window in the column visible, others shaded; not supported on Wayland",
|
||||
defaultKeySequence: "Meta+X",
|
||||
},
|
||||
{
|
||||
name: "column-move-left",
|
||||
description: "Move column left",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+A",
|
||||
},
|
||||
{
|
||||
name: "column-move-right",
|
||||
description: "Move column right",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+D",
|
||||
},
|
||||
{
|
||||
name: "column-move-start",
|
||||
description: "Move column to start",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+Home",
|
||||
},
|
||||
{
|
||||
name: "column-move-end",
|
||||
description: "Move column to end",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+End",
|
||||
},
|
||||
{
|
||||
name: "column-width-increase",
|
||||
description: "Increase column width",
|
||||
defaultKeySequence: "Meta+Ctrl++",
|
||||
},
|
||||
{
|
||||
name: "column-width-decrease",
|
||||
description: "Decrease column width",
|
||||
defaultKeySequence: "Meta+Ctrl+-",
|
||||
},
|
||||
{
|
||||
name: "columns-width-equalize",
|
||||
description: "Equalize widths of visible columns",
|
||||
defaultKeySequence: "Meta+Ctrl+X",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-focused",
|
||||
description: "Center focused window",
|
||||
comment: "Scrolls so that the focused window is centered in the screen",
|
||||
defaultKeySequence: "Meta+Alt+Return",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-left-column",
|
||||
description: "Scroll one column to the left",
|
||||
defaultKeySequence: "Meta+Alt+A",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-right-column",
|
||||
description: "Scroll one column to the right",
|
||||
defaultKeySequence: "Meta+Alt+D",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-left",
|
||||
description: "Scroll left",
|
||||
defaultKeySequence: "Meta+Alt+PgUp",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-right",
|
||||
description: "Scroll right",
|
||||
defaultKeySequence: "Meta+Alt+PgDown",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-start",
|
||||
description: "Scroll to start",
|
||||
defaultKeySequence: "Meta+Alt+Home",
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-end",
|
||||
description: "Scroll to end",
|
||||
defaultKeySequence: "Meta+Alt+End",
|
||||
},
|
||||
];
|
||||
|
||||
const numKeyBindings: NumKeyBinding[] = [
|
||||
{
|
||||
name: "focus-",
|
||||
description: "Move focus to column ",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultModifiers: "Meta",
|
||||
fKeys: false,
|
||||
},
|
||||
{
|
||||
name: "window-move-to-column-",
|
||||
description: "Move window to column ",
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!",
|
||||
defaultModifiers: "Meta+Shift",
|
||||
fKeys: false,
|
||||
},
|
||||
{
|
||||
name: "column-move-to-column-",
|
||||
description: "Move column to position ",
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: false,
|
||||
},
|
||||
{
|
||||
name: "column-move-to-desktop-",
|
||||
description: "Move column to desktop ",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: true,
|
||||
},
|
||||
{
|
||||
name: "tail-move-to-desktop-",
|
||||
description: "Move this and all following columns to desktop ",
|
||||
defaultModifiers: "Meta+Ctrl+Shift+Alt",
|
||||
fKeys: true,
|
||||
},
|
||||
];
|
||||
@@ -1,11 +0,0 @@
|
||||
type LayoutConfig = {
|
||||
gapsInnerHorizontal: number,
|
||||
gapsInnerVertical: number,
|
||||
offScreenOpacity: number,
|
||||
stackColumnsByDefault: boolean,
|
||||
resizeNeighborColumn: boolean,
|
||||
reMaximize: boolean,
|
||||
skipSwitcher: boolean,
|
||||
tiledKeepBelow: boolean,
|
||||
maximizedKeepAbove: boolean,
|
||||
};
|
||||
62
src/lib/behavior/PresetWidths.ts
Normal file
62
src/lib/behavior/PresetWidths.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
class PresetWidths {
|
||||
private readonly presets: ((maxWidth: number) => number)[];
|
||||
|
||||
constructor(presetWidths: string, spacing: number) {
|
||||
this.presets = PresetWidths.parsePresetWidths(presetWidths, spacing);
|
||||
}
|
||||
|
||||
public next(currentWidth: number, minWidth: number, maxWidth: number) {
|
||||
const widths = this.getWidths(minWidth, maxWidth);
|
||||
const nextIndex = widths.findIndex(width => width > currentWidth);
|
||||
return nextIndex >= 0 ? widths[nextIndex] : widths[0];
|
||||
}
|
||||
|
||||
public prev(currentWidth: number, minWidth: number, maxWidth: number) {
|
||||
const widths = this.getWidths(minWidth, maxWidth).reverse();
|
||||
const nextIndex = widths.findIndex(width => width < currentWidth);
|
||||
return nextIndex >= 0 ? widths[nextIndex] : widths[0];
|
||||
}
|
||||
|
||||
public getWidths(minWidth: number, maxWidth: number) {
|
||||
const widths = this.presets.map(f => clamp(f(maxWidth), minWidth, maxWidth));
|
||||
widths.sort((a, b) => a - b);
|
||||
return uniq(widths);
|
||||
}
|
||||
|
||||
private static parsePresetWidths(presetWidths: string, spacing: number): ((maxWidth: number) => number)[] {
|
||||
function getRatioFunction(ratio: number) {
|
||||
return (maxWidth: number) => Math.floor((maxWidth + spacing) * ratio - spacing);
|
||||
}
|
||||
|
||||
return presetWidths.split(",").map((widthStr: string) => {
|
||||
widthStr = widthStr.trim();
|
||||
|
||||
const widthPx = PresetWidths.parseNumberWithSuffix(widthStr, "px");
|
||||
if (widthPx !== undefined) {
|
||||
return () => widthPx;
|
||||
}
|
||||
|
||||
const widthPct = PresetWidths.parseNumberWithSuffix(widthStr, "%");
|
||||
if (widthPct !== undefined) {
|
||||
return getRatioFunction(widthPct / 100.0);
|
||||
}
|
||||
|
||||
return getRatioFunction(PresetWidths.parseNumberSafe(widthStr));
|
||||
});
|
||||
}
|
||||
|
||||
private static parseNumberSafe(str: string) {
|
||||
const num = Number(str);
|
||||
if (isNaN(num) || num <= 0) {
|
||||
throw new Error("Invalid number: " + str);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
private static parseNumberWithSuffix(str: string, suffix: string) {
|
||||
if (!str.endsWith(suffix)) {
|
||||
return undefined;
|
||||
}
|
||||
return PresetWidths.parseNumberSafe(str.substring(0, str.length-suffix.length).trim());
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
class ContextualResizer {
|
||||
public increaseWidth(column: Column, step: number) {
|
||||
constructor(
|
||||
private readonly presetWidths: { getWidths: (minWidth: number, maxWidth: number) => number[] },
|
||||
) {}
|
||||
|
||||
public increaseWidth(column: Column) {
|
||||
const grid = column.grid;
|
||||
const desktop = grid.desktop;
|
||||
const visibleRange = desktop.getCurrentVisibleRange();
|
||||
if(!column.isVisible(visibleRange, true) || column.getWidth() >= column.getMaxWidth()) {
|
||||
const minWidth = column.getMinWidth();
|
||||
const maxWidth = column.getMaxWidth();
|
||||
if(!Range.contains(visibleRange, column) || column.getWidth() >= maxWidth) {
|
||||
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;
|
||||
@@ -17,16 +23,15 @@ class ContextualResizer {
|
||||
const leftSpace = leftVisibleColumn.getLeft() - visibleRange.getLeft();
|
||||
const rightSpace = visibleRange.getRight() - rightVisibleColumn.getRight();
|
||||
|
||||
const newWidth = ContextualResizer.findNextStep(
|
||||
const newWidth = findMinPositive(
|
||||
[
|
||||
visibleRange.getWidth(),
|
||||
column.getWidth() + step,
|
||||
column.getWidth() + leftSpace + rightSpace,
|
||||
column.getWidth() + leftSpace + rightSpace + leftVisibleColumn.getWidth() + grid.config.gapsInnerHorizontal,
|
||||
column.getWidth() + leftSpace + rightSpace + rightVisibleColumn.getWidth() + grid.config.gapsInnerHorizontal,
|
||||
...this.presetWidths.getWidths(minWidth, maxWidth),
|
||||
],
|
||||
width => width - column.getWidth(),
|
||||
)
|
||||
);
|
||||
if (newWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -35,26 +40,28 @@ class ContextualResizer {
|
||||
desktop.scrollCenterVisible(column);
|
||||
}
|
||||
|
||||
public decreaseWidth(column: Column, step: number) {
|
||||
public decreaseWidth(column: Column) {
|
||||
const grid = column.grid;
|
||||
const desktop = grid.desktop;
|
||||
const visibleRange = desktop.getCurrentVisibleRange();
|
||||
if(!column.isVisible(visibleRange, true) || column.getWidth() <= column.getMinWidth()) {
|
||||
const minWidth = column.getMinWidth();
|
||||
const maxWidth = column.getMaxWidth();
|
||||
if(!Range.contains(visibleRange, column) || column.getWidth() <= minWidth) {
|
||||
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;
|
||||
}
|
||||
|
||||
let leftOffScreenColumn = grid.getPrevColumn(leftVisibleColumn);
|
||||
let leftOffScreenColumn = grid.getLeftColumn(leftVisibleColumn);
|
||||
if (leftOffScreenColumn === column) {
|
||||
leftOffScreenColumn = null;
|
||||
}
|
||||
let rightOffScreenColumn = grid.getNextColumn(rightVisibleColumn);
|
||||
let rightOffScreenColumn = grid.getRightColumn(rightVisibleColumn);
|
||||
if (rightOffScreenColumn === column) {
|
||||
rightOffScreenColumn = null;
|
||||
}
|
||||
@@ -64,15 +71,14 @@ class ContextualResizer {
|
||||
const leftOffScreen = leftOffScreenColumn === null ? 0 : leftOffScreenColumn.getWidth() + grid.config.gapsInnerHorizontal - unusedWidth;
|
||||
const rightOffScreen = rightOffScreenColumn === null ? 0 : rightOffScreenColumn.getWidth() + grid.config.gapsInnerHorizontal - unusedWidth;
|
||||
|
||||
const newWidth = ContextualResizer.findNextStep(
|
||||
const newWidth = findMinPositive(
|
||||
[
|
||||
visibleRange.getWidth(),
|
||||
column.getWidth() - step,
|
||||
column.getWidth() - leftOffScreen,
|
||||
column.getWidth() - rightOffScreen,
|
||||
...this.presetWidths.getWidths(minWidth, maxWidth),
|
||||
],
|
||||
width => column.getWidth() - width,
|
||||
)
|
||||
);
|
||||
if (newWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -81,16 +87,21 @@ class ContextualResizer {
|
||||
desktop.scrollCenterVisible(column);
|
||||
}
|
||||
|
||||
private static findNextStep(steps: number[], evaluate: (step: number) => number) {
|
||||
let bestScore = Infinity;
|
||||
let bestStep = undefined;
|
||||
for (const step of steps) {
|
||||
const score = evaluate(step);
|
||||
if (score > 0 && score < bestScore) {
|
||||
bestScore = score;
|
||||
bestStep = step;
|
||||
}
|
||||
}
|
||||
return bestStep;
|
||||
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);
|
||||
}
|
||||
}
|
||||
43
src/lib/behavior/columnResizer/RawResizer.ts
Normal file
43
src/lib/behavior/columnResizer/RawResizer.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
class RawResizer {
|
||||
constructor(
|
||||
private readonly presetWidths: { getWidths: (minWidth: number, maxWidth: number) => number[] },
|
||||
) {}
|
||||
|
||||
public increaseWidth(column: Column) {
|
||||
const newWidth = findMinPositive(
|
||||
[
|
||||
...this.presetWidths.getWidths(column.getMinWidth(), column.getMaxWidth()),
|
||||
],
|
||||
width => width - column.getWidth(),
|
||||
);
|
||||
if (newWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
column.setWidth(newWidth, true);
|
||||
}
|
||||
|
||||
public decreaseWidth(column: Column) {
|
||||
const newWidth = findMinPositive(
|
||||
[
|
||||
...this.presetWidths.getWidths(column.getMinWidth(), column.getMaxWidth()),
|
||||
],
|
||||
width => column.getWidth() - width,
|
||||
);
|
||||
if (newWidth === undefined) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
29
src/lib/config/config.ts
Normal file
29
src/lib/config/config.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
interface Config {
|
||||
gapsOuterTop: number;
|
||||
gapsOuterBottom: number;
|
||||
gapsOuterLeft: number;
|
||||
gapsOuterRight: number;
|
||||
gapsInnerHorizontal: number;
|
||||
gapsInnerVertical: number;
|
||||
stackOffsetX: number;
|
||||
stackOffsetY: number;
|
||||
manualScrollStep: number;
|
||||
presetWidths: string;
|
||||
offScreenOpacity: number;
|
||||
untileOnDrag: boolean;
|
||||
cursorFollowsFocus: boolean;
|
||||
stackColumnsByDefault: boolean;
|
||||
resizeNeighborColumn: boolean;
|
||||
reMaximize: boolean;
|
||||
skipSwitcher: boolean;
|
||||
scrollingLazy: boolean;
|
||||
scrollingCentered: boolean;
|
||||
scrollingGrouped: boolean;
|
||||
gestureScroll: boolean;
|
||||
gestureScrollInvert: boolean;
|
||||
gestureScrollStep: number;
|
||||
tiledKeepBelow: boolean;
|
||||
floatingKeepAbove: boolean;
|
||||
windowRules: string;
|
||||
tiledDesktops: string;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
const defaultWindowRules = `[
|
||||
{
|
||||
"class": "ksmserver-logout-greeter",
|
||||
"class": "(org\\\\.kde\\\\.)?plasmashell",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "(org\\\\.kde\\\\.)?plasmashell",
|
||||
"class": "(org\\\\.kde\\\\.)?polkit-kde-authentication-agent-1",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
@@ -31,28 +31,28 @@ 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",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "zoom",
|
||||
"caption": "Zoom Cloud Meetings|zoom|zoom <2>",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "jetbrains-idea",
|
||||
"class": "jetbrains-.*",
|
||||
"caption": "splash",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "jetbrains-studio",
|
||||
"caption": "splash",
|
||||
"tile": false
|
||||
},
|
||||
{
|
||||
"class": "jetbrains-idea",
|
||||
"caption": "Unstash Changes|Paths Affected by stash@.*",
|
||||
"tile": true
|
||||
},
|
||||
{
|
||||
"class": "jetbrains-studio",
|
||||
"class": "jetbrains-.*",
|
||||
"caption": "Unstash Changes|Paths Affected by stash@.*",
|
||||
"tile": true
|
||||
}
|
||||
@@ -62,32 +62,42 @@ const configDef = [
|
||||
{
|
||||
name: "gapsOuterTop",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsOuterBottom",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsOuterLeft",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsOuterRight",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 16,
|
||||
},
|
||||
{
|
||||
name: "gapsInnerHorizontal",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 8,
|
||||
},
|
||||
{
|
||||
name: "gapsInnerVertical",
|
||||
type: "UInt",
|
||||
default: 18,
|
||||
default: 8,
|
||||
},
|
||||
{
|
||||
name: "stackOffsetX",
|
||||
type: "UInt",
|
||||
default: 8,
|
||||
},
|
||||
{
|
||||
name: "stackOffsetY",
|
||||
type: "UInt",
|
||||
default: 32,
|
||||
},
|
||||
{
|
||||
name: "manualScrollStep",
|
||||
@@ -95,9 +105,9 @@ const configDef = [
|
||||
default: 200,
|
||||
},
|
||||
{
|
||||
name: "manualResizeStep",
|
||||
type: "UInt",
|
||||
default: 600,
|
||||
name: "presetWidths",
|
||||
type: "String",
|
||||
default: "50%, 100%",
|
||||
},
|
||||
{
|
||||
name: "offScreenOpacity",
|
||||
@@ -109,6 +119,11 @@ const configDef = [
|
||||
type: "Bool",
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
name: "cursorFollowsFocus",
|
||||
type: "Bool",
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
name: "stackColumnsByDefault",
|
||||
type: "Bool",
|
||||
@@ -144,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",
|
||||
@@ -163,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;
|
||||
}
|
||||
1
src/lib/extern/global.d.ts
vendored
Normal file
1
src/lib/extern/global.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare const console: Console;
|
||||
47
src/extern/kwin.d.ts → src/lib/extern/kwin.ts
vendored
47
src/extern/kwin.d.ts → src/lib/extern/kwin.ts
vendored
@@ -1,8 +1,12 @@
|
||||
declare const KWin: {
|
||||
readConfig(key: string, defaultValue: any): any;
|
||||
};
|
||||
interface KWin {
|
||||
__brand: "KWin";
|
||||
|
||||
readConfig(key: string, defaultValue: any): any;
|
||||
}
|
||||
|
||||
interface Workspace {
|
||||
__brand: "Workspace";
|
||||
|
||||
declare const Workspace: {
|
||||
readonly activities: string[];
|
||||
readonly desktops: KwinDesktop[];
|
||||
readonly currentDesktop: KwinDesktop;
|
||||
@@ -11,19 +15,20 @@ declare const Workspace: {
|
||||
readonly windows: KwinClient[];
|
||||
readonly cursorPos: Readonly<QmlPoint>;
|
||||
|
||||
activeWindow: KwinClient;
|
||||
activeWindow: KwinClient|null;
|
||||
|
||||
readonly currentDesktopChanged: QSignal<[]>
|
||||
readonly currentDesktopChanged: QSignal<[]>;
|
||||
readonly windowAdded: QSignal<[KwinClient]>;
|
||||
readonly windowRemoved: QSignal<[KwinClient]>;
|
||||
readonly windowActivated: QSignal<[KwinClient]>;
|
||||
readonly desktopsChanged: QSignal<[]>;
|
||||
readonly windowActivated: QSignal<[KwinClient|null]>;
|
||||
readonly screensChanged: QSignal<[]>;
|
||||
readonly activitiesChanged: QSignal<[]>;
|
||||
readonly desktopsChanged: QSignal<[]>;
|
||||
readonly currentActivityChanged: QSignal<[]>;
|
||||
readonly virtualScreenSizeChanged: QSignal<[]>;
|
||||
|
||||
clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop);
|
||||
};
|
||||
clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop): QmlRect;
|
||||
}
|
||||
|
||||
const enum ClientAreaOption {
|
||||
PlacementArea,
|
||||
@@ -43,15 +48,16 @@ const enum MaximizedMode {
|
||||
Maximized,
|
||||
}
|
||||
|
||||
type Tile = unknown;
|
||||
type Output = unknown;
|
||||
interface Tile { __brand: "Tile" }
|
||||
interface Output { __brand: "Output" }
|
||||
|
||||
interface KwinClient {
|
||||
readonly shadeable: boolean;
|
||||
__brand: "KwinClient";
|
||||
|
||||
readonly caption: string;
|
||||
readonly minSize: Readonly<QmlSize>;
|
||||
readonly transient: boolean;
|
||||
readonly transientFor: KwinClient;
|
||||
readonly transientFor: KwinClient | null;
|
||||
readonly clientGeometry: Readonly<QmlRect>;
|
||||
readonly move: boolean;
|
||||
readonly resize: boolean;
|
||||
@@ -65,24 +71,24 @@ interface KwinClient {
|
||||
readonly normalWindow: boolean;
|
||||
readonly managed: boolean;
|
||||
readonly popupWindow: boolean;
|
||||
readonly pid: number;
|
||||
|
||||
fullScreen: boolean;
|
||||
activities: string[]; // empty array means all activities
|
||||
skipSwitcher: boolean;
|
||||
keepAbove: boolean;
|
||||
keepBelow: boolean;
|
||||
shade: boolean;
|
||||
minimized: boolean;
|
||||
frameGeometry: QmlRect;
|
||||
desktops: KwinDesktop[]; // empty array means all desktops
|
||||
tile: Tile;
|
||||
tile: Tile|null;
|
||||
opacity: number;
|
||||
|
||||
readonly fullScreenChanged: QSignal<[]>;
|
||||
readonly desktopsChanged: QSignal<[]>;
|
||||
readonly activitiesChanged: QSignal<[]>;
|
||||
readonly minimizedChanged: QSignal<[]>;
|
||||
readonly maximizedAboutToChange: QSignal<[MaximizedMode]>
|
||||
readonly maximizedAboutToChange: QSignal<[MaximizedMode]>;
|
||||
readonly captionChanged: QSignal<[]>;
|
||||
readonly tileChanged: QSignal<[]>;
|
||||
readonly interactiveMoveResizeStarted: QSignal<[]>;
|
||||
@@ -93,10 +99,13 @@ interface KwinClient {
|
||||
}
|
||||
|
||||
interface KwinDesktop {
|
||||
__brand: "KwinDesktop";
|
||||
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
type ShortcutHandler = {
|
||||
interface ShortcutHandler extends QmlObject {
|
||||
readonly activated: QSignal<[]>;
|
||||
destroy(): void;
|
||||
};
|
||||
}
|
||||
3
src/lib/extern/notification.ts
vendored
Normal file
3
src/lib/extern/notification.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
interface Notification extends QmlObject {
|
||||
sendEvent(): void;
|
||||
}
|
||||
52
src/lib/extern/qt.ts
vendored
Normal file
52
src/lib/extern/qt.ts
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
interface Console {
|
||||
__brand: "Console";
|
||||
|
||||
log(...args: any[]): void;
|
||||
assert(assertion: boolean, message?: string): void;
|
||||
}
|
||||
|
||||
interface Qt {
|
||||
__brand: "Qt";
|
||||
|
||||
rect(x: number, y: number, width: number, height: number): QmlRect;
|
||||
createQmlObject(qml: string, parent: QmlObject): QmlObject;
|
||||
}
|
||||
|
||||
interface QmlObject { __brand: "QmlObject" }
|
||||
|
||||
interface QmlPoint {
|
||||
__brand: "QmlPoint";
|
||||
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface QmlRect {
|
||||
__brand: "QmlRect";
|
||||
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface QmlSize {
|
||||
__brand: "QmlSize";
|
||||
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface QSignal<T extends unknown[]> {
|
||||
__brand: "QSignal";
|
||||
|
||||
connect(handler: (...args: [...T]) => void): void;
|
||||
disconnect(handler: (...args: [...T]) => void): void;
|
||||
}
|
||||
|
||||
interface QmlTimer extends QmlObject {
|
||||
interval: number;
|
||||
readonly triggered: QSignal<[]>;
|
||||
restart(): void;
|
||||
destroy(): void;
|
||||
}
|
||||
486
src/lib/keyBindings/Actions.ts
Normal file
486
src/lib/keyBindings/Actions.ts
Normal file
@@ -0,0 +1,486 @@
|
||||
class Actions {
|
||||
constructor(
|
||||
private readonly config: Actions.Config,
|
||||
) {}
|
||||
|
||||
public readonly focusLeft = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const leftColumn = grid.getLeftColumn(column);
|
||||
if (leftColumn === null) {
|
||||
return;
|
||||
}
|
||||
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.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly focusUp = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const aboveWindow = column.getAboveWindow(window);
|
||||
if (aboveWindow === null) {
|
||||
return;
|
||||
}
|
||||
aboveWindow.focus();
|
||||
};
|
||||
|
||||
public readonly focusDown = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const belowWindow = column.getBelowWindow(window);
|
||||
if (belowWindow === null) {
|
||||
return;
|
||||
}
|
||||
belowWindow.focus();
|
||||
};
|
||||
|
||||
public readonly focusNext = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const belowWindow = column.getBelowWindow(window);
|
||||
if (belowWindow !== null) {
|
||||
belowWindow.focus();
|
||||
} else {
|
||||
const rightColumn = grid.getRightColumn(column);
|
||||
if (rightColumn === null) {
|
||||
return;
|
||||
}
|
||||
rightColumn.getFirstWindow().focus();
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focusPrevious = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const aboveWindow = column.getAboveWindow(window);
|
||||
if (aboveWindow !== null) {
|
||||
aboveWindow.focus();
|
||||
} else {
|
||||
const leftColumn = grid.getLeftColumn(column);
|
||||
if (leftColumn === null) {
|
||||
return;
|
||||
}
|
||||
leftColumn.getLastWindow().focus();
|
||||
}
|
||||
};
|
||||
|
||||
public readonly focusStart = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const firstColumn = grid.getFirstColumn();
|
||||
if (firstColumn === null) {
|
||||
return;
|
||||
}
|
||||
firstColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly focusEnd = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const lastColumn = grid.getLastColumn();
|
||||
if (lastColumn === null) {
|
||||
return;
|
||||
}
|
||||
lastColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly windowMoveLeft = (cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
if (column.getWindowCount() === 1) {
|
||||
// move from own column into existing column
|
||||
const leftColumn = grid.getLeftColumn(column);
|
||||
if (leftColumn === null) {
|
||||
return;
|
||||
}
|
||||
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, FocusPassing.Type.None);
|
||||
}
|
||||
};
|
||||
|
||||
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, FocusPassing.Type.None);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
} else {
|
||||
// move from shared column into own column
|
||||
const newColumn = new Column(grid, column);
|
||||
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();
|
||||
if (canMoveDown) {
|
||||
column.moveWindowDown(window);
|
||||
} 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();
|
||||
if (canMoveUp) {
|
||||
column.moveWindowUp(window);
|
||||
} 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, 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, 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));
|
||||
|
||||
const availableSpace = desktop.tilingArea.width;
|
||||
const gapsWidth = desktop.grid.config.gapsInnerHorizontal * (visibleColumns.length-1);
|
||||
const widths = fillSpace(
|
||||
availableSpace - gapsWidth,
|
||||
visibleColumns.map(column => ({ min: column.getMinWidth(), max: column.getMaxWidth() })),
|
||||
);
|
||||
visibleColumns.forEach((column, index) => column.setWidth(widths[index], true));
|
||||
|
||||
desktop.scrollCenterRange(Range.fromRanges(
|
||||
visibleColumns[0],
|
||||
visibleColumns[visibleColumns.length - 1],
|
||||
));
|
||||
};
|
||||
|
||||
public readonly columnsSqueezeLeft = (cm: ClientManager, dm: DesktopManager, window: Window, focusedColumn: Column, grid: Grid) => {
|
||||
const visibleRange = grid.desktop.getCurrentVisibleRange();
|
||||
if (!Range.contains(visibleRange, focusedColumn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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]);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wantedVisibleColumns = [targetColumn, ...currentVisibleColumns];
|
||||
while (true) {
|
||||
const success = this.squeezeColumns(wantedVisibleColumns);
|
||||
if (success) {
|
||||
break;
|
||||
}
|
||||
const removedColumn = wantedVisibleColumns.pop();
|
||||
if (removedColumn === focusedColumn) {
|
||||
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();
|
||||
if (!Range.contains(visibleRange, focusedColumn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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]);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wantedVisibleColumns = [...currentVisibleColumns, targetColumn];
|
||||
while (true) {
|
||||
const success = this.squeezeColumns(wantedVisibleColumns);
|
||||
if (success) {
|
||||
break;
|
||||
}
|
||||
const removedColumn = wantedVisibleColumns.shift();
|
||||
if (removedColumn === focusedColumn) {
|
||||
break; // don't scroll past the currently focused column
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly squeezeColumns = (columns: Column[]) => {
|
||||
const firstColumn = columns[0];
|
||||
const lastColumn = columns[columns.length-1];
|
||||
const grid = firstColumn.grid;
|
||||
const desktop = grid.desktop;
|
||||
|
||||
const availableSpace = desktop.tilingArea.width;
|
||||
const gapsWidth = grid.config.gapsInnerHorizontal * (columns.length-1);
|
||||
const columnConstraints = columns.map(column => ({ min: column.getMinWidth(), max: column.getWidth() }));
|
||||
const minTotalWidth = gapsWidth + columnConstraints.reduce((acc, constraint) => acc + constraint.min, 0);
|
||||
if (minTotalWidth > availableSpace) {
|
||||
// there's nothing we can do
|
||||
return false;
|
||||
}
|
||||
|
||||
const widths = fillSpace(availableSpace - gapsWidth, columnConstraints);
|
||||
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) => {
|
||||
const desktop = desktopManager.getCurrentDesktop();
|
||||
if (desktop !== undefined) {
|
||||
desktop.adjustScroll(amount, false);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollStart = (cm: ClientManager, dm: DesktopManager) => {
|
||||
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 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());
|
||||
if (scrollAmount !== 0) {
|
||||
grid.desktop.adjustScroll(scrollAmount, true);
|
||||
} else {
|
||||
grid.desktop.scrollToColumn(column, true);
|
||||
}
|
||||
};
|
||||
|
||||
public readonly gridScrollLeftColumn = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange());
|
||||
if (column === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const leftColumn = grid.getLeftColumn(column);
|
||||
if (leftColumn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
grid.desktop.scrollToColumn(leftColumn, false);
|
||||
};
|
||||
|
||||
public readonly gridScrollRightColumn = (cm: ClientManager, dm: DesktopManager) => {
|
||||
const desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange());
|
||||
if (column === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rightColumn = grid.getRightColumn(column);
|
||||
if (rightColumn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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 desktop = dm.getCurrentDesktop();
|
||||
if (desktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const grid = desktop.grid;
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
targetColumn.getWindowToFocus().focus();
|
||||
};
|
||||
|
||||
public readonly windowMoveToColumn = (columnIndex: number, cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null) {
|
||||
return;
|
||||
}
|
||||
window.moveToColumn(targetColumn, true, FocusPassing.Type.None);
|
||||
grid.desktop.autoAdjustScroll();
|
||||
};
|
||||
|
||||
public readonly columnMoveToColumn = (columnIndex: number, cm: ClientManager, dm: DesktopManager, window: Window, column: Column, grid: Grid) => {
|
||||
const targetColumn = grid.getColumnAtIndex(columnIndex);
|
||||
if (targetColumn === null || targetColumn === column) {
|
||||
return;
|
||||
}
|
||||
if (targetColumn.isToTheRightOf(column)) {
|
||||
grid.moveColumn(column, targetColumn);
|
||||
} else {
|
||||
grid.moveColumn(column, grid.getLeftColumn(targetColumn));
|
||||
}
|
||||
};
|
||||
|
||||
public readonly columnMoveToDesktop = (desktopIndex: number, cm: ClientManager, dm: DesktopManager, window: Window, column: Column, oldGrid: Grid) => {
|
||||
const kwinDesktop = Workspace.desktops[desktopIndex];
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newDesktop = dm.getDesktopInCurrentActivity(kwinDesktop);
|
||||
if (newDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = newDesktop.grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
column.moveToGrid(newGrid, newGrid.getLastColumn());
|
||||
};
|
||||
|
||||
public readonly tailMoveToDesktop = (desktopIndex: number, cm: ClientManager, dm: DesktopManager, window: Window, column: Column, oldGrid: Grid) => {
|
||||
const kwinDesktop = Workspace.desktops[desktopIndex];
|
||||
if (kwinDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newDesktop = dm.getDesktopInCurrentActivity(kwinDesktop);
|
||||
if (newDesktop === undefined) {
|
||||
return;
|
||||
}
|
||||
const newGrid = newDesktop.grid;
|
||||
if (newGrid === null || newGrid === oldGrid) {
|
||||
return;
|
||||
}
|
||||
oldGrid.evacuateTail(newGrid, column);
|
||||
};
|
||||
}
|
||||
|
||||
namespace Actions {
|
||||
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 interface ColumnResizer {
|
||||
increaseWidth(column: Column): void;
|
||||
decreaseWidth(column: Column): void;
|
||||
maximizeWidth(column: Column): void;
|
||||
minimizeWidth(column: Column): void;
|
||||
}
|
||||
}
|
||||
283
src/lib/keyBindings/definition.ts
Normal file
283
src/lib/keyBindings/definition.ts
Normal file
@@ -0,0 +1,283 @@
|
||||
function getKeyBindings(world: World, actions: Actions): KeyBinding[] {
|
||||
return [
|
||||
{
|
||||
name: "window-toggle-floating",
|
||||
description: "Toggle floating",
|
||||
defaultKeySequence: "Meta+Space",
|
||||
action: () => world.do(actions.windowToggleFloating),
|
||||
},
|
||||
{
|
||||
name: "focus-left",
|
||||
description: "Move focus left",
|
||||
defaultKeySequence: "Meta+A",
|
||||
action: () => world.doIfTiledFocused(actions.focusLeft),
|
||||
},
|
||||
{
|
||||
name: "focus-right",
|
||||
description: "Move focus right",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+D",
|
||||
action: () => world.doIfTiledFocused(actions.focusRight),
|
||||
},
|
||||
{
|
||||
name: "focus-up",
|
||||
description: "Move focus up",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+W",
|
||||
action: () => world.doIfTiledFocused(actions.focusUp),
|
||||
},
|
||||
{
|
||||
name: "focus-down",
|
||||
description: "Move focus down",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+S",
|
||||
action: () => world.doIfTiledFocused(actions.focusDown),
|
||||
},
|
||||
{
|
||||
name: "focus-next",
|
||||
description: "Move focus to the next window in grid",
|
||||
action: () => world.doIfTiledFocused(actions.focusNext),
|
||||
},
|
||||
{
|
||||
name: "focus-previous",
|
||||
description: "Move focus to the previous window in grid",
|
||||
action: () => world.doIfTiledFocused(actions.focusPrevious),
|
||||
},
|
||||
{
|
||||
name: "focus-start",
|
||||
description: "Move focus to start",
|
||||
defaultKeySequence: "Meta+Home",
|
||||
action: () => world.do(actions.focusStart),
|
||||
},
|
||||
{
|
||||
name: "focus-end",
|
||||
description: "Move focus to end",
|
||||
defaultKeySequence: "Meta+End",
|
||||
action: () => world.do(actions.focusEnd),
|
||||
},
|
||||
{
|
||||
name: "window-move-left",
|
||||
description: "Move window left",
|
||||
comment: "Moves window out of and into columns",
|
||||
defaultKeySequence: "Meta+Shift+A",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveLeft),
|
||||
},
|
||||
{
|
||||
name: "window-move-right",
|
||||
description: "Move window right",
|
||||
comment: "Moves window out of and into columns",
|
||||
defaultKeySequence: "Meta+Shift+D",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveRight),
|
||||
},
|
||||
{
|
||||
name: "window-move-up",
|
||||
description: "Move window up",
|
||||
defaultKeySequence: "Meta+Shift+W",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveUp),
|
||||
},
|
||||
{
|
||||
name: "window-move-down",
|
||||
description: "Move window down",
|
||||
defaultKeySequence: "Meta+Shift+S",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveDown),
|
||||
},
|
||||
{
|
||||
name: "window-move-next",
|
||||
description: "Move window to the next position in grid",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveNext),
|
||||
},
|
||||
{
|
||||
name: "window-move-previous",
|
||||
description: "Move window to the previous position in grid",
|
||||
action: () => world.doIfTiledFocused(actions.windowMovePrevious),
|
||||
},
|
||||
{
|
||||
name: "window-move-start",
|
||||
description: "Move window to start",
|
||||
defaultKeySequence: "Meta+Shift+Home",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveStart),
|
||||
},
|
||||
{
|
||||
name: "window-move-end",
|
||||
description: "Move window to end",
|
||||
defaultKeySequence: "Meta+Shift+End",
|
||||
action: () => world.doIfTiledFocused(actions.windowMoveEnd),
|
||||
},
|
||||
{
|
||||
name: "column-toggle-stacked",
|
||||
description: "Toggle stacked layout for focused column",
|
||||
comment: "Only the active window visible",
|
||||
defaultKeySequence: "Meta+X",
|
||||
action: () => world.doIfTiledFocused(actions.columnToggleStacked),
|
||||
},
|
||||
{
|
||||
name: "column-move-left",
|
||||
description: "Move column left",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+A",
|
||||
action: () => world.doIfTiledFocused(actions.columnMoveLeft),
|
||||
},
|
||||
{
|
||||
name: "column-move-right",
|
||||
description: "Move column right",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+D",
|
||||
action: () => world.doIfTiledFocused(actions.columnMoveRight),
|
||||
},
|
||||
{
|
||||
name: "column-move-start",
|
||||
description: "Move column to start",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+Home",
|
||||
action: () => world.doIfTiledFocused(actions.columnMoveStart),
|
||||
},
|
||||
{
|
||||
name: "column-move-end",
|
||||
description: "Move column to end",
|
||||
defaultKeySequence: "Meta+Ctrl+Shift+End",
|
||||
action: () => world.doIfTiledFocused(actions.columnMoveEnd),
|
||||
},
|
||||
{
|
||||
name: "column-width-increase",
|
||||
description: "Increase column width",
|
||||
defaultKeySequence: "Meta+Ctrl++",
|
||||
action: () => world.doIfTiledFocused(actions.columnWidthIncrease),
|
||||
},
|
||||
{
|
||||
name: "column-width-decrease",
|
||||
description: "Decrease column width",
|
||||
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",
|
||||
defaultKeySequence: "Meta+R",
|
||||
action: () => world.doIfTiledFocused(actions.cyclePresetWidths),
|
||||
},
|
||||
{
|
||||
name: "cycle-preset-widths-reverse",
|
||||
description: "Cycle through preset column widths in reverse",
|
||||
defaultKeySequence: "Meta+Shift+R",
|
||||
action: () => world.doIfTiledFocused(actions.cyclePresetWidthsReverse),
|
||||
},
|
||||
{
|
||||
name: "columns-width-equalize",
|
||||
description: "Equalize widths of visible columns",
|
||||
defaultKeySequence: "Meta+Ctrl+X",
|
||||
action: () => world.do(actions.columnsWidthEqualize),
|
||||
},
|
||||
{
|
||||
name: "columns-squeeze-left",
|
||||
description: "Squeeze left column onto the screen",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultKeySequence: "Meta+Ctrl+A",
|
||||
action: () => world.doIfTiledFocused(actions.columnsSqueezeLeft),
|
||||
},
|
||||
{
|
||||
name: "columns-squeeze-right",
|
||||
description: "Squeeze right column onto the screen",
|
||||
defaultKeySequence: "Meta+Ctrl+D",
|
||||
action: () => world.doIfTiledFocused(actions.columnsSqueezeRight),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-focused",
|
||||
description: "Center focused window",
|
||||
comment: "Scrolls so that the focused window is centered in the screen",
|
||||
defaultKeySequence: "Meta+Alt+Return",
|
||||
action: () => world.doIfTiledFocused(actions.gridScrollFocused),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-left-column",
|
||||
description: "Scroll one column to the left",
|
||||
defaultKeySequence: "Meta+Alt+A",
|
||||
action: () => world.do(actions.gridScrollLeftColumn),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-right-column",
|
||||
description: "Scroll one column to the right",
|
||||
defaultKeySequence: "Meta+Alt+D",
|
||||
action: () => world.do(actions.gridScrollRightColumn),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-left",
|
||||
description: "Scroll left",
|
||||
defaultKeySequence: "Meta+Alt+PgUp",
|
||||
action: () => world.do(actions.gridScrollLeft),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-right",
|
||||
description: "Scroll right",
|
||||
defaultKeySequence: "Meta+Alt+PgDown",
|
||||
action: () => world.do(actions.gridScrollRight),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-start",
|
||||
description: "Scroll to start",
|
||||
defaultKeySequence: "Meta+Alt+Home",
|
||||
action: () => world.do(actions.gridScrollStart),
|
||||
},
|
||||
{
|
||||
name: "grid-scroll-end",
|
||||
description: "Scroll to end",
|
||||
defaultKeySequence: "Meta+Alt+End",
|
||||
action: () => world.do(actions.gridScrollEnd),
|
||||
},
|
||||
{
|
||||
name: "screen-switch",
|
||||
description: "Move Karousel grid to the current screen",
|
||||
defaultKeySequence: "Meta+Ctrl+Return",
|
||||
action: () => world.do(actions.screenSwitch),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getNumKeyBindings(world: World, actions: Actions): NumKeyBinding[] {
|
||||
return [
|
||||
{
|
||||
name: "focus-{}",
|
||||
description: "Move focus to column {}",
|
||||
comment: "Clashes with default KDE shortcuts, may require manual remapping",
|
||||
defaultModifiers: "Meta",
|
||||
fKeys: false,
|
||||
action: (i: number) => world.do(actions.focus.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "window-move-to-column-{}",
|
||||
description: "Move window to column {}",
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!",
|
||||
defaultModifiers: "Meta+Shift",
|
||||
fKeys: false,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.windowMoveToColumn.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "column-move-to-column-{}",
|
||||
description: "Move column to position {}",
|
||||
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: false,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.columnMoveToColumn.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "column-move-to-desktop-{}",
|
||||
description: "Move column to desktop {}",
|
||||
defaultModifiers: "Meta+Ctrl+Shift",
|
||||
fKeys: true,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.columnMoveToDesktop.partial(i)),
|
||||
},
|
||||
{
|
||||
name: "tail-move-to-desktop-{}",
|
||||
description: "Move this and all following columns to desktop {}",
|
||||
defaultModifiers: "Meta+Ctrl+Shift+Alt",
|
||||
fKeys: true,
|
||||
action: (i: number) => world.doIfTiledFocused(actions.tailMoveToDesktop.partial(i)),
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -1,17 +1,19 @@
|
||||
type KeyBinding = {
|
||||
interface KeyBinding {
|
||||
name: string;
|
||||
description: string;
|
||||
comment?: string;
|
||||
defaultKeySequence: 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 () => {
|
||||
@@ -24,14 +26,14 @@ function catchWrap(f: () => void) {
|
||||
};
|
||||
}
|
||||
|
||||
function registerKeyBinding(world: World, config: Actions.Config, shortcutActions: ShortcutAction[], keyBinding: KeyBinding) {
|
||||
function registerKeyBinding(shortcutActions: ShortcutAction[], keyBinding: KeyBinding) {
|
||||
shortcutActions.push(new ShortcutAction(
|
||||
keyBinding,
|
||||
catchWrap(Actions.getAction(world, config, keyBinding.name)),
|
||||
catchWrap(keyBinding.action),
|
||||
));
|
||||
}
|
||||
|
||||
function registerNumKeyBindings(world: World, shortcutActions: ShortcutAction[], numKeyBinding: NumKeyBinding) {
|
||||
function registerNumKeyBindings(shortcutActions: ShortcutAction[], numKeyBinding: NumKeyBinding) {
|
||||
const numPrefix = numKeyBinding.fKeys ? "F" : "";
|
||||
const n = numKeyBinding.fKeys ? 12 : 9;
|
||||
for (let i = 0; i < 12; i++) {
|
||||
@@ -39,28 +41,27 @@ function registerNumKeyBindings(world: World, shortcutActions: ShortcutAction[],
|
||||
const keySequence = i < n ?
|
||||
numKeyBinding.defaultModifiers + "+" + numPrefix + numKey :
|
||||
"";
|
||||
const action = Actions.getNumAction(world, numKeyBinding.name);
|
||||
shortcutActions.push(new ShortcutAction(
|
||||
{
|
||||
name: numKeyBinding.name + numKey,
|
||||
description: numKeyBinding.description + numKey,
|
||||
name: applyMacro(numKeyBinding.name, numKey),
|
||||
description: applyMacro(numKeyBinding.description, numKey),
|
||||
defaultKeySequence: keySequence,
|
||||
},
|
||||
catchWrap(() => action(i)),
|
||||
catchWrap(() => numKeyBinding.action(i)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
function registerKeyBindings(world: World, config: Actions.Config) {
|
||||
const actions = new Actions(config);
|
||||
const shortcutActions: ShortcutAction[] = [];
|
||||
|
||||
for (const keyBinding of keyBindings) {
|
||||
registerKeyBinding(world, config, shortcutActions, keyBinding);
|
||||
for (const keyBinding of getKeyBindings(world, actions)) {
|
||||
registerKeyBinding(shortcutActions, keyBinding);
|
||||
}
|
||||
|
||||
for (const numKeyBinding of numKeyBindings) {
|
||||
registerNumKeyBindings(world, shortcutActions, numKeyBinding);
|
||||
for (const numKeyBinding of getNumKeyBindings(world, actions)) {
|
||||
registerNumKeyBindings(shortcutActions, numKeyBinding);
|
||||
}
|
||||
|
||||
return shortcutActions;
|
||||
@@ -5,46 +5,39 @@ class Column {
|
||||
private readonly windows: LinkedList<Window>;
|
||||
private stacked: boolean;
|
||||
private focusTaker: Window|null;
|
||||
private static readonly minWidth = 10;
|
||||
private static readonly minWidth = 40;
|
||||
|
||||
constructor(grid: Grid, prevColumn: Column|null) {
|
||||
constructor(grid: Grid, leftColumn: Column|null) {
|
||||
this.gridX = 0;
|
||||
this.width = 0;
|
||||
this.windows = new LinkedList();
|
||||
this.stacked = grid.config.stackColumnsByDefault;
|
||||
this.focusTaker = null;
|
||||
this.grid = grid;
|
||||
this.grid.onColumnAdded(this, prevColumn);
|
||||
this.grid.onColumnAdded(this, leftColumn);
|
||||
}
|
||||
|
||||
public moveToGrid(targetGrid: Grid, prevColumn: Column|null) {
|
||||
public moveToGrid(targetGrid: Grid, leftColumn: Column|null) {
|
||||
if (targetGrid === this.grid) {
|
||||
this.grid.onColumnMoved(this, prevColumn);
|
||||
this.grid.moveColumn(this, leftColumn);
|
||||
} else {
|
||||
this.grid.onColumnRemoved(this, false);
|
||||
this.grid.onColumnRemoved(this, this.isFocused() ? FocusPassing.Type.Immediate : FocusPassing.Type.None);
|
||||
this.grid = targetGrid;
|
||||
targetGrid.onColumnAdded(this, prevColumn);
|
||||
targetGrid.onColumnAdded(this, leftColumn);
|
||||
for (const window of this.windows.iterator()) {
|
||||
window.client.kwinClient.desktops = [targetGrid.desktop.kwinDesktop];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public moveAfter(prevColumn: Column|null) {
|
||||
if (prevColumn === this) {
|
||||
return;
|
||||
}
|
||||
this.grid.onColumnMoved(this, prevColumn);
|
||||
}
|
||||
|
||||
public isAfter(other: Column) {
|
||||
return this.gridX > other.gridX;
|
||||
}
|
||||
|
||||
public isBefore(other: Column) {
|
||||
public isToTheLeftOf(other: Column) {
|
||||
return this.gridX < other.gridX;
|
||||
}
|
||||
|
||||
public isToTheRightOf(other: Column) {
|
||||
return this.gridX > other.gridX;
|
||||
}
|
||||
|
||||
public moveWindowUp(window: Window) {
|
||||
this.windows.moveBack(window);
|
||||
this.grid.desktop.onLayoutChanged();
|
||||
@@ -63,11 +56,19 @@ class Column {
|
||||
return this.getWindowCount() === 0;
|
||||
}
|
||||
|
||||
public getPrevWindow(window: Window) {
|
||||
public getFirstWindow(): Window {
|
||||
return this.windows.getFirst()!;
|
||||
}
|
||||
|
||||
public getLastWindow(): Window {
|
||||
return this.windows.getLast()!;
|
||||
}
|
||||
|
||||
public getAboveWindow(window: Window) {
|
||||
return this.windows.getPrev(window);
|
||||
}
|
||||
|
||||
public getNextWindow(window: Window) {
|
||||
public getBelowWindow(window: Window) {
|
||||
return this.windows.getNext(window);
|
||||
}
|
||||
|
||||
@@ -78,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;
|
||||
}
|
||||
@@ -132,6 +133,27 @@ class Column {
|
||||
return this.gridX + this.width;
|
||||
}
|
||||
|
||||
public onUserResizeWidth(
|
||||
startWidth: number,
|
||||
currentDelta: number,
|
||||
resizingLeftSide: boolean,
|
||||
neighbor?: { column: Column, startWidth: number },
|
||||
) {
|
||||
const oldColumnWidth = this.getWidth();
|
||||
this.setWidth(startWidth + currentDelta, true);
|
||||
const actualDelta = this.getWidth() - startWidth;
|
||||
|
||||
let leftEdgeDeltaStep = resizingLeftSide ? oldColumnWidth - this.getWidth() : 0;
|
||||
if (neighbor !== undefined) {
|
||||
const oldNeighborWidth = neighbor.column.getWidth();
|
||||
neighbor.column.setWidth(neighbor.startWidth - actualDelta, true);
|
||||
if (resizingLeftSide) {
|
||||
leftEdgeDeltaStep -= neighbor.column.getWidth() - oldNeighborWidth;
|
||||
}
|
||||
}
|
||||
this.grid.desktop.adjustScroll(-leftEdgeDeltaStep, true);
|
||||
}
|
||||
|
||||
public adjustWindowHeight(window: Window, heightDelta: number, top: boolean) {
|
||||
const otherWindow = top ? this.windows.getPrev(window) : this.windows.getNext(window);
|
||||
if (otherWindow === null) {
|
||||
@@ -173,58 +195,48 @@ class Column {
|
||||
return this.focusTaker;
|
||||
}
|
||||
|
||||
public focus() {
|
||||
const window = this.getFocusTaker() ?? this.windows.getFirst();
|
||||
if (window === null) {
|
||||
return;
|
||||
public getWindowToFocus() {
|
||||
return this.getFocusTaker() ?? this.windows.getFirst()!;
|
||||
}
|
||||
|
||||
public isFocused() {
|
||||
const lastFocusedWindow = this.grid.getLastFocusedWindow();
|
||||
if (lastFocusedWindow === null) {
|
||||
return false;
|
||||
}
|
||||
window.focus();
|
||||
return lastFocusedWindow.column === this && lastFocusedWindow.isFocused();
|
||||
}
|
||||
|
||||
public arrange(x: number, visibleRange: Range, forceOpaque: boolean) {
|
||||
if (this.grid.config.offScreenOpacity < 1.0 && !forceOpaque) {
|
||||
const opacity = this.isVisible(visibleRange, true) ? 100 : this.grid.config.offScreenOpacity;
|
||||
const opacity = Range.contains(visibleRange, this) ? 100 : this.grid.config.offScreenOpacity;
|
||||
for (const window of this.windows.iterator()) {
|
||||
window.client.kwinClient.opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.stacked && this.windows.length() >= 2 && this.canStack()) {
|
||||
if (this.stacked && this.windows.length() >= 2) {
|
||||
this.arrangeStacked(x);
|
||||
return;
|
||||
}
|
||||
let y = this.grid.desktop.tilingArea.y;
|
||||
for (const window of this.windows.iterator()) {
|
||||
window.client.setShade(false);
|
||||
window.arrange(x, y, this.width, window.height);
|
||||
y += window.height + this.grid.config.gapsInnerVertical;
|
||||
}
|
||||
}
|
||||
|
||||
public arrangeStacked(x: number) {
|
||||
const expandedWindow = this.getFocusTaker();
|
||||
let collapsedHeight;
|
||||
for (const window of this.windows.iterator()) {
|
||||
if (window === expandedWindow) {
|
||||
window.client.setShade(false);
|
||||
} else {
|
||||
window.client.setShade(true);
|
||||
collapsedHeight = window.client.kwinClient.frameGeometry.height;
|
||||
}
|
||||
}
|
||||
const nWindows = this.windows.length();
|
||||
const windowWidth = this.width - (nWindows - 1) * this.grid.config.stackOffsetX;
|
||||
const windowHeight = this.grid.desktop.tilingArea.height - (nWindows - 1) * this.grid.config.stackOffsetY;
|
||||
|
||||
const nCollapsed = this.getWindowCount() - 1;
|
||||
const expandedHeight = this.grid.desktop.tilingArea.height - nCollapsed * (collapsedHeight! + this.grid.config.gapsInnerVertical);
|
||||
let y = this.grid.desktop.tilingArea.y;
|
||||
let windowX = x;
|
||||
let windowY = this.grid.desktop.tilingArea.y;
|
||||
for (const window of this.windows.iterator()) {
|
||||
if (window === expandedWindow) {
|
||||
window.arrange(x, y, this.width, expandedHeight);
|
||||
y += expandedHeight;
|
||||
} else {
|
||||
window.arrange(x, y, this.width, window.height);
|
||||
y += collapsedHeight!;
|
||||
}
|
||||
y += this.grid.config.gapsInnerVertical;
|
||||
window.arrange(windowX, windowY, windowWidth, windowHeight);
|
||||
windowX += this.grid.config.stackOffsetX;
|
||||
windowY += this.grid.config.stackOffsetY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,27 +248,13 @@ class Column {
|
||||
this.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
|
||||
private canStack() {
|
||||
for (const window of this.windows.iterator()) {
|
||||
if (!window.client.kwinClient.shadeable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public isVisible(visibleRange: Desktop.Range, fullyVisible: boolean) {
|
||||
if (fullyVisible) {
|
||||
return this.getLeft() >= visibleRange.getLeft() &&
|
||||
this.getRight() <= visibleRange.getRight();
|
||||
public onWindowAdded(window: Window, bottom: boolean) {
|
||||
if (bottom) {
|
||||
this.windows.insertEnd(window);
|
||||
} else {
|
||||
return this.getRight() + this.grid.config.gapsInnerHorizontal > visibleRange.getLeft() &&
|
||||
this.getLeft() - this.grid.config.gapsInnerHorizontal < visibleRange.getRight();
|
||||
this.windows.insertStart(window);
|
||||
}
|
||||
}
|
||||
|
||||
public onWindowAdded(window: Window) {
|
||||
this.windows.insertEnd(window);
|
||||
if (this.width === 0) {
|
||||
this.setWidth(window.client.preferredWidth, false);
|
||||
}
|
||||
@@ -271,9 +269,9 @@ 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.getPrevWindow(window) ?? this.getNextWindow(window);
|
||||
const windowToFocus = this.getAboveWindow(window) ?? this.getBelowWindow(window);
|
||||
|
||||
this.windows.remove(window);
|
||||
|
||||
@@ -286,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,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,31 +1,34 @@
|
||||
class Desktop {
|
||||
public readonly grid: Grid;
|
||||
public readonly kwinDesktop: KwinDesktop;
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly config: Desktop.Config;
|
||||
private scrollX: number;
|
||||
private gestureScrollXInitial: number | null;
|
||||
private dirty: boolean;
|
||||
private dirtyScroll: boolean;
|
||||
private dirtyPins: boolean;
|
||||
public clientArea: QmlRect;
|
||||
public tilingArea: QmlRect;
|
||||
|
||||
constructor(kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig) {
|
||||
this.pinManager = pinManager;
|
||||
this.config = config;
|
||||
constructor(
|
||||
public readonly kwinDesktop: KwinDesktop,
|
||||
private readonly pinManager: PinManager,
|
||||
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.kwinDesktop = kwinDesktop;
|
||||
this.grid = new Grid(this, layoutConfig);
|
||||
this.clientArea = Desktop.getClientArea(kwinDesktop);
|
||||
this.grid = new Grid(this, layoutConfig, focusPasser);
|
||||
this.clientArea = Desktop.getClientArea(this.getScreen(), kwinDesktop);
|
||||
this.tilingArea = Desktop.getTilingArea(this.clientArea, kwinDesktop, pinManager, config);
|
||||
}
|
||||
|
||||
private updateArea() {
|
||||
const newClientArea = Desktop.getClientArea(this.kwinDesktop);
|
||||
if (newClientArea === this.clientArea && !this.dirtyPins) {
|
||||
const newClientArea = Desktop.getClientArea(this.getScreen(), this.kwinDesktop);
|
||||
if (rectEquals(newClientArea, this.clientArea) && !this.dirtyPins) {
|
||||
return;
|
||||
}
|
||||
this.clientArea = newClientArea;
|
||||
@@ -37,8 +40,8 @@ class Desktop {
|
||||
this.autoAdjustScroll();
|
||||
}
|
||||
|
||||
private static getClientArea(kwinDesktop: KwinDesktop) {
|
||||
return Workspace.clientArea(ClientAreaOption.PlacementArea, Workspace.activeScreen, kwinDesktop);
|
||||
private static getClientArea(screen: Output, kwinDesktop: KwinDesktop) {
|
||||
return Workspace.clientArea(ClientAreaOption.PlacementArea, screen, kwinDesktop);
|
||||
}
|
||||
|
||||
private static getTilingArea(clientArea: QmlRect, kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config) {
|
||||
@@ -52,10 +55,10 @@ class Desktop {
|
||||
top,
|
||||
right - left,
|
||||
bottom - top,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public scrollIntoView(range: Desktop.Range) {
|
||||
public scrollIntoView(range: Range) {
|
||||
const left = range.getLeft();
|
||||
const right = range.getRight();
|
||||
const initialVisibleRange = this.getCurrentVisibleRange();
|
||||
@@ -72,10 +75,9 @@ class Desktop {
|
||||
this.setScroll(targetScrollX, false);
|
||||
}
|
||||
|
||||
public scrollCenterRange(range: Desktop.Range) {
|
||||
const windowCenter = range.getLeft() + range.getWidth() / 2;
|
||||
const screenCenter = this.scrollX + this.tilingArea.width / 2;
|
||||
this.adjustScroll(Math.round(windowCenter - screenCenter), false);
|
||||
public scrollCenterRange(range: Range) {
|
||||
const scrollAmount = Range.minus(range, this.getCurrentVisibleRange());
|
||||
this.adjustScroll(scrollAmount, true);
|
||||
}
|
||||
|
||||
public scrollCenterVisible(focusedColumn: Column) {
|
||||
@@ -91,17 +93,17 @@ class Desktop {
|
||||
return;
|
||||
}
|
||||
|
||||
this.scrollToColumn(focusedColumn);
|
||||
this.scrollToColumn(focusedColumn, false);
|
||||
}
|
||||
|
||||
public scrollToColumn(column: Column) {
|
||||
if (this.dirtyScroll || !column.isVisible(this.getCurrentVisibleRange(), true)) {
|
||||
public scrollToColumn(column: Column, force: boolean) {
|
||||
if (force || this.dirtyScroll || !Range.contains(this.getCurrentVisibleRange(), column)) {
|
||||
this.config.scroller.scrollToColumn(this, column);
|
||||
}
|
||||
}
|
||||
|
||||
private getVisibleRange(scrollX: number) {
|
||||
return new Desktop.RangeImpl(scrollX, this.tilingArea.width);
|
||||
return Range.create(scrollX, this.tilingArea.width);
|
||||
}
|
||||
|
||||
public getCurrentVisibleRange() {
|
||||
@@ -125,38 +127,34 @@ class Desktop {
|
||||
this.setScroll(this.scrollX + dx, force);
|
||||
}
|
||||
|
||||
public equalizeVisibleColumnsWidths() {
|
||||
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();
|
||||
const visibleColumns = Array.from(this.grid.getVisibleColumns(visibleRange, true));
|
||||
|
||||
let remainingWidth = this.tilingArea.width - (visibleColumns.length-1) * this.grid.config.gapsInnerHorizontal;
|
||||
let remainingColumns = visibleColumns.length;
|
||||
|
||||
const minWidths = visibleColumns.map(column => column.getMinWidth()).sort((a, b) => b - a);
|
||||
for (const minWidth of minWidths) {
|
||||
if (minWidth > remainingWidth / remainingColumns) {
|
||||
remainingWidth -= minWidth;
|
||||
remainingColumns--;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
const avgWidth = remainingWidth / remainingColumns;
|
||||
for (const column of visibleColumns) {
|
||||
const minWidth = column.getMinWidth();
|
||||
if (minWidth > avgWidth) {
|
||||
column.setWidth(minWidth, true);
|
||||
} else {
|
||||
const columnWidth = Math.round(remainingWidth / remainingColumns);
|
||||
column.setWidth(columnWidth, true);
|
||||
remainingWidth -= column.getWidth();
|
||||
remainingColumns--;
|
||||
}
|
||||
}
|
||||
|
||||
this.scrollCenterRange(Desktop.RangeImpl.fromRanges(
|
||||
visibleColumns[0],
|
||||
visibleColumns[visibleColumns.length - 1],
|
||||
));
|
||||
}
|
||||
|
||||
public arrange() {
|
||||
@@ -169,6 +167,10 @@ class Desktop {
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
public forceArrange() {
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
public onLayoutChanged() {
|
||||
this.dirty = true;
|
||||
this.dirtyScroll = true;
|
||||
@@ -186,47 +188,16 @@ class Desktop {
|
||||
}
|
||||
|
||||
namespace Desktop {
|
||||
export type Config = {
|
||||
marginTop: number,
|
||||
marginBottom: number,
|
||||
marginLeft: number,
|
||||
marginRight: number,
|
||||
scroller: Desktop.Scroller,
|
||||
clamper: Desktop.Clamper,
|
||||
};
|
||||
|
||||
export type Range = {
|
||||
getLeft(): number;
|
||||
getRight(): number;
|
||||
getWidth(): number;
|
||||
}
|
||||
|
||||
export class RangeImpl {
|
||||
private readonly x: number;
|
||||
private readonly width: number;
|
||||
|
||||
constructor(x: number, width: number) {
|
||||
this.x = x;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public getLeft() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public getRight() {
|
||||
return this.x + this.width;
|
||||
}
|
||||
|
||||
public getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public static fromRanges(leftRange: Range, rightRange: Range) {
|
||||
const left = leftRange.getLeft();
|
||||
const right = rightRange.getRight();
|
||||
return new RangeImpl(left, right - left);
|
||||
}
|
||||
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 {
|
||||
@@ -240,7 +211,7 @@ namespace Desktop {
|
||||
this.width = initialColumn.getWidth();
|
||||
}
|
||||
|
||||
public addNeighbors(visibleRange: Desktop.Range, gap: number) {
|
||||
public addNeighbors(visibleRange: Range, gap: number) {
|
||||
const grid = this.left.grid;
|
||||
|
||||
const columnRange = this;
|
||||
@@ -251,8 +222,8 @@ namespace Desktop {
|
||||
return column !== null && canFit(column);
|
||||
}
|
||||
|
||||
let leftColumn = grid.getPrevColumn(this.left);
|
||||
let rightColumn = grid.getNextColumn(this.right);
|
||||
let leftColumn = grid.getLeftColumn(this.left);
|
||||
let rightColumn = grid.getRightColumn(this.right);
|
||||
function checkColumns() {
|
||||
if (!isUsable(leftColumn)) {
|
||||
leftColumn = null;
|
||||
@@ -269,10 +240,10 @@ namespace Desktop {
|
||||
const rightToCenter = rightColumn === null ? Infinity : Math.abs(rightColumn.getRight() - visibleCenter);
|
||||
if (leftToCenter < rightToCenter) {
|
||||
this.addLeft(leftColumn!, gap);
|
||||
leftColumn = grid.getPrevColumn(leftColumn!);
|
||||
leftColumn = grid.getLeftColumn(leftColumn!);
|
||||
} else {
|
||||
this.addRight(rightColumn!, gap);
|
||||
rightColumn = grid.getNextColumn(rightColumn!);
|
||||
rightColumn = grid.getRightColumn(rightColumn!);
|
||||
}
|
||||
checkColumns();
|
||||
}
|
||||
@@ -301,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,17 +1,17 @@
|
||||
import Range = Desktop.Range;
|
||||
|
||||
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;
|
||||
@@ -24,6 +24,18 @@ class Grid {
|
||||
});
|
||||
}
|
||||
|
||||
public moveColumn(column: Column, leftColumn: Column|null) {
|
||||
if (column === leftColumn) {
|
||||
return;
|
||||
}
|
||||
const movedLeft = leftColumn === null ? true : column.isToTheRightOf(leftColumn);
|
||||
const firstMovedColumn = movedLeft ? column : this.getRightColumn(column);
|
||||
this.columns.move(column, leftColumn);
|
||||
this.columnsSetX(firstMovedColumn);
|
||||
this.desktop.onLayoutChanged();
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public moveColumnLeft(column: Column) {
|
||||
this.columns.moveBack(column);
|
||||
this.columnsSetX(column);
|
||||
@@ -32,11 +44,11 @@ class Grid {
|
||||
}
|
||||
|
||||
public moveColumnRight(column: Column) {
|
||||
const nextColumn = this.columns.getNext(column);
|
||||
if (nextColumn === null) {
|
||||
const rightColumn = this.columns.getNext(column);
|
||||
if (rightColumn === null) {
|
||||
return;
|
||||
}
|
||||
this.moveColumnLeft(nextColumn);
|
||||
this.moveColumnLeft(rightColumn);
|
||||
}
|
||||
|
||||
public getWidth() {
|
||||
@@ -47,11 +59,11 @@ class Grid {
|
||||
return this.userResize;
|
||||
}
|
||||
|
||||
public getPrevColumn(column: Column) {
|
||||
public getLeftColumn(column: Column) {
|
||||
return this.columns.getPrev(column);
|
||||
}
|
||||
|
||||
public getNextColumn(column: Column) {
|
||||
public getRightColumn(column: Column) {
|
||||
return this.columns.getNext(column);
|
||||
}
|
||||
|
||||
@@ -94,19 +106,19 @@ class Grid {
|
||||
this.width = x - this.config.gapsInnerHorizontal;
|
||||
}
|
||||
|
||||
public getLeftmostVisibleColumn(visibleRange: Desktop.Range, fullyVisible: boolean) {
|
||||
public getLeftmostVisibleColumn(visibleRange: Range) {
|
||||
for (const column of this.columns.iterator()) {
|
||||
if (column.isVisible(visibleRange, fullyVisible)) {
|
||||
if (Range.contains(visibleRange, column)) {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getRightmostVisibleColumn(visibleRange: Desktop.Range, fullyVisible: boolean) {
|
||||
public getRightmostVisibleColumn(visibleRange: Range) {
|
||||
let last = null;
|
||||
for (const column of this.columns.iterator()) {
|
||||
if (column.isVisible(visibleRange, fullyVisible)) {
|
||||
if (Range.contains(visibleRange, column)) {
|
||||
last = column;
|
||||
} else if (last !== null) {
|
||||
break;
|
||||
@@ -115,29 +127,14 @@ class Grid {
|
||||
return last;
|
||||
}
|
||||
|
||||
public *getVisibleColumns(visibleRange: Desktop.Range, fullyVisible: boolean) {
|
||||
public *getVisibleColumns(visibleRange: Range) {
|
||||
for (const column of this.columns.iterator()) {
|
||||
if (column.isVisible(visibleRange, fullyVisible)) {
|
||||
if (Range.contains(visibleRange, column)) {
|
||||
yield column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getVisibleColumnsWidth(visibleRange: Desktop.Range, fullyVisible: boolean) {
|
||||
let width = 0;
|
||||
let nVisible = 0;
|
||||
for (const column of this.getVisibleColumns(visibleRange, fullyVisible)) {
|
||||
width += column.getWidth();
|
||||
nVisible++;
|
||||
}
|
||||
|
||||
if (nVisible > 0) {
|
||||
width += (nVisible-1) * this.config.gapsInnerHorizontal;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
public arrange(x: number, visibleRange: Range) {
|
||||
for (const column of this.columns.iterator()) {
|
||||
column.arrange(x, visibleRange, this.userResize);
|
||||
@@ -150,61 +147,58 @@ class Grid {
|
||||
}
|
||||
}
|
||||
|
||||
public onColumnAdded(column: Column, prevColumn: Column|null) {
|
||||
if (prevColumn === null) {
|
||||
public onColumnAdded(column: Column, leftColumn: Column|null) {
|
||||
if (leftColumn === null) {
|
||||
this.columns.insertStart(column);
|
||||
} else {
|
||||
this.columns.insertAfter(column, prevColumn);
|
||||
this.columns.insertAfter(column, leftColumn);
|
||||
}
|
||||
this.columnsSetX(column);
|
||||
this.desktop.onLayoutChanged();
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public onColumnRemoved(column: Column, passFocus: boolean) {
|
||||
public onColumnRemoved(column: Column, passFocus: FocusPassing.Type) {
|
||||
const isLastColumn = this.columns.length() === 1;
|
||||
const nextColumn = this.getNextColumn(column);
|
||||
const columnToFocus = isLastColumn ? null : this.getPrevColumn(column) ?? nextColumn;
|
||||
const rightColumn = this.getRightColumn(column);
|
||||
const columnToFocus = isLastColumn ? null : this.getLeftColumn(column) ?? rightColumn;
|
||||
if (column === this.lastFocusedColumn) {
|
||||
this.lastFocusedColumn = columnToFocus;
|
||||
}
|
||||
|
||||
this.columns.remove(column);
|
||||
this.columnsSetX(nextColumn);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onColumnMoved(column: Column, prevColumn: Column|null) {
|
||||
const movedLeft = prevColumn === null ? true : column.isAfter(prevColumn);
|
||||
const firstMovedColumn = movedLeft ? column : this.getNextColumn(column);
|
||||
this.columns.move(column, prevColumn);
|
||||
this.columnsSetX(firstMovedColumn);
|
||||
this.desktop.onLayoutChanged();
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
|
||||
public onColumnWidthChanged(column: Column) {
|
||||
const nextColumn = this.columns.getNext(column);
|
||||
this.columnsSetX(nextColumn);
|
||||
const rightColumn = this.columns.getNext(column);
|
||||
this.columnsSetX(rightColumn);
|
||||
this.desktop.onLayoutChanged();
|
||||
if (!this.userResize) {
|
||||
this.desktop.autoAdjustScroll();
|
||||
}
|
||||
}
|
||||
|
||||
public onColumnFocused(column: Column) {
|
||||
public onColumnFocused(column: Column, window: Window) {
|
||||
const lastFocusedColumn = this.getLastFocusedColumn();
|
||||
if (lastFocusedColumn !== null) {
|
||||
lastFocusedColumn.restoreToTiled();
|
||||
lastFocusedColumn.restoreToTiled(window);
|
||||
}
|
||||
this.lastFocusedColumn = column;
|
||||
this.desktop.scrollToColumn(column);
|
||||
this.desktop.scrollToColumn(column, false);
|
||||
}
|
||||
|
||||
public onScreenSizeChanged() {
|
||||
14
src/lib/layout/LayoutConfig.ts
Normal file
14
src/lib/layout/LayoutConfig.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
interface LayoutConfig {
|
||||
gapsInnerHorizontal: number;
|
||||
gapsInnerVertical: number;
|
||||
stackOffsetX: number;
|
||||
stackOffsetY: number;
|
||||
offScreenOpacity: number;
|
||||
stackColumnsByDefault: boolean;
|
||||
resizeNeighborColumn: boolean;
|
||||
reMaximize: boolean;
|
||||
skipSwitcher: boolean;
|
||||
tiledKeepBelow: boolean;
|
||||
maximizedKeepAbove: boolean;
|
||||
untileOnDrag: boolean;
|
||||
}
|
||||
47
src/lib/layout/Range.ts
Normal file
47
src/lib/layout/Range.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
interface Range {
|
||||
getLeft(): number;
|
||||
getRight(): number;
|
||||
getWidth(): number;
|
||||
}
|
||||
|
||||
namespace Range {
|
||||
export function create(x: number, width: number) {
|
||||
return new Basic(x, width);
|
||||
}
|
||||
|
||||
export function fromRanges(leftRange: Range, rightRange: Range) {
|
||||
const left = leftRange.getLeft();
|
||||
const right = rightRange.getRight();
|
||||
return new Basic(left, right - left);
|
||||
}
|
||||
|
||||
export function contains(parent: Range, child: Range) {
|
||||
return child.getLeft() >= parent.getLeft() &&
|
||||
child.getRight() <= parent.getRight();
|
||||
}
|
||||
|
||||
export function minus(a: Range, b: Range) {
|
||||
const aCenter = a.getLeft() + a.getWidth() / 2;
|
||||
const bCenter = b.getLeft() + b.getWidth() / 2;
|
||||
return Math.round(aCenter - bCenter);
|
||||
}
|
||||
|
||||
class Basic {
|
||||
constructor(
|
||||
private readonly x: number,
|
||||
private readonly width: number,
|
||||
) {}
|
||||
|
||||
public getLeft() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public getRight() {
|
||||
return this.x + this.width;
|
||||
}
|
||||
|
||||
public getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,23 +7,29 @@ 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) {
|
||||
maximizedMode = MaximizedMode.Unmaximized; // defaulting to unmaximized, as this is set in Tiled.prepareClientForTiling
|
||||
}
|
||||
this.focusedState = {
|
||||
fullScreen: false,
|
||||
maximizedMode: MaximizedMode.Unmaximized,
|
||||
fullScreen: this.client.kwinClient.fullScreen,
|
||||
maximizedMode: maximizedMode,
|
||||
};
|
||||
this.skipArrange = false;
|
||||
|
||||
this.skipArrange = this.client.kwinClient.fullScreen || maximizedMode !== MaximizedMode.Unmaximized;
|
||||
this.column = column;
|
||||
column.onWindowAdded(this);
|
||||
column.onWindowAdded(this, true);
|
||||
}
|
||||
|
||||
public moveToColumn(targetColumn: Column) {
|
||||
public moveToColumn(targetColumn: Column, bottom: boolean, passFocus: FocusPassing.Type) {
|
||||
if (targetColumn === this.column) {
|
||||
return;
|
||||
}
|
||||
this.column.onWindowRemoved(this, false);
|
||||
this.column.onWindowRemoved(this, passFocus);
|
||||
this.column = targetColumn;
|
||||
targetColumn.onWindowAdded(this);
|
||||
targetColumn.onWindowAdded(this, bottom);
|
||||
}
|
||||
|
||||
public arrange(x: number, y: number, width: number, height: number) {
|
||||
@@ -36,7 +42,7 @@ class Window {
|
||||
if (this.column.grid.config.reMaximize && this.isFocused()) {
|
||||
// do this here rather than in `onFocused` to ensure it happens after placement
|
||||
// (otherwise placement may not happen at all)
|
||||
if (this.focusedState.maximizedMode > MaximizedMode.Unmaximized) {
|
||||
if (this.focusedState.maximizedMode !== MaximizedMode.Unmaximized) {
|
||||
this.client.setMaximize(
|
||||
this.focusedState.maximizedMode === MaximizedMode.Horizontally || this.focusedState.maximizedMode === MaximizedMode.Maximized,
|
||||
this.focusedState.maximizedMode === MaximizedMode.Vertically || this.focusedState.maximizedMode === MaximizedMode.Maximized,
|
||||
@@ -54,11 +60,12 @@ class Window {
|
||||
}
|
||||
|
||||
public focus() {
|
||||
if (this.client.isShaded()) {
|
||||
// workaround for KWin deactivating clients when unshading immediately after activation
|
||||
this.client.setShade(false);
|
||||
}
|
||||
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() {
|
||||
@@ -66,6 +73,14 @@ class Window {
|
||||
}
|
||||
|
||||
public onFocused() {
|
||||
if (this.column.grid.config.reMaximize && (
|
||||
this.focusedState.maximizedMode !== MaximizedMode.Unmaximized ||
|
||||
this.focusedState.fullScreen
|
||||
)) {
|
||||
// We need to maximize/fullscreen this window, but we can't do it here.
|
||||
// We need to do it in `arrange` to ensure it happens after placement.
|
||||
this.column.grid.desktop.forceArrange();
|
||||
}
|
||||
this.column.onWindowFocused(this);
|
||||
}
|
||||
|
||||
@@ -75,11 +90,10 @@ class Window {
|
||||
}
|
||||
this.client.setFullScreen(false);
|
||||
this.client.setMaximize(false, false);
|
||||
this.column.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
|
||||
public onMaximizedChanged(maximizedMode: MaximizedMode) {
|
||||
const maximized = maximizedMode > MaximizedMode.Unmaximized;
|
||||
const maximized = maximizedMode !== MaximizedMode.Unmaximized;
|
||||
this.skipArrange = maximized;
|
||||
if (this.column.grid.config.tiledKeepBelow) {
|
||||
this.client.kwinClient.keepBelow = !maximized;
|
||||
@@ -107,45 +121,20 @@ class Window {
|
||||
this.column.grid.desktop.onLayoutChanged();
|
||||
}
|
||||
|
||||
public onUserResize(oldGeometry: QmlRect, resizeNeighborColumn: boolean) {
|
||||
const newGeometry = this.client.kwinClient.frameGeometry;
|
||||
const widthDelta = newGeometry.width - oldGeometry.width;
|
||||
const heightDelta = newGeometry.height - oldGeometry.height;
|
||||
if (widthDelta !== 0) {
|
||||
this.column.adjustWidth(widthDelta, true);
|
||||
let leftEdgeDelta = newGeometry.left - oldGeometry.left;
|
||||
const resizingLeftSide = leftEdgeDelta !== 0;
|
||||
if (resizeNeighborColumn && this.column.grid.config.resizeNeighborColumn) {
|
||||
const neighborColumn = resizingLeftSide ? this.column.grid.getPrevColumn(this.column) : this.column.grid.getNextColumn(this.column);
|
||||
if (neighborColumn !== null) {
|
||||
const oldNeighborWidth = neighborColumn.getWidth();
|
||||
neighborColumn.adjustWidth(-widthDelta, true);
|
||||
if (resizingLeftSide) {
|
||||
leftEdgeDelta -= neighborColumn.getWidth() - oldNeighborWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.column.grid.desktop.adjustScroll(-leftEdgeDelta, true);
|
||||
}
|
||||
if (heightDelta !== 0) {
|
||||
this.column.adjustWindowHeight(this, heightDelta, newGeometry.y !== oldGeometry.y);
|
||||
}
|
||||
}
|
||||
|
||||
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 = {
|
||||
fullScreen: boolean,
|
||||
maximizedMode: MaximizedMode,
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
5
src/lib/rules/WindowRule.ts
Normal file
5
src/lib/rules/WindowRule.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
interface WindowRule {
|
||||
class: string | undefined;
|
||||
caption: string | undefined;
|
||||
tile: boolean;
|
||||
}
|
||||
@@ -11,13 +11,14 @@ class WindowRuleEnforcer {
|
||||
}
|
||||
|
||||
public shouldTile(kwinClient: KwinClient) {
|
||||
return Clients.canTileNow(kwinClient) && (
|
||||
this.preferTiling.matches(kwinClient) || (
|
||||
kwinClient.normalWindow &&
|
||||
!kwinClient.transient &&
|
||||
kwinClient.managed &&
|
||||
!this.preferFloating.matches(kwinClient)
|
||||
)
|
||||
return this.preferTiling.matches(kwinClient) || (
|
||||
kwinClient.normalWindow &&
|
||||
!kwinClient.transient &&
|
||||
kwinClient.managed &&
|
||||
kwinClient.pid > -1 &&
|
||||
!kwinClient.fullScreen &&
|
||||
!Clients.isFullScreenGeometry(kwinClient) &&
|
||||
!this.preferFloating.matches(kwinClient)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,7 +30,7 @@ class WindowRuleEnforcer {
|
||||
const enforcer = this;
|
||||
const manager = new SignalManager();
|
||||
manager.connect(kwinClient.captionChanged, () => {
|
||||
const shouldTile = enforcer.shouldTile(kwinClient);
|
||||
const shouldTile = Clients.canTileNow(kwinClient) && enforcer.shouldTile(kwinClient);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (shouldTile && desktop !== undefined) {
|
||||
@@ -49,7 +50,10 @@ class WindowRuleEnforcer {
|
||||
for (const windowRule of windowRules) {
|
||||
const ruleClass = WindowRuleEnforcer.parseRegex(windowRule.class);
|
||||
const ruleCaption = WindowRuleEnforcer.parseRegex(windowRule.caption);
|
||||
const ruleString = ClientMatcher.getRuleString(ruleClass, ruleCaption);
|
||||
const ruleString = ClientMatcher.getRuleString(
|
||||
WindowRuleEnforcer.wrapParens(ruleClass),
|
||||
WindowRuleEnforcer.wrapParens(ruleCaption),
|
||||
);
|
||||
|
||||
(windowRule.tile ? tileRegexes : floatRegexes).push(ruleString);
|
||||
if (ruleCaption !== ".*") {
|
||||
@@ -20,6 +20,6 @@ function initQmlTimer() {
|
||||
return Qt.createQmlObject(
|
||||
`import QtQuick 6.0
|
||||
Timer {}`,
|
||||
qmlBase
|
||||
);
|
||||
qmlBase,
|
||||
) as QmlTimer;
|
||||
}
|
||||
24
src/lib/utils/RateLimiter.ts
Normal file
24
src/lib/utils/RateLimiter.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
class RateLimiter {
|
||||
private i = 0;
|
||||
private intervalStart = 0;
|
||||
|
||||
constructor(
|
||||
private readonly n: number,
|
||||
private readonly intervalMs: number,
|
||||
) {}
|
||||
|
||||
public acquire() {
|
||||
const now = Date.now();
|
||||
if (now - this.intervalStart >= this.intervalMs) {
|
||||
this.i = 0;
|
||||
this.intervalStart = now;
|
||||
}
|
||||
|
||||
if (this.i < this.n) {
|
||||
this.i++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/lib/utils/ShortcutAction.ts
Normal file
37
src/lib/utils/ShortcutAction.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
class ShortcutAction {
|
||||
private readonly shortcutHandler: ShortcutHandler;
|
||||
|
||||
constructor(keyBinding: ShortcutAction.KeyBinding, f: () => void) {
|
||||
this.shortcutHandler = ShortcutAction.initShortcutHandler(keyBinding);
|
||||
this.shortcutHandler.activated.connect(f);
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this.shortcutHandler.destroy();
|
||||
}
|
||||
|
||||
private static initShortcutHandler(keyBinding: ShortcutAction.KeyBinding) {
|
||||
const sequenceLine = keyBinding.defaultKeySequence !== undefined ?
|
||||
` sequence: "${keyBinding.defaultKeySequence}";
|
||||
` :
|
||||
"";
|
||||
|
||||
return Qt.createQmlObject(
|
||||
`import QtQuick 6.0
|
||||
import org.kde.kwin 3.0
|
||||
ShortcutHandler {
|
||||
name: "karousel-${keyBinding.name}";
|
||||
text: "Karousel: ${keyBinding.description}";
|
||||
${sequenceLine}}`,
|
||||
qmlBase,
|
||||
) as ShortcutHandler;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ShortcutAction {
|
||||
export interface KeyBinding {
|
||||
name: string;
|
||||
description: string;
|
||||
defaultKeySequence?: string;
|
||||
}
|
||||
}
|
||||
39
src/lib/utils/collections.ts
Normal file
39
src/lib/utils/collections.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
function union<T>(array0: T[], array1: T[]) {
|
||||
const set = new Set([...array0, ...array1]);
|
||||
return [...set];
|
||||
}
|
||||
|
||||
function uniq(sortedArray: any[]) {
|
||||
const filtered = [];
|
||||
let lastItem;
|
||||
for (const item of sortedArray) {
|
||||
if (item !== lastItem) {
|
||||
filtered.push(item);
|
||||
lastItem = item;
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
function mapGetOrInit<K, V>(map: Map<K, V>, key: K, defaultItem: V) {
|
||||
const item = map.get(key);
|
||||
if (item !== undefined) {
|
||||
return item;
|
||||
} else {
|
||||
map.set(key, defaultItem);
|
||||
return defaultItem;
|
||||
}
|
||||
}
|
||||
|
||||
function findMinPositive<T>(items: T[], evaluate: (item: T) => number) {
|
||||
let bestScore = Infinity;
|
||||
let bestItem = undefined;
|
||||
for (const item of items) {
|
||||
const score = evaluate(item);
|
||||
if (score > 0 && score < bestScore) {
|
||||
bestScore = score;
|
||||
bestItem = item;
|
||||
}
|
||||
}
|
||||
return bestItem;
|
||||
}
|
||||
98
src/lib/utils/fillSpace.ts
Normal file
98
src/lib/utils/fillSpace.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
function fillSpace(availableSpace: number, items: { min: number, max: number }[]) {
|
||||
if (items.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const middleSize = findMiddleSize(availableSpace, items);
|
||||
const sizes = items.map(item => clamp(middleSize, item.min, item.max));
|
||||
if (middleSize !== Math.floor(availableSpace / items.length)) {
|
||||
distributeRemainder(availableSpace, middleSize, sizes, items);
|
||||
}
|
||||
return sizes;
|
||||
|
||||
function findMiddleSize(availableSpace: number, items: { min: number, max: number }[]) {
|
||||
const ranges = buildRanges(items);
|
||||
let requiredSpace = items.reduce((acc, item) => acc + item.min, 0);
|
||||
for (const range of ranges) {
|
||||
const rangeSize = range.end - range.start;
|
||||
const maxRequiredSpaceDelta = rangeSize * range.n;
|
||||
if (requiredSpace + maxRequiredSpaceDelta >= availableSpace) {
|
||||
const positionInRange = (availableSpace - requiredSpace) / maxRequiredSpaceDelta;
|
||||
return Math.floor(range.start + rangeSize * positionInRange);
|
||||
}
|
||||
requiredSpace += maxRequiredSpaceDelta;
|
||||
}
|
||||
return ranges[ranges.length-1].end;
|
||||
}
|
||||
|
||||
function buildRanges(items: { min: number, max: number }[]) {
|
||||
const fenceposts = extractFenceposts(items);
|
||||
if (fenceposts.length === 1) {
|
||||
return [{
|
||||
start: fenceposts[0].value,
|
||||
end: fenceposts[0].value,
|
||||
n: items.length,
|
||||
}];
|
||||
}
|
||||
|
||||
const ranges: Range[] = [];
|
||||
let n = 0;
|
||||
for (let i = 1; i < fenceposts.length; i++) {
|
||||
const startFencepost = fenceposts[i-1];
|
||||
const endFencepost = fenceposts[i];
|
||||
n = n - startFencepost.nMax + startFencepost.nMin;
|
||||
ranges.push({
|
||||
start: startFencepost.value,
|
||||
end: endFencepost.value,
|
||||
n: n,
|
||||
});
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
function extractFenceposts(items: { min: number, max: number }[]) {
|
||||
const fenceposts = new Map<number, Fencepost>();
|
||||
for (const item of items) {
|
||||
mapGetOrInit(fenceposts, item.min, { value: item.min, nMin: 0, nMax: 0 }).nMin++;
|
||||
mapGetOrInit(fenceposts, item.max, { value: item.max, nMin: 0, nMax: 0 }).nMax++;
|
||||
}
|
||||
|
||||
const array = Array.from(fenceposts.values());
|
||||
array.sort((a, b) => a.value - b.value);
|
||||
return array;
|
||||
}
|
||||
|
||||
function distributeRemainder(availableSpace: number, middleSize: number, sizes: number[], constraints: { max: number }[]) {
|
||||
const indexes = Array.from(sizes.keys())
|
||||
.filter(i => sizes[i] === middleSize);
|
||||
indexes.sort((a, b) => constraints[a].max - constraints[b].max);
|
||||
|
||||
const requiredSpace = sum(...sizes);
|
||||
let remainder = availableSpace - requiredSpace;
|
||||
let n = indexes.length;
|
||||
for (const i of indexes) {
|
||||
if (remainder <= 0) {
|
||||
break;
|
||||
}
|
||||
const enlargable = constraints[i].max - sizes[i];
|
||||
if (enlargable > 0) {
|
||||
const enlarge = Math.min(enlargable, Math.ceil(remainder / n));
|
||||
sizes[i] += enlarge;
|
||||
remainder -= enlarge;
|
||||
}
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
interface Range {
|
||||
start: number,
|
||||
end: number,
|
||||
n: number,
|
||||
}
|
||||
|
||||
interface Fencepost {
|
||||
value: number,
|
||||
nMin: number,
|
||||
nMax: number,
|
||||
}
|
||||
}
|
||||
28
src/lib/utils/functions.ts
Normal file
28
src/lib/utils/functions.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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,
|
||||
...head: H
|
||||
) : (...tail: T) => R;
|
||||
}
|
||||
|
||||
Function.prototype.partial = function<H extends any[], T extends any[]>(...head: H) {
|
||||
return (...tail: T) => this(...head, ...tail);
|
||||
};
|
||||
57
src/lib/utils/math.ts
Normal file
57
src/lib/utils/math.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
if (value < min) {
|
||||
return min;
|
||||
}
|
||||
if (value > max) {
|
||||
return max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function sum(...list: number[]) {
|
||||
return list.reduce((acc, val) => acc + val);
|
||||
}
|
||||
|
||||
function rectEquals(a: QmlRect, b: QmlRect) {
|
||||
return a.x === b.x &&
|
||||
a.y === b.y &&
|
||||
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();
|
||||
}
|
||||
3
src/lib/utils/strings.ts
Normal file
3
src/lib/utils/strings.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
function applyMacro(base: string, value: string) {
|
||||
return base.replace("{}", String(value));
|
||||
}
|
||||
@@ -1,29 +1,27 @@
|
||||
function initWorkspaceSignalHandlers(world: World) {
|
||||
function initWorkspaceSignalHandlers(world: World, focusPasser: FocusPassing.Passer) {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(Workspace.windowAdded, (kwinClient: KwinClient) => {
|
||||
if (Clients.canTileEver(kwinClient)) {
|
||||
// never open new tileable clients on all desktops or activities
|
||||
Clients.makeTileable(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) => {
|
||||
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, () => {
|
||||
@@ -34,16 +32,22 @@ function initWorkspaceSignalHandlers(world: World) {
|
||||
world.do(() => {}); // re-arrange desktop
|
||||
});
|
||||
|
||||
manager.connect(Workspace.desktopsChanged, () => {
|
||||
manager.connect(Workspace.screensChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.updateDesktops();
|
||||
})
|
||||
desktopManager.selectScreen(Workspace.activeScreen);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.activitiesChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.updateActivities();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.desktopsChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
desktopManager.updateDesktops();
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(Workspace.virtualScreenSizeChanged, () => {
|
||||
@@ -1,15 +1,17 @@
|
||||
class ClientManager {
|
||||
private readonly world: World;
|
||||
private readonly config: ClientManager.Config;
|
||||
private readonly desktopManager: DesktopManager;
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly clientMap: Map<KwinClient, ClientWrapper>;
|
||||
private lastFocusedClient: KwinClient|null;
|
||||
private readonly windowRuleEnforcer: WindowRuleEnforcer;
|
||||
|
||||
constructor(config: Config, world: World, desktopManager: DesktopManager, pinManager: PinManager) {
|
||||
constructor(
|
||||
config: Config,
|
||||
private readonly world: World,
|
||||
private readonly desktopManager: DesktopManager,
|
||||
private readonly pinManager: PinManager,
|
||||
) {
|
||||
this.world = world;
|
||||
this.config = { keepAbove: config.floatingKeepAbove };
|
||||
this.config = config;
|
||||
this.desktopManager = desktopManager;
|
||||
this.pinManager = pinManager;
|
||||
this.clientMap = new Map();
|
||||
@@ -27,13 +29,19 @@ class ClientManager {
|
||||
|
||||
public addClient(kwinClient: KwinClient) {
|
||||
console.assert(!this.hasClient(kwinClient));
|
||||
const desktop = this.desktopManager.getDesktopForClient(kwinClient);
|
||||
|
||||
let constructState: (client: ClientWrapper) => ClientState.State;
|
||||
let desktop: Desktop | undefined;
|
||||
if (kwinClient.dock) {
|
||||
constructState = () => new ClientState.Docked(this.world, kwinClient);
|
||||
} else if (this.windowRuleEnforcer.shouldTile(kwinClient) && desktop !== undefined) {
|
||||
constructState = (client: ClientWrapper) => new ClientState.Tiled(this.world, client, desktop.grid);
|
||||
} else if (
|
||||
Clients.canTileEver(kwinClient) &&
|
||||
this.windowRuleEnforcer.shouldTile(kwinClient) &&
|
||||
(desktop = this.desktopManager.getDesktopForClient(kwinClient)) !== undefined
|
||||
) {
|
||||
Clients.makeTileable(kwinClient);
|
||||
console.assert(Clients.canTileNow(kwinClient));
|
||||
constructState = (client: ClientWrapper) => new ClientState.Tiled(this.world, client, desktop!.grid);
|
||||
} else {
|
||||
constructState = (client: ClientWrapper) => new ClientState.Floating(this.world, client, this.config, false);
|
||||
}
|
||||
@@ -47,18 +55,21 @@ 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);
|
||||
}
|
||||
|
||||
private findTransientFor(kwinClient: KwinClient) {
|
||||
if (!kwinClient.transient) {
|
||||
if (!kwinClient.transient || kwinClient.transientFor === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -87,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) {
|
||||
@@ -118,7 +130,12 @@ class ClientManager {
|
||||
if (client === undefined) {
|
||||
return;
|
||||
}
|
||||
client.stateManager.setState(() => new ClientState.Pinned(this.world, this.pinManager, this.desktopManager, kwinClient, this.config), false);
|
||||
if (client.getMaximizedMode() !== MaximizedMode.Unmaximized) {
|
||||
// the client is not really kwin-tiled, just maximized
|
||||
kwinClient.tile = null;
|
||||
return;
|
||||
}
|
||||
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();
|
||||
@@ -131,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();
|
||||
@@ -151,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,27 +180,27 @@ class ClientManager {
|
||||
|
||||
public onClientFocused(kwinClient: KwinClient) {
|
||||
this.lastFocusedClient = kwinClient;
|
||||
const window = this.findTiledWindow(kwinClient, true);
|
||||
const window = this.findTiledWindow(kwinClient);
|
||||
if (window !== null) {
|
||||
window.onFocused();
|
||||
}
|
||||
}
|
||||
|
||||
public findTiledWindow(kwinClient: KwinClient, followTransient: boolean) {
|
||||
public findTiledWindow(kwinClient: KwinClient) {
|
||||
const client = this.clientMap.get(kwinClient);
|
||||
if (client === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.findTiledWindowOfClient(client, followTransient);
|
||||
return this.findTiledWindowOfClient(client);
|
||||
}
|
||||
|
||||
private findTiledWindowOfClient(client: ClientWrapper, followTransient: boolean): Window|null {
|
||||
private findTiledWindowOfClient(client: ClientWrapper): Window|null {
|
||||
const clientState = client.stateManager.getState();
|
||||
if (clientState instanceof ClientState.Tiled) {
|
||||
return clientState.window;
|
||||
} else if (followTransient && client.transientFor !== null) {
|
||||
return this.findTiledWindowOfClient(client.transientFor, true);
|
||||
} else if (client.transientFor !== null) {
|
||||
return this.findTiledWindowOfClient(client.transientFor);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -191,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +218,7 @@ class ClientManager {
|
||||
}
|
||||
|
||||
namespace ClientManager {
|
||||
export type Config = {
|
||||
keepAbove: boolean,
|
||||
export interface Config {
|
||||
floatingKeepAbove: boolean;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,17 @@
|
||||
class ClientWrapper {
|
||||
public readonly kwinClient: KwinClient;
|
||||
public readonly stateManager: ClientState.Manager;
|
||||
public transientFor: ClientWrapper | null;
|
||||
private readonly transients: ClientWrapper[];
|
||||
private readonly signalManager: SignalManager;
|
||||
private readonly rulesSignalManager: SignalManager | null;
|
||||
public preferredWidth: number;
|
||||
private maximizedMode: MaximizedMode | undefined;
|
||||
private readonly manipulatingGeometry: Doer;
|
||||
private lastPlacement: QmlRect | null; // workaround for issue #19
|
||||
|
||||
constructor(
|
||||
kwinClient: KwinClient,
|
||||
public readonly kwinClient: KwinClient,
|
||||
constructInitialState: (client: ClientWrapper) => ClientState.State,
|
||||
transientFor: ClientWrapper | null,
|
||||
rulesSignalManager: SignalManager | null,
|
||||
public transientFor: ClientWrapper | null,
|
||||
private readonly rulesSignalManager: SignalManager | null,
|
||||
) {
|
||||
this.kwinClient = kwinClient;
|
||||
this.transientFor = transientFor;
|
||||
@@ -24,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));
|
||||
@@ -52,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(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +78,7 @@ class ClientWrapper {
|
||||
|
||||
public setMaximize(horizontally: boolean, vertically: boolean) {
|
||||
if (!this.kwinClient.maximizable) {
|
||||
this.maximizedMode = MaximizedMode.Unmaximized;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,16 +109,6 @@ class ClientWrapper {
|
||||
});
|
||||
}
|
||||
|
||||
public setShade(shade: boolean) {
|
||||
this.manipulatingGeometry.do(() => {
|
||||
this.kwinClient.shade = shade;
|
||||
});
|
||||
}
|
||||
|
||||
public isShaded() {
|
||||
return this.kwinClient.shade;
|
||||
}
|
||||
|
||||
public getMaximizedMode() {
|
||||
return this.maximizedMode;
|
||||
}
|
||||
@@ -154,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) {
|
||||
@@ -180,7 +168,7 @@ class ClientWrapper {
|
||||
const manager = new SignalManager();
|
||||
|
||||
manager.connect(client.kwinClient.maximizedAboutToChange, (maximizedMode: MaximizedMode) => {
|
||||
if (maximizedMode > MaximizedMode.Unmaximized && client.kwinClient.tile !== null) {
|
||||
if (maximizedMode !== MaximizedMode.Unmaximized && client.kwinClient.tile !== null) {
|
||||
client.kwinClient.tile = null;
|
||||
}
|
||||
client.maximizedMode = maximizedMode;
|
||||
@@ -1,10 +1,21 @@
|
||||
namespace Clients {
|
||||
const prohibitedClasses = [
|
||||
"ksmserver-logout-greeter",
|
||||
"xwaylandvideobridge",
|
||||
];
|
||||
|
||||
export function canTileEver(kwinClient: KwinClient) {
|
||||
return kwinClient.moveable && kwinClient.resizeable && !kwinClient.popupWindow;
|
||||
const shapeable = (kwinClient.moveable && kwinClient.resizeable) || kwinClient.fullScreen; // full-screen windows may become shapeable after exiting full-screen mode
|
||||
return shapeable &&
|
||||
!kwinClient.popupWindow &&
|
||||
!prohibitedClasses.includes(kwinClient.resourceClass);
|
||||
}
|
||||
|
||||
export function canTileNow(kwinClient: KwinClient) {
|
||||
return canTileEver(kwinClient) && !kwinClient.minimized && kwinClient.desktops.length === 1 && kwinClient.activities.length === 1;
|
||||
return canTileEver(kwinClient) &&
|
||||
!kwinClient.minimized &&
|
||||
kwinClient.desktops.length === 1 &&
|
||||
kwinClient.activities.length === 1;
|
||||
}
|
||||
|
||||
export function makeTileable(kwinClient: KwinClient) {
|
||||
@@ -21,22 +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.frameGeometry === fullScreenArea;
|
||||
return kwinClient.clientGeometry.width.round() >= fullScreenArea.width &&
|
||||
kwinClient.clientGeometry.height.round() >= fullScreenArea.height;
|
||||
}
|
||||
|
||||
export function isOnVirtualDesktop(kwinClient: KwinClient, kwinDesktop: KwinDesktop) {
|
||||
@@ -1,22 +1,29 @@
|
||||
class DesktopManager {
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly config: Desktop.Config;
|
||||
public readonly layoutConfig: LayoutConfig;
|
||||
private readonly desktops: Map<string, Desktop>; // key is activityId|desktopId
|
||||
private selectedScreen: Output;
|
||||
private kwinActivities: Set<string>;
|
||||
private kwinDesktops: Set<KwinDesktop>;
|
||||
|
||||
constructor(pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig, currentActivity: string, currentDesktop: KwinDesktop) {
|
||||
constructor(
|
||||
private readonly pinManager: PinManager,
|
||||
private readonly config: Desktop.Config,
|
||||
private readonly layoutConfig: LayoutConfig,
|
||||
private readonly focusPasser: FocusPassing.Passer,
|
||||
private readonly desktopFilter: DesktopFilter,
|
||||
) {
|
||||
this.pinManager = pinManager;
|
||||
this.config = config;
|
||||
this.layoutConfig = layoutConfig;
|
||||
this.desktops = new Map();
|
||||
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) {
|
||||
@@ -43,7 +50,14 @@ class DesktopManager {
|
||||
|
||||
private addDesktop(activity: string, kwinDesktop: KwinDesktop) {
|
||||
const desktopKey = DesktopManager.getDesktopKey(activity, kwinDesktop);
|
||||
const desktop = new Desktop(kwinDesktop, this.pinManager, this.config, this.layoutConfig);
|
||||
const desktop = new Desktop(
|
||||
kwinDesktop,
|
||||
this.pinManager,
|
||||
this.config,
|
||||
() => this.selectedScreen,
|
||||
this.layoutConfig,
|
||||
this.focusPasser,
|
||||
);
|
||||
this.desktops.set(desktopKey, desktop);
|
||||
return desktop;
|
||||
}
|
||||
@@ -72,6 +86,10 @@ class DesktopManager {
|
||||
this.kwinDesktops = newDesktops;
|
||||
}
|
||||
|
||||
public selectScreen(screen: Output) {
|
||||
this.selectedScreen = screen;
|
||||
}
|
||||
|
||||
private removeActivity(activity: string) {
|
||||
for (const kwinDesktop of this.kwinDesktops) {
|
||||
this.destroyDesktop(activity, kwinDesktop);
|
||||
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,16 +14,16 @@ 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)) {
|
||||
if (!Clients.isOnVirtualDesktop(client, kwinDesktop) || client.minimized) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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() {
|
||||
182
src/lib/world/World.ts
Normal file
182
src/lib/world/World.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
class World {
|
||||
private readonly desktopManager: DesktopManager;
|
||||
private readonly clientManager: ClientManager;
|
||||
private readonly pinManager: PinManager;
|
||||
private readonly workspaceSignalManager: SignalManager;
|
||||
private readonly shortcutActions: ShortcutAction[];
|
||||
private readonly screenResizedDelayer: Delayer;
|
||||
private readonly cursorFollowsFocus: boolean;
|
||||
|
||||
constructor(config: Config) {
|
||||
const focusPasser = new FocusPassing.Passer();
|
||||
this.workspaceSignalManager = initWorkspaceSignalHandlers(this, focusPasser);
|
||||
this.cursorFollowsFocus = config.cursorFollowsFocus;
|
||||
|
||||
let presetWidths = {
|
||||
next: (currentWidth: number, minWidth: number, maxWidth: number) => currentWidth,
|
||||
prev: (currentWidth: number, minWidth: number, maxWidth: number) => currentWidth,
|
||||
getWidths: (minWidth: number, maxWidth: number): number[] => [],
|
||||
};
|
||||
try {
|
||||
presetWidths = new PresetWidths(config.presetWidths, config.gapsInnerHorizontal);
|
||||
} catch (error: any) {
|
||||
notificationInvalidPresetWidths.sendEvent();
|
||||
log("failed to parse presetWidths:", error);
|
||||
}
|
||||
|
||||
this.shortcutActions = registerKeyBindings(this, {
|
||||
manualScrollStep: config.manualScrollStep,
|
||||
presetWidths: presetWidths,
|
||||
columnResizer: config.scrollingCentered ? new RawResizer(presetWidths) : new ContextualResizer(presetWidths),
|
||||
});
|
||||
|
||||
this.screenResizedDelayer = new Delayer(1000, () => {
|
||||
// this delay ensures that docks are taken into account by `Workspace.clientArea`
|
||||
for (const desktop of this.desktopManager.getAllDesktops()) {
|
||||
desktop.onLayoutChanged();
|
||||
}
|
||||
this.update();
|
||||
});
|
||||
|
||||
this.pinManager = new PinManager();
|
||||
|
||||
const layoutConfig = {
|
||||
gapsInnerHorizontal: config.gapsInnerHorizontal,
|
||||
gapsInnerVertical: config.gapsInnerVertical,
|
||||
stackOffsetX: config.stackOffsetX,
|
||||
stackOffsetY: config.stackOffsetY,
|
||||
offScreenOpacity: config.offScreenOpacity / 100.0,
|
||||
stackColumnsByDefault: config.stackColumnsByDefault,
|
||||
resizeNeighborColumn: config.resizeNeighborColumn,
|
||||
reMaximize: config.reMaximize,
|
||||
skipSwitcher: config.skipSwitcher,
|
||||
tiledKeepBelow: config.tiledKeepBelow,
|
||||
maximizedKeepAbove: config.floatingKeepAbove,
|
||||
untileOnDrag: config.untileOnDrag,
|
||||
};
|
||||
|
||||
this.desktopManager = new DesktopManager(
|
||||
this.pinManager,
|
||||
{
|
||||
marginTop: config.gapsOuterTop,
|
||||
marginBottom: config.gapsOuterBottom,
|
||||
marginLeft: config.gapsOuterLeft,
|
||||
marginRight: config.gapsOuterRight,
|
||||
scroller: World.createScroller(config),
|
||||
clamper: config.scrollingLazy ? new EdgeClamper() : new CenterClamper(),
|
||||
gestureScroll: config.gestureScroll,
|
||||
gestureScrollInvert: config.gestureScrollInvert,
|
||||
gestureScrollStep: config.gestureScrollStep,
|
||||
},
|
||||
layoutConfig,
|
||||
focusPasser,
|
||||
new DesktopFilter(config.tiledDesktops),
|
||||
);
|
||||
this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager);
|
||||
this.addExistingClients();
|
||||
this.update();
|
||||
}
|
||||
|
||||
private static createScroller(config: Config) {
|
||||
if (config.scrollingLazy) {
|
||||
return new LazyScroller();
|
||||
} else if (config.scrollingCentered) {
|
||||
return new CenteredScroller();
|
||||
} else if (config.scrollingGrouped) {
|
||||
return new GroupedScroller();
|
||||
} else {
|
||||
log("No scrolling mode selected, using default");
|
||||
return new LazyScroller();
|
||||
}
|
||||
}
|
||||
|
||||
private addExistingClients() {
|
||||
for (const kwinClient of Workspace.windows) {
|
||||
this.clientManager.addClient(kwinClient);
|
||||
}
|
||||
}
|
||||
|
||||
private update() {
|
||||
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) {
|
||||
f(this.clientManager, this.desktopManager);
|
||||
this.update();
|
||||
}
|
||||
|
||||
public doIfTiled(
|
||||
kwinClient: KwinClient,
|
||||
f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void,
|
||||
) {
|
||||
const window = this.clientManager.findTiledWindow(kwinClient);
|
||||
if (window === null) {
|
||||
return;
|
||||
}
|
||||
const column = window.column;
|
||||
const grid = column.grid;
|
||||
f(this.clientManager, this.desktopManager, window, column, grid);
|
||||
this.update();
|
||||
}
|
||||
|
||||
public doIfTiledFocused(
|
||||
f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void,
|
||||
) {
|
||||
if (Workspace.activeWindow === null) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
shortcutAction.destroy();
|
||||
}
|
||||
this.clientManager.destroy();
|
||||
this.desktopManager.destroy();
|
||||
}
|
||||
|
||||
public onScreenResized() {
|
||||
this.screenResizedDelayer.run();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace ClientState {
|
||||
world.onScreenResized();
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
this.world.onScreenResized();
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace ClientState {
|
||||
constructor(world: World, client: ClientWrapper, config: ClientManager.Config, limitHeight: boolean) {
|
||||
this.client = client;
|
||||
this.config = config;
|
||||
if (config.keepAbove) {
|
||||
if (config.floatingKeepAbove) {
|
||||
client.kwinClient.keepAbove = true;
|
||||
}
|
||||
if (limitHeight && client.kwinClient.tile === null) {
|
||||
@@ -16,13 +16,11 @@ namespace ClientState {
|
||||
this.signalManager = Floating.initSignalManager(world, client.kwinClient);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
if (this.config.keepAbove) {
|
||||
this.client.kwinClient.keepAbove = false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move to `Tiled.restoreClientAfterTiling`
|
||||
private static limitHeight(client: ClientWrapper) {
|
||||
const placementArea = Workspace.clientArea(
|
||||
ClientAreaOption.PlacementArea,
|
||||
@@ -32,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)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +48,7 @@ namespace ClientState {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
manager.connect(kwinClient.frameGeometryChanged, () => {
|
||||
// on Wayland, this fires after `tileChanged`
|
||||
if (kwinClient.tile !== null) {
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,14 @@ namespace ClientState {
|
||||
this.pinManager = pinManager;
|
||||
this.desktopManager = desktopManager;
|
||||
this.config = config;
|
||||
if (config.keepAbove) {
|
||||
if (config.floatingKeepAbove) {
|
||||
kwinClient.keepAbove = true;
|
||||
}
|
||||
this.signalManager = Pinned.initSignalManager(world, pinManager, kwinClient);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
if (this.config.keepAbove) {
|
||||
this.kwinClient.keepAbove = true;
|
||||
}
|
||||
this.pinManager.removeClient(this.kwinClient);
|
||||
for (const desktop of this.desktopManager.getDesktopsForClient(this.kwinClient)) {
|
||||
desktop.onPinsChanged();
|
||||
@@ -53,7 +50,15 @@ namespace ClientState {
|
||||
for (const desktop of desktopManager.getDesktopsForClient(kwinClient)) {
|
||||
desktop.onPinsChanged();
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.minimizedChanged, () => {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
for (const desktop of desktopManager.getDesktopsForClient(kwinClient)) {
|
||||
desktop.onPinsChanged();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.desktopsChanged, () => {
|
||||
@@ -3,6 +3,7 @@ namespace ClientState {
|
||||
public readonly window: Window;
|
||||
private readonly defaultState: Tiled.WindowState;
|
||||
private readonly signalManager: SignalManager;
|
||||
private static readonly maxExternalFrameGeometryChangedIntervalMs = 1000;
|
||||
|
||||
constructor(world: World, client: ClientWrapper, grid: Grid) {
|
||||
this.defaultState = { skipSwitcher: client.kwinClient.skipSwitcher };
|
||||
@@ -12,10 +13,10 @@ namespace ClientState {
|
||||
const window = new Window(client, column);
|
||||
|
||||
this.window = window;
|
||||
this.signalManager = Tiled.initSignalManager(world, window);
|
||||
this.signalManager = Tiled.initSignalManager(world, window, grid.config);
|
||||
}
|
||||
|
||||
public destroy(passFocus: boolean) {
|
||||
public destroy(passFocus: FocusPassing.Type) {
|
||||
this.signalManager.destroy();
|
||||
|
||||
const window = this.window;
|
||||
@@ -26,7 +27,7 @@ namespace ClientState {
|
||||
Tiled.restoreClientAfterTiling(client, grid.config, this.defaultState, grid.desktop.clientArea);
|
||||
}
|
||||
|
||||
private static initSignalManager(world: World, window: Window) {
|
||||
private static initSignalManager(world: World, window: Window, config: LayoutConfig) {
|
||||
const client = window.client;
|
||||
const kwinClient = client.kwinClient;
|
||||
const manager = new SignalManager();
|
||||
@@ -36,7 +37,7 @@ namespace ClientState {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (desktop === undefined) {
|
||||
// windows on multiple desktops are not supported
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
clientManager.floatClient(client);
|
||||
return;
|
||||
}
|
||||
Tiled.moveWindowToGrid(window, desktop.grid);
|
||||
@@ -48,12 +49,12 @@ namespace ClientState {
|
||||
const desktop = desktopManager.getDesktopForClient(kwinClient);
|
||||
if (desktop === undefined) {
|
||||
// windows on multiple activities are not supported
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
clientManager.floatClient(client);
|
||||
return;
|
||||
}
|
||||
Tiled.moveWindowToGrid(window, desktop.grid);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.minimizedChanged, () => {
|
||||
console.assert(kwinClient.minimized);
|
||||
@@ -68,33 +69,51 @@ namespace ClientState {
|
||||
});
|
||||
});
|
||||
|
||||
let moving = false;
|
||||
let resizing = false;
|
||||
let resizingBorder = false;
|
||||
let resizeStartWidth = 0;
|
||||
let resizeNeighbor: { column: Column, startWidth: number } | undefined;
|
||||
manager.connect(kwinClient.interactiveMoveResizeStarted, () => {
|
||||
if (kwinClient.move) {
|
||||
if (world.untileOnDrag) {
|
||||
if (config.untileOnDrag) {
|
||||
world.do((clientManager, desktopManager) => {
|
||||
clientManager.floatKwinClient(kwinClient);
|
||||
clientManager.floatClient(client);
|
||||
});
|
||||
} else {
|
||||
moving = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (kwinClient.resize) {
|
||||
resizing = true;
|
||||
resizingBorder = Workspace.cursorPos.x > kwinClient.clientGeometry.right ||
|
||||
Workspace.cursorPos.x < kwinClient.clientGeometry.left;
|
||||
resizeStartWidth = window.column.getWidth();
|
||||
if (config.resizeNeighborColumn) {
|
||||
const resizeNeighborColumn = Tiled.getResizeNeighborColumn(window);
|
||||
if (resizeNeighborColumn !== null) {
|
||||
resizeNeighbor = {
|
||||
column: resizeNeighborColumn,
|
||||
startWidth: resizeNeighborColumn.getWidth(),
|
||||
};
|
||||
}
|
||||
}
|
||||
window.column.grid.onUserResizeStarted();
|
||||
}
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.interactiveMoveResizeFinished, () => {
|
||||
if (moving) {
|
||||
moving = false;
|
||||
world.do(() => window.column.grid.desktop.onLayoutChanged()); // move the dragged window back to its position
|
||||
}
|
||||
if (resizing) {
|
||||
resizing = false;
|
||||
resizeNeighbor = undefined;
|
||||
window.column.grid.onUserResizeFinished();
|
||||
}
|
||||
});
|
||||
|
||||
const externalFrameGeometryChangedRateLimiter = new RateLimiter(4, Tiled.maxExternalFrameGeometryChangedIntervalMs);
|
||||
manager.connect(kwinClient.frameGeometryChanged, (oldGeometry: QmlRect) => {
|
||||
// on Wayland, this fires after `tileChanged`
|
||||
if (kwinClient.tile !== null) {
|
||||
@@ -104,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;
|
||||
@@ -112,23 +136,51 @@ namespace ClientState {
|
||||
const dx = Math.round(newCenterX - oldCenterX);
|
||||
const dy = Math.round(newCenterY - oldCenterY);
|
||||
if (dx !== 0 || dy !== 0) {
|
||||
// TODO: instead of passing dx and dy, remember relative (to the parent) x and y for each
|
||||
// transient window and use them for `moveTransients` and `ensureTransientsVisible`
|
||||
client.moveTransients(dx, dy);
|
||||
}
|
||||
|
||||
if (kwinClient.resize) {
|
||||
world.do(() => window.onUserResize(oldGeometry, resizingBorder));
|
||||
world.do(() => {
|
||||
if (newGeometry.width !== oldGeometry.width) {
|
||||
window.column.onUserResizeWidth(
|
||||
resizeStartWidth,
|
||||
newGeometry.width - resizeStartWidth,
|
||||
newGeometry.x !== oldGeometry.x,
|
||||
resizeNeighbor,
|
||||
);
|
||||
}
|
||||
if (newGeometry.height !== oldGeometry.height) {
|
||||
window.column.adjustWindowHeight(
|
||||
window,
|
||||
newGeometry.height - oldGeometry.height,
|
||||
newGeometry.y !== oldGeometry.y,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if (
|
||||
!window.column.grid.isUserResizing() &&
|
||||
!client.isManipulatingGeometry(newGeometry) &&
|
||||
client.getMaximizedMode() === MaximizedMode.Unmaximized &&
|
||||
!Clients.isFullScreenGeometry(kwinClient) // not using `kwinClient.fullScreen` because it may not be set yet at this point
|
||||
) {
|
||||
world.do(() => window.onFrameGeometryChanged());
|
||||
if (externalFrameGeometryChangedRateLimiter.acquire()) {
|
||||
world.do(() => window.onFrameGeometryChanged());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.fullScreenChanged, () => {
|
||||
world.do(() => window.onFullScreenChanged(kwinClient.fullScreen));
|
||||
world.do((clientManager, desktopManager) => {
|
||||
// some clients only turn out to be untileable after exiting full-screen mode
|
||||
if (!Clients.canTileEver(kwinClient)) {
|
||||
clientManager.floatClient(client);
|
||||
return;
|
||||
}
|
||||
|
||||
window.onFullScreenChanged(kwinClient.fullScreen);
|
||||
});
|
||||
});
|
||||
|
||||
manager.connect(kwinClient.tileChanged, () => {
|
||||
@@ -143,6 +195,18 @@ namespace ClientState {
|
||||
return manager;
|
||||
}
|
||||
|
||||
private static getResizeNeighborColumn(window: Window) {
|
||||
const kwinClient = window.client.kwinClient;
|
||||
const column = window.column;
|
||||
if (Workspace.cursorPos.x > rectRightRound(kwinClient.clientGeometry)) {
|
||||
return column.grid.getRightColumn(column);
|
||||
} else if (Workspace.cursorPos.x < kwinClient.clientGeometry.x.round()) {
|
||||
return column.grid.getLeftColumn(column);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static moveWindowToGrid(window: Window, grid: Grid) {
|
||||
if (grid === window.column.grid) {
|
||||
// window already on the given grid
|
||||
@@ -150,17 +214,26 @@ namespace ClientState {
|
||||
}
|
||||
|
||||
const newColumn = new Column(grid, grid.getLastFocusedColumn() ?? grid.getLastColumn());
|
||||
window.moveToColumn(newColumn);
|
||||
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.setFullScreen(false);
|
||||
|
||||
if (client.kwinClient.tile !== null) {
|
||||
client.setMaximize(false, true); // disable quick tile mode
|
||||
}
|
||||
@@ -177,7 +250,6 @@ namespace ClientState {
|
||||
if (config.offScreenOpacity < 1.0) {
|
||||
client.kwinClient.opacity = 1.0;
|
||||
}
|
||||
client.setShade(false);
|
||||
client.setFullScreen(false);
|
||||
if (client.kwinClient.tile === null) {
|
||||
client.setMaximize(false, false);
|
||||
@@ -187,8 +259,8 @@ namespace ClientState {
|
||||
}
|
||||
|
||||
namespace Tiled {
|
||||
export type WindowState = {
|
||||
skipSwitcher: boolean,
|
||||
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,3 +0,0 @@
|
||||
function init() {
|
||||
return new World(loadConfig());
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
function init() {
|
||||
return new World(loadConfig());
|
||||
}
|
||||
|
||||
function loadConfig(): Config {
|
||||
const config: any = {};
|
||||
for (const entry of configDef) {
|
||||
8
src/main/tsconfig.json
Normal file
8
src/main/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": [
|
||||
"../extern/**/*",
|
||||
"../lib/**/*",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
type WindowRule = {
|
||||
class: string | undefined,
|
||||
caption: string | undefined,
|
||||
tile: boolean,
|
||||
};
|
||||
43
src/tests/flows/centerFocused.ts
Normal file
43
src/tests/flows/centerFocused.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
tests.register("Center focused", 5, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [client0, client1, client2] = workspaceMock.createClientsWithWidths(300, 152, 300);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(client0));
|
||||
Assert.assert(clientManager.hasClient(client1));
|
||||
Assert.assert(clientManager.hasClient(client2));
|
||||
});
|
||||
Assert.assert(workspaceMock.activeWindow === client2);
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
|
||||
// center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.centered(config, tilingArea, client2);
|
||||
Assert.fullyVisible(client1.getActualFrameGeometry());
|
||||
Assert.fullyVisible(client2.getActualFrameGeometry());
|
||||
|
||||
// undo center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
|
||||
// center client2
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.centered(config, tilingArea, client2);
|
||||
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.getActualFrameGeometry());
|
||||
Assert.fullyVisible(client2.getActualFrameGeometry());
|
||||
|
||||
// center client1
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
|
||||
// undo center client1 (no scrolling should occur, because all clients are already visible and centered)
|
||||
qtMock.fireShortcut("karousel-grid-scroll-focused");
|
||||
Assert.columnsFillTilingArea([client0, client1, client2]);
|
||||
});
|
||||
124
src/tests/flows/columnsSqueezeSide.ts
Normal file
124
src/tests/flows/columnsSqueezeSide.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
tests.register("columns squeeze side", 5, () => {
|
||||
const baseTestCases = [
|
||||
{ widths: [500, 500], blocked: [false, false], possible: true },
|
||||
{ widths: [500, 768], blocked: [false, false], possible: true },
|
||||
{ widths: [500, 500], blocked: [false, true], possible: true },
|
||||
{ widths: [500, 200, 200], blocked: [false, false, false], possible: true },
|
||||
{ widths: [500, 200, 200], blocked: [false, false, true], possible: true },
|
||||
{ widths: [500, 200, 200], blocked: [true, false, true], possible: true },
|
||||
{ widths: [500, 500, 500], blocked: [false, true, true], possible: false },
|
||||
];
|
||||
|
||||
const testCasesLeft = baseTestCases.map((baseTestCase, i) => ({
|
||||
...baseTestCase,
|
||||
name: "left " + i,
|
||||
action: "karousel-columns-squeeze-left",
|
||||
focus: baseTestCase.widths.length-1,
|
||||
}));
|
||||
|
||||
const testCasesRight = baseTestCases.map((baseTestCase, i) => ({
|
||||
...baseTestCase,
|
||||
widths: baseTestCase.widths.slice().reverse(),
|
||||
blocked: baseTestCase.blocked.slice().reverse(),
|
||||
name: "right " + i,
|
||||
action: "karousel-columns-squeeze-right",
|
||||
focus: 0,
|
||||
}));
|
||||
|
||||
const testCases = [...testCasesLeft, ...testCasesRight];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
const assertOpt = { message: `Case: ${testCase.name}` };
|
||||
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const clients = workspaceMock.createClientsWithWidths(...testCase.widths);
|
||||
workspaceMock.activeWindow = clients[testCase.focus];
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
if (testCase.blocked[i]) {
|
||||
clients[i].minSize = new MockQmlSize(testCase.widths[i], 100);
|
||||
}
|
||||
}
|
||||
|
||||
if (testCase.possible) {
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
Assert.columnsFillTilingArea(clients, assertOpt);
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
if (testCase.blocked[i]) {
|
||||
Assert.equal(clients[i].getActualFrameGeometry().width, testCase.widths[i], assertOpt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const frames = clients.map(client => client.getActualFrameGeometry());
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
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)", 5, () => {
|
||||
const baseTestCases = [
|
||||
{ focus: 0, startVisible: [true, true, false], endVisible: [true, true, false] },
|
||||
{ focus: 1, startVisible: [false, true, true], endVisible: [true, true, false] },
|
||||
{ focus: 2, startVisible: [false, true, true], endVisible: [false, true, true] },
|
||||
];
|
||||
|
||||
const testCasesLeft = baseTestCases.map((baseTestCase, i) => ({
|
||||
...baseTestCase,
|
||||
name: "left " + i,
|
||||
action: "karousel-columns-squeeze-left",
|
||||
scrollStart: false,
|
||||
}));
|
||||
|
||||
const testCasesRight = baseTestCases.map((baseTestCase, i) => ({
|
||||
focus: 2 - baseTestCase.focus,
|
||||
startVisible: baseTestCase.startVisible.slice().reverse(),
|
||||
endVisible: baseTestCase.endVisible.slice().reverse(),
|
||||
name: "right " + i,
|
||||
action: "karousel-columns-squeeze-right",
|
||||
scrollStart: true,
|
||||
}));
|
||||
|
||||
const testCases = [...testCasesLeft, ...testCasesRight];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
const assertMsg = `Case: ${testCase.name}`;
|
||||
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
function assertVisible(clients: MockKwinClient[], visible: boolean[]) {
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
if (visible[i]) {
|
||||
Assert.fullyVisible(clients[i].getActualFrameGeometry(), { message: assertMsg, skip: 1 });
|
||||
} else {
|
||||
Assert.notFullyVisible(clients[i].getActualFrameGeometry(), { message: assertMsg, skip: 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const clients = workspaceMock.createClientsWithWidths(300, 300, 300);
|
||||
for (const client of clients) {
|
||||
client.minSize = new MockQmlSize(300, 100);
|
||||
}
|
||||
if (testCase.scrollStart) {
|
||||
qtMock.fireShortcut("karousel-grid-scroll-start");
|
||||
}
|
||||
workspaceMock.activeWindow = clients[testCase.focus];
|
||||
assertVisible(clients, testCase.startVisible);
|
||||
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
assertVisible(clients, testCase.endVisible);
|
||||
|
||||
const frames = clients.map(client => client.getActualFrameGeometry());
|
||||
qtMock.fireShortcut(testCase.action);
|
||||
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" });
|
||||
});
|
||||
});
|
||||
34
src/tests/flows/dragTiled.ts
Normal file
34
src/tests/flows/dragTiled.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
tests.register("Drag tiled window, untile", 20, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.untileOnDrag = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
const clientManager = getClientManager(world);
|
||||
|
||||
const [client0, client1] = workspaceMock.createClients(2);
|
||||
Assert.tiledClient(clientManager, client0);
|
||||
Assert.tiledClient(clientManager, client1);
|
||||
Assert.grid(config, tilingArea, 100, [[client0], [client1]], true);
|
||||
|
||||
workspaceMock.moveWindow(client0, new MockQmlPoint(10, 10));
|
||||
Assert.notTiledClient(clientManager, client0);
|
||||
Assert.tiledClient(clientManager, client1);
|
||||
Assert.grid(config, tilingArea, 100, [[client1]], true);
|
||||
});
|
||||
|
||||
tests.register("Drag tiled window, keep tiled", 20, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.untileOnDrag = false;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
const clientManager = getClientManager(world);
|
||||
|
||||
const [client0, client1] = workspaceMock.createClients(2);
|
||||
Assert.tiledClient(clientManager, client0);
|
||||
Assert.tiledClient(clientManager, client1);
|
||||
Assert.grid(config, tilingArea, 100, [[client0], [client1]], true);
|
||||
|
||||
const move = new MockQmlPoint(10, 10);
|
||||
workspaceMock.moveWindow(client0, move, move, move, move, move, move, move, move, move); // many moves in order to trigger externalFrameGeometryChangedRateLimiter
|
||||
Assert.tiledClient(clientManager, client0);
|
||||
Assert.tiledClient(clientManager, client1);
|
||||
Assert.grid(config, tilingArea, 100, [[client0], [client1]], true);
|
||||
});
|
||||
44
src/tests/flows/externalResize.ts
Normal file
44
src/tests/flows/externalResize.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
tests.register("External resize", 1, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
function getClientDesiredFrame(width: number) {
|
||||
return new MockQmlRect(10, 10, width, 200);
|
||||
}
|
||||
|
||||
function getTiledFrame(width: number) {
|
||||
return new MockQmlRect(
|
||||
tilingArea.x + Math.round((tilingArea.width - width) / 2),
|
||||
tilingArea.y,
|
||||
width,
|
||||
tilingArea.height,
|
||||
);
|
||||
}
|
||||
|
||||
const [client] = workspaceMock.createClientsWithFrames(getClientDesiredFrame(100));
|
||||
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.getActualFrameGeometry(), getTiledFrame(110), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
|
||||
client.frameGeometry = getClientDesiredFrame(120);
|
||||
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.getActualFrameGeometry(), getTiledFrame(130), { message: "We should re-arrange the window, respecting its new desired width" });
|
||||
|
||||
client.frameGeometry = getClientDesiredFrame(140);
|
||||
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.getActualFrameGeometry(), getClientDesiredFrame(200), { message: "We should give up and let the client have its desired frame" });
|
||||
}
|
||||
|
||||
timeControl(addTime => {
|
||||
testExternalResizing();
|
||||
addTime(1000);
|
||||
// the concession has expired, let's test again
|
||||
testExternalResizing();
|
||||
});
|
||||
});
|
||||
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);
|
||||
});
|
||||
191
src/tests/flows/layering.ts
Normal file
191
src/tests/flows/layering.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
tests.register("tiledKeepBelow", 10, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.tiledKeepBelow = true;
|
||||
config.floatingKeepAbove = false;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const pinGeometry = new MockQmlRect(0, 0, 200, screen.height);
|
||||
|
||||
const [client] = workspaceMock.createClients(1);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null);
|
||||
});
|
||||
Assert.assert(client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
client.pin(pinGeometry);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
client.unpin();
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null);
|
||||
});
|
||||
Assert.assert(client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
client.pin(pinGeometry);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null);
|
||||
});
|
||||
Assert.assert(client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
});
|
||||
|
||||
tests.register("floatingKeepAbove", 10, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.tiledKeepBelow = false;
|
||||
config.floatingKeepAbove = true;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const pinGeometry = new MockQmlRect(0, 0, 200, screen.height);
|
||||
|
||||
const [client] = workspaceMock.createClients(1);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(client.keepAbove);
|
||||
|
||||
client.pin(pinGeometry);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(client.keepAbove);
|
||||
|
||||
client.unpin();
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(client.keepAbove);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
|
||||
client.pin(pinGeometry);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(client.keepAbove);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null);
|
||||
});
|
||||
Assert.assert(!client.keepBelow);
|
||||
Assert.assert(!client.keepAbove);
|
||||
});
|
||||
|
||||
tests.register("No layering", 10, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.tiledKeepBelow = false;
|
||||
config.floatingKeepAbove = false;
|
||||
// In this mode, Karousel shouldn't change keepBelow or keepAbove.
|
||||
// Except when tiling a window, keepAbove should still be cleared.
|
||||
|
||||
const pinGeometry = new MockQmlRect(0, 0, 200, screen.height);
|
||||
|
||||
const testCases = [
|
||||
{ keepBelow: false, keepAbove: false },
|
||||
{ keepBelow: false, keepAbove: true },
|
||||
{ keepBelow: true, keepAbove: false },
|
||||
{ keepBelow: true, keepAbove: true },
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
const assertOptions = { message: JSON.stringify(testCase) };
|
||||
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [client] = workspaceMock.createClients(1);
|
||||
client.keepBelow = testCase.keepBelow;
|
||||
client.keepAbove = testCase.keepAbove;
|
||||
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.equal(client.keepAbove, testCase.keepAbove, assertOptions);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.equal(client.keepAbove, testCase.keepAbove, assertOptions);
|
||||
|
||||
client.pin(pinGeometry);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.equal(client.keepAbove, testCase.keepAbove, assertOptions);
|
||||
|
||||
client.unpin();
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.equal(client.keepAbove, testCase.keepAbove, assertOptions);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.assert(!client.keepAbove, assertOptions);
|
||||
client.keepAbove = testCase.keepAbove;
|
||||
|
||||
client.pin(pinGeometry);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) === null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.equal(client.keepAbove, testCase.keepAbove, assertOptions);
|
||||
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.findTiledWindow(client) !== null, assertOptions);
|
||||
});
|
||||
Assert.equal(client.keepBelow, testCase.keepBelow, assertOptions);
|
||||
Assert.assert(!client.keepAbove, assertOptions);
|
||||
}
|
||||
});
|
||||
98
src/tests/flows/layout.ts
Normal file
98
src/tests/flows/layout.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
tests.register("Focus and move windows", 1, () => {
|
||||
const config = getDefaultConfig();
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [client1, client2, client3] = workspaceMock.createClients(3);
|
||||
world.do((clientManager, desktopManager) => {
|
||||
Assert.assert(clientManager.hasClient(client1));
|
||||
Assert.assert(clientManager.hasClient(client2));
|
||||
Assert.assert(clientManager.hasClient(client3));
|
||||
});
|
||||
Assert.assert(workspaceMock.activeWindow === client3);
|
||||
|
||||
function testLayout(shortcutName: string, grid: MockKwinClient[][]) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
Assert.grid(config, tilingArea, 100, grid, true, [], { skip: 1 });
|
||||
}
|
||||
|
||||
function testFocus(shortcutName: string, expectedFocus: KwinClient) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
Assert.assert(workspaceMock.activeWindow === expectedFocus, {
|
||||
message: `wrong activeWindow: ${workspaceMock.activeWindow?.pid}`,
|
||||
skip: 1,
|
||||
});
|
||||
};
|
||||
|
||||
testLayout("karousel-column-move-right", [ [client1], [client2], [client3] ]);
|
||||
|
||||
testLayout("karousel-window-move-left", [ [client1], [client2,client3] ]);
|
||||
testLayout("karousel-window-move-left", [ [client1], [client3], [client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client1,client3], [client2] ]);
|
||||
testFocus("karousel-focus-right", client2);
|
||||
testLayout("karousel-window-move-left", [ [client1,client3,client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client2], [client1,client3] ]);
|
||||
testLayout("karousel-window-move-left", [ [client2], [client1,client3] ]);
|
||||
testFocus("karousel-focus-2", client3);
|
||||
testFocus("karousel-focus-up", client1);
|
||||
testLayout("karousel-column-move-left", [ [client1,client3], [client2] ]);
|
||||
testLayout("karousel-window-move-right", [ [client3], [client1], [client2] ]);
|
||||
|
||||
testFocus("karousel-focus-3", client2);
|
||||
testLayout("karousel-window-move-start", [ [client2], [client3], [client1] ]);
|
||||
testLayout("karousel-window-move-to-column-3", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-column-move-left", [ [client1,client2], [client3] ]);
|
||||
testLayout("karousel-column-move-end", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-column-move-to-column-1", [ [client1,client2], [client3] ]);
|
||||
testLayout("karousel-column-move-right", [ [client3], [client1,client2] ]);
|
||||
|
||||
testLayout("karousel-window-move-previous", [ [client3], [client2,client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client3], [client2], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client3,client2], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client2,client3], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client2], [client3], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client2], [client3], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client2,client3], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3,client2], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client2], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client2,client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client1], [client2] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client1], [client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client3], [client1,client2] ]);
|
||||
|
||||
const col1Win1 = client3;
|
||||
const col2Win1 = client1;
|
||||
const col2Win2 = client2;
|
||||
|
||||
testFocus("karousel-focus-up", col2Win1);
|
||||
testFocus("karousel-focus-up", col2Win1);
|
||||
testFocus("karousel-focus-down", col2Win2);
|
||||
testFocus("karousel-focus-left", col1Win1);
|
||||
testFocus("karousel-focus-left", col1Win1);
|
||||
testFocus("karousel-focus-right", col2Win2);
|
||||
testFocus("karousel-focus-right", col2Win2);
|
||||
|
||||
testFocus("karousel-focus-2", col2Win2);
|
||||
testFocus("karousel-focus-1", col1Win1);
|
||||
testFocus("karousel-focus-2", col2Win2);
|
||||
testFocus("karousel-focus-start", col1Win1);
|
||||
testFocus("karousel-focus-end", col2Win2);
|
||||
|
||||
testFocus("karousel-focus-up", col2Win1);
|
||||
testFocus("karousel-focus-left", col1Win1);
|
||||
testFocus("karousel-focus-right", col2Win1);
|
||||
testFocus("karousel-focus-2", col2Win1);
|
||||
testFocus("karousel-focus-1", col1Win1);
|
||||
testFocus("karousel-focus-2", col2Win1);
|
||||
testFocus("karousel-focus-start", col1Win1);
|
||||
testFocus("karousel-focus-end", col2Win1);
|
||||
|
||||
testFocus("karousel-focus-down", col2Win2);
|
||||
testFocus("karousel-focus-start", col1Win1);
|
||||
testFocus("karousel-focus-next", col2Win1);
|
||||
testFocus("karousel-focus-next", col2Win2);
|
||||
testFocus("karousel-focus-next", col2Win2);
|
||||
testFocus("karousel-focus-previous", col2Win1);
|
||||
testFocus("karousel-focus-previous", col1Win1);
|
||||
testFocus("karousel-focus-previous", col1Win1);
|
||||
});
|
||||
47
src/tests/flows/lazyScroller.ts
Normal file
47
src/tests/flows/lazyScroller.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
tests.register("LazyScroller", 20, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.scrollingLazy = true;
|
||||
config.scrollingCentered = false;
|
||||
config.scrollingGrouped = false;
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
|
||||
const [client1] = workspaceMock.createClientsWithWidths(300);
|
||||
Assert.grid(config, tilingArea, 300, [[client1]], true);
|
||||
|
||||
const [client2] = workspaceMock.createClientsWithWidths(300);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2]], true);
|
||||
|
||||
const [client3] = workspaceMock.createClientsWithWidths(300);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.equal(rectRight(client3.getActualFrameGeometry()), rectRight(tilingArea));
|
||||
|
||||
runOneOf(
|
||||
() => { workspaceMock.activeWindow = client2; },
|
||||
() => { qtMock.fireShortcut("karousel-focus-2"); },
|
||||
() => { qtMock.fireShortcut("karousel-focus-left"); },
|
||||
);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
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;
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
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"); },
|
||||
);
|
||||
Assert.grid(config, tilingArea, 300, [[client1], [client2], [client3]], false);
|
||||
Assert.equal(client1.getActualFrameGeometry().x, tilingArea.x);
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user