diff --git a/src/common.ts b/src/common.ts index 9e85b514..8a55ff39 100644 --- a/src/common.ts +++ b/src/common.ts @@ -91,7 +91,7 @@ interface IConfig { interface IDriverWindow { readonly fullScreen: boolean; - readonly geometry: Rect; + readonly geometry: Readonly; readonly id: string; readonly maximized: boolean; readonly shouldIgnore: boolean; @@ -106,7 +106,7 @@ interface IDriverWindow { interface ISurface { readonly id: string; readonly ignore: boolean; - readonly workingArea: Rect; + readonly workingArea: Readonly; next(): ISurface | null; } diff --git a/src/util/rect.ts b/src/util/rect.ts index 82a881fa..94ab0d5a 100644 --- a/src/util/rect.ts +++ b/src/util/rect.ts @@ -19,10 +19,13 @@ // DEALINGS IN THE SOFTWARE. class Rect { - public readonly height: number; - public readonly width: number; - public readonly x: number; - public readonly y: number; + constructor( + public x: number, + public y: number, + public width: number, + public height: number, + ) { + } public get maxX(): number { return this.x + this.width; } public get maxY(): number { return this.y + this.height; } @@ -34,11 +37,8 @@ class Rect { ]; } - constructor(x: number, y: number, w: number, h: number) { - this.height = h; - this.width = w; - this.x = x; - this.y = y; + public clone(): Rect { + return new Rect(this.x, this.y, this.width, this.height); } public equals(other: Rect): boolean { @@ -59,6 +59,14 @@ class Rect { ); } + public gap_mut(left: number, right: number, top: number, bottom: number): this { + this.x += left; + this.y += top; + this.width -= (left + right); + this.height -= (top + bottom); + return this; + } + public includes(other: Rect): boolean { return ( this.x <= other.x &&