ClientWrapper: move tiling- and floating-specific functions to ClientState.Floating and ClientState.Tiled

This commit is contained in:
Peter Fajdiga
2023-09-08 15:40:16 +02:00
parent ec64b47ceb
commit c57c8391fb
3 changed files with 34 additions and 34 deletions

View File

@@ -90,37 +90,6 @@ class ClientWrapper {
return this.manipulatingGeometry.isDoing();
}
public prepareForTiling() {
this.kwinClient.keepBelow = true;
this.setFullScreen(false);
if (this.kwinClient.tile !== null) {
this.setMaximize(false, true); // disable quick tile mode
}
this.setMaximize(false, false);
}
public restoreAfterTiling(screenSize: QRect) {
this.kwinClient.keepBelow = false;
this.setShade(false);
this.setFullScreen(false);
if (this.kwinClient.tile === null) {
this.setMaximize(false, false);
}
this.ensureVisible(screenSize);
}
public prepareForFloating() {
const placementArea = workspace.clientArea(ClientAreaOption.PlacementArea, this.kwinClient.screen, this.kwinClient.desktop);
const clientRect = this.kwinClient.frameGeometry;
const width = this.preferredWidth;
this.place(
clientRect.x,
clientRect.y,
width,
Math.min(clientRect.height, Math.round(placementArea.height / 2)),
);
}
private addTransient(transient: ClientWrapper) {
this.transients.push(transient);
}

View File

@@ -2,10 +2,22 @@ namespace ClientState {
export class Floating implements State {
constructor(client: ClientWrapper | null) {
if (client !== null && client.kwinClient.tile === null) {
client.prepareForFloating();
Floating.prepareClientForFloating(client);
}
}
public destroy(passFocus: boolean) {}
private static prepareClientForFloating(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)),
);
}
}
}

View File

@@ -4,7 +4,7 @@ namespace ClientState {
private readonly signalManager: SignalManager;
constructor(world: World, client: ClientWrapper, grid: Grid) {
client.prepareForTiling();
Tiled.prepareClientForTiling(client);
const column = new Column(grid, grid.getLastFocusedColumn() ?? grid.getLastColumn());
const window = new Window(client, column);
@@ -21,7 +21,7 @@ namespace ClientState {
const client = window.client;
window.destroy(passFocus);
client.restoreAfterTiling(grid.desktop.clientArea);
Tiled.restoreClientAfterTiling(client, grid.desktop.clientArea);
}
private static initSignalManager(world: World, window: Window) {
@@ -121,5 +121,24 @@ namespace ClientState {
const newColumn = new Column(newGrid, newGrid.getLastFocusedColumn() ?? newGrid.getLastColumn());
window.moveToColumn(newColumn);
}
private static prepareClientForTiling(client: ClientWrapper) {
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, screenSize: QRect) {
client.kwinClient.keepBelow = false;
client.setShade(false);
client.setFullScreen(false);
if (client.kwinClient.tile === null) {
client.setMaximize(false, false);
}
client.ensureVisible(screenSize);
}
}
}