mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-09-11 00:15:37 +03:00
feat(wayland): 🔥 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.
This commit is contained in:
parent
8ca1838f68
commit
3277a21888
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,108 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
|
||||
//
|
||||
// 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user