From 014a777ff5cb0bb1a9ca00f63a79d4dcfb11f9e2 Mon Sep 17 00:00:00 2001 From: Mikhail Zolotukhin Date: Tue, 19 Oct 2021 00:27:17 +0300 Subject: [PATCH] refactor: :recycle: move rect fuctions to Rect class --- src/driver/surface.ts | 3 +-- src/driver/window.ts | 7 +++---- src/util/kwinutil.ts | 14 -------------- src/util/rect.ts | 8 ++++++++ 4 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 src/util/kwinutil.ts diff --git a/src/driver/surface.ts b/src/driver/surface.ts index dd66fea6..9c9cf6f3 100644 --- a/src/driver/surface.ts +++ b/src/driver/surface.ts @@ -4,7 +4,6 @@ // SPDX-License-Identifier: MIT import Config from "../config"; -import { toRect } from "../util/kwinutil"; import Rect from "../util/rect"; export interface DriverSurface { @@ -66,7 +65,7 @@ export class DriverSurfaceImpl implements DriverSurface { this.ignore = this.config.ignoreActivity.indexOf(activityName) >= 0 || this.config.ignoreScreen.indexOf(screen) >= 0; - this.workingArea = toRect( + this.workingArea = Rect.fromQRect( this.kwinApi.workspace.clientArea( this.kwinApi.KWin.PlacementArea, screen, diff --git a/src/driver/window.ts b/src/driver/window.ts index 4ad1b9e1..aa06af96 100644 --- a/src/driver/window.ts +++ b/src/driver/window.ts @@ -6,7 +6,6 @@ import { DriverSurface, DriverSurfaceImpl } from "./surface"; import Rect from "../util/rect"; -import { toQRect, toRect } from "../util/kwinutil"; import { clip, matchWords } from "../util/func"; import Config from "../config"; import { Log } from "../util/log"; @@ -42,7 +41,7 @@ export class DriverWindowImpl implements DriverWindow { } public get geometry(): Rect { - return toRect(this.client.geometry); + return Rect.fromQRect(this.client.geometry); } public get active(): boolean { @@ -199,7 +198,7 @@ export class DriverWindowImpl implements DriverWindow { if (geometry !== undefined) { geometry = this.adjustGeometry(geometry); if (this.config.preventProtrusion) { - const area = toRect( + const area = Rect.fromQRect( this.kwinApi.workspace.clientArea( this.kwinApi.KWin.PlacementArea, this.client.screen, @@ -214,7 +213,7 @@ export class DriverWindowImpl implements DriverWindow { geometry = this.adjustGeometry(geometry); } } - this.client.geometry = toQRect(geometry); + this.client.geometry = geometry.toQRect(); } } diff --git a/src/util/kwinutil.ts b/src/util/kwinutil.ts deleted file mode 100644 index fb12a263..00000000 --- a/src/util/kwinutil.ts +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: 2018-2019 Eon S. Jeon -// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin -// -// SPDX-License-Identifier: MIT - -import Rect from "./rect"; - -export function toQRect(rect: Rect): QRect { - return Qt.rect(rect.x, rect.y, rect.width, rect.height); -} - -export function toRect(qrect: QRect): Rect { - return new Rect(qrect.x, qrect.y, qrect.width, qrect.height); -} diff --git a/src/util/rect.ts b/src/util/rect.ts index f514d92e..90fcea0f 100644 --- a/src/util/rect.ts +++ b/src/util/rect.ts @@ -11,6 +11,10 @@ export default class Rect { public height: number ) {} + public static fromQRect(qRect: QRect): Rect { + return new Rect(qRect.x, qRect.y, qRect.width, qRect.height); + } + public get maxX(): number { return this.x + this.width; } @@ -82,6 +86,10 @@ export default class Rect { ); } + 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(", ") + ")"; }