Skip to content

Add window based on current pos #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add window based on current pos
  • Loading branch information
Raven-002 committed Jun 18, 2024
commit 9dbdd44e97838bed3d043121432c9b02655af4c5
4 changes: 3 additions & 1 deletion src/controller/actions/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ export class ShortcutManager {
return;
}
if (this.ctrl.windowExtensions.get(window)!.isTiled) {
this.ctrl.windowExtensions.get(window)!.shouldTile = false;
this.ctrl.driverManager.untileWindow(window);
} else {
this.ctrl.driverManager.addWindow(window);
this.ctrl.windowExtensions.get(window)!.shouldTile = true;
this.ctrl.driverManager.addWindowToPosition(window, null);
}
this.ctrl.driverManager.rebuildLayout();
}
Expand Down
48 changes: 22 additions & 26 deletions src/controller/actions/windowhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { MaximizeMode, Tile, Window } from "kwin-api";
import { Controller } from "../";
import { GRect } from "../../util/geometry";
import { GPoint, GRect } from "../../util/geometry";
import { Log } from "../../util/log";
import { WindowExtensions } from "../extensions";

Expand All @@ -24,6 +24,9 @@ export class WindowHooks {
window.interactiveMoveResizeStepped.connect(
this.interactiveMoveResizeStepped.bind(this),
);
window.interactiveMoveResizeFinished.connect(
this.interactiveMoveResizeFinished.bind(this),
);
window.tileChanged.connect(this.tileChanged.bind(this));
window.fullScreenChanged.connect(this.fullscreenChanged.bind(this));
window.minimizedChanged.connect(this.minimizedChanged.bind(this));
Expand Down Expand Up @@ -158,32 +161,25 @@ export class WindowHooks {
this.ctrl.driverManager.rebuildLayout(this.window.output);
}
}

interactiveMoveResizeFinished() {
if (
this.ctrl.driverManager.buildingLayout ||
this.ctrl.driverManager.resizingLayout ||
!this.extensions.shouldTile
) {
return;
}
this.putWindowInBestTile(false)
}

putWindowInBestTile(): void {
if (this.extensions.lastTiledLocation != null) {
// fancy and illegally long code to place tile in a similar position from when it was untiled
let tile = this.ctrl.workspace
.tilingForScreen(this.window.output)
.bestTileForPosition(
this.extensions.lastTiledLocation.x,
this.extensions.lastTiledLocation.y,
);
// if its null then its root tile (usually)
if (tile == null) {
tile = this.ctrl.workspace.tilingForScreen(
this.window.output,
).rootTile;
}
this.ctrl.driverManager.putWindowInTile(
this.window,
tile,
new GRect(tile.absoluteGeometry).directionFromPoint(
this.extensions.lastTiledLocation,
),
);
} else {
this.ctrl.driverManager.addWindow(this.window);
putWindowInBestTile(prefer_last: boolean = true): void {
let positionToMatch: GPoint|null = null; // Null uses the middle of the window.
if (this.extensions.lastTiledLocation != null && prefer_last) {
positionToMatch = this.extensions.lastTiledLocation;
}

this.ctrl.driverManager.addWindowToPosition(this.window, positionToMatch);
this.ctrl.driverManager.rebuildLayout(this.window.output);
}

Expand All @@ -208,7 +204,7 @@ export class WindowHooks {
!this.window.minimized &&
!(this.extensions.maximized && this.extensions.isSingleMaximized)
) {
this.putWindowInBestTile();
this.putWindowInBestTile(true);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/controller/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class WindowExtensions {
private previousDesktopsInternal: Desktop[] = [];
isTiled: boolean = false; // not is in a tile, but is registered in engine
wasTiled: boolean = false; // windows that were tiled when they could be (minimized/maximized/fullscreen)
shouldTile: boolean = true;
lastTiledLocation: GPoint | null = null;
clientHooks: WindowHooks | null = null;
isSingleMaximized: boolean = false; // whether the window is solo maximized or not (in accordance with maximize single windows)
Expand Down
32 changes: 30 additions & 2 deletions src/driver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { TilingDriver } from "./driver";
import { EngineConfig, TilingEngineFactory } from "../engine";
import { Window, Tile, Output } from "kwin-api";
import { QTimer } from "kwin-api/qt";
import { Direction } from "../util/geometry";
import { QPoint, QTimer } from "kwin-api/qt";
import { Direction, GRect } from "../util/geometry";
import { Controller } from "../controller";
import { Log } from "../util/log";
import { Config, Borders } from "../util/config";
Expand Down Expand Up @@ -262,6 +262,34 @@ export class DriverManager {
}
}

addWindowToPosition(window: Window, pos: QPoint|null, desktops?: Desktop[]): void {
// If no position is given, use the middle of the window.
if (pos == null) {
pos = {
x: window.pos.x + window.size.width / 2,
y: window.pos.y + window.size.height / 2
};
}

let tile = this.ctrl.workspace
.tilingForScreen(window.output)
.bestTileForPosition(pos.x, pos.y);

// if its null then its root tile (usually)
if (tile == null) {
tile = this.ctrl.workspace.tilingForScreen(
window.output,
).rootTile;
}
this.putWindowInTile(
window,
tile,
new GRect(tile.absoluteGeometry).directionFromPoint(
pos,
),
);
}

addWindow(window: Window, desktops?: Desktop[]): void {
if (desktops == undefined) {
desktops =
Expand Down