From 3277a21888f6a660190124aab7041e19f7bd72d4 Mon Sep 17 00:00:00 2001 From: Mikhail Zolotukhin Date: Thu, 23 Sep 2021 02:46:11 +0300 Subject: [PATCH] feat(wayland): :fire: remove qmlSetTimer It does not work for some reason. Using timer is not a good idea and if we a bound to do so, it is better to create destinct ones in the qml itself instead of using arbitary number of ones with singleton. This will potentially break the code in places, where timer was used. We need to test it and provide distinct timer in QML, which are working. --- src/driver/index.ts | 4 -- src/engine/index.ts | 7 +- src/engine/layout/monocle_layout.ts | 19 +++-- src/util/timer.ts | 108 ---------------------------- 4 files changed, 9 insertions(+), 129 deletions(-) delete mode 100644 src/util/timer.ts diff --git a/src/driver/index.ts b/src/driver/index.ts index 915f61da..c5b2226f 100644 --- a/src/driver/index.ts +++ b/src/driver/index.ts @@ -16,7 +16,6 @@ import { WindowState } from "../engine/window"; import Config from "../config"; import Debug from "../util/debug"; -import { TimersPool } from "../util/timer"; export interface DriverContext { readonly screens: DriverSurface[]; @@ -147,9 +146,6 @@ export class KWinDriver implements DriverContext { this.entered = false; this.qml = qmlObjects; this.kwinApi = kwinApi; - - // Init timers singleton, so that we can use qmlSetTimeout freely - TimersPool.instance(this.qml.scriptRoot, this.debug); } /** diff --git a/src/engine/index.ts b/src/engine/index.ts index 11e93bda..3b26a511 100644 --- a/src/engine/index.ts +++ b/src/engine/index.ts @@ -19,7 +19,6 @@ import RectDelta from "../util/rectdelta"; import { overlap, wrapIndex } from "../util/func"; import Config from "../config"; import Debug from "../util/debug"; -import qmlSetTimeout from "../util/timer"; import { WindowsLayout } from "./layout"; export type Direction = "up" | "down" | "left" | "right"; @@ -318,11 +317,7 @@ export class TilingEngine implements Engine { */ public enforceSize(window: Window): void { if (window.tiled && !window.actualGeometry.equals(window.geometry)) { - qmlSetTimeout(() => { - if (window.tiled) { - window.commit(); - } - }, 10); + window.commit(); } } diff --git a/src/engine/layout/monocle_layout.ts b/src/engine/layout/monocle_layout.ts index 9805f114..04aed513 100644 --- a/src/engine/layout/monocle_layout.ts +++ b/src/engine/layout/monocle_layout.ts @@ -22,7 +22,6 @@ import { import Rect from "../../util/rect"; import Config from "../../config"; -import qmlSetTimeout from "../../util/timer"; import { Controller } from "../../controller"; import { Engine } from ".."; @@ -50,16 +49,14 @@ export default class MonocleLayout implements WindowsLayout { /* KWin-specific `monocleMinimizeRest` option */ if (this.config.monocleMinimizeRest) { const tiles = [...tileables]; - qmlSetTimeout(() => { - const current = controller.currentWindow; - if (current && current.tiled) { - tiles.forEach((window) => { - if (window !== current) { - (window.window as KWinWindow).client.minimized = true; - } - }); - } - }, 50); + const current = controller.currentWindow; + if (current && current.tiled) { + tiles.forEach((window) => { + if (window !== current) { + (window.window as KWinWindow).client.minimized = true; + } + }); + } } } diff --git a/src/util/timer.ts b/src/util/timer.ts deleted file mode 100644 index fe9d80e6..00000000 --- a/src/util/timer.ts +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin -// -// SPDX-License-Identifier: MIT - -/* eslint-disable @typescript-eslint/ban-types */ - -/** - * @module - * This module basically reimplements standard JS setTimeout function - * in Qt QML environment. The setTimeout function is not availible in Qt - * JavaScript environment. - */ - -import Debug from "./debug"; - -/** - * Timer pool. Manages all dynamically created QML timers. Used as singleton to preserve - * standard JS setTimeout api. - */ -export class TimersPool { - private static _instance: TimersPool; - - /** - * Get an instance of timer pool. - * @param scriptRoot where to create QML Timers. Cannot be ommited in the first call. - */ - public static instance(scriptRoot?: object, debug?: Debug): TimersPool { - if (scriptRoot && debug) { - if (TimersPool._instance) { - return TimersPool._instance; - } else { - return new TimersPool(scriptRoot, debug); - } - } else { - if (TimersPool._instance) { - throw "Cannot create TimerPool instance first time, when there is not enough arguments!"; - } else { - return TimersPool._instance; - } - } - } - - /** - * All the timers, that have been created - */ - public timers: QQmlTimer[]; - - /** - * Number of the created timers - */ - public numTimers: number; - - /** - * Where to create QML timers - */ - private scriptRoot: object; - - private debug: Debug; - - constructor(scriptRoot: object, debug: Debug) { - this.scriptRoot = scriptRoot; - this.debug = debug; - - this.timers = []; - this.numTimers = 0; - } - - public setTimeout(func: () => void, timeout: number): void { - if (this.timers.length === 0) { - this.numTimers++; - this.debug.debugObj(() => [ - "setTimeout/newTimer", - { numTimers: this.numTimers }, - ]); - } - - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const timer: QQmlTimer = - this.timers.pop() || - Qt.createQmlObject("import QtQuick 2.0; Timer {}", this.scriptRoot); - - const callback = (): void => { - try { - timer.triggered.disconnect(callback); - } catch (e) { - /* ignore */ - } - try { - func(); - } catch (e) { - /* ignore */ - } - this.timers.push(timer); - }; - - timer.interval = timeout; - timer.repeat = false; - timer.triggered.connect(callback); - timer.start(); - } -} - -/** - * setTimeout from standard JS, but for Qt JS Runtime - */ -export default function qmlSetTimeout(func: () => void, timeout: number): void { - TimersPool.instance().setTimeout(func, timeout); -}