diff --git a/src/common.ts b/src/common.ts index 65ebef3..af6db90 100644 --- a/src/common.ts +++ b/src/common.ts @@ -77,10 +77,16 @@ class Rect implements IRect { } public copyFrom(other: IRect) { - this.height = other.height; - this.width = other.width; - this.x = other.x; - this.y = other.y; + this.set(other.x, other.y, other.width, other.height); + } + + public equals(other: IRect) { + return ( + this.x === other.x && + this.y === other.y && + this.width === other.width && + this.height === other.height + ); } public toQRect(): QRect { diff --git a/src/engine.ts b/src/engine.ts index f5df6e0..83a9f53 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -133,7 +133,6 @@ class TilingEngine { if (!tile) return; if (!tile.isTileable) return; - tile.adjustPadding(); tile.commitGeometry(); } diff --git a/src/layouts/monoclelayout.ts b/src/layouts/monoclelayout.ts index bf91114..fa84a96 100644 --- a/src/layouts/monoclelayout.ts +++ b/src/layouts/monoclelayout.ts @@ -20,7 +20,7 @@ class MonocleLayout implements ILayout { public apply = (tiles: Tile[], area: Rect): void => { - tiles.forEach((tile) => tile.geometry.copyFrom(area)); + tiles.forEach((tile) => tile.setGeometryRect(area)); } public handleUserInput(input: UserInput) { diff --git a/src/layouts/spreadlayout.ts b/src/layouts/spreadlayout.ts index e783e00..b5885f7 100644 --- a/src/layouts/spreadlayout.ts +++ b/src/layouts/spreadlayout.ts @@ -38,7 +38,7 @@ class SpreadLayout implements ILayout { } for (let i = 0; i < tiles.length; i++) - tiles[i].geometry.set( + tiles[i].setGeometry( area.x + ((i < numTiles) ? spaceWidth * (numTiles - i - 1) : 0), area.y, cardWidth, diff --git a/src/layouts/stairlayout.ts b/src/layouts/stairlayout.ts index 8ecea05..7971048 100644 --- a/src/layouts/stairlayout.ts +++ b/src/layouts/stairlayout.ts @@ -34,7 +34,7 @@ class StairLayout implements ILayout { for (let i = 0; i < len; i++) { const dx = space * (len - i - 1); const dy = space * i; - tiles[i].geometry.set( + tiles[i].setGeometry( area.x + dx, area.y + dy, area.width - dx, diff --git a/src/layouts/tilelayout.ts b/src/layouts/tilelayout.ts index 2f9d815..2c5da31 100644 --- a/src/layouts/tilelayout.ts +++ b/src/layouts/tilelayout.ts @@ -51,7 +51,7 @@ class TileLayout implements ILayout { const stackX = (masterWidth > 0) ? masterWidth + 1 + halfgap : 0; for (let i = 0; i < masterCount; i++) - tiles[i].geometry.set( + tiles[i].setGeometry( area.x, area.y + (masterHeight + gap) * i, masterWidth, @@ -59,7 +59,7 @@ class TileLayout implements ILayout { ); for (let i = 0; i < stackCount; i++) - tiles[masterCount + i].geometry.set( + tiles[masterCount + i].setGeometry( area.x + stackX, area.y + (stackHeight + gap) * i, stackWidth, diff --git a/src/tile.ts b/src/tile.ts index 0633fac..11db9b2 100644 --- a/src/tile.ts +++ b/src/tile.ts @@ -23,9 +23,9 @@ class Tile { public client: KWin.Client; public floatGeometry: Rect; public floating: boolean; - public geometry: Rect; public isError: boolean; + private geometry: Rect; private padWidth: number; private padHeight: number; @@ -80,13 +80,6 @@ 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(); @@ -98,41 +91,12 @@ 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) - if (this.clientGeometry.width === this.geometry.width) - if (this.clientGeometry.height === this.geometry.height) { + /* do not commit if not actually changed */ + if (this.geometry.equals(this.clientGeometry)) { this.arrangeCount = 0; return; } - /* do not resize fixed-size windows */ - if (!this.client.resizeable) { - this.geometry.width = this.clientGeometry.width; - this.geometry.height = this.clientGeometry.height; - } - - /* respect min/max size limit */ - 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(); } @@ -158,9 +122,58 @@ class Tile { this.geometry.height -= 1; } + public setGeometry(x: number, y: number, width: number, height: number) { + this.geometry.set(x, y, width, height); + this.adjustGeometry(); + } + + public setGeometryRect(geometry: IRect) { + this.geometry.copyFrom(geometry); + this.adjustGeometry(); + } + public toggleFloat() { this.floating = !this.floating; if (this.floating === false) this.floatGeometry.copyFrom(this.client.geometry); } + + /* private methods */ + private adjustGeometry() { + /* respect resize increment */ + const unit = this.client.basicUnit; + if (!(unit.width === 1 && unit.height === 1)) /* NOT free-size */ { + this.adjustPadding(); + + 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 resize fixed-size windows */ + if (!this.client.resizeable) { + this.geometry.width = this.clientGeometry.width; + this.geometry.height = this.clientGeometry.height; + } + + /* respect min/max size limit */ + 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); + } + + private 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}]); + } + }