adjust tile geometry whenever it is updated

This commit is contained in:
Eon S. Jeon 2018-12-18 14:22:31 +09:00
parent 8023304921
commit b9fb00ae90
7 changed files with 67 additions and 49 deletions

View File

@ -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 {

View File

@ -133,7 +133,6 @@ class TilingEngine {
if (!tile) return;
if (!tile.isTileable) return;
tile.adjustPadding();
tile.commitGeometry();
}

View File

@ -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) {

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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}]);
}
}