99 Commits
v0.3.1 ... v0.5

Author SHA1 Message Date
Peter Fajdiga
43f425c868 config: set overscroll default to 0 2023-09-22 17:45:11 +02:00
Peter Fajdiga
5c5127f7ce bump version to 0.5 2023-09-22 17:42:16 +02:00
Peter Fajdiga
8664f05998 ClientManager: prevent glitchy placement when maximizing a pinned client 2023-09-22 17:36:54 +02:00
Peter Fajdiga
e4f6a32d42 make pinning work with kwin-tiled windows of any frameGeometry 2023-09-22 17:25:32 +02:00
Peter Fajdiga
2882bb8d5d base pinning on KwinClient.tile instead of frameGeometry 2023-09-22 14:40:25 +02:00
Peter Fajdiga
5ef71c92ce Column: prevent stacking columns with unshadeable windows 2023-09-22 11:15:35 +02:00
Peter Fajdiga
de59979a6e Tiled: restructure branches in moveResizedChanged handler 2023-09-22 10:54:12 +02:00
Peter Fajdiga
71d7d60837 ClientManager: use kwinClient parameters 2023-09-20 20:14:30 +02:00
Peter Fajdiga
7f44d23dd0 kwin.d.ts: merge AbstractClient and TopLevel 2023-09-20 20:13:23 +02:00
Peter Fajdiga
aceffae5f9 config.ui: add tooltips 2023-09-20 19:53:33 +02:00
Peter Fajdiga
09e5eaca88 add re-maximize setting 2023-09-19 21:15:01 +02:00
Peter Fajdiga
734dd8a4cc fix re-full-screen bug with Kate on Wayland 2023-09-19 21:05:59 +02:00
Peter Fajdiga
aeabb396f9 Revert "remove re-maximize and re-fullscreen functionality" (fixes #18)
This reverts commit 4f06f17b
2023-09-19 21:04:27 +02:00
Peter Fajdiga
05b9ebc325 handle grid changes during a full-screen window 2023-09-19 18:58:50 +02:00
Peter Fajdiga
4728afb5ea Grid: set preferred width in increaseColumnWidth and decreaseColumnWidth 2023-09-17 19:17:50 +02:00
Peter Fajdiga
653cb20e43 ClientWrapper: remove obsolete TODO 2023-09-17 19:17:50 +02:00
Peter Fajdiga
0cb2b68bf6 implement workaround that fixes #19 2023-09-17 19:17:50 +02:00
Peter Fajdiga
b8b8900754 Tiled: call World.do only if condition satisfied 2023-09-17 08:00:32 +02:00
Peter Fajdiga
14c006b5b1 Window.onFullScreenChanged: remove check for isFocused 2023-09-16 15:34:12 +02:00
Peter Fajdiga
9fe6be9b91 implement pinning (resolves #8) 2023-09-16 14:55:38 +02:00
Peter Fajdiga
97d1592318 add option for setting keepAbove on floating windows (fixes #15) 2023-09-16 14:51:46 +02:00
Peter Fajdiga
cc8cc04b05 WindowRuleEnforcer.shouldTile: don't tile transient windows 2023-09-10 18:18:48 +02:00
Peter Fajdiga
cc74d3610a WindowRuleEnforcer.shouldTile: explode condition 2023-09-10 18:17:25 +02:00
Peter Fajdiga
088725402e WindowRuleEnforcer: refactor function -> private static 2023-09-10 17:31:54 +02:00
Peter Fajdiga
25b7507b30 fix incorrect movement of transient windows (bug introduced in f4e9822f29) 2023-09-09 15:01:59 +02:00
Peter Fajdiga
9b32caafdc config/loader.ts: declare return type of loadConfig 2023-09-09 12:58:56 +02:00
Peter Fajdiga
668d579d63 prevent resizing new floating windows 2023-09-09 11:08:01 +02:00
Peter Fajdiga
f4e9822f29 ClientManager.addClient: avoid constructing state twice 2023-09-09 09:19:37 +02:00
Peter Fajdiga
bdb0a4aeb0 ClientWrapper: refactor constructor parameter initialState -> constructInitialState 2023-09-09 09:11:01 +02:00
Peter Fajdiga
dde1a12fce ClientManager.addClient: use variable kwinClient 2023-09-09 09:01:01 +02:00
Peter Fajdiga
c57c8391fb ClientWrapper: move tiling- and floating-specific functions to ClientState.Floating and ClientState.Tiled 2023-09-08 15:40:16 +02:00
Peter Fajdiga
ec64b47ceb Tiled: add comment regarding kwinClient.fullScreen 2023-09-06 22:53:36 +02:00
Peter Fajdiga
b055345e48 readme: update key bindings 2023-09-04 20:24:17 +02:00
Peter Fajdiga
eb43f45287 bump version to 0.4 2023-09-04 20:20:06 +02:00
Peter Fajdiga
e61d7538b2 re-arrange desktop when switching to it 2023-09-03 19:58:01 +02:00
Peter Fajdiga
a3c0976f55 main.qml: remove start and stop logs 2023-09-03 19:25:10 +02:00
Peter Fajdiga
b372489eb5 ClientState: remove unnecessary ClientState. prefixes 2023-09-03 19:13:33 +02:00
Peter Fajdiga
fa974a68aa kwin.d.ts: add comments for desktop and activities 2023-09-03 19:13:33 +02:00
Peter Fajdiga
20517aed7f Desktop.updateArea: set dirty flag 2023-09-03 14:15:01 +02:00
Peter Fajdiga
b49082d51d DesktopManager.getDesktop: fix desktop number validity check 2023-09-02 12:33:08 +02:00
Peter Fajdiga
08135a4ad4 prevent setting incorrect frameGeometry to windows that went from Karousel-tiled to Kwin-quick-tiled 2023-09-02 10:54:47 +02:00
Peter Fajdiga
681ae38d85 ClientState.Manager.setState: construct the new state after destroying the old one 2023-09-02 10:45:02 +02:00
Peter Fajdiga
9912a8d917 ClientState: split into files 2023-09-02 10:24:07 +02:00
Peter Fajdiga
1bcf768588 unset kwinClient.tile on maximize 2023-09-02 09:42:53 +02:00
Peter Fajdiga
c84fddc618 Tiled: guess maximized or full screen based on frameGeometry 2023-09-02 09:42:52 +02:00
Peter Fajdiga
ad62dafdc7 kwin.d.ts: move desktop property to TopLevel to reflect documentation 2023-09-02 09:14:45 +02:00
Peter Fajdiga
425c5c9e5b remove rectEqual 2023-09-02 09:07:28 +02:00
Peter Fajdiga
4b0f259c6d Window.onFrameGeometryChanged: remove parameter oldGeometry 2023-09-02 09:01:08 +02:00
Peter Fajdiga
a5ecc94479 prepend "Karousel:" to logs 2023-09-01 21:17:11 +02:00
Peter Fajdiga
a3f479e2e6 World: rename desktopManager 2023-09-01 17:24:42 +02:00
Peter Fajdiga
daef95731b add semicolons after type aliases 2023-09-01 17:24:42 +02:00
Peter Fajdiga
3b3bb679de qt.d.ts: define QmlObject as unknown 2023-09-01 17:24:42 +02:00
Peter Fajdiga
566c8fe53d kwin.d.ts: mark readonly properties 2023-09-01 17:24:42 +02:00
Peter Fajdiga
07ce7d4e60 Tiled: rename client 2023-09-01 14:18:40 +02:00
Peter Fajdiga
0dfc29b1eb define enum ClientAreaOption 2023-09-01 14:03:52 +02:00
Peter Fajdiga
4d784c5d01 keyBindings: allow up to 12 numerical key bindings, regardless of defaults 2023-08-30 21:59:44 +02:00
Peter Fajdiga
a4d27a2885 keyBindings: add comments regarding clashes with default KDE shortcuts 2023-08-30 21:46:48 +02:00
Peter Fajdiga
f703f0655a rename directory "clientState" 2023-08-30 21:21:14 +02:00
Peter Fajdiga
963949b039 clientstate.Manager: redefine State type 2023-08-30 21:20:17 +02:00
Peter Fajdiga
22ee707207 Desktop: correctly set clientArea (fixes bug from 0e59f382) 2023-08-30 20:58:00 +02:00
Peter Fajdiga
8d6e4f9bc7 add type parameters to QSignal 2023-08-29 23:39:53 +02:00
Peter Fajdiga
075f6c7e3d qt.d.ts: define void return type for QSignal methods 2023-08-29 23:16:41 +02:00
Peter Fajdiga
5404b61d20 kwin.d.ts: remove X11Client 2023-08-29 22:29:06 +02:00
Peter Fajdiga
76b0016055 create workaround for issue #9 2023-08-29 22:27:36 +02:00
Peter Fajdiga
64cdb90f4a define kwin client types 2023-08-29 22:19:16 +02:00
Peter Fajdiga
80ecc7e6c9 define kwin types 2023-08-29 22:19:16 +02:00
Peter Fajdiga
0e59f382b4 Desktop: refactor clientArea and tilingArea 2023-08-29 22:19:16 +02:00
Peter Fajdiga
6001dd5b02 define qt types 2023-08-29 22:19:16 +02:00
Peter Fajdiga
201dd4463e ClientMatcher: remove String cast 2023-08-29 22:19:16 +02:00
Peter Fajdiga
10718bc2c7 use type instead of interface 2023-08-29 21:03:32 +02:00
Peter Fajdiga
b15bb85037 split up extern.d.ts into multiple files 2023-08-29 21:03:19 +02:00
Peter Fajdiga
4904d075ae show a notification if window rules JSON invalid 2023-08-28 23:53:11 +02:00
Peter Fajdiga
7871bbbe6d capitalize "Window Rules" tab title in config dialog 2023-08-28 23:49:04 +02:00
Peter Fajdiga
d91ea7b412 ClientWrapper: handle Kwin's quick tiles 2023-08-27 09:40:13 +02:00
Peter Fajdiga
37e9b85279 Tiled: untile when tiling using Kwin's tiling system 2023-08-25 17:15:12 +02:00
Peter Fajdiga
0bdb4af0e6 create ClientState namespace 2023-08-25 15:27:16 +02:00
Peter Fajdiga
4f06f17ba7 remove re-maximize and re-fullscreen functionality 2023-08-25 14:22:31 +02:00
Peter Fajdiga
382cbe101b Window: unset fullscreen before unmaximizing 2023-08-25 13:58:43 +02:00
Peter Fajdiga
e580acf979 update column widths after screen size change 2023-08-25 12:46:01 +02:00
Peter Fajdiga
453c4ece2c Grid: rename field desktop 2023-08-25 11:58:27 +02:00
Peter Fajdiga
15b77d0207 re-arrange after window move 2023-08-25 11:02:08 +02:00
Peter Fajdiga
d23c13c344 Desktop: fix unnecessary overscroll removing right margin on window close 2023-08-25 11:01:30 +02:00
Peter Fajdiga
c4307e187f use namespaces instead of modules 2023-08-25 11:01:30 +02:00
Peter Fajdiga
463da59197 add krunner to default window rules 2023-08-25 11:01:30 +02:00
Peter Fajdiga
c5ec40e5ea World.update: make private 2023-08-25 11:01:30 +02:00
Peter Fajdiga
2f4268fc94 mark remaining methods and fields explicitly public or private 2023-08-25 11:01:30 +02:00
Peter Fajdiga
f1911b1247 Desktop: rename ScrollPos 2023-08-25 11:01:30 +02:00
Peter Fajdiga
5b71f1c48f DesktopManager: rename methods 2023-08-25 11:01:30 +02:00
Peter Fajdiga
c7e7b91f3f rename ScrollView to Desktop 2023-08-25 11:01:30 +02:00
Peter Fajdiga
4b3a403559 rename desktopNumber and virtualDesktop 2023-08-25 11:01:30 +02:00
Peter Fajdiga
9477b7e337 refactor arrange 2023-08-25 11:01:30 +02:00
Peter Fajdiga
c87ef982ae ClientWrapper: prevent moving transient windows on other desktops 2023-08-25 11:01:30 +02:00
Peter Fajdiga
de3e78424a ScrollView: ScrollPos -> ScrollView.Pos 2023-08-25 11:01:30 +02:00
Peter Fajdiga
3039033ea9 World.getFocusedWindow: add ability to follow transientFor 2023-08-25 11:01:30 +02:00
Peter Fajdiga
de0f89062a World.doIfTiled: extract helper method findTiledWindow 2023-08-25 11:01:30 +02:00
Peter Fajdiga
0831c1be8b LinkedList: LinkedListNode -> LinkedList.Node 2023-08-25 11:01:30 +02:00
Peter Fajdiga
d6bfe2fd03 mark methods explicitly public or private 2023-08-25 11:01:30 +02:00
Peter Fajdiga
048bf2a51a Grid.moveColumnLeft: call ScrollView.onGridReordered 2023-08-25 11:01:30 +02:00
Peter Fajdiga
a949dca458 readme: update key bindings 2023-08-16 21:40:27 +02:00
50 changed files with 1821 additions and 1102 deletions

View File

@@ -1,6 +1,6 @@
.PHONY: *
TSC_SCRIPT_FLAGS = --lib es2020 ./src/extern.d.ts
TSC_SCRIPT_FLAGS = --lib es2020 ./src/extern/qt.d.ts
config:
mkdir -p ./package/contents/config

View File

@@ -28,9 +28,9 @@ Here's the default ones:
| --- | --- |
| Meta+Space | Toggle floating |
| Meta+A | Move focus left |
| Meta+D | Move focus right |
| Meta+W | Move focus up |
| Meta+S | Move focus down |
| 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) |
| 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) |
@@ -49,9 +49,11 @@ Here's the default ones:
| 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 |
| Meta+Alt+PgUp | Scroll left |
| Meta+Alt+PgDown | Scroll right |
| Meta+Alt+Home | Scroll to start |
| Meta+Alt+End | Scroll to end |
| Meta+[N] | Move focus to column N |
| 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+!) |
| Meta+Ctrl+Shift+F[N] | Move column to desktop N |

View File

@@ -1,4 +1,4 @@
interface KeyBinding {
type KeyBinding = {
name: string;
description: string;
comment?: string;
@@ -6,7 +6,7 @@ interface KeyBinding {
action: string;
}
interface NumKeyBinding {
type NumKeyBinding = {
name: string;
description: string;
comment?: string;

View File

@@ -1,5 +1,6 @@
import QtQuick 2.15
import org.kde.kwin 3.0
import org.kde.notification 1.0
import "./main.js" as Karousel
Item {
@@ -9,11 +10,19 @@ Item {
Component.onCompleted: {
qmlBase.karouselInstance = Karousel.init();
print("script started");
}
Component.onDestruction: {
qmlBase.karouselInstance.destroy();
print("script stopped");
}
Notification {
id: notificationInvalidWindowRules
componentName: "plasma_workspace"
eventId: "notification"
title: "Karousel"
text: "Your Window Rules JSON is malformed, please review your Karousel configuration"
flags: Notification.Persistent
urgency: Notification.HighUrgency
}
}

View File

@@ -15,15 +15,13 @@
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QGridLayout" name="layout_tab_general" columnstretch="0,1">
<layout class="QFormLayout" name="layout_tab_general">
<item row="0" column="0">
<widget class="QLabel" name="label_gapsOuterTop">
<property name="text">
<string>Top margin:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
@@ -45,9 +43,6 @@
<property name="text">
<string>Bottom margin:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
@@ -69,9 +64,6 @@
<property name="text">
<string>Left margin:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
@@ -93,9 +85,6 @@
<property name="text">
<string>Right margin:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
@@ -117,9 +106,6 @@
<property name="text">
<string>Horizontal gaps between windows:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
@@ -141,9 +127,6 @@
<property name="text">
<string>Vertical gaps between windows:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="1">
@@ -165,9 +148,6 @@
<property name="text">
<string>Overscroll amount:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="1">
@@ -189,9 +169,6 @@
<property name="text">
<string>Manual scroll step size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="7" column="1">
@@ -209,41 +186,109 @@
</item>
<item row="8" column="1">
<spacer name="separator_behavior">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_behavior">
<property name="text">
<string>Behavior:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="kcfg_untileOnDrag">
<property name="text">
<string>Un-tile windows by dragging them</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="10" column="1">
<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</string>
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<widget class="QCheckBox" name="kcfg_resizeNeighborColumn">
<property name="text">
<string>Resize neighbor column on edge resize</string>
</property>
<property name="toolTip">
<string>When resizing a column by dragging its edge, also inversely resize the column on the other side of the edge</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QCheckBox" name="kcfg_reMaximize">
<property name="text">
<string>Re-maximize tiled windows</string>
</property>
<property name="toolTip">
<string>Restore maximized and full-screen states of tiled windows on focus</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<spacer name="bottomSpacer_tab_general">
<item row="13" column="1">
<spacer name="separator_layering">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
<item row="14" column="0">
<widget class="QLabel" name="label_layering">
<property name="text">
<string>Layering mode:</string>
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QRadioButton" name="kcfg_tiledKeepBelow">
<property name="text">
<string>Keep tiled windows below</string>
</property>
</widget>
</item>
<item row="15" column="1">
<widget class="QRadioButton" name="kcfg_floatingKeepAbove">
<property name="text">
<string>Keep floating windows above</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_windowRules">
<attribute name="title">
<string>Window rules</string>
<string>Window Rules</string>
</attribute>
<layout class="QVBoxLayout" name="layout_tab_windowRules">
<item>

View File

@@ -9,7 +9,7 @@
}],
"Id": "karousel",
"ServiceTypes": ["KWin/Script"],
"Version": "0.3.1",
"Version": "0.5",
"License": "GPLv3",
"Website": "https://github.com/peterfajdiga/karousel",
"BugReportUrl": "https://github.com/peterfajdiga/karousel/issues"

View File

@@ -1,8 +1,8 @@
module Actions {
namespace Actions {
export function init(world: World, config: Config) {
return {
focusLeft: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const prevColumn = grid.getPrevColumn(column);
if (prevColumn === null) {
return;
@@ -12,7 +12,7 @@ module Actions {
},
focusRight: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const nextColumn = grid.getNextColumn(column);
if (nextColumn === null) {
return;
@@ -22,7 +22,7 @@ module Actions {
},
focusUp: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const prevWindow = column.getPrevWindow(window);
if (prevWindow === null) {
return;
@@ -32,7 +32,7 @@ module Actions {
},
focusDown: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const nextWindow = column.getNextWindow(window);
if (nextWindow === null) {
return;
@@ -42,27 +42,29 @@ module Actions {
},
focusStart: () => {
const grid = world.getCurrentGrid();
const firstColumn = grid.getFirstColumn();
if (firstColumn === null) {
return;
}
firstColumn.focus();
grid.container.arrange();
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const firstColumn = grid.getFirstColumn();
if (firstColumn === null) {
return;
}
firstColumn.focus();
});
},
focusEnd: () => {
const grid = world.getCurrentGrid();
const lastColumn = grid.getLastColumn();
if (lastColumn === null) {
return;
}
lastColumn.focus();
grid.container.arrange();
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const lastColumn = grid.getLastColumn();
if (lastColumn === null) {
return;
}
lastColumn.focus();
});
},
windowMoveLeft: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
if (column.getWindowCount() === 1) {
// move from own column into existing column
const prevColumn = grid.getPrevColumn(column);
@@ -70,18 +72,17 @@ module Actions {
return;
}
window.moveToColumn(prevColumn);
grid.container.onGridReordered();
grid.desktop.autoAdjustScroll();
} else {
// move from shared column into own column
const newColumn = new Column(grid, grid.getPrevColumn(column));
window.moveToColumn(newColumn);
}
grid.container.arrange();
});
},
windowMoveRight: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
if (column.getWindowCount() === 1) {
// move from own column into existing column
const nextColumn = grid.getNextColumn(column);
@@ -89,97 +90,89 @@ module Actions {
return;
}
window.moveToColumn(nextColumn);
grid.container.onGridReordered();
grid.desktop.autoAdjustScroll();
} else {
// move from shared column into own column
const newColumn = new Column(grid, column);
window.moveToColumn(newColumn);
}
grid.container.arrange();
});
},
windowMoveUp: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
// TODO (optimization): only arrange moved windows
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
column.moveWindowUp(window);
grid.container.arrange(); // TODO (optimization): only arrange moved windows
});
},
windowMoveDown: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
// TODO (optimization): only arrange moved windows
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
column.moveWindowDown(window);
grid.container.arrange(); // TODO (optimization): only arrange moved windows
});
},
windowMoveStart: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const newColumn = new Column(grid, null);
window.moveToColumn(newColumn);
grid.container.arrange();
});
},
windowMoveEnd: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const newColumn = new Column(grid, grid.getLastColumn());
window.moveToColumn(newColumn);
grid.container.arrange();
});
},
windowToggleFloating: () => {
const kwinClient = workspace.activeClient;
world.toggleFloatingClient(kwinClient);
world.do((clientManager, desktopManager) => {
clientManager.toggleFloatingClient(kwinClient);
});
},
columnMoveLeft: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
grid.moveColumnLeft(column);
grid.container.arrange();
});
},
columnMoveRight: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
grid.moveColumnRight(column);
grid.container.arrange();
});
},
columnMoveStart: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
column.moveAfter(null);
grid.container.arrange();
});
},
columnMoveEnd: () => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
column.moveAfter(grid.getLastColumn());
grid.container.arrange();
});
},
columnToggleStacked: () => {
world.doIfTiledFocused(false, (window, column, grid) => {
world.doIfTiledFocused(false, (world, desktopManager, window, column, grid) => {
column.toggleStacked();
grid.container.arrange();
});
},
columnWidthIncrease: () => {
world.doIfTiledFocused(false, (window, column, grid) => {
world.doIfTiledFocused(false, (world, desktopManager, window, column, grid) => {
grid.increaseColumnWidth(column);
grid.container.arrange();
});
},
columnWidthDecrease: () => {
world.doIfTiledFocused(false, (window, column, grid) => {
world.doIfTiledFocused(false, (world, desktopManager, window, column, grid) => {
grid.decreaseColumnWidth(column);
grid.container.arrange();
});
},
@@ -192,66 +185,65 @@ module Actions {
},
gridScrollStart: () => {
const grid = world.getCurrentGrid();
const firstColumn = grid.getFirstColumn();
if (firstColumn === null) {
return;
}
grid.container.scrollToColumn(firstColumn);
grid.container.arrange();
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const firstColumn = grid.getFirstColumn();
if (firstColumn === null) {
return;
}
grid.desktop.scrollToColumn(firstColumn);
});
},
gridScrollEnd: () => {
const grid = world.getCurrentGrid();
const lastColumn = grid.getLastColumn();
if (lastColumn === null) {
return;
}
grid.container.scrollToColumn(lastColumn);
grid.container.arrange();
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const lastColumn = grid.getLastColumn();
if (lastColumn === null) {
return;
}
grid.desktop.scrollToColumn(lastColumn);
});
},
gridScrollFocused: () => {
const focusedWindow = world.getFocusedWindow();
if (focusedWindow === null) {
return;
}
const column = focusedWindow.column;
const grid = column.grid;
grid.container.scrollCenterColumn(column);
grid.container.arrange();
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
grid.desktop.scrollCenterColumn(column);
})
},
gridScrollLeftColumn: () => {
const grid = world.getCurrentGrid();
const column = grid.getLeftmostVisibleColumn(grid.container.getCurrentScrollPos(), true);
if (column === null) {
return;
}
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentScrollPos(), true);
if (column === null) {
return;
}
const prevColumn = grid.getPrevColumn(column);
if (prevColumn === null) {
return;
}
const prevColumn = grid.getPrevColumn(column);
if (prevColumn === null) {
return;
}
grid.container.scrollToColumn(prevColumn);
grid.container.arrange();
grid.desktop.scrollToColumn(prevColumn);
});
},
gridScrollRightColumn: () => {
const grid = world.getCurrentGrid();
const column = grid.getRightmostVisibleColumn(grid.container.getCurrentScrollPos(), true);
if (column === null) {
return;
}
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentScrollPos(), true);
if (column === null) {
return;
}
const nextColumn = grid.getNextColumn(column);
if (nextColumn === null) {
return;
}
const nextColumn = grid.getNextColumn(column);
if (nextColumn === null) {
return;
}
grid.container.scrollToColumn(nextColumn);
grid.container.arrange();
grid.desktop.scrollToColumn(nextColumn);
});
},
};
}
@@ -259,28 +251,29 @@ module Actions {
export function initNum(world: World) {
return {
focusColumn: (columnIndex: number) => {
const grid = world.getCurrentGrid();
const targetColumn = grid.getColumnAtIndex(columnIndex);
if (targetColumn === null) {
return null;
}
targetColumn.focus();
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
const targetColumn = grid.getColumnAtIndex(columnIndex);
if (targetColumn === null) {
return null;
}
targetColumn.focus();
});
},
windowMoveToColumn: (columnIndex: number) => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const targetColumn = grid.getColumnAtIndex(columnIndex);
if (targetColumn === null) {
return null;
}
window.moveToColumn(targetColumn);
grid.container.onGridReordered();
grid.container.arrange();
grid.desktop.autoAdjustScroll();
});
},
columnMoveToColumn: (columnIndex: number) => {
world.doIfTiledFocused(true, (window, column, grid) => {
world.doIfTiledFocused(true, (world, desktopManager, window, column, grid) => {
const targetColumn = grid.getColumnAtIndex(columnIndex);
if (targetColumn === null || targetColumn === column) {
return null;
@@ -290,46 +283,41 @@ module Actions {
} else {
column.moveAfter(grid.getPrevColumn(targetColumn));
}
grid.container.arrange();
});
},
columnMoveToDesktop: (desktopIndex: number) => {
world.doIfTiledFocused(true, (window, column, oldGrid) => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
const desktopNumber = desktopIndex + 1;
const newGrid = world.getGridInCurrentActivity(desktopNumber);
const newGrid = desktopManager.getDesktopInCurrentActivity(desktopNumber).grid;
if (newGrid === null || newGrid === oldGrid) {
return;
}
column.moveToGrid(newGrid, newGrid.getLastColumn());
oldGrid.container.arrange();
newGrid.container.arrange();
});
},
tailMoveToDesktop: (desktopIndex: number) => {
world.doIfTiledFocused(true, (window, column, oldGrid) => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
const desktopNumber = desktopIndex + 1;
const newGrid = world.getGridInCurrentActivity(desktopNumber);
const newGrid = desktopManager.getDesktopInCurrentActivity(desktopNumber).grid;
if (newGrid === null || newGrid === oldGrid) {
return;
}
oldGrid.evacuateTail(newGrid, column);
oldGrid.container.arrange();
newGrid.container.arrange();
});
},
};
}
function gridScroll(world: World, amount: number) {
const scrollAmount = amount;
const grid = world.getCurrentGrid();
grid.container.adjustScroll(scrollAmount, false);
grid.container.arrange();
world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid;
grid.desktop.adjustScroll(amount, false);
});
}
export type Config = {
manualScrollStep: number,
}
};
}

10
src/ClientAreaOption.ts Normal file
View File

@@ -0,0 +1,10 @@
enum ClientAreaOption {
PlacementArea,
MovementArea,
MaximizeArea,
MaximizeFullArea,
FullScreenArea,
WorkArea,
FullArea,
ScreenArea,
}

View File

@@ -10,5 +10,8 @@ type Config = {
untileOnDrag: boolean,
stackColumnsByDefault: boolean,
resizeNeighborColumn: boolean,
reMaximize: boolean,
tiledKeepBelow: boolean,
floatingKeepAbove: boolean,
windowRules: string,
}
};

View File

@@ -15,6 +15,10 @@ const defaultWindowRules = `[
"class": "kruler",
"tile": false
},
{
"class": "krunner",
"tile": false
},
{
"class": "zoom",
"caption": "Zoom Cloud Meetings",
@@ -81,7 +85,7 @@ const configDef = [
{
"name": "overscroll",
"type": "UInt",
"default": 18
"default": 0
},
{
"name": "manualScrollStep",
@@ -103,6 +107,21 @@ const configDef = [
"type": "Bool",
"default": false
},
{
"name": "reMaximize",
"type": "Bool",
"default": false
},
{
"name": "tiledKeepBelow",
"type": "Bool",
"default": true
},
{
"name": "floatingKeepAbove",
"type": "Bool",
"default": false
},
{
"name": "windowRules",
"type": "String",

View File

@@ -1,4 +1,4 @@
function loadConfig() {
function loadConfig(): Config {
const config: any = {};
for (const entry of configDef) {
config[entry.name] = KWin.readConfig(entry.name, entry.default);

13
src/extern.d.ts vendored
View File

@@ -1,13 +0,0 @@
declare const qmlBase;
declare const console;
declare const KWin;
declare const Qt;
declare const workspace;
declare const options;
type AbstractClient = any;
type TopLevel = any;
type X11Client = any;
type QRect = any;
type QSignal = any;
type QQmlTimer = any;

6
src/extern/global.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
declare const qmlBase: QmlObject;
declare const notificationInvalidWindowRules: Notification;
type Notification = {
sendEvent(): void;
};

75
src/extern/kwin.d.ts vendored Normal file
View File

@@ -0,0 +1,75 @@
declare const KWin: {
// Functions
readConfig(key: string, defaultValue: any): any;
registerShortcut(name: string, description: string, keySequence: string, callback: () => void): void;
};
declare const workspace: {
// Read-write Properties
readonly desktops: number;
readonly currentDesktop: number;
readonly currentActivity: string;
// Read-write Properties
activeClient: KwinClient;
// Signals
currentDesktopChanged: QSignal<[oldDesktopNumber: number]>
clientAdded: QSignal<[KwinClient]>;
clientRemoved: QSignal<[KwinClient]>;
clientMinimized: QSignal<[KwinClient]>;
clientUnminimized: QSignal<[KwinClient]>;
clientMaximizeSet: QSignal<[KwinClient, horizontally: boolean, vertically: boolean]>;
clientActivated: QSignal<[KwinClient]>;
numberDesktopsChanged: QSignal<[oldNumberOfVirtualDesktops: number]>;
currentActivityChanged: QSignal<[newActivity: string]>;
virtualScreenSizeChanged: QSignal<[void]>;
// Functions
clientArea(option: ClientAreaOption, screenNumber: number, desktopNumber: number);
clientList(): KwinClient[];
};
type Tile = any;
interface KwinClient {
// Read-only Properties
readonly shadeable: boolean;
readonly caption: string;
readonly minSize: QSize;
readonly transient: boolean;
readonly transientFor: KwinClient;
readonly move: boolean;
readonly resize: boolean;
readonly resizeable: boolean;
readonly screen: number;
readonly resourceClass: QByteArray;
readonly dock: boolean;
readonly normalWindow: boolean;
readonly managed: boolean;
// Read-write Properties
fullScreen: boolean;
activities: string[]; // empty array means all activities
keepAbove: boolean;
keepBelow: boolean;
shade: boolean;
minimized: boolean;
frameGeometry: QRect;
desktop: number; // -1 means all desktops
tile: Tile;
// Signals
fullScreenChanged: QSignal<[void]>;
desktopChanged: QSignal<[void]>;
activitiesChanged: QSignal<[KwinClient]>;
captionChanged: QSignal<[void]>;
tileChanged: QSignal<[Tile]>;
moveResizedChanged: QSignal<[void]>;
moveResizeCursorChanged: QSignal<[void]>;
clientStartUserMovedResized: QSignal<[void]>;
frameGeometryChanged: QSignal<[KwinClient, oldGeometry: QRect]>;
// Functions
setMaximize(vertically: boolean, horizontally: boolean): void;
}

41
src/extern/qt.d.ts vendored Normal file
View File

@@ -0,0 +1,41 @@
declare const console: {
log(...args: any[]);
assert(boolean);
};
declare const Qt: {
rect(x: number, y: number, width: number, height: number): QRect;
createQmlObject(qml: string, parent: QmlObject);
};
type QmlObject = unknown;
type QByteArray = string;
type QRect = {
x: number;
y: number;
width: number;
height: number;
top: number;
bottom: number;
left: number;
right: number;
};
type QSize = {
width: number;
height: number;
};
type QSignal<T extends unknown[]> = {
connect(handler: (...args: [...T]) => void): void;
disconnect(handler: (...args: [...T]) => void): void;
};
type QQmlTimer = {
interval: number;
triggered: QSignal<[void]>;
restart(): void;
destroy(): void;
};

View File

@@ -14,18 +14,21 @@ const keyBindings: KeyBinding[] = [
{
"name": "focus-right",
"description": "Move focus right",
"comment": "Clashes with default KDE shortcuts, may require manual remapping",
"defaultKeySequence": "Meta+D",
"action": "focusRight",
},
{
"name": "focus-up",
"description": "Move focus up",
"comment": "Clashes with default KDE shortcuts, may require manual remapping",
"defaultKeySequence": "Meta+W",
"action": "focusUp",
},
{
"name": "focus-down",
"description": "Move focus down",
"comment": "Clashes with default KDE shortcuts, may require manual remapping",
"defaultKeySequence": "Meta+S",
"action": "focusDown",
},
@@ -170,6 +173,7 @@ const numKeyBindings: NumKeyBinding[] = [
{
"name": "focus-",
"description": "Move focus to column ",
"comment": "Clashes with default KDE shortcuts, may require manual remapping",
"defaultModifiers": "Meta",
"fKeys": false,
"action": "focusColumn",

View File

@@ -1,27 +1,27 @@
interface KeyBinding {
type KeyBinding = {
name: string;
description: string;
comment?: string;
defaultKeySequence: string;
action: keyof ReturnType<typeof Actions.init>;
}
};
interface NumKeyBinding {
type NumKeyBinding = {
name: string;
description: string;
comment?: string;
defaultModifiers: string;
fKeys: boolean;
action: keyof ReturnType<typeof Actions.initNum>;
}
};
function catchWrap(f: () => void) {
return () => {
try {
f();
} catch (error: any) {
console.log(error);
console.log(error.stack);
log(error);
log(error.stack);
}
};
}
@@ -38,12 +38,15 @@ function registerKeyBinding(name: string, description: string, keySequence: stri
function registerNumKeyBindings(name: string, description: string, modifiers: string, fKeys: boolean, callback: (i: number) => void) {
const numPrefix = fKeys ? "F" : "";
const n = fKeys ? 12 : 9;
for (let i = 0; i < n; i++) {
for (let i = 0; i < 12; i++) {
const numKey = String(i + 1);
const keySequence = i < n ?
modifiers + "+" + numPrefix + numKey :
"";
registerKeyBinding(
name + numKey,
description + numKey,
modifiers + "+" + numPrefix + numKey,
keySequence,
() => callback(i),
);
}

View File

@@ -17,7 +17,7 @@ class Column {
this.grid.onColumnAdded(this, prevColumn);
}
moveToGrid(targetGrid: Grid, prevColumn: Column|null) {
public moveToGrid(targetGrid: Grid, prevColumn: Column|null) {
if (targetGrid === this.grid) {
this.grid.onColumnMoved(this, prevColumn);
} else {
@@ -25,55 +25,57 @@ class Column {
this.grid = targetGrid;
targetGrid.onColumnAdded(this, prevColumn);
for (const window of this.windows.iterator()) {
window.client.kwinClient.desktop = targetGrid.container.desktop;
window.client.kwinClient.desktop = targetGrid.desktop.desktopNumber;
}
}
}
moveAfter(prevColumn: Column|null) {
public moveAfter(prevColumn: Column|null) {
if (prevColumn === this) {
return;
}
this.grid.onColumnMoved(this, prevColumn);
}
isAfter(other: Column) {
public isAfter(other: Column) {
return this.gridX > other.gridX;
}
isBefore(other: Column) {
public isBefore(other: Column) {
return this.gridX < other.gridX;
}
moveWindowUp(window: Window) {
public moveWindowUp(window: Window) {
this.windows.moveBack(window);
this.grid.desktop.onLayoutChanged();
}
moveWindowDown(window: Window) {
public moveWindowDown(window: Window) {
this.windows.moveForward(window);
this.grid.desktop.onLayoutChanged();
}
getWindowCount() {
public getWindowCount() {
return this.windows.length();
}
isEmpty() {
public isEmpty() {
return this.getWindowCount() === 0;
}
getPrevWindow(window: Window) {
public getPrevWindow(window: Window) {
return this.windows.getPrev(window);
}
getNextWindow(window: Window) {
public getNextWindow(window: Window) {
return this.windows.getNext(window);
}
getWidth() {
public getWidth() {
return this.width;
}
getMinWidth() {
public getMinWidth() {
let maxMinWidth = Column.minWidth;
for (const window of this.windows.iterator()) {
const minWidth = window.client.kwinClient.minSize.width;
@@ -84,11 +86,11 @@ class Column {
return maxMinWidth;
}
getMaxWidth() {
return this.grid.container.tilingArea.width;
public getMaxWidth() {
return this.grid.desktop.tilingArea.width;
}
setWidth(width: number, setPreferred: boolean) {
public setWidth(width: number, setPreferred: boolean) {
width = clamp(width, this.getMinWidth(), this.getMaxWidth());
const oldWidth = this.width;
this.width = width;
@@ -102,21 +104,34 @@ class Column {
}
}
adjustWidth(widthDelta: number, setPreferred: boolean) {
public adjustWidth(widthDelta: number, setPreferred: boolean) {
this.setWidth(this.width + widthDelta, setPreferred);
}
public updateWidth() {
let minErr = Infinity;
let closestPreferredWidth = this.width;
for (const window of this.windows.iterator()) {
const err = Math.abs(window.client.preferredWidth - this.width);
if (err < minErr) {
minErr = err;
closestPreferredWidth = window.client.preferredWidth;
}
}
this.setWidth(closestPreferredWidth, false);
}
// returns x position of left edge in grid space
getLeft() {
public getLeft() {
return this.gridX;
}
// returns x position of right edge in grid space
getRight() {
public getRight() {
return this.gridX + this.width;
}
adjustWindowHeight(window: Window, heightDelta: number, top: boolean) {
public adjustWindowHeight(window: Window, heightDelta: number, top: boolean) {
const otherWindow = top ? this.windows.getPrev(window) : this.windows.getNext(window);
if (otherWindow === null) {
return;
@@ -124,9 +139,11 @@ class Column {
window.height += heightDelta;
otherWindow.height -= heightDelta;
this.grid.desktop.onLayoutChanged();
}
resizeWindows() {
public resizeWindows() {
const nWindows = this.windows.length();
if (nWindows === 0) {
return;
@@ -135,7 +152,7 @@ class Column {
this.stacked = this.grid.config.stackColumnsByDefault;
}
let remainingPixels = this.grid.container.tilingArea.height - (nWindows-1) * this.grid.config.gapsInnerVertical;
let remainingPixels = this.grid.desktop.tilingArea.height - (nWindows-1) * this.grid.config.gapsInnerVertical;
let remainingWindows = nWindows;
for (const window of this.windows.iterator()) {
const windowHeight = Math.round(remainingPixels / remainingWindows);
@@ -144,16 +161,18 @@ class Column {
remainingWindows--;
}
// TODO: respect min height
this.grid.desktop.onLayoutChanged();
}
getFocusTaker() {
public getFocusTaker() {
if (this.focusTaker === null || !this.windows.contains(this.focusTaker)) {
return null;
}
return this.focusTaker;
}
focus() {
public focus() {
const window = this.getFocusTaker() ?? this.windows.getFirst();
if (window === null) {
return;
@@ -161,12 +180,12 @@ class Column {
window.focus();
}
arrange(x: number) {
if (this.stacked && this.windows.length() >= 2) {
public arrange(x: number) {
if (this.stacked && this.windows.length() >= 2 && this.canStack()) {
this.arrangeStacked(x);
return;
}
let y = this.grid.container.tilingArea.y;
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);
@@ -174,7 +193,7 @@ class Column {
}
}
arrangeStacked(x: number) {
public arrangeStacked(x: number) {
const expandedWindow = this.getFocusTaker();
let collapsedHeight;
for (const window of this.windows.iterator()) {
@@ -187,28 +206,38 @@ class Column {
}
const nCollapsed = this.getWindowCount() - 1;
const expandedHeight = this.grid.container.tilingArea.height - nCollapsed * (collapsedHeight + this.grid.config.gapsInnerVertical);
let y = this.grid.container.tilingArea.y;
const expandedHeight = this.grid.desktop.tilingArea.height - nCollapsed * (collapsedHeight! + this.grid.config.gapsInnerVertical);
let y = 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 += collapsedHeight!;
}
y += this.grid.config.gapsInnerVertical;
}
}
toggleStacked() {
public toggleStacked() {
if (this.windows.length() < 2) {
return;
}
this.stacked = !this.stacked;
this.grid.desktop.onLayoutChanged();
}
public isVisible(scrollPos: ScrollPos, fullyVisible: boolean) {
private canStack() {
for (const window of this.windows.iterator()) {
if (!window.client.kwinClient.shadeable) {
return false;
}
}
return true;
}
public isVisible(scrollPos: Desktop.ScrollPos, fullyVisible: boolean) {
if (fullyVisible) {
return this.getLeft() >= scrollPos.getLeft() &&
this.getRight() <= scrollPos.getRight();
@@ -218,7 +247,7 @@ class Column {
}
}
onWindowAdded(window: Window) {
public onWindowAdded(window: Window) {
this.windows.insertEnd(window);
if (this.width === 0) {
this.setWidth(window.client.preferredWidth, false);
@@ -230,9 +259,11 @@ class Column {
if (window.isFocused()) {
this.onWindowFocused(window);
}
this.grid.desktop.onLayoutChanged();
}
onWindowRemoved(window: Window, passFocus: boolean) {
public onWindowRemoved(window: Window, passFocus: boolean) {
const lastWindow = this.windows.length() === 1;
const windowToFocus = this.getPrevWindow(window) ?? this.getNextWindow(window);
@@ -251,21 +282,23 @@ class Column {
windowToFocus.focus();
}
}
this.grid.desktop.onLayoutChanged();
}
onWindowFocused(window: Window) {
public onWindowFocused(window: Window) {
this.grid.onColumnFocused(this);
this.focusTaker = window;
}
restoreToTiled() {
public restoreToTiled() {
const lastFocusedWindow = this.getFocusTaker();
if (lastFocusedWindow !== null) {
lastFocusedWindow.restoreToTiled();
}
}
destroy(passFocus: boolean) {
private destroy(passFocus: boolean) {
this.grid.onColumnRemoved(this, passFocus);
}
}

198
src/layout/Desktop.ts Normal file
View File

@@ -0,0 +1,198 @@
class Desktop {
public readonly grid: Grid;
public readonly desktopNumber: number;
private readonly pinManager: PinManager;
private readonly config: Desktop.Config;
private scrollX: number;
private dirty: boolean;
private dirtyPins: boolean;
public clientArea: QRect;
public tilingArea: QRect;
constructor(desktopNumber: number, pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig) {
this.pinManager = pinManager;
this.config = config;
this.scrollX = 0;
this.dirty = true;
this.dirtyPins = true;
this.desktopNumber = desktopNumber;
this.grid = new Grid(this, layoutConfig);
this.clientArea = Desktop.getClientArea(desktopNumber);
this.tilingArea = Desktop.getTilingArea(this.clientArea, desktopNumber, pinManager, config);
}
private updateArea() {
const newClientArea = Desktop.getClientArea(this.desktopNumber);
if (newClientArea === this.clientArea && !this.dirtyPins) {
return;
}
this.clientArea = newClientArea;
this.tilingArea = Desktop.getTilingArea(newClientArea, this.desktopNumber, this.pinManager, this.config);
this.dirty = true;
this.dirtyPins = false;
this.grid.onScreenSizeChanged();
this.autoAdjustScroll();
}
private static getClientArea(desktopNumber: number) {
return workspace.clientArea(ClientAreaOption.PlacementArea, 0, desktopNumber);
}
private static getTilingArea(clientArea: QRect, desktopNumber: number, pinManager: PinManager, config: Desktop.Config) {
const availableSpace = pinManager.getAvailableSpace(desktopNumber, clientArea);
const top = availableSpace.top + config.marginTop;
const bottom = availableSpace.bottom - config.marginBottom;
const left = availableSpace.left + config.marginLeft;
const right = availableSpace.right - config.marginRight;
return Qt.rect(
left,
top,
right - left + 1,
bottom - top + 1,
)
}
// calculates Desktop.Pos that scrolls the column into view
public getScrollPosForColumn(column: Column) {
const left = column.getLeft();
const right = column.getRight();
const initialScrollPos = this.getCurrentScrollPos();
let targetScrollX: number;
if (left < initialScrollPos.getLeft()) {
targetScrollX = left;
} else if (right > initialScrollPos.getRight()) {
targetScrollX = right - this.tilingArea.width;
} else {
return this.getScrollPos(this.clampScrollX(this.scrollX));
}
const overscroll = this.getTargetOverscroll(targetScrollX, left < initialScrollPos.getLeft());
return this.getScrollPos(this.clampScrollX(targetScrollX + overscroll));
}
private getTargetOverscroll(targetScrollX: number, scrollLeft: boolean) {
if (this.config.overscroll === 0) {
return 0;
}
const visibleColumnsWidth = this.grid.getVisibleColumnsWidth(this.getScrollPos(targetScrollX), true);
const remainingSpace = this.tilingArea.width - visibleColumnsWidth;
const overscrollX = Math.min(this.config.overscroll, Math.round(remainingSpace / 2));
const direction = scrollLeft ? -1 : 1;
return overscrollX * direction;
}
public scrollToColumn(column: Column) {
this.setScroll(this.getScrollPosForColumn(column).x, true);
}
public scrollCenterColumn(column: Column) {
const windowCenter = column.getLeft() + column.getWidth() / 2;
const screenCenter = this.scrollX + this.tilingArea.width / 2;
this.adjustScroll(Math.round(windowCenter - screenCenter), false);
}
public autoAdjustScroll() {
const focusedColumn = this.grid.getLastFocusedColumn();
if (focusedColumn === null) {
this.removeOverscroll();
return;
}
if (focusedColumn.grid !== this.grid) {
return;
}
this.scrollToColumn(focusedColumn);
}
private getScrollPos(scrollX: number) {
return new Desktop.ScrollPos(scrollX, this.tilingArea.width);
}
public getCurrentScrollPos() {
return this.getScrollPos(this.scrollX);
}
private clampScrollX(x: number) {
let minScroll = 0;
let maxScroll = this.grid.getWidth() - this.tilingArea.width;
if (maxScroll < 0) {
const centerScroll = Math.round(maxScroll / 2);
minScroll = centerScroll;
maxScroll = centerScroll;
}
return clamp(x, minScroll, maxScroll);
}
private setScroll(x: number, force: boolean) {
const oldScrollX = this.scrollX;
this.scrollX = force ? x : this.clampScrollX(x);
if (this.scrollX !== oldScrollX) {
this.onLayoutChanged();
}
}
private applyScrollPos(scrollPos: Desktop.ScrollPos) {
this.setScroll(scrollPos.x, true);
}
public adjustScroll(dx: number, force: boolean) {
this.setScroll(this.scrollX + dx, force);
}
private removeOverscroll() {
this.setScroll(this.scrollX, false);
}
public arrange() {
// TODO (optimization): only arrange visible windows
this.updateArea();
if (!this.dirty) {
return;
}
this.grid.arrange(this.tilingArea.x - this.scrollX);
this.dirty = false;
}
public onLayoutChanged() {
this.dirty = true;
}
public onPinsChanged() {
this.dirty = true;
this.dirtyPins = true;
}
public destroy() {
this.grid.destroy();
}
}
namespace Desktop {
export type Config = {
marginTop: number,
marginBottom: number,
marginLeft: number,
marginRight: number,
overscroll: number,
};
export class ScrollPos {
public readonly x: number;
public 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;
}
}
}

View File

@@ -1,5 +1,5 @@
class Grid {
public readonly container: ScrollView;
public readonly desktop: Desktop;
public readonly config: LayoutConfig;
private readonly columns: LinkedList<Column>;
private lastFocusedColumn: Column|null;
@@ -7,8 +7,8 @@ class Grid {
private userResize: boolean; // is any part of the grid being resized by the user
private readonly userResizeFinishedDelayer: Delayer;
constructor(container: ScrollView, config: LayoutConfig) {
this.container = container;
constructor(desktop: Desktop, config: LayoutConfig) {
this.desktop = desktop;
this.config = config;
this.columns = new LinkedList();
this.lastFocusedColumn = null;
@@ -16,18 +16,20 @@ class Grid {
this.userResize = false;
this.userResizeFinishedDelayer = new Delayer(50, () => {
// this delay prevents windows' contents from freezing after resizing
this.container.onGridWidthChanged();
this.container.arrange();
this.desktop.onLayoutChanged();
this.desktop.autoAdjustScroll();
this.desktop.arrange();
});
}
moveColumnLeft(column: Column) {
public moveColumnLeft(column: Column) {
this.columns.moveBack(column);
this.columnsSetX(column);
this.container.onGridWidthChanged();
this.desktop.onLayoutChanged();
this.desktop.autoAdjustScroll();
}
moveColumnRight(column: Column) {
public moveColumnRight(column: Column) {
const nextColumn = this.columns.getNext(column);
if (nextColumn === null) {
return;
@@ -35,37 +37,45 @@ class Grid {
this.moveColumnLeft(nextColumn);
}
getWidth() {
public getWidth() {
return this.width;
}
getPrevColumn(column: Column) {
public getPrevColumn(column: Column) {
return this.columns.getPrev(column);
}
getNextColumn(column: Column) {
public getNextColumn(column: Column) {
return this.columns.getNext(column);
}
getFirstColumn() {
public getFirstColumn() {
return this.columns.getFirst();
}
getLastColumn() {
public getLastColumn() {
return this.columns.getLast();
}
getColumnAtIndex(i: number) {
public getColumnAtIndex(i: number) {
return this.columns.getItemAtIndex(i);
}
getLastFocusedColumn() {
public getLastFocusedColumn() {
if (this.lastFocusedColumn === null || this.lastFocusedColumn.grid !== this) {
return null;
}
return this.lastFocusedColumn;
}
public getLastFocusedWindow() {
const lastFocusedColumn = this.getLastFocusedColumn();
if (lastFocusedColumn === null) {
return null;
}
return lastFocusedColumn.getFocusTaker();
}
private columnsSetX(firstMovedColumn: Column|null) {
const lastUnmovedColumn = firstMovedColumn === null ? this.columns.getLast() : this.columns.getPrev(firstMovedColumn);
let x = lastUnmovedColumn === null ? 0 : lastUnmovedColumn.getRight() + this.config.gapsInnerHorizontal;
@@ -78,7 +88,7 @@ class Grid {
this.width = x - this.config.gapsInnerHorizontal;
}
getLeftmostVisibleColumn(scrollPos: ScrollPos, fullyVisible: boolean) {
public getLeftmostVisibleColumn(scrollPos: Desktop.ScrollPos, fullyVisible: boolean) {
const scrollX = scrollPos.getLeft();
for (const column of this.columns.iterator()) {
const x = fullyVisible ? column.getLeft() : column.getRight() + (this.config.gapsInnerHorizontal - 1);
@@ -89,7 +99,7 @@ class Grid {
return null;
}
getRightmostVisibleColumn(scrollPos: ScrollPos, fullyVisible: boolean) {
public getRightmostVisibleColumn(scrollPos: Desktop.ScrollPos, fullyVisible: boolean) {
const scrollX = scrollPos.getRight();
let last = null;
for (const column of this.columns.iterator()) {
@@ -103,7 +113,7 @@ class Grid {
return last;
}
getVisibleColumnsWidth(scrollPos: ScrollPos, fullyVisible: boolean) {
public getVisibleColumnsWidth(scrollPos: Desktop.ScrollPos, fullyVisible: boolean) {
let width = 0;
let nVisible = 0;
for (const column of this.columns.iterator()) {
@@ -120,7 +130,7 @@ class Grid {
return width;
}
getLeftOffScreenColumn(scrollPos: ScrollPos) {
private getLeftOffScreenColumn(scrollPos: Desktop.ScrollPos) {
const leftVisible = this.getLeftmostVisibleColumn(scrollPos, true);
if (leftVisible === null) {
return null;
@@ -128,7 +138,7 @@ class Grid {
return this.getPrevColumn(leftVisible);
}
getRightOffScreenColumn(scrollPos: ScrollPos) {
private getRightOffScreenColumn(scrollPos: Desktop.ScrollPos) {
const rightVisible = this.getRightmostVisibleColumn(scrollPos, true);
if (rightVisible === null) {
return null;
@@ -136,10 +146,10 @@ class Grid {
return this.getNextColumn(rightVisible);
}
increaseColumnWidth(column: Column) {
const scrollPos = this.container.getScrollPosForColumn(column);
public increaseColumnWidth(column: Column) {
const scrollPos = this.desktop.getScrollPosForColumn(column);
if (this.width < scrollPos.width) {
column.adjustWidth(scrollPos.width - this.width, false);
column.adjustWidth(scrollPos.width - this.width, true);
return;
}
@@ -160,15 +170,15 @@ class Grid {
const expandLeft = leftVisibleWidth < rightVisibleWidth;
const widthDelta = (expandLeft ? leftVisibleWidth : rightVisibleWidth) + this.config.gapsInnerHorizontal;
if (expandLeft) {
this.container.adjustScroll(widthDelta, false);
this.desktop.adjustScroll(widthDelta, false);
}
column.adjustWidth(widthDelta, true);
}
decreaseColumnWidth(column: Column) {
const scrollPos = this.container.getScrollPosForColumn(column);
public decreaseColumnWidth(column: Column) {
const scrollPos = this.desktop.getScrollPosForColumn(column);
if (this.width <= scrollPos.width) {
column.setWidth(Math.round(column.getWidth() / 2), false);
column.setWidth(Math.round(column.getWidth() / 2), true);
return;
}
@@ -190,29 +200,35 @@ class Grid {
const widthDelta = (shrinkLeft ? leftInvisibleWidth : rightInvisibleWidth);
if (shrinkLeft) {
const maxDelta = column.getWidth() - column.getMinWidth();
this.container.adjustScroll(-Math.min(widthDelta, maxDelta), false);
this.desktop.adjustScroll(-Math.min(widthDelta, maxDelta), false);
}
column.adjustWidth(-widthDelta, true);
}
arrange(x: number) {
public arrange(x: number) {
for (const column of this.columns.iterator()) {
column.arrange(x);
x += column.getWidth() + this.config.gapsInnerHorizontal;
}
const focusedWindow = this.getLastFocusedWindow();
if (focusedWindow !== null) {
focusedWindow.client.ensureTransientsVisible(this.desktop.clientArea);
}
}
onColumnAdded(column: Column, prevColumn: Column|null) {
public onColumnAdded(column: Column, prevColumn: Column|null) {
if (prevColumn === null) {
this.columns.insertStart(column);
} else {
this.columns.insertAfter(column, prevColumn);
}
this.columnsSetX(column);
this.container.onGridWidthChanged();
this.desktop.onLayoutChanged();
this.desktop.autoAdjustScroll();
}
onColumnRemoved(column: Column, passFocus: boolean) {
public onColumnRemoved(column: Column, passFocus: boolean) {
const isLastColumn = this.columns.length() === 1;
const nextColumn = this.getNextColumn(column);
const columnToFocus = isLastColumn ? null : this.getPrevColumn(column) ?? nextColumn;
@@ -226,63 +242,67 @@ class Grid {
if (passFocus && columnToFocus !== null) {
columnToFocus.focus();
} else {
this.container.onGridWidthChanged();
this.desktop.autoAdjustScroll();
}
this.desktop.onLayoutChanged();
}
onColumnMoved(column: Column, prevColumn: Column|null) {
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.container.onGridReordered();
this.desktop.onLayoutChanged();
this.desktop.autoAdjustScroll();
}
onColumnWidthChanged(column: Column, oldWidth: number, width: number) {
public onColumnWidthChanged(column: Column, oldWidth: number, width: number) {
const nextColumn = this.columns.getNext(column);
this.columnsSetX(nextColumn);
if (!this.userResize) {
this.container.onGridWidthChanged();
this.desktop.autoAdjustScroll();
}
this.desktop.onLayoutChanged();
}
onColumnFocused(column: Column) {
public onColumnFocused(column: Column) {
const lastFocusedColumn = this.getLastFocusedColumn();
if (lastFocusedColumn !== null) {
lastFocusedColumn.restoreToTiled();
}
this.lastFocusedColumn = column;
this.container.scrollToColumn(column);
this.desktop.scrollToColumn(column);
}
onScreenSizeChanged() {
public onScreenSizeChanged() {
for (const column of this.columns.iterator()) {
column.updateWidth();
column.resizeWindows();
}
}
onUserResizeStarted() {
public onUserResizeStarted() {
this.userResize = true;
}
onUserResizeFinished() {
public onUserResizeFinished() {
this.userResize = false;
this.userResizeFinishedDelayer.run();
}
evacuateTail(targetGrid: Grid, startColumn: Column) {
public evacuateTail(targetGrid: Grid, startColumn: Column) {
for (const column of this.columns.iteratorFrom(startColumn)) {
column.moveToGrid(targetGrid, targetGrid.getLastColumn());
}
}
evacuate(targetGrid: Grid) {
public evacuate(targetGrid: Grid) {
for (const column of this.columns.iterator()) {
column.moveToGrid(targetGrid, targetGrid.getLastColumn());
}
}
destroy() {
public destroy() {
this.userResizeFinishedDelayer.destroy();
}
}

View File

@@ -3,4 +3,7 @@ type LayoutConfig = {
gapsInnerVertical: number,
stackColumnsByDefault: boolean,
resizeNeighborColumn: boolean,
}
reMaximize: boolean,
tiledKeepBelow: boolean,
maximizedKeepAbove: boolean,
};

View File

@@ -1,17 +0,0 @@
class ScrollPos {
public readonly x: number;
public 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;
}
}

View File

@@ -1,154 +0,0 @@
class ScrollView {
public readonly world: World;
public readonly grid: Grid;
public readonly desktop: number;
private readonly config: ScrollView.Config;
private scrollX: number;
public clientArea: QRect;
public tilingArea: QRect;
constructor(world: World, desktop: number, config: ScrollView.Config, layoutConfig: LayoutConfig) {
this.config = config;
this.world = world;
this.scrollX = 0;
this.desktop = desktop;
this.grid = new Grid(this, layoutConfig);
this.updateArea();
}
updateArea() {
const newClientArea = workspace.clientArea(workspace.PlacementArea, 0, this.desktop);
if (newClientArea === this.clientArea) {
return;
}
this.clientArea = newClientArea;
this.tilingArea = Qt.rect(
newClientArea.x + this.config.marginLeft,
newClientArea.y + this.config.marginTop,
newClientArea.width - this.config.marginLeft - this.config.marginRight,
newClientArea.height - this.config.marginTop - this.config.marginBottom,
)
this.grid.onScreenSizeChanged();
this.autoAdjustScroll();
}
// calculates ScrollPos that scrolls the column into view
public getScrollPosForColumn(column: Column) {
const left = column.getLeft();
const right = column.getRight();
const initialScrollPos = this.getCurrentScrollPos();
let targetScrollX: number;
if (left < initialScrollPos.getLeft()) {
targetScrollX = this.clampScrollX(left);
} else if (right > initialScrollPos.getRight()) {
targetScrollX = this.clampScrollX(right - this.tilingArea.width);
} else {
return this.getScrollPos(this.clampScrollX(this.scrollX));
}
const overscroll = this.getTargetOverscroll(targetScrollX, left < initialScrollPos.getLeft());
return this.getScrollPos(this.clampScrollX(targetScrollX + overscroll));
}
private getTargetOverscroll(targetScrollX: number, scrollLeft: boolean) {
if (this.config.overscroll === 0) {
return 0;
}
const visibleColumnsWidth = this.grid.getVisibleColumnsWidth(this.getScrollPos(targetScrollX), true);
const remainingSpace = this.tilingArea.width - visibleColumnsWidth;
const overscrollX = Math.min(this.config.overscroll, Math.round(remainingSpace / 2));
const direction = scrollLeft ? -1 : 1;
return overscrollX * direction;
}
scrollToColumn(column: Column) {
this.scrollX = this.getScrollPosForColumn(column).x;
}
scrollCenterColumn(column: Column) {
const windowCenter = column.getLeft() + column.getWidth() / 2;
const screenCenter = this.scrollX + this.tilingArea.width / 2;
this.adjustScroll(Math.round(windowCenter - screenCenter), false);
}
private autoAdjustScroll() {
const focusedWindow = this.world.getFocusedWindow();
if (focusedWindow === null) {
this.removeOverscroll();
return;
}
const column = focusedWindow.column;
if (column.grid !== this.grid) {
return;
}
this.scrollToColumn(column);
}
private getScrollPos(scrollX: number) {
return new ScrollPos(scrollX, this.tilingArea.width);
}
public getCurrentScrollPos() {
return this.getScrollPos(this.scrollX);
}
private clampScrollX(x: number) {
let minScroll = 0;
let maxScroll = this.grid.getWidth() - this.tilingArea.width;
if (maxScroll < 0) {
const centerScroll = Math.round(maxScroll / 2);
minScroll = centerScroll;
maxScroll = centerScroll;
}
return clamp(x, minScroll, maxScroll);
}
private setScroll(x: number, force: boolean) {
this.scrollX = force ? x : this.clampScrollX(x);
}
private applyScrollPos(scrollPos: ScrollPos) {
this.scrollX = scrollPos.x;
}
adjustScroll(dx: number, force: boolean) {
this.setScroll(this.scrollX + dx, force);
}
private removeOverscroll() {
this.setScroll(this.scrollX, false);
}
public arrange() {
// TODO (optimization): only arrange visible windows
this.updateArea();
this.grid.arrange(this.tilingArea.x - this.scrollX);
this.world.ensureFocusedTransientsVisible(); // TODO: refactor - call from elsewhere
}
public onGridWidthChanged() {
this.autoAdjustScroll();
}
public onGridReordered() {
this.autoAdjustScroll();
}
public destroy() {
this.grid.destroy();
}
}
module ScrollView {
export type Config = {
marginTop: number,
marginBottom: number,
marginLeft: number,
marginRight: number,
overscroll: number,
}
}

View File

@@ -18,7 +18,7 @@ class Window {
column.onWindowAdded(this);
}
moveToColumn(targetColumn: Column) {
public moveToColumn(targetColumn: Column) {
if (targetColumn === this.column) {
return;
}
@@ -27,21 +27,31 @@ class Window {
targetColumn.onWindowAdded(this);
}
arrange(x: number, y: number, width: number, height: number) {
public arrange(x: number, y: number, width: number, height: number) {
if (this.skipArrange) {
// window is maximized, fullscreen, or being manually resized, prevent fighting with the user
return;
}
this.client.place(x, y, width, height);
if (this.isFocused()) {
let maximized = false;
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)
this.client.setMaximize(this.focusedState.maximizedVertically, this.focusedState.maximizedHorizontally);
this.client.setFullScreen(this.focusedState.fullScreen);
if (this.focusedState.maximizedVertically || this.focusedState.maximizedHorizontally) {
this.client.setMaximize(this.focusedState.maximizedVertically, this.focusedState.maximizedHorizontally);
maximized = true;
}
if (this.focusedState.fullScreen) {
this.client.setFullScreen(true);
maximized = true;
}
}
if (!maximized) {
this.client.place(x, y, width, height);
}
}
focus() {
public focus() {
if (this.client.isShaded()) {
// workaround for KWin deactivating clients when unshading immediately after activation
this.client.setShade(false);
@@ -49,41 +59,54 @@ class Window {
this.client.focus();
}
isFocused() {
public isFocused() {
return this.client.isFocused();
}
onFocused() {
public onFocused() {
this.column.onWindowFocused(this);
}
restoreToTiled() {
public restoreToTiled() {
if (this.isFocused()) {
return;
}
this.client.setMaximize(false, false);
this.client.setFullScreen(false);
this.client.setMaximize(false, false);
this.column.grid.desktop.onLayoutChanged();
}
onMaximizedChanged(horizontally: boolean, vertically: boolean) {
public onMaximizedChanged(horizontally: boolean, vertically: boolean) {
const maximized = horizontally || vertically;
this.skipArrange = maximized;
this.client.kwinClient.keepBelow = !maximized;
if (this.column.grid.config.tiledKeepBelow) {
this.client.kwinClient.keepBelow = !maximized;
}
if (this.column.grid.config.maximizedKeepAbove) {
this.client.kwinClient.keepAbove = maximized;
}
if (this.isFocused()) {
this.focusedState.maximizedHorizontally = horizontally;
this.focusedState.maximizedVertically = vertically;
}
this.column.grid.desktop.onLayoutChanged();
}
onFullScreenChanged(fullScreen: boolean) {
public onFullScreenChanged(fullScreen: boolean) {
this.skipArrange = fullScreen;
if (this.isFocused()) {
if (this.column.grid.config.tiledKeepBelow) {
this.client.kwinClient.keepBelow = !fullScreen;
}
if (this.column.grid.config.maximizedKeepAbove) {
this.client.kwinClient.keepAbove = fullScreen;
}
if (this.isFocused()) {
this.focusedState.fullScreen = fullScreen;
}
this.column.grid.desktop.onLayoutChanged();
}
onUserResize(oldGeometry: QRect, resizeNeighborColumn: boolean) {
public onUserResize(oldGeometry: QRect, resizeNeighborColumn: boolean) {
const newGeometry = this.client.kwinClient.frameGeometry;
const widthDelta = newGeometry.width - oldGeometry.width;
const heightDelta = newGeometry.height - oldGeometry.height;
@@ -101,19 +124,20 @@ class Window {
}
}
}
this.column.grid.container.adjustScroll(-leftEdgeDelta, true);
this.column.grid.desktop.adjustScroll(-leftEdgeDelta, true);
}
if (heightDelta !== 0) {
this.column.adjustWindowHeight(this, heightDelta, newGeometry.y !== oldGeometry.y);
}
}
onProgrammaticResize(oldGeometry: QRect) {
public onFrameGeometryChanged() {
const newGeometry = this.client.kwinClient.frameGeometry;
this.column.setWidth(newGeometry.width, true);
this.column.grid.desktop.onLayoutChanged();
}
destroy(passFocus: boolean) {
public destroy(passFocus: boolean) {
this.column.onWindowRemoved(this, passFocus);
}
}

View File

@@ -5,8 +5,8 @@ class ClientMatcher {
this.rules = rules;
}
matches(kwinClient: AbstractClient) {
const rule = this.rules.get(String(kwinClient.resourceClass));
public matches(kwinClient: KwinClient) {
const rule = this.rules.get(kwinClient.resourceClass);
if (rule === undefined) {
return false;
}

View File

@@ -2,4 +2,4 @@ type WindowRule = {
class: string,
caption: string,
tile: boolean,
}
};

View File

@@ -3,21 +3,25 @@ class WindowRuleEnforcer {
private readonly preferTiling: ClientMatcher;
private readonly followCaption: Set<string>;
constructor(world: World, windowRules: WindowRule[]) {
const [mapFloat, mapTile] = createWindowRuleMaps(windowRules);
constructor(windowRules: WindowRule[]) {
const [mapFloat, mapTile] = WindowRuleEnforcer.createWindowRuleMaps(windowRules);
this.preferFloating = new ClientMatcher(mapFloat);
this.preferTiling = new ClientMatcher(mapTile);
this.followCaption = new Set([...mapFloat.keys(), ...mapTile.keys()]);
}
shouldTile(kwinClient: AbstractClient) {
public shouldTile(kwinClient: KwinClient) {
return Clients.canTileNow(kwinClient) && (
this.preferTiling.matches(kwinClient) ||
kwinClient.normalWindow && kwinClient.managed && !this.preferFloating.matches(kwinClient)
this.preferTiling.matches(kwinClient) || (
kwinClient.normalWindow &&
!kwinClient.transient &&
kwinClient.managed &&
!this.preferFloating.matches(kwinClient)
)
);
}
initClientSignalManager(world: World, kwinClient: AbstractClient) {
public initClientSignalManager(world: World, kwinClient: KwinClient) {
if (!this.followCaption.has(kwinClient.resourceClass)) {
return null;
}
@@ -26,58 +30,60 @@ class WindowRuleEnforcer {
const manager = new SignalManager();
manager.connect(kwinClient.captionChanged, () => {
const shouldTile = enforcer.shouldTile(kwinClient);
if (shouldTile) {
world.tileClient(kwinClient);
} else {
world.untileClient(kwinClient);
}
world.do((clientManager, desktopManager) => {
if (shouldTile) {
clientManager.tileClient(kwinClient);
} else {
clientManager.untileClient(kwinClient);
}
});
});
return manager;
}
}
function createWindowRuleMaps(windowRules: WindowRule[]) {
const mapFloat = new Map<string, string[]>();
const mapTile = new Map<string, string[]>();
for (const windowRule of windowRules) {
const map = windowRule.tile ? mapTile : mapFloat;
let captions = map.get(windowRule.class);
if (captions === undefined) {
captions = [];
map.set(windowRule.class, captions);
private static createWindowRuleMaps(windowRules: WindowRule[]) {
const mapFloat = new Map<string, string[]>();
const mapTile = new Map<string, string[]>();
for (const windowRule of windowRules) {
const map = windowRule.tile ? mapTile : mapFloat;
let captions = map.get(windowRule.class);
if (captions === undefined) {
captions = [];
map.set(windowRule.class, captions);
}
if (windowRule.caption !== undefined) {
captions.push(windowRule.caption);
}
}
if (windowRule.caption !== undefined) {
captions.push(windowRule.caption);
return [
WindowRuleEnforcer.createWindowRuleRegexMap(mapFloat),
WindowRuleEnforcer.createWindowRuleRegexMap(mapTile),
];
}
private static createWindowRuleRegexMap(windowRuleMap: Map<string, string[]>) {
const regexMap = new Map<string, RegExp>;
for (const [k, v] of windowRuleMap) {
regexMap.set(k, WindowRuleEnforcer.joinRegexes(v));
}
return regexMap;
}
return [
createWindowRuleRegexMap(mapFloat),
createWindowRuleRegexMap(mapTile),
];
}
private static joinRegexes(regexes: string[]) {
if (regexes.length == 0) {
return new RegExp("");
}
function createWindowRuleRegexMap(windowRuleMap: Map<string, string[]>) {
const regexMap = new Map<string, RegExp>;
for (const [k, v] of windowRuleMap) {
regexMap.set(k, joinRegexes(v));
}
return regexMap;
}
if (regexes.length == 1) {
return new RegExp("^" + regexes[0] + "$");
}
function joinRegexes(regexes: string[]) {
if (regexes.length == 0) {
return new RegExp("");
const joinedRegexes = regexes.map(WindowRuleEnforcer.wrapParens).join("|");
return new RegExp("^" + joinedRegexes + "$");
}
if (regexes.length == 1) {
return new RegExp("^" + regexes[0] + "$");
private static wrapParens(str: string) {
return "(" + str + ")";
}
const joinedRegexes = regexes.map(wrapParens).join("|");
return new RegExp("^" + joinedRegexes + "$");
}
function wrapParens(str: string) {
return "(" + str + ")";
}

View File

@@ -7,11 +7,11 @@ class Delayer {
this.timer.triggered.connect(f);
}
run() {
public run() {
this.timer.restart();
}
destroy() {
public destroy() {
this.timer.destroy();
}
}

View File

@@ -5,13 +5,13 @@ class Doer {
this.nCalls = 0;
}
do (f: () => void) {
public do (f: () => void) {
this.nCalls++;
f();
this.nCalls--;
}
isDoing() {
public isDoing() {
return this.nCalls > 0;
}
}

View File

@@ -1,7 +1,7 @@
class LinkedList<T> {
private firstNode: LinkedListNode<T>|null;
private lastNode: LinkedListNode<T>|null;
private readonly itemMap: Map<T, LinkedListNode<T>>;
private firstNode: LinkedList.Node<T>|null;
private lastNode: LinkedList.Node<T>|null;
private readonly itemMap: Map<T, LinkedList.Node<T>>;
constructor() {
this.firstNode = null;
@@ -17,31 +17,31 @@ class LinkedList<T> {
return node;
}
insertBefore(item: T, nextItem: T) {
public insertBefore(item: T, nextItem: T) {
const nextNode = this.getNode(nextItem);
this.insert(item, nextNode.prev, nextNode);
}
insertAfter(item: T, prevItem: T) {
public insertAfter(item: T, prevItem: T) {
const prevNode = this.getNode(prevItem);
this.insert(item, prevNode, prevNode.next);
}
insertStart(item: T) {
public insertStart(item: T) {
this.insert(item, null, this.firstNode);
}
insertEnd(item: T) {
public insertEnd(item: T) {
this.insert(item, this.lastNode, null);
}
private insert(item: T, prevNode: LinkedListNode<T>|null, nextNode: LinkedListNode<T>|null) {
const node = new LinkedListNode(item);
private insert(item: T, prevNode: LinkedList.Node<T>|null, nextNode: LinkedList.Node<T>|null) {
const node = new LinkedList.Node(item);
this.itemMap.set(item, node);
this.insertNode(node, prevNode, nextNode);
}
private insertNode(node: LinkedListNode<T>, prevNode: LinkedListNode<T>|null, nextNode: LinkedListNode<T>|null) {
private insertNode(node: LinkedList.Node<T>, prevNode: LinkedList.Node<T>|null, nextNode: LinkedList.Node<T>|null) {
node.prev = prevNode;
node.next = nextNode;
if (nextNode !== null) {
@@ -60,31 +60,31 @@ class LinkedList<T> {
}
}
getPrev(item: T) {
public getPrev(item: T) {
const prevNode = this.getNode(item).prev;
return prevNode === null ? null : prevNode.item;
}
getNext(item: T) {
public getNext(item: T) {
const nextNode = this.getNode(item).next;
return nextNode === null ? null : nextNode.item;
}
getFirst() {
public getFirst() {
if (this.firstNode === null) {
return null;
}
return this.firstNode.item;
}
getLast() {
public getLast() {
if (this.lastNode === null) {
return null;
}
return this.lastNode.item;
}
getItemAtIndex(index: number) {
public getItemAtIndex(index: number) {
let node = this.firstNode;
if (node === null) {
return null;
@@ -98,13 +98,13 @@ class LinkedList<T> {
return node.item;
}
remove(item: T) {
public remove(item: T) {
const node = this.getNode(item);
this.itemMap.delete(item);
this.removeNode(node);
}
private removeNode(node: LinkedListNode<T>) {
private removeNode(node: LinkedList.Node<T>) {
const prevNode = node.prev;
const nextNode = node.next;
if (prevNode !== null) {
@@ -121,11 +121,11 @@ class LinkedList<T> {
}
}
contains(item: T) {
public contains(item: T) {
return this.itemMap.has(item);
}
private swap(node0: LinkedListNode<T>, node1: LinkedListNode<T>) {
private swap(node0: LinkedList.Node<T>, node1: LinkedList.Node<T>) {
console.assert(node0.next === node1 && node1.prev === node0);
const prevNode = node0.prev;
const nextNode = node1.next;
@@ -150,7 +150,7 @@ class LinkedList<T> {
}
}
move(item: T, prevItem: T|null) {
public move(item: T, prevItem: T|null) {
const node = this.getNode(item);
this.removeNode(node);
if (prevItem === null) {
@@ -161,7 +161,7 @@ class LinkedList<T> {
}
}
moveBack(item: T) {
public moveBack(item: T) {
const node = this.getNode(item);
if (node.prev !== null) {
console.assert(node !== this.firstNode);
@@ -169,7 +169,7 @@ class LinkedList<T> {
}
}
moveForward(item: T) {
public moveForward(item: T) {
const node = this.getNode(item);
if (node.next !== null) {
console.assert(node !== this.lastNode);
@@ -177,32 +177,34 @@ class LinkedList<T> {
}
}
length() {
public length() {
return this.itemMap.size;
}
*iterator() {
public *iterator() {
for (let node = this.firstNode; node !== null; node = node.next) {
yield node.item;
}
}
*iteratorFrom(startItem: T) {
for (let node: LinkedListNode<T>|null = this.getNode(startItem); node !== null; node = node.next) {
public *iteratorFrom(startItem: T) {
for (let node: LinkedList.Node<T>|null = this.getNode(startItem); node !== null; node = node.next) {
yield node.item;
}
}
}
// TODO (optimization): reuse nodes
class LinkedListNode<T> {
public readonly item: T;
public prev: LinkedListNode<T>|null;
public next: LinkedListNode<T>|null;
namespace LinkedList {
// TODO (optimization): reuse nodes
export class Node<T> {
public readonly item: T;
public prev: Node<T> | null;
public next: Node<T> | null;
constructor(item: T) {
this.item = item;
this.prev = null;
this.next = null;
constructor(item: T) {
this.item = item;
this.prev = null;
this.next = null;
}
}
}

View File

@@ -1,16 +1,16 @@
class SignalManager {
private connections: { signal: QSignal, handler: (...args: any[]) => void }[];
private connections: { signal: QSignal<any>, handler: (...args: any) => void }[];
constructor() {
this.connections = [];
}
connect(signal: QSignal, handler: (...args: any[]) => void) {
public connect<T extends unknown[]>(signal: QSignal<T>, handler: (...args: [...T]) => void) {
signal.connect(handler);
this.connections.push({ signal: signal, handler: handler });
}
destroy() {
public destroy() {
for (const connection of this.connections) {
connection.signal.disconnect(connection.handler);
}

3
src/utils/log.ts Normal file
View File

@@ -0,0 +1,3 @@
function log(...args: any[]) {
console.log("Karousel:", ...args);
}

View File

@@ -8,9 +8,7 @@ function clamp(value: number, min: number, max: number) {
return value;
}
function rectEqual(a: QRect, b: QRect) {
return a.x === b.x &&
a.y === b.y &&
a.width === b.width &&
a.height === b.height;
function union<T>(array0: T[], array1: T[]) {
const set = new Set([...array0, ...array1]);
return [...set];
}

View File

@@ -1,8 +1,7 @@
function initWorkspaceSignalHandlers(world: World) {
const manager = new SignalManager();
manager.connect(workspace.clientAdded, (kwinClient: AbstractClient) => {
console.assert(!world.hasClient(kwinClient));
manager.connect(workspace.clientAdded, (kwinClient: KwinClient) => {
if (Clients.canTileEver(kwinClient)) {
// never open new tileable clients on all desktops or activities
if (kwinClient.desktop <= 0) {
@@ -12,48 +11,56 @@ function initWorkspaceSignalHandlers(world: World) {
kwinClient.activities = [workspace.currentActivity];
}
}
world.addClient(kwinClient);
});
manager.connect(workspace.clientRemoved, (kwinClient: AbstractClient) => {
console.assert(world.hasClient(kwinClient));
world.removeClient(kwinClient, true);
});
manager.connect(workspace.clientMinimized, (kwinClient: AbstractClient) => {
world.minimizeClient(kwinClient);
});
manager.connect(workspace.clientUnminimized, (kwinClient: AbstractClient) => {
world.unminimizeClient(kwinClient);
});
manager.connect(workspace.clientMaximizeSet, (kwinClient: AbstractClient, horizontally: boolean, vertically: boolean) => {
world.doIfTiled(kwinClient, false, (window, column, grid) => {
window.onMaximizedChanged(horizontally, vertically);
grid.container.arrange();
world.do((clientManager, desktopManager) => {
clientManager.addClient(kwinClient)
});
});
manager.connect(workspace.clientActivated, (kwinClient: AbstractClient) => {
manager.connect(workspace.clientRemoved, (kwinClient: KwinClient) => {
world.do((clientManager, desktopManager) => {
clientManager.removeClient(kwinClient, true);
});
});
manager.connect(workspace.clientMinimized, (kwinClient: KwinClient) => {
world.do((clientManager, desktopManager) => {
clientManager.minimizeClient(kwinClient);
});
});
manager.connect(workspace.clientUnminimized, (kwinClient: KwinClient) => {
world.do((clientManager, desktopManager) => {
clientManager.unminimizeClient(kwinClient);
});
});
manager.connect(workspace.clientMaximizeSet, (kwinClient: KwinClient, horizontally: boolean, vertically: boolean) => {
if ((horizontally || vertically) && kwinClient.tile !== null) {
kwinClient.tile = null;
}
world.doIfTiled(kwinClient, false, (world, desktopManager, window, column, grid) => {
window.onMaximizedChanged(horizontally, vertically);
});
});
manager.connect(workspace.clientActivated, (kwinClient: KwinClient) => {
if (kwinClient === null) {
return;
}
world.onClientFocused(kwinClient);
world.doIfTiled(kwinClient, true, (window, column, grid) => {
window.onFocused();
grid.container.arrange();
world.do((clientManager, desktopManager) => {
clientManager.onClientFocused(kwinClient);
});
});
manager.connect(workspace.clientFullScreenSet, (kwinClient: X11Client, fullScreen: boolean, user: boolean) => {
world.doIfTiled(kwinClient, false, (window, column, grid) => {
window.onFullScreenChanged(fullScreen);
grid.container.arrange();
});
manager.connect(workspace.currentDesktopChanged, () => {
world.do(() => {}); // re-arrange desktop
});
manager.connect(workspace.numberDesktopsChanged, (oldNumberOfDesktops: number) => {
manager.connect(workspace.currentActivityChanged, () => {
world.do(() => {}); // re-arrange desktop
});
manager.connect(workspace.numberDesktopsChanged, (oldNumberOfVirtualDesktops: number) => {
world.updateDesktops();
});

204
src/world/ClientManager.ts Normal file
View File

@@ -0,0 +1,204 @@
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) {
this.world = world;
this.config = { keepAbove: config.floatingKeepAbove };
this.desktopManager = desktopManager;
this.pinManager = pinManager;
this.clientMap = new Map();
this.lastFocusedClient = null;
let parsedWindowRules: WindowRule[] = [];
try {
parsedWindowRules = JSON.parse(config.windowRules);
} catch (error: any) {
notificationInvalidWindowRules.sendEvent();
log("failed to parse windowRules:", error);
}
this.windowRuleEnforcer = new WindowRuleEnforcer(parsedWindowRules);
}
public addClient(kwinClient: KwinClient) {
console.assert(!this.hasClient(kwinClient));
let constructState: (client: ClientWrapper) => ClientState.State;
if (kwinClient.dock) {
constructState = () => new ClientState.Docked(this.world, kwinClient);
} else if (this.windowRuleEnforcer.shouldTile(kwinClient)) {
const grid = this.desktopManager.getDesktopForClient(kwinClient).grid;
constructState = (client: ClientWrapper) => new ClientState.Tiled(this.world, client, grid);
} else {
constructState = (client: ClientWrapper) => new ClientState.Floating(this.world, client, this.config, false);
}
const client = new ClientWrapper(
kwinClient,
constructState,
this.findTransientFor(kwinClient),
this.windowRuleEnforcer.initClientSignalManager(this.world, kwinClient),
);
this.clientMap.set(kwinClient, client);
}
public removeClient(kwinClient: KwinClient, passFocus: boolean) {
console.assert(this.hasClient(kwinClient));
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
client.destroy(passFocus && kwinClient === this.lastFocusedClient);
this.clientMap.delete(kwinClient);
}
private findTransientFor(kwinClient: KwinClient) {
if (!kwinClient.transient) {
return null;
}
const transientFor = this.clientMap.get(kwinClient.transientFor);
if (transientFor === undefined) {
return null;
}
return transientFor;
}
public minimizeClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientState.Tiled) {
client.stateManager.setState(() => new ClientState.TiledMinimized(), kwinClient === this.lastFocusedClient);
}
}
public unminimizeClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientState.TiledMinimized) {
const grid = this.desktopManager.getDesktopForClient(kwinClient).grid;
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false);
}
}
public tileClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientState.Tiled) {
return;
}
const grid = this.desktopManager.getDesktopForClient(kwinClient).grid;
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false);
}
public untileClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientState.Tiled) {
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
}
}
public pinClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
client.stateManager.setState(() => new ClientState.Pinned(this.world, this.pinManager, this.desktopManager, kwinClient, this.config), false);
this.pinManager.addClient(kwinClient);
for (const desktop of this.desktopManager.getDesktopsForClient(kwinClient)) {
desktop.onPinsChanged();
}
}
public unpinClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
console.assert(client.stateManager.getState() instanceof ClientState.Pinned);
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, false), false);
this.pinManager.removeClient(kwinClient);
for (const desktop of this.desktopManager.getDesktopsForClient(kwinClient)) {
desktop.onPinsChanged();
}
}
public toggleFloatingClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
const clientState = client.stateManager.getState();
if ((clientState instanceof ClientState.Floating || clientState instanceof ClientState.Pinned) && Clients.canTileEver(kwinClient)) {
Clients.makeTileable(kwinClient);
const grid = this.desktopManager.getDesktopForClient(kwinClient).grid;
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false);
} else if (clientState instanceof ClientState.Tiled) {
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
}
}
public hasClient(kwinClient: KwinClient) {
return this.clientMap.has(kwinClient);
}
public onClientFocused(kwinClient: KwinClient) {
this.lastFocusedClient = kwinClient;
const window = this.findTiledWindow(kwinClient, true);
if (window !== null) {
window.onFocused();
}
}
public findTiledWindow(kwinClient: KwinClient, followTransient: boolean) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return null;
}
return this.findTiledWindowOfClient(client, followTransient);
}
private findTiledWindowOfClient(client: ClientWrapper, followTransient: boolean): 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 {
return null;
}
}
private removeAllClients() {
for (const kwinClient of Array.from(this.clientMap.keys())) {
this.removeClient(kwinClient, false);
}
}
public destroy() {
this.removeAllClients();
}
}
namespace ClientManager {
export type Config = {
keepAbove: boolean,
}
}

View File

@@ -1,23 +0,0 @@
class ClientStateDocked {
private readonly world: World;
private readonly signalManager: SignalManager;
constructor(world: World, kwinClient: AbstractClient) {
this.world = world;
this.signalManager = ClientStateDocked.initSignalManager(world, kwinClient);
world.onScreenResized();
}
destroy(passFocus: boolean) {
this.signalManager.destroy();
this.world.onScreenResized();
}
private static initSignalManager(world: World, kwinClient: AbstractClient) {
const manager = new SignalManager();
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: TopLevel, oldGeometry: QRect) => {
world.onScreenResized();
});
return manager;
}
}

View File

@@ -1,30 +0,0 @@
class ClientStateManager {
private state: ClientState;
constructor(initialState: ClientState) {
this.state = initialState;
}
setState(newState: ClientState, passFocus: boolean) {
this.state.destroy(passFocus);
this.state = newState;
}
getState() {
return this.state;
}
destroy(passFocus: boolean) {
this.state.destroy(passFocus);
}
}
type ClientState = ClientStateTiled | ClientStateTiledMinimized | ClientStateFloating | ClientStateDocked;
class ClientStateTiledMinimized {
destroy(passFocus: boolean) {}
}
class ClientStateFloating {
destroy(passFocus: boolean) {}
}

View File

@@ -1,110 +0,0 @@
class ClientStateTiled {
readonly window: Window;
private readonly signalManager: SignalManager;
constructor(world: World, client: ClientWrapper) {
client.prepareForTiling();
const grid = world.getClientGrid(client.kwinClient);
const column = new Column(grid, grid.getLastFocusedColumn() ?? grid.getLastColumn());
const window = new Window(client, column);
grid.container.arrange();
this.window = window;
this.signalManager = ClientStateTiled.initSignalManager(world, window);
}
destroy(passFocus: boolean) {
this.signalManager.destroy();
const window = this.window;
const grid = window.column.grid;
const clientWrapper = window.client;
window.destroy(passFocus);
grid.container.arrange();
clientWrapper.prepareForFloating(grid.container.clientArea);
}
static initSignalManager(world: World, window: Window) {
const client = window.client;
const kwinClient = client.kwinClient;
const manager = new SignalManager();
manager.connect(kwinClient.desktopChanged, () => {
if (kwinClient.desktop === -1) {
// windows on all desktops are not supported
world.untileClient(kwinClient);
return;
}
ClientStateTiled.moveWindowToCorrectGrid(world, window);
});
manager.connect(kwinClient.activitiesChanged, (kwinClient: AbstractClient) => {
if (kwinClient.activities.length !== 1) {
// windows on multiple activities are not supported
world.untileClient(kwinClient);
return;
}
ClientStateTiled.moveWindowToCorrectGrid(world, window);
})
let lastResize = false;
manager.connect(kwinClient.moveResizedChanged, () => {
if (world.untileOnDrag && kwinClient.move) {
world.untileClient(kwinClient);
return;
}
const grid = window.column.grid;
const resize = kwinClient.resize;
if (!lastResize && resize) {
grid.onUserResizeStarted();
}
if (lastResize && !resize) {
grid.onUserResizeFinished();
}
lastResize = resize;
});
let cursorChangedAfterResizeStart = false;
manager.connect(kwinClient.moveResizeCursorChanged, () => {
cursorChangedAfterResizeStart = true;
});
manager.connect(kwinClient.clientStartUserMovedResized, () => {
cursorChangedAfterResizeStart = false;
});
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: TopLevel, oldGeometry: QRect) => {
const scrollView = window.column.grid.container;
if (kwinClient.resize) {
window.onUserResize(oldGeometry, !cursorChangedAfterResizeStart);
scrollView.arrange();
} else {
const maximized = rectEqual(kwinClient.frameGeometry, scrollView.clientArea);
if (!client.isManipulatingGeometry() && !kwinClient.fullScreen && !maximized) {
window.onProgrammaticResize(oldGeometry);
scrollView.arrange();
}
}
});
return manager;
}
static moveWindowToCorrectGrid(world: World, window: Window) {
const kwinClient = window.client.kwinClient;
const oldGrid = window.column.grid;
const newGrid = world.getClientGrid(kwinClient);
if (oldGrid === newGrid) {
// window already on the correct grid
return;
}
const newColumn = new Column(newGrid, newGrid.getLastFocusedColumn() ?? newGrid.getLastColumn());
window.moveToColumn(newColumn);
oldGrid.container.arrange();
newGrid.container.arrange();
}
}

View File

@@ -1,115 +1,104 @@
class ClientWrapper {
public readonly kwinClient: AbstractClient;
public readonly stateManager: ClientStateManager;
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 readonly manipulatingGeometry: Doer;
private lastPlacement: QRect | null; // workaround for issue #19
constructor(
kwinClient: AbstractClient,
initialState: ClientState,
kwinClient: KwinClient,
constructInitialState: (client: ClientWrapper) => ClientState.State,
transientFor: ClientWrapper | null,
rulesSignalManager: SignalManager | null,
) {
this.kwinClient = kwinClient;
this.stateManager = new ClientStateManager(initialState);
this.transientFor = transientFor;
this.transients = [];
if (transientFor !== null) {
transientFor.addTransient(this);
}
this.signalManager = ClientWrapper.initSignalManager(this);
this.rulesSignalManager = rulesSignalManager;
this.preferredWidth = kwinClient.frameGeometry.width;
this.manipulatingGeometry = new Doer();
this.lastPlacement = null;
this.stateManager = new ClientState.Manager(constructInitialState(this));
}
place(x: number, y: number, width: number, height: number) {
public place(x: number, y: number, width: number, height: number) {
this.manipulatingGeometry.do(() => {
if (this.kwinClient.resize) {
// window is being manually resized, prevent fighting with the user
return;
}
this.kwinClient.frameGeometry = Qt.rect(x, y, width, height);
this.lastPlacement = Qt.rect(x, y, width, height);
this.kwinClient.frameGeometry = this.lastPlacement;
});
}
private moveTransient(dx: number, dy: number) {
// TODO: prevent moving off the grid
if (this.stateManager.getState() instanceof ClientStateFloating) {
const frame = this.kwinClient.frameGeometry;
this.kwinClient.frameGeometry = Qt.rect(
frame.x + dx,
frame.y + dy,
frame.width,
frame.height,
);
private moveTransient(dx: number, dy: number, desktopNumber: number) {
if (this.stateManager.getState() instanceof ClientState.Floating) {
if (this.kwinClient.desktop === desktopNumber) {
const frame = this.kwinClient.frameGeometry;
this.kwinClient.frameGeometry = Qt.rect(
frame.x + dx,
frame.y + dy,
frame.width,
frame.height,
);
}
for (const transient of this.transients) {
transient.moveTransient(dx, dy);
transient.moveTransient(dx, dy, desktopNumber);
}
}
}
focus() {
public moveTransients(dx: number, dy: number) {
for (const transient of this.transients) {
transient.moveTransient(dx, dy, this.kwinClient.desktop);
}
}
public focus() {
workspace.activeClient = this.kwinClient;
}
isFocused() {
public isFocused() {
return workspace.activeClient === this.kwinClient;
}
setMaximize(horizontally: boolean, vertically: boolean) {
public setMaximize(horizontally: boolean, vertically: boolean) {
this.manipulatingGeometry.do(() => {
this.kwinClient.setMaximize(vertically, horizontally);
});
}
setFullScreen(fullScreen: boolean) {
public setFullScreen(fullScreen: boolean) {
this.manipulatingGeometry.do(() => {
this.kwinClient.fullScreen = fullScreen;
});
}
setShade(shade: boolean) {
public setShade(shade: boolean) {
this.manipulatingGeometry.do(() => {
this.kwinClient.shade = shade;
});
}
isShaded() {
public isShaded() {
return this.kwinClient.shade;
}
isManipulatingGeometry() {
public isManipulatingGeometry(newGeometry: QRect | null) {
if (newGeometry !== null && newGeometry === this.lastPlacement) {
return true;
}
return this.manipulatingGeometry.isDoing();
}
prepareForTiling() {
this.kwinClient.keepBelow = true;
this.setFullScreen(false);
this.setMaximize(false, false);
}
prepareForFloating(screenSize: QRect) {
this.kwinClient.keepBelow = false;
this.setShade(false);
this.setFullScreen(false);
this.setMaximize(false, false);
const clientRect = this.kwinClient.frameGeometry;
const width = this.preferredWidth;
this.place(
clamp(clientRect.x, screenSize.left, screenSize.right - width),
clientRect.y,
width,
Math.min(clientRect.height, Math.round(screenSize.height / 2)),
);
}
private addTransient(transient: ClientWrapper) {
this.transients.push(transient);
}
@@ -121,15 +110,17 @@ class ClientWrapper {
public ensureTransientsVisible(screenSize: QRect) {
for (const transient of this.transients) {
if (transient.stateManager.getState() instanceof ClientStateFloating) {
if (transient.stateManager.getState() instanceof ClientState.Floating) {
transient.ensureVisible(screenSize);
transient.ensureTransientsVisible(screenSize);
}
}
}
public ensureVisible(screenSize: QRect) {
if (this.kwinClient.desktop !== workspace.currentDesktop) {
return;
}
const frame = this.kwinClient.frameGeometry;
if (frame.left < 0) {
frame.x = 0;
@@ -138,9 +129,8 @@ class ClientWrapper {
}
}
destroy(passFocus: boolean) {
public destroy(passFocus: boolean) {
this.stateManager.destroy(passFocus);
this.signalManager.destroy();
if (this.rulesSignalManager !== null) {
this.rulesSignalManager.destroy();
}
@@ -151,23 +141,4 @@ class ClientWrapper {
transient.transientFor = null;
}
}
static initSignalManager(client: ClientWrapper) {
const manager = new SignalManager();
manager.connect(client.kwinClient.frameGeometryChanged, (kwinClient: TopLevel, oldGeometry: QRect) => {
if (client.stateManager.getState() instanceof ClientStateTiled) {
const newGeometry = client.kwinClient.frameGeometry;
const oldCenterX = oldGeometry.x + oldGeometry.width/2;
const oldCenterY = oldGeometry.y + oldGeometry.height/2;
const newCenterX = newGeometry.x + newGeometry.width/2;
const newCenterY = newGeometry.y + newGeometry.height/2;
const dx = Math.round(newCenterX - oldCenterX);
const dy = Math.round(newCenterY - oldCenterY);
for (const transient of client.transients) {
transient.moveTransient(dx, dy);
}
}
});
return manager;
}
}

View File

@@ -1,13 +1,13 @@
module Clients {
export function canTileEver(kwinClient: AbstractClient) {
namespace Clients {
export function canTileEver(kwinClient: KwinClient) {
return kwinClient.resizeable;
}
export function canTileNow(kwinClient: AbstractClient) {
export function canTileNow(kwinClient: KwinClient) {
return canTileEver(kwinClient) && !kwinClient.minimized && kwinClient.desktop > 0 && kwinClient.activities.length === 1;
}
export function makeTileable(kwinClient: AbstractClient) {
export function makeTileable(kwinClient: KwinClient) {
if (kwinClient.minimized) {
kwinClient.minimized = false;
}
@@ -18,4 +18,18 @@ module Clients {
kwinClient.activities = [workspace.currentActivity];
}
}
export function isMaximizedGeometry(kwinClient: KwinClient) {
const maximizeArea = workspace.clientArea(ClientAreaOption.MaximizeArea, kwinClient.screen, kwinClient.desktop);
return kwinClient.frameGeometry === maximizeArea;
}
export function isFullScreenGeometry(kwinClient: KwinClient) {
const fullScreenArea = workspace.clientArea(ClientAreaOption.FullScreenArea, kwinClient.screen, kwinClient.desktop);
return kwinClient.frameGeometry === fullScreenArea;
}
export function isOnVirtualDesktop(kwinClient: KwinClient, desktopNumber: number) {
return kwinClient.desktop === desktopNumber || kwinClient.desktop === -1;
}
}

147
src/world/DesktopManager.ts Normal file
View File

@@ -0,0 +1,147 @@
class DesktopManager {
private readonly pinManager: PinManager;
private readonly config: Desktop.Config;
public readonly layoutConfig: LayoutConfig;
private readonly desktopsPerActivity: Map<string, Desktop[]>;
private nVirtualDesktops: number;
constructor(pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig, currentActivity: string) {
this.pinManager = pinManager;
this.config = config;
this.layoutConfig = layoutConfig;
this.desktopsPerActivity = new Map();
this.nVirtualDesktops = 0;
this.update()
this.addActivity(currentActivity);
}
public update() {
this.setNVirtualDesktops(workspace.desktops);
}
public getDesktop(activity: string, desktopNumber: number) {
const desktopIndex = desktopNumber - 1;
if (desktopIndex >= this.nVirtualDesktops || desktopIndex < 0) {
throw new Error("invalid desktop number: " + String(desktopNumber));
}
if (!this.desktopsPerActivity.has(activity)) {
this.addActivity(activity);
}
return this.desktopsPerActivity.get(activity)![desktopIndex];
}
public getCurrentDesktop() {
return this.getDesktop(workspace.currentActivity, workspace.currentDesktop);
}
public getDesktopInCurrentActivity(desktopNumber: number) {
return this.getDesktop(workspace.currentActivity, desktopNumber);
}
public getDesktopForClient(kwinClient: KwinClient) {
console.assert(kwinClient.activities.length === 1 && kwinClient.desktop > 0);
return this.getDesktop(kwinClient.activities[0], kwinClient.desktop);
}
private setNVirtualDesktops(nVirtualDesktops: number) {
if (nVirtualDesktops > this.nVirtualDesktops) {
this.addDesktopsToActivities(nVirtualDesktops - this.nVirtualDesktops);
} else if (nVirtualDesktops < this.nVirtualDesktops) {
this.removeDesktopsFromActivities(this.nVirtualDesktops - nVirtualDesktops);
}
this.nVirtualDesktops = nVirtualDesktops;
}
private addDesktopsToActivities(n: number) {
for (const desktops of this.desktopsPerActivity.values()) {
this.addDesktops(desktops, n);
}
}
private addDesktops(desktops: Desktop[], n: number) {
const nStart = desktops.length;
for (let i = 0; i < n; i++) {
const desktopNumber = nStart + i + 1;
desktops.push(new Desktop(desktopNumber, this.pinManager, this.config, this.layoutConfig));
}
}
private removeDesktopsFromActivities(n: number) {
const lastRemainingDesktopIndex = this.nVirtualDesktops - n - 1;
for (const desktops of this.desktopsPerActivity.values()) {
const targetDesktop = desktops[lastRemainingDesktopIndex];
for (let i = 0; i < n; i++) {
const removedDesktop = desktops.pop()!;
removedDesktop.grid.evacuate(targetDesktop.grid);
}
}
}
private addActivity(activity: string) {
const desktops: Desktop[] = [];
this.addDesktops(desktops, this.nVirtualDesktops);
this.desktopsPerActivity.set(activity, desktops);
}
private removeActivity(activity: string) {
const removedDesktops = this.desktopsPerActivity.get(activity)!;
this.desktopsPerActivity.delete(activity);
const targetActivityDesktops = this.desktopsPerActivity.values().next().value;
for (let i = 0; i < removedDesktops.length; i++) {
removedDesktops[i].grid.evacuate(targetActivityDesktops[i]);
}
}
public destroy() {
for (const desktop of this.desktops()) {
desktop.destroy();
}
}
public *desktops() {
for (const desktops of this.desktopsPerActivity.values()) {
for (const desktop of desktops) {
yield desktop;
}
}
}
public *getDesktopsForClient(kwinClient: KwinClient) {
const activities = kwinClient.activities.length > 0 ? kwinClient.activities : this.desktopsPerActivity.keys();
for (const activity of activities) {
if (!this.desktopsPerActivity.has(activity)) {
this.addActivity(activity);
}
const activityDesktops = this.desktopsPerActivity.get(activity)!;
if (kwinClient.desktop === -1) {
for (const desktop of activityDesktops) {
yield desktop;
}
} else {
const desktopIndex = kwinClient.desktop - 1;
yield activityDesktops[desktopIndex];
}
}
}
// empty array means all
public *getDesktops(desktopNumbers: number[], inputActivities: string[]) {
const activities = inputActivities.length > 0 ? inputActivities : this.desktopsPerActivity.keys();
for (const activity of activities) {
if (!this.desktopsPerActivity.has(activity)) {
this.addActivity(activity);
}
const activityDesktops = this.desktopsPerActivity.get(activity)!;
if (desktopNumbers.length === 0) {
for (const desktop of activityDesktops) {
yield desktop;
}
} else {
for (const desktopNumber of desktopNumbers) {
const desktopIndex = desktopNumber - 1;
yield activityDesktops[desktopIndex];
}
}
}
}
}

86
src/world/PinManager.ts Normal file
View File

@@ -0,0 +1,86 @@
class PinManager {
private readonly pinnedClients: Set<KwinClient>;
constructor() {
this.pinnedClients = new Set();
}
public addClient(kwinClient: KwinClient) {
this.pinnedClients.add(kwinClient);
}
public removeClient(kwinClient: KwinClient) {
this.pinnedClients.delete(kwinClient);
}
public getAvailableSpace(desktopNumber: number, screen: QRect) {
const baseLot = new PinManager.Lot(screen.top, screen.bottom, screen.left, screen.right);
let lots = [baseLot];
for (const client of this.pinnedClients) {
if (!Clients.isOnVirtualDesktop(client, desktopNumber)) {
continue;
}
const newLots: PinManager.Lot[] = [];
for (const lot of lots) {
lot.split(newLots, client.frameGeometry);
}
lots = newLots;
}
let largestLot = baseLot;
let largestArea = 0;
for (const lot of lots) {
const area = lot.area();
if (area > largestArea) {
largestArea = area;
largestLot = lot;
}
}
return largestLot;
}
}
namespace PinManager {
export class Lot {
private static readonly minWidth = 200;
private static readonly minHeight = 200;
constructor(
public readonly top: number,
public readonly bottom: number,
public readonly left: number,
public readonly right: number,
) {}
public split(destLots: Lot[], obstacle: QRect) {
if (!this.contains(obstacle)) {
// don't split
destLots.push(this);
return;
}
if (obstacle.top - this.top >= Lot.minHeight) {
destLots.push(new Lot(this.top, obstacle.top, this.left, this.right));
}
if (this.bottom - obstacle.bottom >= Lot.minHeight) {
destLots.push(new Lot(obstacle.bottom, 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 (this.right - obstacle.right >= Lot.minWidth) {
destLots.push(new Lot(this.top, this.bottom, obstacle.right, this.right));
}
}
private contains(obstacle: QRect) {
return obstacle.right >= this.left && obstacle.left <= this.right &&
obstacle.bottom >= this.top && obstacle.top <= this.bottom;
}
public area() {
return (this.bottom - this.top) * (this.right - this.left);
}
}
}

View File

@@ -1,85 +0,0 @@
class ScrollViewManager {
private readonly world: World;
private readonly config: ScrollView.Config;
public readonly layoutConfig: LayoutConfig;
private readonly scrollViewsPerActivity: Map<string, ScrollView[]>;
private nDesktops: number;
constructor(world: World, config: ScrollView.Config, layoutConfig: LayoutConfig, currentActivity: string, nDesktops: number) {
this.config = config;
this.layoutConfig = layoutConfig;
this.world = world;
this.scrollViewsPerActivity = new Map();
this.nDesktops = 0;
this.setNDesktops(nDesktops);
this.addActivity(currentActivity);
}
get(activity: string, desktopNumber: number) {
const desktopIndex = desktopNumber - 1;
if (desktopIndex >= this.nDesktops || this.nDesktops < 0) {
throw new Error("invalid desktop number: " + String(desktopNumber));
}
if (!this.scrollViewsPerActivity.has(activity)) {
this.addActivity(activity);
}
return this.scrollViewsPerActivity.get(activity)![desktopIndex];
}
setNDesktops(nDesktops: number) {
if (nDesktops > this.nDesktops) {
this.addDesktopsToActivities(nDesktops - this.nDesktops);
} else if (nDesktops < this.nDesktops) {
this.removeDesktopsFromActivities(this.nDesktops - nDesktops);
}
this.nDesktops = nDesktops;
}
private addDesktopsToActivities(n: number) {
for (const scrollViews of this.scrollViewsPerActivity.values()) {
this.addDesktops(scrollViews, n);
}
}
private addDesktops(scrollViews: ScrollView[], n: number) {
const nStart = scrollViews.length;
for (let i = 0; i < n; i++) {
const desktopNumber = nStart + i + 1;
scrollViews.push(new ScrollView(this.world, desktopNumber, this.config, this.layoutConfig));
}
}
private removeDesktopsFromActivities(n: number) {
const lastRemainingDesktopIndex = this.nDesktops - n - 1;
for (const scrollViews of this.scrollViewsPerActivity.values()) {
const targetScrollView = scrollViews[lastRemainingDesktopIndex];
for (let i = 0; i < n; i++) {
const removedScrollView = scrollViews.pop()!;
removedScrollView.grid.evacuate(targetScrollView.grid);
}
}
}
addActivity(activity: string) {
const scrollViews: ScrollView[] = [];
this.addDesktops(scrollViews, this.nDesktops);
this.scrollViewsPerActivity.set(activity, scrollViews);
}
removeActivity(activity: string) {
const removedScrollViews = this.scrollViewsPerActivity.get(activity)!;
this.scrollViewsPerActivity.delete(activity);
const targetActivityScrollViews = this.scrollViewsPerActivity.values().next().value;
for (let i = 0; i < removedScrollViews.length; i++) {
removedScrollViews[i].grid.evacuate(targetActivityScrollViews[i]);
}
}
*scrollViews() {
for (const scrollViews of this.scrollViewsPerActivity.values()) {
for (const scrollView of scrollViews) {
yield scrollView;
}
}
}
}

View File

@@ -1,36 +1,28 @@
class World {
public readonly untileOnDrag: boolean;
private readonly scrollViewManager: ScrollViewManager;
private readonly clientMap: Map<AbstractClient, ClientWrapper>;
private lastFocusedClient: AbstractClient|null;
private readonly desktopManager: DesktopManager;
public readonly clientManager: ClientManager;
private readonly pinManager: PinManager;
private readonly workspaceSignalManager: SignalManager;
private readonly windowRuleEnforcer: WindowRuleEnforcer;
private readonly screenResizedDelayer: Delayer;
constructor(config: Config) {
this.untileOnDrag = config.untileOnDrag;
this.clientMap = new Map();
this.lastFocusedClient = null;
this.workspaceSignalManager = initWorkspaceSignalHandlers(this);
let parsedWindowRules: WindowRule[] = [];
try {
parsedWindowRules = JSON.parse(config.windowRules);
} catch (error: any) {
console.log("failed to parse windowRules:", error);
}
this.windowRuleEnforcer = new WindowRuleEnforcer(this, parsedWindowRules);
this.screenResizedDelayer = new Delayer(1000, () => {
// this delay ensures that docks get taken into account by `workspace.clientArea`
const gridManager = this.scrollViewManager; // workaround for bug in Qt5's JS engine
for (const scrollView of gridManager.scrollViews()) {
scrollView.arrange();
const desktopManager = this.desktopManager; // workaround for bug in Qt5's JS engine
for (const desktop of desktopManager.desktops()) {
desktop.onLayoutChanged();
}
this.update();
});
this.scrollViewManager = new ScrollViewManager(
this,
this.pinManager = new PinManager();
this.desktopManager = new DesktopManager(
this.pinManager,
{
marginTop: config.gapsOuterTop,
marginBottom: config.gapsOuterBottom,
@@ -38,207 +30,72 @@ class World {
marginRight: config.gapsOuterRight,
overscroll: config.overscroll,
},
config,
{
gapsInnerHorizontal: config.gapsInnerHorizontal,
gapsInnerVertical: config.gapsInnerVertical,
stackColumnsByDefault: config.stackColumnsByDefault,
resizeNeighborColumn: config.resizeNeighborColumn,
reMaximize: config.reMaximize,
tiledKeepBelow: config.tiledKeepBelow,
maximizedKeepAbove: config.floatingKeepAbove,
},
workspace.currentActivity,
workspace.desktops,
);
this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager);
this.addExistingClients();
}
updateDesktops() {
this.scrollViewManager.setNDesktops(workspace.desktops);
this.update();
}
private addExistingClients() {
const kwinClients = workspace.clientList();
for (let i = 0; i < kwinClients.length; i++) {
const kwinClient = kwinClients[i];
this.addClient(kwinClient);
this.clientManager.addClient(kwinClient);
}
}
getGrid(activity: string, desktopNumber: number) {
console.assert(desktopNumber > 0 && desktopNumber <= workspace.desktops);
return this.scrollViewManager.get(activity, desktopNumber).grid;
public updateDesktops() {
this.desktopManager.update();
}
getGridInCurrentActivity(desktopNumber: number) {
return this.getGrid(workspace.currentActivity, desktopNumber);
private update() {
this.desktopManager.getCurrentDesktop().arrange();
}
getCurrentGrid() {
return this.getGrid(workspace.currentActivity, workspace.currentDesktop);
public do(f: (clientManager: ClientManager, desktopManager: DesktopManager) => void) {
f(this.clientManager, this.desktopManager);
this.update();
}
getClientGrid(kwinClient: AbstractClient) {
console.assert(kwinClient.activities.length === 1);
return this.getGrid(kwinClient.activities[0], kwinClient.desktop);
}
addClient(kwinClient: AbstractClient) {
const client = new ClientWrapper(
kwinClient,
new ClientStateFloating(),
this.findTransientFor(kwinClient),
this.windowRuleEnforcer.initClientSignalManager(this, kwinClient),
);
this.clientMap.set(kwinClient, client);
if (kwinClient.dock) {
client.stateManager.setState(new ClientStateDocked(this, kwinClient), false);
} else if (this.windowRuleEnforcer.shouldTile(kwinClient)) {
client.stateManager.setState(new ClientStateTiled(this, client), false);
}
}
removeClient(kwinClient: AbstractClient, passFocus: boolean) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
public doIfTiled(
kwinClient: KwinClient,
followTransient: boolean,
f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void,
) {
const window = this.clientManager.findTiledWindow(kwinClient, followTransient);
if (window === null) {
return;
}
client.destroy(passFocus && kwinClient === this.lastFocusedClient);
this.clientMap.delete(kwinClient);
const column = window.column;
const grid = column.grid;
f(this.clientManager, this.desktopManager, window, column, grid);
this.update();
}
findTransientFor(kwinClient: AbstractClient) {
if (!kwinClient.transient) {
return null;
}
const transientFor = this.clientMap.get(kwinClient.transientFor);
if (transientFor === undefined) {
return null;
}
return transientFor;
}
public ensureFocusedTransientsVisible() {
this.doIfTiledFocused(true, (window, column, grid) => {
window.client.ensureTransientsVisible(grid.container.clientArea);
});
}
minimizeClient(kwinClient: AbstractClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientStateTiled) {
client.stateManager.setState(new ClientStateTiledMinimized(), kwinClient === this.lastFocusedClient);
}
}
unminimizeClient(kwinClient: AbstractClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientStateTiledMinimized) {
client.stateManager.setState(new ClientStateTiled(this, client), false);
}
}
tileClient(kwinClient: AbstractClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientStateTiled) {
return;
}
client.stateManager.setState(new ClientStateTiled(this, client), false);
}
untileClient(kwinClient: AbstractClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientStateTiled) {
client.stateManager.setState(new ClientStateFloating(), false);
}
}
toggleFloatingClient(kwinClient: AbstractClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
const clientState = client.stateManager.getState();
if (clientState instanceof ClientStateFloating && Clients.canTileEver(kwinClient)) {
Clients.makeTileable(kwinClient);
client.stateManager.setState(new ClientStateTiled(this, client), false);
} else if (clientState instanceof ClientStateTiled) {
client.stateManager.setState(new ClientStateFloating(), false);
}
}
hasClient(kwinClient: AbstractClient) {
return this.clientMap.has(kwinClient);
}
onClientFocused(kwinClient: AbstractClient) {
this.lastFocusedClient = kwinClient;
}
private doIfTiledInner(client: ClientWrapper, followTransient: boolean, f: (window: Window, column: Column, grid: Grid) => void) {
const clientState = client.stateManager.getState();
if (clientState instanceof ClientStateTiled) {
const window = clientState.window;
const column = window.column;
const grid = column.grid;
f(window, column, grid);
} else if (followTransient && client.transientFor !== null) {
this.doIfTiledInner(client.transientFor, true, f);
}
}
doIfTiled(kwinClient: AbstractClient, followTransient: boolean, f: (window: Window, column: Column, grid: Grid) => void) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
this.doIfTiledInner(client, followTransient, f);
}
doIfTiledFocused(followTransient: boolean, f: (window: Window, column: Column, grid: Grid) => void) {
public doIfTiledFocused(
followTransient: boolean,
f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void,
) {
this.doIfTiled(workspace.activeClient, followTransient, f);
}
getFocusedWindow() {
const activeClient = workspace.activeClient;
if (activeClient === null) {
return null;
}
const client = this.clientMap.get(activeClient);
if (client === undefined) {
return null;
}
const clientState = client.stateManager.getState();
if (clientState instanceof ClientStateTiled) {
return clientState.window;
} else {
return null;
}
}
removeAllClients() {
for (const kwinClient of Array.from(this.clientMap.keys())) {
this.removeClient(kwinClient, false);
}
}
destroy() {
public destroy() {
this.workspaceSignalManager.destroy();
this.removeAllClients();
for (const scrollView of this.scrollViewManager.scrollViews()) {
scrollView.destroy();
}
this.clientManager.destroy();
this.desktopManager.destroy();
}
onScreenResized() {
public onScreenResized() {
this.screenResizedDelayer.run();
}
}

View File

@@ -0,0 +1,25 @@
namespace ClientState {
export class Docked implements State {
private readonly world: World;
private readonly signalManager: SignalManager;
constructor(world: World, kwinClient: KwinClient) {
this.world = world;
this.signalManager = Docked.initSignalManager(world, kwinClient);
world.onScreenResized();
}
public destroy(passFocus: boolean) {
this.signalManager.destroy();
this.world.onScreenResized();
}
private static initSignalManager(world: World, kwinClient: KwinClient) {
const manager = new SignalManager();
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QRect) => {
world.onScreenResized();
});
return manager;
}
}
}

View File

@@ -0,0 +1,62 @@
namespace ClientState {
export class Floating implements State {
private readonly client: ClientWrapper;
private readonly config: ClientManager.Config;
private readonly signalManager: SignalManager;
constructor(world: World, client: ClientWrapper, config: ClientManager.Config, limitHeight: boolean) {
this.client = client;
this.config = config;
if (config.keepAbove) {
client.kwinClient.keepAbove = true;
}
if (limitHeight && client.kwinClient.tile === null) {
Floating.limitHeight(client);
}
this.signalManager = Floating.initSignalManager(world, client.kwinClient);
}
public destroy(passFocus: boolean) {
this.signalManager.destroy();
if (this.config.keepAbove) {
this.client.kwinClient.keepAbove = false;
}
}
private static limitHeight(client: ClientWrapper) {
const placementArea = workspace.clientArea(ClientAreaOption.PlacementArea, client.kwinClient.screen, client.kwinClient.desktop);
const clientRect = client.kwinClient.frameGeometry;
const width = client.preferredWidth;
client.place(
clientRect.x,
clientRect.y,
width,
Math.min(clientRect.height, Math.round(placementArea.height / 2)),
);
}
private static initSignalManager(world: World, kwinClient: KwinClient) {
const manager = new SignalManager();
manager.connect(kwinClient.tileChanged, () => {
// on X11, this fires after `frameGeometryChanged`
if (kwinClient.tile !== null) {
world.do((clientManager, desktopManager) => {
clientManager.pinClient(kwinClient);
});
}
});
manager.connect(kwinClient.frameGeometryChanged, () => {
// on Wayland, this fires after `tileChanged`
if (kwinClient.tile !== null) {
world.do((clientManager, desktopManager) => {
clientManager.pinClient(kwinClient);
});
}
})
return manager;
}
}
}

View File

@@ -0,0 +1,26 @@
namespace ClientState {
export class Manager {
private state: State;
constructor(initialState: State) {
this.state = initialState;
}
public setState(constructNewState: () => State, passFocus: boolean) {
this.state.destroy(passFocus);
this.state = constructNewState();
}
public getState() {
return this.state;
}
public destroy(passFocus: boolean) {
this.state.destroy(passFocus);
}
}
export type State = {
destroy(passFocus: boolean): void;
};
}

View File

@@ -0,0 +1,87 @@
namespace ClientState {
export class Pinned implements State {
private readonly kwinClient: KwinClient;
private readonly pinManager: PinManager;
private readonly desktopManager: DesktopManager;
private readonly config: ClientManager.Config;
private readonly signalManager: SignalManager;
constructor(world: World, pinManager: PinManager, desktopManager: DesktopManager, kwinClient: KwinClient, config: ClientManager.Config) {
this.kwinClient = kwinClient;
this.pinManager = pinManager;
this.desktopManager = desktopManager;
this.config = config;
if (config.keepAbove) {
kwinClient.keepAbove = true;
}
this.signalManager = Pinned.initSignalManager(world, pinManager, kwinClient);
}
public destroy(passFocus: boolean) {
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();
}
}
private static initSignalManager(world: World, pinManager: PinManager, kwinClient: KwinClient) {
const manager = new SignalManager();
let oldDesktopNumber = kwinClient.desktop;
let oldActivities = kwinClient.activities;
manager.connect(kwinClient.tileChanged, () => {
if (kwinClient.tile === null) {
world.do((clientManager, desktopManager) => {
clientManager.unpinClient(kwinClient);
});
}
});
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QRect) => {
if (kwinClient.tile === null) {
world.do((clientManager, desktopManager) => {
clientManager.unpinClient(kwinClient);
});
return;
}
world.do((clientManager, desktopManager) => {
for (const desktop of desktopManager.getDesktopsForClient(kwinClient)) {
desktop.onPinsChanged();
}
})
});
manager.connect(kwinClient.desktopChanged, () => {
const changedDesktops = oldDesktopNumber === -1 || kwinClient.desktop === -1 ?
[] :
[oldDesktopNumber, kwinClient.desktop];
world.do((clientManager, desktopManager) => {
for (const desktop of desktopManager.getDesktops(changedDesktops, kwinClient.activities)) {
desktop.onPinsChanged();
}
});
oldDesktopNumber = kwinClient.desktop;
});
manager.connect(kwinClient.activitiesChanged, (kwinClient: KwinClient) => {
const desktops = kwinClient.desktop === -1 ? [] : [kwinClient.desktop];
const changedActivities = oldActivities.length === 0 || kwinClient.activities.length === 0 ?
[] :
union(oldActivities, kwinClient.activities);
world.do((clientManager, desktopManager) => {
for (const desktop of desktopManager.getDesktops(desktops, changedActivities)) {
desktop.onPinsChanged();
}
});
oldActivities = kwinClient.activities;
});
return manager;
}
}
}

View File

@@ -0,0 +1,168 @@
namespace ClientState {
export class Tiled implements State {
public readonly window: Window;
private readonly signalManager: SignalManager;
constructor(world: World, client: ClientWrapper, grid: Grid) {
Tiled.prepareClientForTiling(client, grid.config);
const column = new Column(grid, grid.getLastFocusedColumn() ?? grid.getLastColumn());
const window = new Window(client, column);
this.window = window;
this.signalManager = Tiled.initSignalManager(world, window);
}
public destroy(passFocus: boolean) {
this.signalManager.destroy();
const window = this.window;
const grid = window.column.grid;
const client = window.client;
window.destroy(passFocus);
Tiled.restoreClientAfterTiling(client, grid.config, grid.desktop.clientArea);
}
private static initSignalManager(world: World, window: Window) {
const client = window.client;
const kwinClient = client.kwinClient;
const manager = new SignalManager();
manager.connect(kwinClient.desktopChanged, () => {
world.do((clientManager, desktopManager) => {
if (kwinClient.desktop === -1) {
// windows on all desktops are not supported
clientManager.untileClient(kwinClient);
return;
}
Tiled.moveWindowToCorrectGrid(desktopManager, window);
});
});
manager.connect(kwinClient.activitiesChanged, () => {
world.do((clientManager, desktopManager) => {
if (kwinClient.activities.length !== 1) {
// windows on multiple activities are not supported
clientManager.untileClient(kwinClient);
return;
}
Tiled.moveWindowToCorrectGrid(desktopManager, window);
});
})
let lastResize = false;
manager.connect(kwinClient.moveResizedChanged, () => {
world.do((clientManager, desktopManager) => {
if (kwinClient.move) {
if (world.untileOnDrag) {
clientManager.untileClient(kwinClient);
}
return;
}
const grid = window.column.grid;
const resize = kwinClient.resize;
if (!lastResize && resize) {
grid.onUserResizeStarted();
}
if (lastResize && !resize) {
grid.onUserResizeFinished();
}
lastResize = resize;
});
});
let cursorChangedAfterResizeStart = false;
manager.connect(kwinClient.moveResizeCursorChanged, () => {
cursorChangedAfterResizeStart = true;
});
manager.connect(kwinClient.clientStartUserMovedResized, () => {
cursorChangedAfterResizeStart = false;
});
manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QRect) => {
// on Wayland, this fires after `tileChanged`
if (kwinClient.tile !== null) {
world.do((clientManager, desktopManager) => {
clientManager.pinClient(kwinClient);
});
return;
}
const newGeometry = client.kwinClient.frameGeometry;
const oldCenterX = oldGeometry.x + oldGeometry.width/2;
const oldCenterY = oldGeometry.y + oldGeometry.height/2;
const newCenterX = newGeometry.x + newGeometry.width/2;
const newCenterY = newGeometry.y + newGeometry.height/2;
const dx = Math.round(newCenterX - oldCenterX);
const dy = Math.round(newCenterY - oldCenterY);
if (dx !== 0 || dy !== 0) {
client.moveTransients(dx, dy);
}
if (kwinClient.resize) {
world.do(() => window.onUserResize(oldGeometry, !cursorChangedAfterResizeStart));
} else if (
!client.isManipulatingGeometry(newGeometry) &&
!Clients.isMaximizedGeometry(kwinClient) &&
!Clients.isFullScreenGeometry(kwinClient) // not using `kwinClient.fullScreen` because it may not be set yet at this point
) {
world.do(() => window.onFrameGeometryChanged());
}
});
manager.connect(kwinClient.fullScreenChanged, () => {
world.do(() => window.onFullScreenChanged(kwinClient.fullScreen));
});
manager.connect(kwinClient.tileChanged, () => {
// on X11, this fires after `frameGeometryChanged`
if (kwinClient.tile !== null) {
world.do((clientManager, desktopManager) => {
clientManager.pinClient(kwinClient);
});
}
});
return manager;
}
private static moveWindowToCorrectGrid(desktopManager: DesktopManager, window: Window) {
const kwinClient = window.client.kwinClient;
const oldGrid = window.column.grid;
const newGrid = desktopManager.getDesktopForClient(kwinClient).grid;
if (oldGrid === newGrid) {
// window already on the correct grid
return;
}
const newColumn = new Column(newGrid, newGrid.getLastFocusedColumn() ?? newGrid.getLastColumn());
window.moveToColumn(newColumn);
}
private static prepareClientForTiling(client: ClientWrapper, config: LayoutConfig) {
if (config.tiledKeepBelow) {
client.kwinClient.keepBelow = true;
}
client.setFullScreen(false);
if (client.kwinClient.tile !== null) {
client.setMaximize(false, true); // disable quick tile mode
}
client.setMaximize(false, false);
}
private static restoreClientAfterTiling(client: ClientWrapper, config: LayoutConfig, screenSize: QRect) {
if (config.tiledKeepBelow) {
client.kwinClient.keepBelow = false;
}
client.setShade(false);
client.setFullScreen(false);
if (client.kwinClient.tile === null) {
client.setMaximize(false, false);
}
client.ensureVisible(screenSize);
}
}
}

View File

@@ -0,0 +1,5 @@
namespace ClientState {
export class TiledMinimized implements State {
public destroy(passFocus: boolean) {}
}
}