4 Commits
v0.8 ... kwin5

Author SHA1 Message Date
Peter Fajdiga
21eacd7ba4 Makefile: package: rename package dir to karousel 2024-10-27 14:44:35 +01:00
Peter Fajdiga
5004417285 bump package to 0.7.2 2024-10-27 13:51:52 +01:00
Peter Fajdiga
a110aee7ce ClientWrapper: implement workaround for Qt5 JS bug 2024-09-10 23:33:56 +02:00
Peter Fajdiga
817ea64171 DesktopManager: fix getDesktopForClient 2024-08-30 12:14:40 +02:00
28 changed files with 433 additions and 511 deletions

View File

@@ -11,13 +11,13 @@ build:
tsc --outFile ./package/contents/code/main.js tsc --outFile ./package/contents/code/main.js
install: build config install: build config
kpackagetool6 --type=KWin/Script -i ./package || kpackagetool6 --type=KWin/Script -u ./package kpackagetool5 --type=KWin/Script -i ./package || kpackagetool5 --type=KWin/Script -u ./package
uninstall: uninstall:
kpackagetool6 --type=KWin/Script -r karousel kpackagetool5 --type=KWin/Script -r ./package
package: build config package: build config
tar -czf ./karousel_${subst .,_,${VERSION}}.tar.gz ./package tar -czf ./karousel_${subst .,_,${VERSION}}.tar.gz ./package --transform s/package/karousel/
logs: logs:
journalctl -t kwin_x11 -g '^qml:|^file://.*karousel' -f journalctl -t kwin_x11 -g '^qml:|^file://.*karousel' -f

View File

@@ -3,6 +3,7 @@ type KeyBinding = {
description: string; description: string;
comment?: string; comment?: string;
defaultKeySequence: string; defaultKeySequence: string;
action: string;
} }
type NumKeyBinding = { type NumKeyBinding = {
@@ -11,6 +12,7 @@ type NumKeyBinding = {
comment?: string; comment?: string;
defaultModifiers: string; defaultModifiers: string;
fKeys: boolean; fKeys: boolean;
action: string;
} }
function formatComment(comment: string | undefined) { function formatComment(comment: string | undefined) {

View File

@@ -1,7 +1,7 @@
import QtQuick 6.0 import QtQuick 2.15
import org.kde.kwin 3.0 import org.kde.kwin 3.0
import org.kde.notification 1.0 import org.kde.notification 1.0
import "../code/main.js" as Karousel import "./main.js" as Karousel
Item { Item {
id: qmlBase id: qmlBase

View File

@@ -1,5 +1,4 @@
{ {
"KPackageStructure": "KWin/Script",
"KPlugin": { "KPlugin": {
"Name": "Karousel", "Name": "Karousel",
"Description": "Scrollable tiling extension for KWin", "Description": "Scrollable tiling extension for KWin",
@@ -9,13 +8,13 @@
"Name": "Peter Fajdiga" "Name": "Peter Fajdiga"
}], }],
"Id": "karousel", "Id": "karousel",
"Version": "0.8", "ServiceTypes": ["KWin/Script"],
"Version": "0.7.2",
"License": "GPLv3", "License": "GPLv3",
"Website": "https://github.com/peterfajdiga/karousel", "Website": "https://github.com/peterfajdiga/karousel",
"BugReportUrl": "https://github.com/peterfajdiga/karousel/issues" "BugReportUrl": "https://github.com/peterfajdiga/karousel/issues"
}, },
"X-Plasma-API": "declarativescript", "X-Plasma-API": "declarativescript",
"X-Plasma-API-Minimum-Version": "6.0", "X-Plasma-MainScript": "code/main.qml",
"X-Plasma-MainScript": "ui/main.qml",
"X-KDE-ConfigModule": "kwin/effects/configs/kcm_kwin4_genericscripted" "X-KDE-ConfigModule": "kwin/effects/configs/kcm_kwin4_genericscripted"
} }

View File

@@ -1,7 +1,7 @@
namespace Actions { namespace Actions {
export function getAction(world: World, config: Config, name: string) { export function init(world: World, config: Config) {
switch (name) { return {
case "focus-left": return () => { focusLeft: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const prevColumn = grid.getPrevColumn(column); const prevColumn = grid.getPrevColumn(column);
if (prevColumn === null) { if (prevColumn === null) {
@@ -9,9 +9,9 @@ namespace Actions {
} }
prevColumn.focus(); prevColumn.focus();
}); });
}; },
case "focus-right": return () => { focusRight: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const nextColumn = grid.getNextColumn(column); const nextColumn = grid.getNextColumn(column);
if (nextColumn === null) { if (nextColumn === null) {
@@ -19,9 +19,9 @@ namespace Actions {
} }
nextColumn.focus(); nextColumn.focus();
}); });
}; },
case "focus-up": return () => { focusUp: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const prevWindow = column.getPrevWindow(window); const prevWindow = column.getPrevWindow(window);
if (prevWindow === null) { if (prevWindow === null) {
@@ -29,9 +29,9 @@ namespace Actions {
} }
prevWindow.focus(); prevWindow.focus();
}); });
}; },
case "focus-down": return () => { focusDown: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const nextWindow = column.getNextWindow(window); const nextWindow = column.getNextWindow(window);
if (nextWindow === null) { if (nextWindow === null) {
@@ -39,9 +39,9 @@ namespace Actions {
} }
nextWindow.focus(); nextWindow.focus();
}); });
}; },
case "focus-start": return () => { focusStart: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const firstColumn = grid.getFirstColumn(); const firstColumn = grid.getFirstColumn();
@@ -50,9 +50,9 @@ namespace Actions {
} }
firstColumn.focus(); firstColumn.focus();
}); });
}; },
case "focus-end": return () => { focusEnd: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const lastColumn = grid.getLastColumn(); const lastColumn = grid.getLastColumn();
@@ -61,9 +61,9 @@ namespace Actions {
} }
lastColumn.focus(); lastColumn.focus();
}); });
}; },
case "window-move-left": return () => { windowMoveLeft: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
if (column.getWindowCount() === 1) { if (column.getWindowCount() === 1) {
// move from own column into existing column // move from own column into existing column
@@ -79,9 +79,9 @@ namespace Actions {
window.moveToColumn(newColumn); window.moveToColumn(newColumn);
} }
}); });
}; },
case "window-move-right": return () => { windowMoveRight: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
if (column.getWindowCount() === 1) { if (column.getWindowCount() === 1) {
// move from own column into existing column // move from own column into existing column
@@ -97,100 +97,100 @@ namespace Actions {
window.moveToColumn(newColumn); window.moveToColumn(newColumn);
} }
}); });
}; },
case "window-move-up": return () => { windowMoveUp: () => {
// TODO (optimization): only arrange moved windows // TODO (optimization): only arrange moved windows
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
column.moveWindowUp(window); column.moveWindowUp(window);
}); });
}; },
case "window-move-down": return () => { windowMoveDown: () => {
// TODO (optimization): only arrange moved windows // TODO (optimization): only arrange moved windows
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
column.moveWindowDown(window); column.moveWindowDown(window);
}); });
}; },
case "window-move-start": return () => { windowMoveStart: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const newColumn = new Column(grid, null); const newColumn = new Column(grid, null);
window.moveToColumn(newColumn); window.moveToColumn(newColumn);
}); });
}; },
case "window-move-end": return () => { windowMoveEnd: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const newColumn = new Column(grid, grid.getLastColumn()); const newColumn = new Column(grid, grid.getLastColumn());
window.moveToColumn(newColumn); window.moveToColumn(newColumn);
}); });
}; },
case "window-toggle-floating": return () => { windowToggleFloating: () => {
const kwinClient = Workspace.activeWindow; const kwinClient = workspace.activeClient;
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
clientManager.toggleFloatingClient(kwinClient); clientManager.toggleFloatingClient(kwinClient);
}); });
}; },
case "column-move-left": return () => { columnMoveLeft: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
grid.moveColumnLeft(column); grid.moveColumnLeft(column);
}); });
}; },
case "column-move-right": return () => { columnMoveRight: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
grid.moveColumnRight(column); grid.moveColumnRight(column);
}); });
}; },
case "column-move-start": return () => { columnMoveStart: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
column.moveAfter(null); column.moveAfter(null);
}); });
}; },
case "column-move-end": return () => { columnMoveEnd: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
column.moveAfter(grid.getLastColumn()); column.moveAfter(grid.getLastColumn());
}); });
}; },
case "column-toggle-stacked": return () => { columnToggleStacked: () => {
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
column.toggleStacked(); column.toggleStacked();
}); });
}; },
case "column-width-increase": return () => { columnWidthIncrease: () => {
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
config.columnResizer.increaseWidth(column, config.manualResizeStep); config.columnResizer.increaseWidth(column, config.manualResizeStep);
}); });
}; },
case "column-width-decrease": return () => { columnWidthDecrease: () => {
world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(false, (clientManager, desktopManager, window, column, grid) => {
config.columnResizer.decreaseWidth(column, config.manualResizeStep); config.columnResizer.decreaseWidth(column, config.manualResizeStep);
}); });
}; },
case "columns-width-equalize": return () => { columnsWidthEqualize: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
desktopManager.getCurrentDesktop().equalizeVisibleColumnsWidths(); desktopManager.getCurrentDesktop().equalizeVisibleColumnsWidths();
}); });
}; },
case "grid-scroll-left": return () => { gridScrollLeft: () => {
gridScroll(world, -config.manualScrollStep); gridScroll(world, -config.manualScrollStep);
}; },
case "grid-scroll-right": return () => { gridScrollRight: () => {
gridScroll(world, config.manualScrollStep); gridScroll(world, config.manualScrollStep);
}; },
case "grid-scroll-start": return () => { gridScrollStart: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const firstColumn = grid.getFirstColumn(); const firstColumn = grid.getFirstColumn();
@@ -199,9 +199,9 @@ namespace Actions {
} }
grid.desktop.scrollToColumn(firstColumn); grid.desktop.scrollToColumn(firstColumn);
}); });
}; },
case "grid-scroll-end": return () => { gridScrollEnd: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const lastColumn = grid.getLastColumn(); const lastColumn = grid.getLastColumn();
@@ -210,15 +210,15 @@ namespace Actions {
} }
grid.desktop.scrollToColumn(lastColumn); grid.desktop.scrollToColumn(lastColumn);
}); });
}; },
case "grid-scroll-focused": return () => { gridScrollFocused: () => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
grid.desktop.scrollCenterRange(column); grid.desktop.scrollCenterRange(column);
}) })
}; },
case "grid-scroll-left-column": return () => { gridScrollLeftColumn: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true); const column = grid.getLeftmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
@@ -233,9 +233,9 @@ namespace Actions {
grid.desktop.scrollToColumn(prevColumn); grid.desktop.scrollToColumn(prevColumn);
}); });
}; },
case "grid-scroll-right-column": return () => { gridScrollRightColumn: () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true); const column = grid.getRightmostVisibleColumn(grid.desktop.getCurrentVisibleRange(), true);
@@ -250,15 +250,13 @@ namespace Actions {
grid.desktop.scrollToColumn(nextColumn); grid.desktop.scrollToColumn(nextColumn);
}); });
}; },
};
default: throw new Error("unknown action: " + name);
}
} }
export function getNumAction(world: World, name: string) { export function initNum(world: World) {
switch (name) { return {
case "focus-": return (columnIndex: number) => { focusColumn: (columnIndex: number) => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const grid = desktopManager.getCurrentDesktop().grid; const grid = desktopManager.getCurrentDesktop().grid;
const targetColumn = grid.getColumnAtIndex(columnIndex); const targetColumn = grid.getColumnAtIndex(columnIndex);
@@ -267,9 +265,9 @@ namespace Actions {
} }
targetColumn.focus(); targetColumn.focus();
}); });
}; },
case "window-move-to-column-": return (columnIndex: number) => { windowMoveToColumn: (columnIndex: number) => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const targetColumn = grid.getColumnAtIndex(columnIndex); const targetColumn = grid.getColumnAtIndex(columnIndex);
if (targetColumn === null) { if (targetColumn === null) {
@@ -278,9 +276,9 @@ namespace Actions {
window.moveToColumn(targetColumn); window.moveToColumn(targetColumn);
grid.desktop.autoAdjustScroll(); grid.desktop.autoAdjustScroll();
}); });
}; },
case "column-move-to-column-": return (columnIndex: number) => { columnMoveToColumn: (columnIndex: number) => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => {
const targetColumn = grid.getColumnAtIndex(columnIndex); const targetColumn = grid.getColumnAtIndex(columnIndex);
if (targetColumn === null || targetColumn === column) { if (targetColumn === null || targetColumn === column) {
@@ -292,38 +290,30 @@ namespace Actions {
column.moveAfter(grid.getPrevColumn(targetColumn)); column.moveAfter(grid.getPrevColumn(targetColumn));
} }
}); });
}; },
case "column-move-to-desktop-": return (desktopIndex: number) => { columnMoveToDesktop: (desktopIndex: number) => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
const kwinDesktop = Workspace.desktops[desktopIndex]; const desktopNumber = desktopIndex + 1;
if (kwinDesktop === undefined) { const newGrid = desktopManager.getDesktopInCurrentActivity(desktopNumber).grid;
return;
}
const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid;
if (newGrid === null || newGrid === oldGrid) { if (newGrid === null || newGrid === oldGrid) {
return; return;
} }
column.moveToGrid(newGrid, newGrid.getLastColumn()); column.moveToGrid(newGrid, newGrid.getLastColumn());
}); });
}; },
case "tail-move-to-desktop-": return (desktopIndex: number) => { tailMoveToDesktop: (desktopIndex: number) => {
world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => { world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => {
const kwinDesktop = Workspace.desktops[desktopIndex]; const desktopNumber = desktopIndex + 1;
if (kwinDesktop === undefined) { const newGrid = desktopManager.getDesktopInCurrentActivity(desktopNumber).grid;
return;
}
const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid;
if (newGrid === null || newGrid === oldGrid) { if (newGrid === null || newGrid === oldGrid) {
return; return;
} }
oldGrid.evacuateTail(newGrid, column); oldGrid.evacuateTail(newGrid, column);
}); });
}; },
};
default: throw new Error("unknown num action: " + name);
}
} }
function gridScroll(world: World, amount: number) { function gridScroll(world: World, amount: number) {

67
src/extern/kwin.d.ts vendored
View File

@@ -1,28 +1,28 @@
declare const KWin: { declare const KWin: {
readConfig(key: string, defaultValue: any): any; readConfig(key: string, defaultValue: any): any;
registerShortcut(name: string, description: string, keySequence: string, callback: () => void): void;
}; };
declare const Workspace: { declare const workspace: {
readonly activities: string[]; readonly desktops: number;
readonly desktops: KwinDesktop[]; readonly currentDesktop: number;
readonly currentDesktop: KwinDesktop;
readonly currentActivity: string; readonly currentActivity: string;
readonly activeScreen: Output;
readonly windows: KwinClient[];
readonly cursorPos: QmlPoint;
activeWindow: KwinClient; activeClient: KwinClient;
readonly currentDesktopChanged: QSignal<[]> readonly currentDesktopChanged: QSignal<[]>
readonly windowAdded: QSignal<[KwinClient]>; readonly clientAdded: QSignal<[KwinClient]>;
readonly windowRemoved: QSignal<[KwinClient]>; readonly clientRemoved: QSignal<[KwinClient]>;
readonly windowActivated: QSignal<[KwinClient]>; readonly clientMinimized: QSignal<[KwinClient]>;
readonly desktopsChanged: QSignal<[]>; readonly clientUnminimized: QSignal<[KwinClient]>;
readonly activitiesChanged: QSignal<[]>; readonly clientMaximizeSet: QSignal<[KwinClient, horizontally: boolean, vertically: boolean]>;
readonly clientActivated: QSignal<[KwinClient]>;
readonly numberDesktopsChanged: QSignal<[]>;
readonly currentActivityChanged: QSignal<[]>; readonly currentActivityChanged: QSignal<[]>;
readonly virtualScreenSizeChanged: QSignal<[]>; readonly virtualScreenSizeChanged: QSignal<[]>;
clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop); clientArea(option: ClientAreaOption, screenNumber: number, desktopNumber: number);
clientList(): KwinClient[];
}; };
const enum ClientAreaOption { const enum ClientAreaOption {
@@ -36,15 +36,7 @@ const enum ClientAreaOption {
ScreenArea, ScreenArea,
} }
const enum MaximizedMode {
Unmaximized,
Vertically,
Horizontally,
Maximized,
}
type Tile = unknown; type Tile = unknown;
type Output = unknown;
interface KwinClient { interface KwinClient {
readonly shadeable: boolean; readonly shadeable: boolean;
@@ -54,17 +46,14 @@ interface KwinClient {
readonly transientFor: KwinClient; readonly transientFor: KwinClient;
readonly move: boolean; readonly move: boolean;
readonly resize: boolean; readonly resize: boolean;
readonly moveable: boolean;
readonly resizeable: boolean; readonly resizeable: boolean;
readonly fullScreenable: boolean; readonly screen: number;
readonly maximizable: boolean;
readonly output: Output;
readonly resourceClass: QByteArray; readonly resourceClass: QByteArray;
readonly dock: boolean; readonly dock: boolean;
readonly normalWindow: boolean; readonly normalWindow: boolean;
readonly managed: boolean; readonly managed: boolean;
readonly popupWindow: boolean;
opacity: number;
fullScreen: boolean; fullScreen: boolean;
activities: string[]; // empty array means all activities activities: string[]; // empty array means all activities
skipSwitcher: boolean; skipSwitcher: boolean;
@@ -73,30 +62,18 @@ interface KwinClient {
shade: boolean; shade: boolean;
minimized: boolean; minimized: boolean;
frameGeometry: QmlRect; frameGeometry: QmlRect;
desktops: KwinDesktop[]; // empty array means all desktops desktop: number; // -1 means all desktops
tile: Tile; tile: Tile;
opacity: number;
readonly fullScreenChanged: QSignal<[]>; readonly fullScreenChanged: QSignal<[]>;
readonly desktopsChanged: QSignal<[]>; readonly desktopChanged: QSignal<[]>;
readonly activitiesChanged: QSignal<[]>; readonly activitiesChanged: QSignal<[]>;
readonly minimizedChanged: QSignal<[]>;
readonly maximizedChanged: QSignal<[]>
readonly maximizedAboutToChange: QSignal<[MaximizedMode]>
readonly captionChanged: QSignal<[]>; readonly captionChanged: QSignal<[]>;
readonly tileChanged: QSignal<[]>; readonly tileChanged: QSignal<[]>;
readonly interactiveMoveResizeStarted: QSignal<[]>; readonly moveResizedChanged: QSignal<[]>;
readonly interactiveMoveResizeFinished: QSignal<[]>; readonly moveResizeCursorChanged: QSignal<[]>;
readonly frameGeometryChanged: QSignal<[oldGeometry: QmlRect]>; readonly clientStartUserMovedResized: QSignal<[]>;
readonly frameGeometryChanged: QSignal<[KwinClient, oldGeometry: QmlRect]>;
setMaximize(vertically: boolean, horizontally: boolean): void; setMaximize(vertically: boolean, horizontally: boolean): void;
} }
interface KwinDesktop {
readonly id: string;
}
type ShortcutHandler = {
readonly activated: QSignal<[]>;
destroy(): void;
};

5
src/extern/qt.d.ts vendored
View File

@@ -13,11 +13,6 @@ type QmlObject = unknown;
type QByteArray = string; type QByteArray = string;
type QmlPoint = {
x: number;
y: number;
}
type QmlRect = { type QmlRect = {
x: number; x: number;
y: number; y: number;

View File

@@ -3,148 +3,176 @@ const keyBindings: KeyBinding[] = [
name: "window-toggle-floating", name: "window-toggle-floating",
description: "Toggle floating", description: "Toggle floating",
defaultKeySequence: "Meta+Space", defaultKeySequence: "Meta+Space",
action: "windowToggleFloating",
}, },
{ {
name: "focus-left", name: "focus-left",
description: "Move focus left", description: "Move focus left",
defaultKeySequence: "Meta+A", defaultKeySequence: "Meta+A",
action: "focusLeft",
}, },
{ {
name: "focus-right", name: "focus-right",
description: "Move focus right", description: "Move focus right",
comment: "Clashes with default KDE shortcuts, may require manual remapping", comment: "Clashes with default KDE shortcuts, may require manual remapping",
defaultKeySequence: "Meta+D", defaultKeySequence: "Meta+D",
action: "focusRight",
}, },
{ {
name: "focus-up", name: "focus-up",
description: "Move focus up", description: "Move focus up",
comment: "Clashes with default KDE shortcuts, may require manual remapping", comment: "Clashes with default KDE shortcuts, may require manual remapping",
defaultKeySequence: "Meta+W", defaultKeySequence: "Meta+W",
action: "focusUp",
}, },
{ {
name: "focus-down", name: "focus-down",
description: "Move focus down", description: "Move focus down",
comment: "Clashes with default KDE shortcuts, may require manual remapping", comment: "Clashes with default KDE shortcuts, may require manual remapping",
defaultKeySequence: "Meta+S", defaultKeySequence: "Meta+S",
action: "focusDown",
}, },
{ {
name: "focus-start", name: "focus-start",
description: "Move focus to start", description: "Move focus to start",
defaultKeySequence: "Meta+Home", defaultKeySequence: "Meta+Home",
action: "focusStart",
}, },
{ {
name: "focus-end", name: "focus-end",
description: "Move focus to end", description: "Move focus to end",
defaultKeySequence: "Meta+End", defaultKeySequence: "Meta+End",
action: "focusEnd",
}, },
{ {
name: "window-move-left", name: "window-move-left",
description: "Move window left", description: "Move window left",
comment: "Moves window out of and into columns", comment: "Moves window out of and into columns",
defaultKeySequence: "Meta+Shift+A", defaultKeySequence: "Meta+Shift+A",
action: "windowMoveLeft",
}, },
{ {
name: "window-move-right", name: "window-move-right",
description: "Move window right", description: "Move window right",
comment: "Moves window out of and into columns", comment: "Moves window out of and into columns",
defaultKeySequence: "Meta+Shift+D", defaultKeySequence: "Meta+Shift+D",
action: "windowMoveRight",
}, },
{ {
name: "window-move-up", name: "window-move-up",
description: "Move window up", description: "Move window up",
defaultKeySequence: "Meta+Shift+W", defaultKeySequence: "Meta+Shift+W",
action: "windowMoveUp",
}, },
{ {
name: "window-move-down", name: "window-move-down",
description: "Move window down", description: "Move window down",
defaultKeySequence: "Meta+Shift+S", defaultKeySequence: "Meta+Shift+S",
action: "windowMoveDown",
}, },
{ {
name: "window-move-start", name: "window-move-start",
description: "Move window to start", description: "Move window to start",
defaultKeySequence: "Meta+Shift+Home", defaultKeySequence: "Meta+Shift+Home",
action: "windowMoveStart",
}, },
{ {
name: "window-move-end", name: "window-move-end",
description: "Move window to end", description: "Move window to end",
defaultKeySequence: "Meta+Shift+End", defaultKeySequence: "Meta+Shift+End",
action: "windowMoveEnd",
}, },
{ {
name: "column-toggle-stacked", name: "column-toggle-stacked",
description: "Toggle stacked layout for focused column", description: "Toggle stacked layout for focused column",
comment: "One window in the column visible, others shaded; not supported on Wayland", comment: "One window in the column visible, others shaded; not supported on Wayland",
defaultKeySequence: "Meta+X", defaultKeySequence: "Meta+X",
action: "columnToggleStacked",
}, },
{ {
name: "column-move-left", name: "column-move-left",
description: "Move column left", description: "Move column left",
defaultKeySequence: "Meta+Ctrl+Shift+A", defaultKeySequence: "Meta+Ctrl+Shift+A",
action: "columnMoveLeft",
}, },
{ {
name: "column-move-right", name: "column-move-right",
description: "Move column right", description: "Move column right",
defaultKeySequence: "Meta+Ctrl+Shift+D", defaultKeySequence: "Meta+Ctrl+Shift+D",
action: "columnMoveRight",
}, },
{ {
name: "column-move-start", name: "column-move-start",
description: "Move column to start", description: "Move column to start",
defaultKeySequence: "Meta+Ctrl+Shift+Home", defaultKeySequence: "Meta+Ctrl+Shift+Home",
action: "columnMoveStart",
}, },
{ {
name: "column-move-end", name: "column-move-end",
description: "Move column to end", description: "Move column to end",
defaultKeySequence: "Meta+Ctrl+Shift+End", defaultKeySequence: "Meta+Ctrl+Shift+End",
action: "columnMoveEnd",
}, },
{ {
name: "column-width-increase", name: "column-width-increase",
description: "Increase column width", description: "Increase column width",
defaultKeySequence: "Meta+Ctrl++", defaultKeySequence: "Meta+Ctrl++",
action: "columnWidthIncrease",
}, },
{ {
name: "column-width-decrease", name: "column-width-decrease",
description: "Decrease column width", description: "Decrease column width",
defaultKeySequence: "Meta+Ctrl+-", defaultKeySequence: "Meta+Ctrl+-",
action: "columnWidthDecrease",
}, },
{ {
name: "columns-width-equalize", name: "columns-width-equalize",
description: "Equalize widths of visible columns", description: "Equalize widths of visible columns",
defaultKeySequence: "Meta+Ctrl+X", defaultKeySequence: "Meta+Ctrl+X",
action: "columnsWidthEqualize",
}, },
{ {
name: "grid-scroll-focused", name: "grid-scroll-focused",
description: "Center focused window", description: "Center focused window",
comment: "Scrolls so that the focused window is centered in the screen", comment: "Scrolls so that the focused window is centered in the screen",
defaultKeySequence: "Meta+Alt+Return", defaultKeySequence: "Meta+Alt+Return",
action: "gridScrollFocused",
}, },
{ {
name: "grid-scroll-left-column", name: "grid-scroll-left-column",
description: "Scroll one column to the left", description: "Scroll one column to the left",
defaultKeySequence: "Meta+Alt+A", defaultKeySequence: "Meta+Alt+A",
action: "gridScrollLeftColumn",
}, },
{ {
name: "grid-scroll-right-column", name: "grid-scroll-right-column",
description: "Scroll one column to the right", description: "Scroll one column to the right",
defaultKeySequence: "Meta+Alt+D", defaultKeySequence: "Meta+Alt+D",
action: "gridScrollRightColumn",
}, },
{ {
name: "grid-scroll-left", name: "grid-scroll-left",
description: "Scroll left", description: "Scroll left",
defaultKeySequence: "Meta+Alt+PgUp", defaultKeySequence: "Meta+Alt+PgUp",
action: "gridScrollLeft",
}, },
{ {
name: "grid-scroll-right", name: "grid-scroll-right",
description: "Scroll right", description: "Scroll right",
defaultKeySequence: "Meta+Alt+PgDown", defaultKeySequence: "Meta+Alt+PgDown",
action: "gridScrollRight",
}, },
{ {
name: "grid-scroll-start", name: "grid-scroll-start",
description: "Scroll to start", description: "Scroll to start",
defaultKeySequence: "Meta+Alt+Home", defaultKeySequence: "Meta+Alt+Home",
action: "gridScrollStart",
}, },
{ {
name: "grid-scroll-end", name: "grid-scroll-end",
description: "Scroll to end", description: "Scroll to end",
defaultKeySequence: "Meta+Alt+End", defaultKeySequence: "Meta+Alt+End",
action: "gridScrollEnd",
}, },
]; ];
@@ -155,6 +183,7 @@ const numKeyBindings: NumKeyBinding[] = [
comment: "Clashes with default KDE shortcuts, may require manual remapping", comment: "Clashes with default KDE shortcuts, may require manual remapping",
defaultModifiers: "Meta", defaultModifiers: "Meta",
fKeys: false, fKeys: false,
action: "focusColumn",
}, },
{ {
name: "window-move-to-column-", name: "window-move-to-column-",
@@ -162,6 +191,7 @@ const numKeyBindings: NumKeyBinding[] = [
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!", comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!",
defaultModifiers: "Meta+Shift", defaultModifiers: "Meta+Shift",
fKeys: false, fKeys: false,
action: "windowMoveToColumn",
}, },
{ {
name: "column-move-to-column-", name: "column-move-to-column-",
@@ -169,17 +199,20 @@ const numKeyBindings: NumKeyBinding[] = [
comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!", comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!",
defaultModifiers: "Meta+Ctrl+Shift", defaultModifiers: "Meta+Ctrl+Shift",
fKeys: false, fKeys: false,
action: "columnMoveToColumn",
}, },
{ {
name: "column-move-to-desktop-", name: "column-move-to-desktop-",
description: "Move column to desktop ", description: "Move column to desktop ",
defaultModifiers: "Meta+Ctrl+Shift", defaultModifiers: "Meta+Ctrl+Shift",
fKeys: true, fKeys: true,
action: "columnMoveToDesktop",
}, },
{ {
name: "tail-move-to-desktop-", name: "tail-move-to-desktop-",
description: "Move this and all following columns to desktop ", description: "Move this and all following columns to desktop ",
defaultModifiers: "Meta+Ctrl+Shift+Alt", defaultModifiers: "Meta+Ctrl+Shift+Alt",
fKeys: true, fKeys: true,
action: "tailMoveToDesktop",
}, },
]; ];

View File

@@ -3,6 +3,7 @@ type KeyBinding = {
description: string; description: string;
comment?: string; comment?: string;
defaultKeySequence: string; defaultKeySequence: string;
action: keyof ReturnType<typeof Actions.init>;
}; };
type NumKeyBinding = { type NumKeyBinding = {
@@ -11,6 +12,7 @@ type NumKeyBinding = {
comment?: string; comment?: string;
defaultModifiers: string; defaultModifiers: string;
fKeys: boolean; fKeys: boolean;
action: keyof ReturnType<typeof Actions.initNum>;
}; };
function catchWrap(f: () => void) { function catchWrap(f: () => void) {
@@ -24,44 +26,45 @@ function catchWrap(f: () => void) {
}; };
} }
function registerKeyBinding(world: World, config: Actions.Config, shortcutActions: ShortcutAction[], keyBinding: KeyBinding) { function registerKeyBinding(name: string, description: string, keySequence: string, callback: () => void) {
shortcutActions.push(new ShortcutAction( KWin.registerShortcut(
keyBinding, "karousel-" + name,
catchWrap(Actions.getAction(world, config, keyBinding.name)), "Karousel: " + description,
)); keySequence,
catchWrap(callback),
);
} }
function registerNumKeyBindings(world: World, shortcutActions: ShortcutAction[], numKeyBinding: NumKeyBinding) { function registerNumKeyBindings(name: string, description: string, modifiers: string, fKeys: boolean, callback: (i: number) => void) {
const numPrefix = numKeyBinding.fKeys ? "F" : ""; const numPrefix = fKeys ? "F" : "";
const n = numKeyBinding.fKeys ? 12 : 9; const n = fKeys ? 12 : 9;
for (let i = 0; i < 12; i++) { for (let i = 0; i < 12; i++) {
const numKey = String(i + 1); const numKey = String(i + 1);
const keySequence = i < n ? const keySequence = i < n ?
numKeyBinding.defaultModifiers + "+" + numPrefix + numKey : modifiers + "+" + numPrefix + numKey :
""; "";
const action = Actions.getNumAction(world, numKeyBinding.name); registerKeyBinding(
shortcutActions.push(new ShortcutAction( name + numKey,
{ description + numKey,
name: numKeyBinding.name + numKey, keySequence,
description: numKeyBinding.description + numKey, () => callback(i),
defaultKeySequence: keySequence, );
},
catchWrap(() => action(i)),
));
} }
} }
// TODO: refactor function registerKeyBindings(world: World, config: Config) {
function registerKeyBindings(world: World, config: Actions.Config) { const actions = Actions.init(world, {
const shortcutActions: ShortcutAction[] = []; manualScrollStep: config.manualScrollStep,
manualResizeStep: config.manualResizeStep,
columnResizer: config.scrollingCentered ? new RawResizer() : new ContextualResizer(),
});
for (const keyBinding of keyBindings) { for (const binding of keyBindings) {
registerKeyBinding(world, config, shortcutActions, keyBinding); registerKeyBinding(binding.name, binding.description, binding.defaultKeySequence, actions[binding.action]);
} }
for (const numKeyBinding of numKeyBindings) { const numActions = Actions.initNum(world);
registerNumKeyBindings(world, shortcutActions, numKeyBinding); for (const binding of numKeyBindings) {
registerNumKeyBindings(binding.name, binding.description, binding.defaultModifiers, binding.fKeys, numActions[binding.action]);
} }
return shortcutActions;
} }

View File

@@ -25,7 +25,7 @@ class Column {
this.grid = targetGrid; this.grid = targetGrid;
targetGrid.onColumnAdded(this, prevColumn); targetGrid.onColumnAdded(this, prevColumn);
for (const window of this.windows.iterator()) { for (const window of this.windows.iterator()) {
window.client.kwinClient.desktops = [targetGrid.desktop.kwinDesktop]; window.client.kwinClient.desktop = targetGrid.desktop.desktopNumber;
} }
} }
} }

View File

@@ -1,6 +1,6 @@
class Desktop { class Desktop {
public readonly grid: Grid; public readonly grid: Grid;
public readonly kwinDesktop: KwinDesktop; public readonly desktopNumber: number;
private readonly pinManager: PinManager; private readonly pinManager: PinManager;
private readonly config: Desktop.Config; private readonly config: Desktop.Config;
private scrollX: number; private scrollX: number;
@@ -10,26 +10,26 @@ class Desktop {
public clientArea: QmlRect; public clientArea: QmlRect;
public tilingArea: QmlRect; public tilingArea: QmlRect;
constructor(kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig) { constructor(desktopNumber: number, pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig) {
this.pinManager = pinManager; this.pinManager = pinManager;
this.config = config; this.config = config;
this.scrollX = 0; this.scrollX = 0;
this.dirty = true; this.dirty = true;
this.dirtyScroll = true; this.dirtyScroll = true;
this.dirtyPins = true; this.dirtyPins = true;
this.kwinDesktop = kwinDesktop; this.desktopNumber = desktopNumber;
this.grid = new Grid(this, layoutConfig); this.grid = new Grid(this, layoutConfig);
this.clientArea = Desktop.getClientArea(kwinDesktop); this.clientArea = Desktop.getClientArea(desktopNumber);
this.tilingArea = Desktop.getTilingArea(this.clientArea, kwinDesktop, pinManager, config); this.tilingArea = Desktop.getTilingArea(this.clientArea, desktopNumber, pinManager, config);
} }
private updateArea() { private updateArea() {
const newClientArea = Desktop.getClientArea(this.kwinDesktop); const newClientArea = Desktop.getClientArea(this.desktopNumber);
if (newClientArea === this.clientArea && !this.dirtyPins) { if (newClientArea === this.clientArea && !this.dirtyPins) {
return; return;
} }
this.clientArea = newClientArea; this.clientArea = newClientArea;
this.tilingArea = Desktop.getTilingArea(newClientArea, this.kwinDesktop, this.pinManager, this.config); this.tilingArea = Desktop.getTilingArea(newClientArea, this.desktopNumber, this.pinManager, this.config);
this.dirty = true; this.dirty = true;
this.dirtyScroll = true; this.dirtyScroll = true;
this.dirtyPins = false; this.dirtyPins = false;
@@ -37,12 +37,12 @@ class Desktop {
this.autoAdjustScroll(); this.autoAdjustScroll();
} }
private static getClientArea(kwinDesktop: KwinDesktop) { private static getClientArea(desktopNumber: number) {
return Workspace.clientArea(ClientAreaOption.PlacementArea, Workspace.activeScreen, kwinDesktop); return workspace.clientArea(ClientAreaOption.PlacementArea, 0, desktopNumber);
} }
private static getTilingArea(clientArea: QmlRect, kwinDesktop: KwinDesktop, pinManager: PinManager, config: Desktop.Config) { private static getTilingArea(clientArea: QmlRect, desktopNumber: number, pinManager: PinManager, config: Desktop.Config) {
const availableSpace = pinManager.getAvailableSpace(kwinDesktop, clientArea); const availableSpace = pinManager.getAvailableSpace(desktopNumber, clientArea);
const top = availableSpace.top + config.marginTop; const top = availableSpace.top + config.marginTop;
const bottom = availableSpace.bottom - config.marginBottom; const bottom = availableSpace.bottom - config.marginBottom;
const left = availableSpace.left + config.marginLeft; const left = availableSpace.left + config.marginLeft;

View File

@@ -10,7 +10,8 @@ class Window {
this.height = client.kwinClient.frameGeometry.height; this.height = client.kwinClient.frameGeometry.height;
this.focusedState = { this.focusedState = {
fullScreen: false, fullScreen: false,
maximizedMode: MaximizedMode.Unmaximized, maximizedHorizontally: false,
maximizedVertically: false,
}; };
this.skipArrange = false; this.skipArrange = false;
this.column = column; this.column = column;
@@ -36,11 +37,8 @@ class Window {
if (this.column.grid.config.reMaximize && this.isFocused()) { if (this.column.grid.config.reMaximize && this.isFocused()) {
// do this here rather than in `onFocused` to ensure it happens after placement // do this here rather than in `onFocused` to ensure it happens after placement
// (otherwise placement may not happen at all) // (otherwise placement may not happen at all)
if (this.focusedState.maximizedMode > MaximizedMode.Unmaximized) { if (this.focusedState.maximizedVertically || this.focusedState.maximizedHorizontally) {
this.client.setMaximize( this.client.setMaximize(this.focusedState.maximizedVertically, this.focusedState.maximizedHorizontally);
this.focusedState.maximizedMode === MaximizedMode.Horizontally || this.focusedState.maximizedMode === MaximizedMode.Maximized,
this.focusedState.maximizedMode === MaximizedMode.Vertically || this.focusedState.maximizedMode === MaximizedMode.Maximized,
);
maximized = true; maximized = true;
} }
if (this.focusedState.fullScreen) { if (this.focusedState.fullScreen) {
@@ -78,8 +76,8 @@ class Window {
this.column.grid.desktop.onLayoutChanged(); this.column.grid.desktop.onLayoutChanged();
} }
public onMaximizedChanged(maximizedMode: MaximizedMode) { public onMaximizedChanged(horizontally: boolean, vertically: boolean) {
const maximized = maximizedMode > MaximizedMode.Unmaximized; const maximized = horizontally || vertically;
this.skipArrange = maximized; this.skipArrange = maximized;
if (this.column.grid.config.tiledKeepBelow) { if (this.column.grid.config.tiledKeepBelow) {
this.client.kwinClient.keepBelow = !maximized; this.client.kwinClient.keepBelow = !maximized;
@@ -88,7 +86,8 @@ class Window {
this.client.kwinClient.keepAbove = maximized; this.client.kwinClient.keepAbove = maximized;
} }
if (this.isFocused()) { if (this.isFocused()) {
this.focusedState.maximizedMode = maximizedMode; this.focusedState.maximizedHorizontally = horizontally;
this.focusedState.maximizedVertically = vertically;
} }
this.column.grid.desktop.onLayoutChanged(); this.column.grid.desktop.onLayoutChanged();
} }
@@ -146,6 +145,7 @@ class Window {
namespace Window { namespace Window {
export type State = { export type State = {
fullScreen: boolean, fullScreen: boolean,
maximizedMode: MaximizedMode, maximizedHorizontally: boolean,
maximizedVertically: boolean,
} }
} }

View File

@@ -1,3 +1,6 @@
function init() { function init() {
return new World(loadConfig()); const config = loadConfig();
const world = new World(config);
registerKeyBindings(world, config);
return world;
} }

View File

@@ -33,9 +33,9 @@ class WindowRuleEnforcer {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const desktop = desktopManager.getDesktopForClient(kwinClient); const desktop = desktopManager.getDesktopForClient(kwinClient);
if (shouldTile && desktop !== undefined) { if (shouldTile && desktop !== undefined) {
clientManager.tileKwinClient(kwinClient, desktop.grid); clientManager.tileClient(kwinClient, desktop.grid);
} else { } else {
clientManager.floatKwinClient(kwinClient); clientManager.untileClient(kwinClient);
} }
}); });
}); });

View File

@@ -18,7 +18,7 @@ class Delayer {
function initQmlTimer() { function initQmlTimer() {
return Qt.createQmlObject( return Qt.createQmlObject(
`import QtQuick 6.0 `import QtQuick 2.15
Timer {}`, Timer {}`,
qmlBase qmlBase
); );

View File

@@ -1,25 +0,0 @@
class ShortcutAction {
private readonly shortcutHandler: ShortcutHandler;
constructor(keyBinding: KeyBinding, f: () => void) {
this.shortcutHandler = ShortcutAction.initShortcutHandler(keyBinding);
this.shortcutHandler.activated.connect(f);
}
public destroy() {
this.shortcutHandler.destroy();
}
private static initShortcutHandler(keyBinding: KeyBinding) {
return Qt.createQmlObject(
`import QtQuick 6.0
import org.kde.kwin 3.0
ShortcutHandler {
name: "karousel-${keyBinding.name}";
text: "Karousel: ${keyBinding.description}";
sequence: "${keyBinding.defaultKeySequence}";
}`,
qmlBase,
);
}
}

View File

@@ -1,23 +1,49 @@
function initWorkspaceSignalHandlers(world: World) { function initWorkspaceSignalHandlers(world: World) {
const manager = new SignalManager(); const manager = new SignalManager();
manager.connect(Workspace.windowAdded, (kwinClient: KwinClient) => { manager.connect(workspace.clientAdded, (kwinClient: KwinClient) => {
if (Clients.canTileEver(kwinClient)) { if (Clients.canTileEver(kwinClient)) {
// never open new tileable clients on all desktops or activities // never open new tileable clients on all desktops or activities
Clients.makeTileable(kwinClient); if (kwinClient.desktop <= 0) {
kwinClient.desktop = workspace.currentDesktop;
}
if (kwinClient.activities.length !== 1) {
kwinClient.activities = [workspace.currentActivity];
}
} }
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
clientManager.addClient(kwinClient) clientManager.addClient(kwinClient)
}); });
}); });
manager.connect(Workspace.windowRemoved, (kwinClient: KwinClient) => { manager.connect(workspace.clientRemoved, (kwinClient: KwinClient) => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
clientManager.removeClient(kwinClient, true); clientManager.removeClient(kwinClient, true);
}); });
}); });
manager.connect(Workspace.windowActivated, (kwinClient: KwinClient) => { 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, (clientManager, desktopManager, window, column, grid) => {
window.onMaximizedChanged(horizontally, vertically);
});
});
manager.connect(workspace.clientActivated, (kwinClient: KwinClient) => {
if (kwinClient === null) { if (kwinClient === null) {
return; return;
} }
@@ -26,27 +52,19 @@ function initWorkspaceSignalHandlers(world: World) {
}); });
}); });
manager.connect(Workspace.currentDesktopChanged, () => { manager.connect(workspace.currentDesktopChanged, () => {
world.do(() => {}); // re-arrange desktop world.do(() => {}); // re-arrange desktop
}); });
manager.connect(Workspace.currentActivityChanged, () => { manager.connect(workspace.currentActivityChanged, () => {
world.do(() => {}); // re-arrange desktop world.do(() => {}); // re-arrange desktop
}); });
manager.connect(Workspace.desktopsChanged, () => { manager.connect(workspace.numberDesktopsChanged, () => {
world.do((clientManager, desktopManager) => { world.updateDesktops();
desktopManager.updateDesktops();
})
}); });
manager.connect(Workspace.activitiesChanged, () => { manager.connect(workspace.virtualScreenSizeChanged, () => {
world.do((clientManager, desktopManager) => {
desktopManager.updateActivities();
})
});
manager.connect(Workspace.virtualScreenSizeChanged, () => {
world.onScreenResized(); world.onScreenResized();
}); });

View File

@@ -76,41 +76,44 @@ class ClientManager {
return; return;
} }
if (client.stateManager.getState() instanceof ClientState.Tiled) { if (client.stateManager.getState() instanceof ClientState.Tiled) {
client.stateManager.setState( client.stateManager.setState(() => new ClientState.TiledMinimized(), kwinClient === this.lastFocusedClient);
() => new ClientState.TiledMinimized(this.world, client),
kwinClient === this.lastFocusedClient,
);
} }
} }
public tileClient(client: ClientWrapper, grid: Grid) { public unminimizeClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientState.TiledMinimized) {
const desktop = this.desktopManager.getDesktopForClient(kwinClient);
if (desktop !== undefined) {
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, desktop.grid), false);
} else {
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, false), false);
}
}
}
public tileClient(kwinClient: KwinClient, grid: Grid) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
}
if (client.stateManager.getState() instanceof ClientState.Tiled) { if (client.stateManager.getState() instanceof ClientState.Tiled) {
return; return;
} }
client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false); client.stateManager.setState(() => new ClientState.Tiled(this.world, client, grid), false);
} }
public floatClient(client: ClientWrapper) { public untileClient(kwinClient: KwinClient) {
if (client.stateManager.getState() instanceof ClientState.Floating) {
return;
}
client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
}
public tileKwinClient(kwinClient: KwinClient, grid: Grid) {
const client = this.clientMap.get(kwinClient); const client = this.clientMap.get(kwinClient);
if (client === undefined) { if (client === undefined) {
return; return;
} }
this.tileClient(client, grid); if (client.stateManager.getState() instanceof ClientState.Tiled) {
} client.stateManager.setState(() => new ClientState.Floating(this.world, client, this.config, true), false);
public floatKwinClient(kwinClient: KwinClient) {
const client = this.clientMap.get(kwinClient);
if (client === undefined) {
return;
} }
this.floatClient(client);
} }
public pinClient(kwinClient: KwinClient) { public pinClient(kwinClient: KwinClient) {

View File

@@ -3,10 +3,8 @@ class ClientWrapper {
public readonly stateManager: ClientState.Manager; public readonly stateManager: ClientState.Manager;
public transientFor: ClientWrapper | null; public transientFor: ClientWrapper | null;
private readonly transients: ClientWrapper[]; private readonly transients: ClientWrapper[];
private readonly signalManager: SignalManager;
private readonly rulesSignalManager: SignalManager | null; private readonly rulesSignalManager: SignalManager | null;
public preferredWidth: number; public preferredWidth: number;
private maximizedMode: MaximizedMode | undefined;
private readonly manipulatingGeometry: Doer; private readonly manipulatingGeometry: Doer;
private lastPlacement: QmlRect | null; // workaround for issue #19 private lastPlacement: QmlRect | null; // workaround for issue #19
@@ -22,7 +20,6 @@ class ClientWrapper {
if (transientFor !== null) { if (transientFor !== null) {
transientFor.addTransient(this); transientFor.addTransient(this);
} }
this.signalManager = ClientWrapper.initSignalManager(this);
this.rulesSignalManager = rulesSignalManager; this.rulesSignalManager = rulesSignalManager;
this.preferredWidth = kwinClient.frameGeometry.width; this.preferredWidth = kwinClient.frameGeometry.width;
this.manipulatingGeometry = new Doer(); this.manipulatingGeometry = new Doer();
@@ -36,20 +33,21 @@ class ClientWrapper {
// window is being manually resized, prevent fighting with the user // window is being manually resized, prevent fighting with the user
return; return;
} }
this.lastPlacement = Qt.rect(x, y, width, height); const clientWrapper = this; // workaround for bug in Qt5's JS engine
this.kwinClient.frameGeometry = this.lastPlacement; clientWrapper.lastPlacement = Qt.rect(x, y, width, height);
if (this.kwinClient.frameGeometry !== this.lastPlacement) { clientWrapper.kwinClient.frameGeometry = clientWrapper.lastPlacement;
if (clientWrapper.kwinClient.frameGeometry !== clientWrapper.lastPlacement) {
// frameGeometry assignment failed. This sometimes happens on Wayland // frameGeometry assignment failed. This sometimes happens on Wayland
// when a window is off-screen, effectively making it stuck there. // when a window is off-screen, effectively making it stuck there.
this.kwinClient.frameGeometry.x = x; // This makes it unstuck. clientWrapper.kwinClient.frameGeometry.x = x; // This makes it unstuck.
this.kwinClient.frameGeometry = this.lastPlacement; clientWrapper.kwinClient.frameGeometry = clientWrapper.lastPlacement;
} }
}); });
} }
private moveTransient(dx: number, dy: number, kwinDesktops: KwinDesktop[]) { private moveTransient(dx: number, dy: number, desktopNumber: number) {
if (this.stateManager.getState() instanceof ClientState.Floating) { if (this.stateManager.getState() instanceof ClientState.Floating) {
if (Clients.isOnOneOfVirtualDesktops(this.kwinClient, kwinDesktops)) { if (this.kwinClient.desktop === desktopNumber) {
const frame = this.kwinClient.frameGeometry; const frame = this.kwinClient.frameGeometry;
this.kwinClient.frameGeometry = Qt.rect( this.kwinClient.frameGeometry = Qt.rect(
frame.x + dx, frame.x + dx,
@@ -60,52 +58,32 @@ class ClientWrapper {
} }
for (const transient of this.transients) { for (const transient of this.transients) {
transient.moveTransient(dx, dy, kwinDesktops); transient.moveTransient(dx, dy, desktopNumber);
} }
} }
} }
public moveTransients(dx: number, dy: number) { public moveTransients(dx: number, dy: number) {
for (const transient of this.transients) { for (const transient of this.transients) {
transient.moveTransient(dx, dy, this.kwinClient.desktops); transient.moveTransient(dx, dy, this.kwinClient.desktop);
} }
} }
public focus() { public focus() {
Workspace.activeWindow = this.kwinClient; workspace.activeClient = this.kwinClient;
} }
public isFocused() { public isFocused() {
return Workspace.activeWindow === this.kwinClient; return workspace.activeClient === this.kwinClient;
} }
public setMaximize(horizontally: boolean, vertically: boolean) { public setMaximize(horizontally: boolean, vertically: boolean) {
if (!this.kwinClient.maximizable) {
return;
}
if (this.maximizedMode === undefined) {
if (horizontally && vertically) {
this.maximizedMode = MaximizedMode.Maximized;
} else if (horizontally) {
this.maximizedMode = MaximizedMode.Horizontally;
} else if (vertically) {
this.maximizedMode = MaximizedMode.Vertically;
} else {
this.maximizedMode = MaximizedMode.Unmaximized;
}
}
this.manipulatingGeometry.do(() => { this.manipulatingGeometry.do(() => {
this.kwinClient.setMaximize(vertically, horizontally); this.kwinClient.setMaximize(vertically, horizontally);
}); });
} }
public setFullScreen(fullScreen: boolean) { public setFullScreen(fullScreen: boolean) {
if (!this.kwinClient.fullScreenable) {
return;
}
this.manipulatingGeometry.do(() => { this.manipulatingGeometry.do(() => {
this.kwinClient.fullScreen = fullScreen; this.kwinClient.fullScreen = fullScreen;
}); });
@@ -121,10 +99,6 @@ class ClientWrapper {
return this.kwinClient.shade; return this.kwinClient.shade;
} }
public getMaximizedMode() {
return this.maximizedMode;
}
public isManipulatingGeometry(newGeometry: QmlRect | null) { public isManipulatingGeometry(newGeometry: QmlRect | null) {
if (newGeometry !== null && newGeometry === this.lastPlacement) { if (newGeometry !== null && newGeometry === this.lastPlacement) {
return true; return true;
@@ -151,7 +125,7 @@ class ClientWrapper {
} }
public ensureVisible(screenSize: QmlRect) { public ensureVisible(screenSize: QmlRect) {
if (!Clients.isOnVirtualDesktop(this.kwinClient, Workspace.currentDesktop)) { if (this.kwinClient.desktop !== workspace.currentDesktop) {
return; return;
} }
const frame = this.kwinClient.frameGeometry; const frame = this.kwinClient.frameGeometry;
@@ -164,7 +138,6 @@ class ClientWrapper {
public destroy(passFocus: boolean) { public destroy(passFocus: boolean) {
this.stateManager.destroy(passFocus); this.stateManager.destroy(passFocus);
this.signalManager.destroy();
if (this.rulesSignalManager !== null) { if (this.rulesSignalManager !== null) {
this.rulesSignalManager.destroy(); this.rulesSignalManager.destroy();
} }
@@ -175,17 +148,4 @@ class ClientWrapper {
transient.transientFor = null; transient.transientFor = null;
} }
} }
private static initSignalManager(client: ClientWrapper) {
const manager = new SignalManager();
manager.connect(client.kwinClient.maximizedAboutToChange, (maximizedMode: MaximizedMode) => {
if (maximizedMode > MaximizedMode.Unmaximized && client.kwinClient.tile !== null) {
client.kwinClient.tile = null;
}
client.maximizedMode = maximizedMode;
});
return manager;
}
} }

View File

@@ -1,49 +1,35 @@
namespace Clients { namespace Clients {
export function canTileEver(kwinClient: KwinClient) { export function canTileEver(kwinClient: KwinClient) {
return kwinClient.moveable && kwinClient.resizeable && !kwinClient.popupWindow; return kwinClient.resizeable;
} }
export function canTileNow(kwinClient: KwinClient) { export function canTileNow(kwinClient: KwinClient) {
return canTileEver(kwinClient) && !kwinClient.minimized && kwinClient.desktops.length === 1 && kwinClient.activities.length === 1; return canTileEver(kwinClient) && !kwinClient.minimized && kwinClient.desktop > 0 && kwinClient.activities.length === 1;
} }
export function makeTileable(kwinClient: KwinClient) { export function makeTileable(kwinClient: KwinClient) {
if (kwinClient.minimized) { if (kwinClient.minimized) {
kwinClient.minimized = false; kwinClient.minimized = false;
} }
if (kwinClient.desktops.length !== 1) { if (kwinClient.desktop <= 0) {
kwinClient.desktops = [Workspace.currentDesktop]; kwinClient.desktop = workspace.currentDesktop;
} }
if (kwinClient.activities.length !== 1) { if (kwinClient.activities.length !== 1) {
kwinClient.activities = [Workspace.currentActivity]; kwinClient.activities = [workspace.currentActivity];
} }
} }
export function getKwinDesktopApprox(kwinClient: KwinClient) { export function isMaximizedGeometry(kwinClient: KwinClient) {
switch (kwinClient.desktops.length) { const maximizeArea = workspace.clientArea(ClientAreaOption.MaximizeArea, kwinClient.screen, kwinClient.desktop);
case 0: return kwinClient.frameGeometry === maximizeArea;
return Workspace.currentDesktop;
case 1:
return kwinClient.desktops[0];
default:
if (kwinClient.desktops.includes(Workspace.currentDesktop)) {
return Workspace.currentDesktop;
} else {
return kwinClient.desktops[0];
}
}
} }
export function isFullScreenGeometry(kwinClient: KwinClient) { export function isFullScreenGeometry(kwinClient: KwinClient) {
const fullScreenArea = Workspace.clientArea(ClientAreaOption.FullScreenArea, kwinClient.output, getKwinDesktopApprox(kwinClient)); const fullScreenArea = workspace.clientArea(ClientAreaOption.FullScreenArea, kwinClient.screen, kwinClient.desktop);
return kwinClient.frameGeometry === fullScreenArea; return kwinClient.frameGeometry === fullScreenArea;
} }
export function isOnVirtualDesktop(kwinClient: KwinClient, kwinDesktop: KwinDesktop) { export function isOnVirtualDesktop(kwinClient: KwinClient, desktopNumber: number) {
return kwinClient.desktops.length === 0 || kwinClient.desktops.includes(kwinDesktop); return kwinClient.desktop === desktopNumber || kwinClient.desktop === -1;
}
export function isOnOneOfVirtualDesktops(kwinClient: KwinClient, kwinDesktops: KwinDesktop[]) {
return kwinClient.desktops.length === 0 || kwinClient.desktops.some(d => kwinDesktops.includes(d));
} }
} }

View File

@@ -2,125 +2,147 @@ class DesktopManager {
private readonly pinManager: PinManager; private readonly pinManager: PinManager;
private readonly config: Desktop.Config; private readonly config: Desktop.Config;
public readonly layoutConfig: LayoutConfig; public readonly layoutConfig: LayoutConfig;
private readonly desktops: Map<string, Desktop>; // key is activityId|desktopId private readonly desktopsPerActivity: Map<string, Desktop[]>;
private kwinActivities: Set<string>; private nVirtualDesktops: number;
private kwinDesktops: Set<KwinDesktop>;
constructor(pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig, currentActivity: string, currentDesktop: KwinDesktop) { constructor(pinManager: PinManager, config: Desktop.Config, layoutConfig: LayoutConfig, currentActivity: string) {
this.pinManager = pinManager; this.pinManager = pinManager;
this.config = config; this.config = config;
this.layoutConfig = layoutConfig; this.layoutConfig = layoutConfig;
this.desktops = new Map(); this.desktopsPerActivity = new Map();
this.kwinActivities = new Set(Workspace.activities); this.nVirtualDesktops = 0;
this.kwinDesktops = new Set(Workspace.desktops); this.update()
this.addDesktop(currentActivity, currentDesktop); this.addActivity(currentActivity);
} }
public getDesktop(activity: string, kwinDesktop: KwinDesktop) { public update() {
const desktopKey = DesktopManager.getDesktopKey(activity, kwinDesktop); this.setNVirtualDesktops(workspace.desktops);
const desktop = this.desktops.get(desktopKey); }
if (desktop !== undefined) {
return desktop; public getDesktop(activity: string, desktopNumber: number) {
} else { const desktopIndex = desktopNumber - 1;
return this.addDesktop(activity, kwinDesktop); 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() { public getCurrentDesktop() {
return this.getDesktop(Workspace.currentActivity, Workspace.currentDesktop); return this.getDesktop(workspace.currentActivity, workspace.currentDesktop);
} }
public getDesktopInCurrentActivity(kwinDesktop: KwinDesktop) { public getDesktopInCurrentActivity(desktopNumber: number) {
return this.getDesktop(Workspace.currentActivity, kwinDesktop); return this.getDesktop(workspace.currentActivity, desktopNumber);
} }
public getDesktopForClient(kwinClient: KwinClient) { public getDesktopForClient(kwinClient: KwinClient) {
if (kwinClient.activities.length !== 1 || kwinClient.desktops.length !== 1) { if (kwinClient.activities.length !== 1 || kwinClient.desktop <= 0) {
return undefined; return undefined;
} }
return this.getDesktop(kwinClient.activities[0], kwinClient.desktops[0]); return this.getDesktop(kwinClient.activities[0], kwinClient.desktop);
} }
private addDesktop(activity: string, kwinDesktop: KwinDesktop) { private setNVirtualDesktops(nVirtualDesktops: number) {
const desktopKey = DesktopManager.getDesktopKey(activity, kwinDesktop); if (nVirtualDesktops > this.nVirtualDesktops) {
const desktop = new Desktop(kwinDesktop, this.pinManager, this.config, this.layoutConfig); this.addDesktopsToActivities(nVirtualDesktops - this.nVirtualDesktops);
this.desktops.set(desktopKey, desktop); } else if (nVirtualDesktops < this.nVirtualDesktops) {
return desktop; this.removeDesktopsFromActivities(this.nVirtualDesktops - nVirtualDesktops);
}
this.nVirtualDesktops = nVirtualDesktops;
} }
private static getDesktopKey(activity: string, kwinDesktop: KwinDesktop) { private addDesktopsToActivities(n: number) {
return activity + "|" + kwinDesktop.id; for (const desktops of this.desktopsPerActivity.values()) {
this.addDesktops(desktops, n);
}
} }
public updateActivities() { private addDesktops(desktops: Desktop[], n: number) {
const newActivities = new Set(Workspace.activities); const nStart = desktops.length;
for (const activity of this.kwinActivities) { for (let i = 0; i < n; i++) {
if (!newActivities.has(activity)) { const desktopNumber = nStart + i + 1;
this.removeActivity(activity); 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);
} }
} }
this.kwinActivities = newActivities;
} }
public updateDesktops() { private addActivity(activity: string) {
const newDesktops = new Set(Workspace.desktops); const desktops: Desktop[] = [];
for (const desktop of this.kwinDesktops) { this.addDesktops(desktops, this.nVirtualDesktops);
if (!newDesktops.has(desktop)) { this.desktopsPerActivity.set(activity, desktops);
this.removeKwinDesktop(desktop);
}
}
this.kwinDesktops = newDesktops;
} }
private removeActivity(activity: string) { private removeActivity(activity: string) {
for (const kwinDesktop of this.kwinDesktops) { const removedDesktops = this.desktopsPerActivity.get(activity)!;
this.destroyDesktop(activity, kwinDesktop); 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]);
private removeKwinDesktop(kwinDesktop: KwinDesktop) {
for (const activity of this.kwinActivities) {
this.destroyDesktop(activity, kwinDesktop);
}
}
private destroyDesktop(activity: string, kwinDesktop: KwinDesktop) {
const desktopKey = DesktopManager.getDesktopKey(activity, kwinDesktop);
const desktop = this.desktops.get(desktopKey);
if (desktop !== undefined) {
desktop.destroy();
this.desktops.delete(desktopKey);
} }
} }
public destroy() { public destroy() {
for (const desktop of this.desktops.values()) { for (const desktop of this.desktops()) {
desktop.destroy(); desktop.destroy();
} }
} }
public *getAllDesktops() { public *desktops() {
for (const desktop of this.desktops.values()) { for (const desktops of this.desktopsPerActivity.values()) {
yield desktop; for (const desktop of desktops) {
yield desktop;
}
} }
} }
public getDesktopsForClient(kwinClient: KwinClient) { public *getDesktopsForClient(kwinClient: KwinClient) {
const desktops = this.getDesktops(kwinClient.activities, kwinClient.desktops); // workaround for QTBUG-109880 const activities = kwinClient.activities.length > 0 ? kwinClient.activities : this.desktopsPerActivity.keys();
return desktops; 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 // empty array means all
public *getDesktops(activities: string[], kwinDesktops: KwinDesktop[]) { public *getDesktops(desktopNumbers: number[], inputActivities: string[]) {
const matchedActivities = activities.length > 0 ? activities : this.kwinActivities.keys(); const activities = inputActivities.length > 0 ? inputActivities : this.desktopsPerActivity.keys();
const matchedDesktops = kwinDesktops.length > 0 ? kwinDesktops : this.kwinDesktops.keys(); for (const activity of activities) {
for (const matchedActivity of matchedActivities) { if (!this.desktopsPerActivity.has(activity)) {
for (const matchedDesktop of matchedDesktops) { this.addActivity(activity);
const desktopKey = DesktopManager.getDesktopKey(matchedActivity, matchedDesktop); }
const desktop = this.desktops.get(desktopKey); const activityDesktops = this.desktopsPerActivity.get(activity)!;
if (desktop !== undefined) { if (desktopNumbers.length === 0) {
for (const desktop of activityDesktops) {
yield desktop; yield desktop;
} }
} else {
for (const desktopNumber of desktopNumbers) {
const desktopIndex = desktopNumber - 1;
yield activityDesktops[desktopIndex];
}
} }
} }
} }

View File

@@ -13,11 +13,11 @@ class PinManager {
this.pinnedClients.delete(kwinClient); this.pinnedClients.delete(kwinClient);
} }
public getAvailableSpace(kwinDesktop: KwinDesktop, screen: QmlRect) { public getAvailableSpace(desktopNumber: number, screen: QmlRect) {
const baseLot = new PinManager.Lot(screen.top, screen.bottom, screen.left, screen.right); const baseLot = new PinManager.Lot(screen.top, screen.bottom, screen.left, screen.right);
let lots = [baseLot]; let lots = [baseLot];
for (const client of this.pinnedClients) { for (const client of this.pinnedClients) {
if (!Clients.isOnVirtualDesktop(client, kwinDesktop)) { if (!Clients.isOnVirtualDesktop(client, desktopNumber)) {
continue; continue;
} }

View File

@@ -4,21 +4,16 @@ class World {
public readonly clientManager: ClientManager; public readonly clientManager: ClientManager;
private readonly pinManager: PinManager; private readonly pinManager: PinManager;
private readonly workspaceSignalManager: SignalManager; private readonly workspaceSignalManager: SignalManager;
private readonly shortcutActions: ShortcutAction[];
private readonly screenResizedDelayer: Delayer; private readonly screenResizedDelayer: Delayer;
constructor(config: Config) { constructor(config: Config) {
this.untileOnDrag = config.untileOnDrag; this.untileOnDrag = config.untileOnDrag;
this.workspaceSignalManager = initWorkspaceSignalHandlers(this); this.workspaceSignalManager = initWorkspaceSignalHandlers(this);
this.shortcutActions = registerKeyBindings(this, {
manualScrollStep: config.manualScrollStep,
manualResizeStep: config.manualResizeStep,
columnResizer: config.scrollingCentered ? new RawResizer() : new ContextualResizer(),
});
this.screenResizedDelayer = new Delayer(1000, () => { this.screenResizedDelayer = new Delayer(1000, () => {
// this delay ensures that docks are taken into account by `Workspace.clientArea` // this delay ensures that docks are taken into account by `workspace.clientArea`
for (const desktop of this.desktopManager.getAllDesktops()) { const desktopManager = this.desktopManager; // workaround for bug in Qt5's JS engine
for (const desktop of desktopManager.desktops()) {
desktop.onLayoutChanged(); desktop.onLayoutChanged();
} }
this.update(); this.update();
@@ -52,8 +47,7 @@ class World {
clamper: config.scrollingLazy ? new EdgeClamper() : new CenterClamper(), clamper: config.scrollingLazy ? new EdgeClamper() : new CenterClamper(),
}, },
layoutConfig, layoutConfig,
Workspace.currentActivity, workspace.currentActivity,
Workspace.currentDesktop,
); );
this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager); this.clientManager = new ClientManager(config, this, this.desktopManager, this.pinManager);
this.addExistingClients(); this.addExistingClients();
@@ -61,13 +55,17 @@ class World {
} }
private addExistingClients() { private addExistingClients() {
const kwinClients = Workspace.windows; const kwinClients = workspace.clientList();
for (let i = 0; i < kwinClients.length; i++) { for (let i = 0; i < kwinClients.length; i++) {
const kwinClient = kwinClients[i]; const kwinClient = kwinClients[i];
this.clientManager.addClient(kwinClient); this.clientManager.addClient(kwinClient);
} }
} }
public updateDesktops() {
this.desktopManager.update();
}
private update() { private update() {
this.desktopManager.getCurrentDesktop().arrange(); this.desktopManager.getCurrentDesktop().arrange();
} }
@@ -96,14 +94,11 @@ class World {
followTransient: boolean, followTransient: boolean,
f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void, f: (clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) => void,
) { ) {
this.doIfTiled(Workspace.activeWindow, followTransient, f); this.doIfTiled(workspace.activeClient, followTransient, f);
} }
public destroy() { public destroy() {
this.workspaceSignalManager.destroy(); this.workspaceSignalManager.destroy();
for (const shortcutAction of this.shortcutActions) {
shortcutAction.destroy();
}
this.clientManager.destroy(); this.clientManager.destroy();
this.desktopManager.destroy(); this.desktopManager.destroy();
} }

View File

@@ -16,7 +16,7 @@ namespace ClientState {
private static initSignalManager(world: World, kwinClient: KwinClient) { private static initSignalManager(world: World, kwinClient: KwinClient) {
const manager = new SignalManager(); const manager = new SignalManager();
manager.connect(kwinClient.frameGeometryChanged, () => { manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QmlRect) => {
world.onScreenResized(); world.onScreenResized();
}); });
return manager; return manager;

View File

@@ -24,11 +24,7 @@ namespace ClientState {
} }
private static limitHeight(client: ClientWrapper) { private static limitHeight(client: ClientWrapper) {
const placementArea = Workspace.clientArea( const placementArea = workspace.clientArea(ClientAreaOption.PlacementArea, client.kwinClient.screen, client.kwinClient.desktop);
ClientAreaOption.PlacementArea,
client.kwinClient.output,
Clients.getKwinDesktopApprox(client.kwinClient),
);
const clientRect = client.kwinClient.frameGeometry; const clientRect = client.kwinClient.frameGeometry;
const width = client.preferredWidth; const width = client.preferredWidth;
client.place( client.place(

View File

@@ -30,8 +30,8 @@ namespace ClientState {
private static initSignalManager(world: World, pinManager: PinManager, kwinClient: KwinClient) { private static initSignalManager(world: World, pinManager: PinManager, kwinClient: KwinClient) {
const manager = new SignalManager(); const manager = new SignalManager();
let oldDesktopNumber = kwinClient.desktop;
let oldActivities = kwinClient.activities; let oldActivities = kwinClient.activities;
let oldDesktops = kwinClient.desktops;
manager.connect(kwinClient.tileChanged, () => { manager.connect(kwinClient.tileChanged, () => {
if (kwinClient.tile === null) { if (kwinClient.tile === null) {
@@ -41,7 +41,7 @@ namespace ClientState {
} }
}); });
manager.connect(kwinClient.frameGeometryChanged, () => { manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QmlRect) => {
if (kwinClient.tile === null) { if (kwinClient.tile === null) {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
clientManager.unpinClient(kwinClient); clientManager.unpinClient(kwinClient);
@@ -56,24 +56,25 @@ namespace ClientState {
}) })
}); });
manager.connect(kwinClient.desktopsChanged, () => { manager.connect(kwinClient.desktopChanged, () => {
const changedDesktops = oldDesktops.length === 0 || kwinClient.desktops.length === 0 ? const changedDesktops = oldDesktopNumber === -1 || kwinClient.desktop === -1 ?
[] : [] :
union(oldDesktops, kwinClient.desktops); [oldDesktopNumber, kwinClient.desktop];
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
for (const desktop of desktopManager.getDesktops(kwinClient.activities, changedDesktops)) { for (const desktop of desktopManager.getDesktops(changedDesktops, kwinClient.activities)) {
desktop.onPinsChanged(); desktop.onPinsChanged();
} }
}); });
oldDesktops = kwinClient.desktops; oldDesktopNumber = kwinClient.desktop;
}); });
manager.connect(kwinClient.activitiesChanged, () => { manager.connect(kwinClient.activitiesChanged, () => {
const desktops = kwinClient.desktop === -1 ? [] : [kwinClient.desktop];
const changedActivities = oldActivities.length === 0 || kwinClient.activities.length === 0 ? const changedActivities = oldActivities.length === 0 || kwinClient.activities.length === 0 ?
[] : [] :
union(oldActivities, kwinClient.activities); union(oldActivities, kwinClient.activities);
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
for (const desktop of desktopManager.getDesktops(changedActivities, kwinClient.desktops)) { for (const desktop of desktopManager.getDesktops(desktops, changedActivities)) {
desktop.onPinsChanged(); desktop.onPinsChanged();
} }
}); });

View File

@@ -31,12 +31,12 @@ namespace ClientState {
const kwinClient = client.kwinClient; const kwinClient = client.kwinClient;
const manager = new SignalManager(); const manager = new SignalManager();
manager.connect(kwinClient.desktopsChanged, () => { manager.connect(kwinClient.desktopChanged, () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
const desktop = desktopManager.getDesktopForClient(kwinClient); const desktop = desktopManager.getDesktopForClient(kwinClient);
if (desktop === undefined) { if (desktop === undefined) {
// windows on multiple desktops are not supported // windows on all desktops are not supported
clientManager.floatKwinClient(kwinClient); clientManager.untileClient(kwinClient);
return; return;
} }
Tiled.moveWindowToGrid(window, desktop.grid); Tiled.moveWindowToGrid(window, desktop.grid);
@@ -48,54 +48,44 @@ namespace ClientState {
const desktop = desktopManager.getDesktopForClient(kwinClient); const desktop = desktopManager.getDesktopForClient(kwinClient);
if (desktop === undefined) { if (desktop === undefined) {
// windows on multiple activities are not supported // windows on multiple activities are not supported
clientManager.floatKwinClient(kwinClient); clientManager.untileClient(kwinClient);
return; return;
} }
Tiled.moveWindowToGrid(window, desktop.grid); Tiled.moveWindowToGrid(window, desktop.grid);
}); });
}) })
manager.connect(kwinClient.minimizedChanged, () => { let lastResize = false;
console.assert(kwinClient.minimized); manager.connect(kwinClient.moveResizedChanged, () => {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
clientManager.minimizeClient(kwinClient); if (kwinClient.move) {
}); if (world.untileOnDrag) {
}); clientManager.untileClient(kwinClient);
}
manager.connect(kwinClient.maximizedAboutToChange, (maximizedMode: MaximizedMode) => { return;
world.do(() => {
window.onMaximizedChanged(maximizedMode);
});
});
let resizing = false;
let resizingBorder = false;
manager.connect(kwinClient.interactiveMoveResizeStarted, () => {
if (kwinClient.move) {
if (world.untileOnDrag) {
world.do((clientManager, desktopManager) => {
clientManager.floatKwinClient(kwinClient);
});
} }
return;
}
if (kwinClient.resize) { const grid = window.column.grid;
resizing = true; const resize = kwinClient.resize;
resizingBorder = Workspace.cursorPos.x > kwinClient.frameGeometry.right || if (!lastResize && resize) {
Workspace.cursorPos.x < kwinClient.frameGeometry.left; grid.onUserResizeStarted();
window.column.grid.onUserResizeStarted(); }
} if (lastResize && !resize) {
grid.onUserResizeFinished();
}
lastResize = resize;
});
}); });
manager.connect(kwinClient.interactiveMoveResizeFinished, () => { let cursorChangedAfterResizeStart = false;
if (resizing) { manager.connect(kwinClient.moveResizeCursorChanged, () => {
resizing = false; cursorChangedAfterResizeStart = true;
window.column.grid.onUserResizeFinished(); });
} manager.connect(kwinClient.clientStartUserMovedResized, () => {
cursorChangedAfterResizeStart = false;
}); });
manager.connect(kwinClient.frameGeometryChanged, (oldGeometry: QmlRect) => { manager.connect(kwinClient.frameGeometryChanged, (kwinClient: KwinClient, oldGeometry: QmlRect) => {
// on Wayland, this fires after `tileChanged` // on Wayland, this fires after `tileChanged`
if (kwinClient.tile !== null) { if (kwinClient.tile !== null) {
world.do((clientManager, desktopManager) => { world.do((clientManager, desktopManager) => {
@@ -116,11 +106,11 @@ namespace ClientState {
} }
if (kwinClient.resize) { if (kwinClient.resize) {
world.do(() => window.onUserResize(oldGeometry, resizingBorder)); world.do(() => window.onUserResize(oldGeometry, !cursorChangedAfterResizeStart));
} else if ( } else if (
!window.column.grid.isUserResizing() && !window.column.grid.isUserResizing() &&
!client.isManipulatingGeometry(newGeometry) && !client.isManipulatingGeometry(newGeometry) &&
client.getMaximizedMode() === MaximizedMode.Unmaximized && !Clients.isMaximizedGeometry(kwinClient) &&
!Clients.isFullScreenGeometry(kwinClient) // not using `kwinClient.fullScreen` because it may not be set yet at this point !Clients.isFullScreenGeometry(kwinClient) // not using `kwinClient.fullScreen` because it may not be set yet at this point
) { ) {
world.do(() => window.onFrameGeometryChanged()); world.do(() => window.onFrameGeometryChanged());

View File

@@ -1,31 +1,5 @@
namespace ClientState { namespace ClientState {
export class TiledMinimized implements State { export class TiledMinimized implements State {
private readonly signalManager: SignalManager; public destroy(passFocus: boolean) {}
constructor(world: World, client: ClientWrapper) {
this.signalManager = TiledMinimized.initSignalManager(world, client);
}
public destroy(passFocus: boolean) {
this.signalManager.destroy();
}
private static initSignalManager(world: World, client: ClientWrapper) {
const manager = new SignalManager();
manager.connect(client.kwinClient.minimizedChanged, () => {
console.assert(!client.kwinClient.minimized);
world.do((clientManager, desktopManager) => {
const desktop = desktopManager.getDesktopForClient(client.kwinClient);
if (desktop !== undefined) {
clientManager.tileClient(client, desktop.grid);
} else {
clientManager.floatClient(client);
}
});
});
return manager;
}
} }
} }