Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
respect window resize increment hints
Browse files Browse the repository at this point in the history
- calculate window size based on increment hint, if available.
- fixes freezing issues with xterm, lxterm, and similar applications
  • Loading branch information
esjeon committed Dec 17, 2018
1 parent 5caa4e0 commit 18cba1c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class Rect implements IRect {
public toQRect(): QRect {
return Qt.rect(this.x, this.y, this.width, this.height);
}

public toString(): string {
return "Rect(" + [this.x, this.y, this.width, this.height].join(", ") + ")";
}
}

function clip(min: number, value: number, max: number): number {
Expand Down
1 change: 1 addition & 0 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class TilingEngine {
if (!tile) return;
if (!tile.isTileable) return;

tile.adjustPadding();
tile.commitGeometry();
}

Expand Down
4 changes: 4 additions & 0 deletions src/kwin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ declare namespace KWin {
readonly utility: boolean;
readonly windowRole: string;

readonly clientPos: QPoint;
readonly clientSize: QSize;

/* signal */
activitiesChanged: QSignal;
geometryChanged: QSignal;
Expand Down Expand Up @@ -110,6 +113,7 @@ declare namespace KWin {
minimized: boolean;
noBorder: boolean;
onAllDesktops: boolean;
basicUnit: QSize;

/* signals */
desktopChanged: QSignal;
Expand Down
5 changes: 5 additions & 0 deletions src/qt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
interface QRect extends IRect {
}

interface QPoint {
x: number;
y: number;
}

interface QSize {
width: number;
height: number;
Expand Down
30 changes: 30 additions & 0 deletions src/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ class Tile {
public geometry: Rect;
public isError: boolean;

private padWidth: number;
private padHeight: number;

constructor(client: KWin.Client) {
this.arrangeCount = 0;
this.client = client;
this.floatGeometry = Rect.from(client.geometry);
this.floating = false;
this.geometry = Rect.from(client.geometry);
this.isError = false;

this.padWidth = 0;
this.padHeight = 0;
}

/*
Expand Down Expand Up @@ -74,6 +80,13 @@ class Tile {
* Methods
*/

public adjustPadding() {
const size = this.client.clientSize;
this.padWidth = this.client.geometry.width - size.width;
this.padHeight = this.client.geometry.height - size.height;
debugObj(() => ["adjustPadding", {size, w: this.padWidth, h: this.padHeight}]);
}

public commitGeometry(reset?: boolean) {
if (this.floating) {
this.client.geometry = this.floatGeometry.toQRect();
Expand All @@ -85,6 +98,22 @@ class Tile {
if (this.arrangeCount > 5) // TODO: define arbitrary constant
return;

/* respect resize increment */
const unit = this.client.basicUnit;
if (reset && !(unit.width === 1 && unit.height === 1)) /* NOT free-size */ {
const geom = this.geometry;
const base = this.client.minSize;

const nw = Math.floor((geom.width - base.width ) / unit.width);
const nh = Math.floor((geom.height - base.height) / unit.height);
this.geometry.width = base.width + unit.width * nw + this.padWidth;
this.geometry.height = base.height + unit.height * nh + this.padHeight;

const pw = this.padWidth;
const ph = this.padHeight;
debugObj(() => ["commitGometry", {geom, base, unit, pw, ph}]);
}

/* do not commit if not changed */
if (this.clientGeometry.x === this.geometry.x)
if (this.clientGeometry.y === this.geometry.y)
Expand All @@ -104,6 +133,7 @@ class Tile {
this.geometry.width = clip(this.client.minSize.width , this.geometry.width , this.client.maxSize.width );
this.geometry.height = clip(this.client.minSize.height, this.geometry.height, this.client.maxSize.height);

debugObj(() => ["commitGeometry", {client: this.client, from: this.client.geometry, to: this.geometry}]);
this.client.geometry = this.geometry.toQRect();
}

Expand Down

0 comments on commit 18cba1c

Please sign in to comment.