refactor: 🚨 fix function return type rule

This commit is contained in:
Mikhail Zolotukhin 2021-09-16 19:39:56 +03:00
parent 6c586c9033
commit cc693602f4
17 changed files with 81 additions and 71 deletions

View File

@ -24,6 +24,7 @@
"rules": { "rules": {
"curly": "error", "curly": "error",
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/naming-convention": [ "@typescript-eslint/naming-convention": [
"error", "error",
{ {

View File

@ -153,7 +153,8 @@ export class ConfigImpl implements Config {
if (this.kwinApi.KWin.readConfig(configKey, defaultValue)) if (this.kwinApi.KWin.readConfig(configKey, defaultValue))
this.layoutOrder.push(layoutClass.id); this.layoutOrder.push(layoutClass.id);
// TODO: Refactor this: config should not create factories. It is not its responsibility // TODO: Refactor this: config should not create factories. It is not its responsibility
this.layoutFactories[layoutClass.id] = () => new layoutClass(this); this.layoutFactories[layoutClass.id] = (): WindowsLayout =>
new layoutClass(this);
}); });
this.maximizeSoleTile = this.kwinApi.KWin.readConfig( this.maximizeSoleTile = this.kwinApi.KWin.readConfig(

View File

@ -67,7 +67,7 @@ export class TilingController implements Controller {
/** /**
* Entry point: start tiling window management * Entry point: start tiling window management
*/ */
public start() { public start(): void {
console.log("Let's get down to bismuth!"); console.log("Let's get down to bismuth!");
this.debug.debug(() => "Config: " + this.config); this.debug.debug(() => "Config: " + this.config);
@ -239,11 +239,11 @@ export class TilingController implements Controller {
} }
} }
public onWindowFocused(window: Window) { public onWindowFocused(window: Window): void {
window.timestamp = new Date().getTime(); window.timestamp = new Date().getTime();
} }
public onShortcut(input: Shortcut, data?: any) { public onShortcut(input: Shortcut, data?: any): void {
if (this.config.directionalKeyMode === "focus") { if (this.config.directionalKeyMode === "focus") {
switch (input) { switch (input) {
case Shortcut.Up: case Shortcut.Up:

View File

@ -172,11 +172,11 @@ export class KWinDriver implements DriverContext {
* Bind script to the various KWin events * Bind script to the various KWin events
*/ */
public bindEvents(): void { public bindEvents(): void {
const onNumberScreensChanged = (count: number) => { const onNumberScreensChanged = (count: number): void => {
this.controller.onSurfaceUpdate("screens=" + count); this.controller.onSurfaceUpdate("screens=" + count);
}; };
const onScreenResized = (screen: number) => { const onScreenResized = (screen: number): void => {
const srf = new KWinSurface( const srf = new KWinSurface(
screen, screen,
this.kwinApi.workspace.currentActivity, this.kwinApi.workspace.currentActivity,
@ -188,18 +188,18 @@ export class KWinDriver implements DriverContext {
this.controller.onSurfaceUpdate("resized " + srf.toString()); this.controller.onSurfaceUpdate("resized " + srf.toString());
}; };
const onCurrentActivityChanged = (_activity: string) => { const onCurrentActivityChanged = (_activity: string): void => {
this.controller.onCurrentSurfaceChanged(); this.controller.onCurrentSurfaceChanged();
}; };
const onCurrentDesktopChanged = ( const onCurrentDesktopChanged = (
_desktop: number, _desktop: number,
_client: KWin.Client _client: KWin.Client
) => { ): void => {
this.controller.onCurrentSurfaceChanged(); this.controller.onCurrentSurfaceChanged();
}; };
const onClientAdded = (client: KWin.Client) => { const onClientAdded = (client: KWin.Client): void => {
// NOTE: windowShown can be fired in various situations. // NOTE: windowShown can be fired in various situations.
// We need only the first one - when window is created. // We need only the first one - when window is created.
let handled = false; let handled = false;
@ -222,7 +222,7 @@ export class KWinDriver implements DriverContext {
qmlSetTimeout(handler, 50); qmlSetTimeout(handler, 50);
}; };
const onClientRemoved = (client: KWin.Client) => { const onClientRemoved = (client: KWin.Client): void => {
const window = this.windowMap.get(client); const window = this.windowMap.get(client);
if (window) { if (window) {
this.controller.onWindowRemoved(window); this.controller.onWindowRemoved(window);
@ -234,7 +234,7 @@ export class KWinDriver implements DriverContext {
client: KWin.Client, client: KWin.Client,
h: boolean, h: boolean,
v: boolean v: boolean
) => { ): void => {
const maximized = h === true && v === true; const maximized = h === true && v === true;
const window = this.windowMap.get(client); const window = this.windowMap.get(client);
if (window) { if (window) {
@ -247,14 +247,14 @@ export class KWinDriver implements DriverContext {
client: KWin.Client, client: KWin.Client,
fullScreen: boolean, fullScreen: boolean,
user: boolean user: boolean
) => { ): void => {
this.controller.onWindowChanged( this.controller.onWindowChanged(
this.windowMap.get(client), this.windowMap.get(client),
"fullscreen=" + fullScreen + " user=" + user "fullscreen=" + fullScreen + " user=" + user
); );
}; };
const onClientMinimized = (client: KWin.Client) => { const onClientMinimized = (client: KWin.Client): void => {
if (this.config.preventMinimize) { if (this.config.preventMinimize) {
client.minimized = false; client.minimized = false;
this.kwinApi.workspace.activeClient = client; this.kwinApi.workspace.activeClient = client;
@ -265,7 +265,7 @@ export class KWinDriver implements DriverContext {
); );
}; };
const onClientUnminimized = (client: KWin.Client) => const onClientUnminimized = (client: KWin.Client): void =>
this.controller.onWindowChanged( this.controller.onWindowChanged(
this.windowMap.get(client), this.windowMap.get(client),
"unminimized" "unminimized"
@ -322,7 +322,7 @@ export class KWinDriver implements DriverContext {
* Manage window with the particular KWin clientship * Manage window with the particular KWin clientship
* @param client window client object specified by KWin * @param client window client object specified by KWin
*/ */
private manageWindow(client: KWin.Client) { private manageWindow(client: KWin.Client): void {
// Add window to our window map // Add window to our window map
const window = this.windowMap.add(client); const window = this.windowMap.add(client);
@ -336,12 +336,12 @@ export class KWinDriver implements DriverContext {
this.controller.manageWindow(window); this.controller.manageWindow(window);
} }
public showNotification(text: string) { public showNotification(text: string): void {
this.qml.popupDialog.show(text); this.qml.popupDialog.show(text);
} }
private bindMainShortcuts() { private bindMainShortcuts(): void {
const bind = (seq: string, title: string, input: Shortcut) => { const bind = (seq: string, title: string, input: Shortcut): void => {
title = "Bismuth: " + title; title = "Bismuth: " + title;
seq = "Meta+" + seq; seq = "Meta+" + seq;
this.kwinApi.KWin.registerShortcut(title, "", seq, () => { this.kwinApi.KWin.registerShortcut(title, "", seq, () => {
@ -379,12 +379,12 @@ export class KWinDriver implements DriverContext {
bind("Return", "Set master", Shortcut.SetMaster); bind("Return", "Set master", Shortcut.SetMaster);
} }
private bindLayoutShortcuts() { private bindLayoutShortcuts(): void {
const bind = ( const bind = (
seq: string, seq: string,
title: string, title: string,
layoutClass: WindowsLayoutClass layoutClass: WindowsLayoutClass
) => { ): void => {
title = "Bismuth: " + title + " Layout"; title = "Bismuth: " + title + " Layout";
seq = seq !== "" ? "Meta+" + seq : ""; seq = seq !== "" ? "Meta+" + seq : "";
this.kwinApi.KWin.registerShortcut(title, "", seq, () => { this.kwinApi.KWin.registerShortcut(title, "", seq, () => {
@ -408,7 +408,7 @@ export class KWinDriver implements DriverContext {
* prevention and auto-disconnect on termination. * prevention and auto-disconnect on termination.
*/ */
private connect(signal: QSignal, handler: (..._: any[]) => void): () => void { private connect(signal: QSignal, handler: (..._: any[]) => void): () => void {
const wrapper = (...args: any[]) => { const wrapper = (...args: any[]): void => {
/* HACK: `workspace` become undefined when the script is disabled. */ /* HACK: `workspace` become undefined when the script is disabled. */
if (typeof this.kwinApi.workspace === "undefined") if (typeof this.kwinApi.workspace === "undefined")
signal.disconnect(wrapper); signal.disconnect(wrapper);
@ -443,7 +443,7 @@ export class KWinDriver implements DriverContext {
} }
} }
private bindWindowEvents(window: Window, client: KWin.Client) { private bindWindowEvents(window: Window, client: KWin.Client): void {
let moving = false; let moving = false;
let resizing = false; let resizing = false;

View File

@ -47,13 +47,13 @@ export default class KWinMousePoller {
}); });
} }
public start() { public start(): void {
this.startCount += 1; this.startCount += 1;
if (this.config.pollMouseXdotool) if (this.config.pollMouseXdotool)
this.qml.mousePoller.connectSource(KWinMousePoller.COMMAND); this.qml.mousePoller.connectSource(KWinMousePoller.COMMAND);
} }
public stop() { public stop(): void {
this.startCount = Math.max(this.startCount - 1, 0); this.startCount = Math.max(this.startCount - 1, 0);
} }

View File

@ -21,7 +21,7 @@ export class KWinSurface implements DriverSurface {
activity: string, activity: string,
desktop: number, desktop: number,
config: Config config: Config
) { ): string {
let path = String(screen); let path = String(screen);
if (config.layoutPerActivity) path += "@" + activity; if (config.layoutPerActivity) path += "@" + activity;
if (config.layoutPerDesktop) path += "#" + desktop; if (config.layoutPerDesktop) path += "#" + desktop;

View File

@ -26,7 +26,7 @@ export interface DriverWindow {
} }
export class KWinWindow implements DriverWindow { export class KWinWindow implements DriverWindow {
public static generateID(client: KWin.Client) { public static generateID(client: KWin.Client): string {
return String(client) + "/" + client.windowId; return String(client) + "/" + client.windowId;
} }

View File

@ -87,7 +87,7 @@ export class TilingEngine implements Engine {
* *
* Used when tile is resized using mouse. * Used when tile is resized using mouse.
*/ */
public adjustLayout(basis: Window) { public adjustLayout(basis: Window): void {
const srf = basis.surface; const srf = basis.surface;
const layout = this.layouts.getCurrentLayout(srf); const layout = this.layouts.getCurrentLayout(srf);
if (layout.adjust) { if (layout.adjust) {
@ -111,7 +111,7 @@ export class TilingEngine implements Engine {
window: Window, window: Window,
dir: "east" | "west" | "south" | "north", dir: "east" | "west" | "south" | "north",
step: -1 | 1 step: -1 | 1
) { ): void {
const srf = window.surface; const srf = window.surface;
// TODO: configurable step size? // TODO: configurable step size?
@ -150,7 +150,7 @@ export class TilingEngine implements Engine {
basis: Window, basis: Window,
dir: "east" | "west" | "south" | "north", dir: "east" | "west" | "south" | "north",
step: -1 | 1 step: -1 | 1
) { ): void {
const srf = basis.surface; const srf = basis.surface;
if (dir === "east") { if (dir === "east") {
@ -217,7 +217,7 @@ export class TilingEngine implements Engine {
window: Window, window: Window,
dir: "east" | "west" | "south" | "north", dir: "east" | "west" | "south" | "north",
step: -1 | 1 step: -1 | 1
) { ): void {
const state = window.state; const state = window.state;
if (Window.isFloatingState(state)) this.resizeFloat(window, dir, step); if (Window.isFloatingState(state)) this.resizeFloat(window, dir, step);
else if (Window.isTiledState(state)) this.resizeTile(window, dir, step); else if (Window.isTiledState(state)) this.resizeTile(window, dir, step);
@ -239,7 +239,7 @@ export class TilingEngine implements Engine {
* *
* @param screenSurface screen's surface, on which windows should be arranged * @param screenSurface screen's surface, on which windows should be arranged
*/ */
public arrangeScreen(screenSurface: DriverSurface) { public arrangeScreen(screenSurface: DriverSurface): void {
const layout = this.layouts.getCurrentLayout(screenSurface); const layout = this.layouts.getCurrentLayout(screenSurface);
const workingArea = screenSurface.workingArea; const workingArea = screenSurface.workingArea;
@ -315,7 +315,7 @@ export class TilingEngine implements Engine {
/** /**
* Register the given window to WM. * Register the given window to WM.
*/ */
public manage(window: Window) { public manage(window: Window): void {
if (!window.shouldIgnore) { if (!window.shouldIgnore) {
/* engine#arrange will update the state when required. */ /* engine#arrange will update the state when required. */
window.state = WindowState.Undecided; window.state = WindowState.Undecided;
@ -327,14 +327,14 @@ export class TilingEngine implements Engine {
/** /**
* Unregister the given window from WM. * Unregister the given window from WM.
*/ */
public unmanage(window: Window) { public unmanage(window: Window): void {
this.windows.remove(window); this.windows.remove(window);
} }
/** /**
* Focus the next or previous window. * Focus the next or previous window.
*/ */
public focusOrder(step: -1 | 1) { public focusOrder(step: -1 | 1): void {
const window = this.controller.currentWindow; const window = this.controller.currentWindow;
/* if no current window, select the first tile. */ /* if no current window, select the first tile. */
@ -372,7 +372,7 @@ export class TilingEngine implements Engine {
/** /**
* Focus a neighbor at the given direction. * Focus a neighbor at the given direction.
*/ */
public focusDir(dir: Direction) { public focusDir(dir: Direction): void {
const window = this.controller.currentWindow; const window = this.controller.currentWindow;
/* if no current window, select the first tile. */ /* if no current window, select the first tile. */
@ -395,7 +395,7 @@ export class TilingEngine implements Engine {
/** /**
* Swap the position of the current window with the next or previous window. * Swap the position of the current window with the next or previous window.
*/ */
public swapOrder(window: Window, step: -1 | 1) { public swapOrder(window: Window, step: -1 | 1): void {
const srf = window.surface; const srf = window.surface;
const visibles = this.windows.getVisibleWindows(srf); const visibles = this.windows.getVisibleWindows(srf);
if (visibles.length < 2) return; if (visibles.length < 2) return;
@ -410,7 +410,7 @@ export class TilingEngine implements Engine {
/** /**
* Swap the position of the current window with a neighbor at the given direction. * Swap the position of the current window with a neighbor at the given direction.
*/ */
public swapDirection(dir: Direction) { public swapDirection(dir: Direction): void {
const window = this.controller.currentWindow; const window = this.controller.currentWindow;
if (window === null) { if (window === null) {
/* if no current window, select the first tile. */ /* if no current window, select the first tile. */
@ -432,7 +432,7 @@ export class TilingEngine implements Engine {
* @param window a floating window * @param window a floating window
* @param dir which direction * @param dir which direction
*/ */
public moveFloat(window: Window, dir: Direction) { public moveFloat(window: Window, dir: Direction): void {
const srf = window.surface; const srf = window.surface;
// TODO: configurable step size? // TODO: configurable step size?
@ -462,7 +462,7 @@ export class TilingEngine implements Engine {
window.forceSetGeometry(new Rect(x, y, geometry.width, geometry.height)); window.forceSetGeometry(new Rect(x, y, geometry.width, geometry.height));
} }
public swapDirOrMoveFloat(dir: Direction) { public swapDirOrMoveFloat(dir: Direction): void {
const window = this.controller.currentWindow; const window = this.controller.currentWindow;
if (!window) return; if (!window) return;
@ -474,7 +474,7 @@ export class TilingEngine implements Engine {
/** /**
* Toggle float mode of window. * Toggle float mode of window.
*/ */
public toggleFloat(window: Window) { public toggleFloat(window: Window): void {
window.state = !window.tileable ? WindowState.Tiled : WindowState.Floating; window.state = !window.tileable ? WindowState.Tiled : WindowState.Floating;
} }
@ -485,7 +485,7 @@ export class TilingEngine implements Engine {
* windows: windows will be tiled if more than half are floating, and will * windows: windows will be tiled if more than half are floating, and will
* be floated otherwise. * be floated otherwise.
*/ */
public floatAll(srf: DriverSurface) { public floatAll(srf: DriverSurface): void {
const windows = this.windows.getVisibleWindows(srf); const windows = this.windows.getVisibleWindows(srf);
const numFloats = windows.reduce<number>((count, window) => { const numFloats = windows.reduce<number>((count, window) => {
return window.state === WindowState.Floating ? count + 1 : count; return window.state === WindowState.Floating ? count + 1 : count;
@ -513,14 +513,14 @@ export class TilingEngine implements Engine {
* Some layouts depend on this assumption, and will make such windows more * Some layouts depend on this assumption, and will make such windows more
* visible than others. * visible than others.
*/ */
public setMaster(window: Window) { public setMaster(window: Window): void {
this.windows.setMaster(window); this.windows.setMaster(window);
} }
/** /**
* Change the layout of the current surface to the next. * Change the layout of the current surface to the next.
*/ */
public cycleLayout(step: 1 | -1) { public cycleLayout(step: 1 | -1): void {
const layout = this.layouts.cycleLayout( const layout = this.layouts.cycleLayout(
this.controller.currentSurface, this.controller.currentSurface,
step step
@ -533,7 +533,7 @@ export class TilingEngine implements Engine {
/** /**
* Set the layout of the current surface to the specified layout. * Set the layout of the current surface to the specified layout.
*/ */
public setLayout(layoutClassID: string) { public setLayout(layoutClassID: string): void {
const layout = this.layouts.setLayout( const layout = this.layouts.setLayout(
this.controller.currentSurface, this.controller.currentSurface,
layoutClassID layoutClassID
@ -586,19 +586,19 @@ export class TilingEngine implements Engine {
.getVisibleTiles(this.controller.currentSurface) .getVisibleTiles(this.controller.currentSurface)
.filter( .filter(
vertical vertical
? (tile) => tile.geometry.y * sign > basis.geometry.y * sign ? (tile): boolean => tile.geometry.y * sign > basis.geometry.y * sign
: (tile) => tile.geometry.x * sign > basis.geometry.x * sign : (tile): boolean => tile.geometry.x * sign > basis.geometry.x * sign
) )
.filter( .filter(
vertical vertical
? (tile) => ? (tile): boolean =>
overlap( overlap(
basis.geometry.x, basis.geometry.x,
basis.geometry.maxX, basis.geometry.maxX,
tile.geometry.x, tile.geometry.x,
tile.geometry.maxX tile.geometry.maxX
) )
: (tile) => : (tile): boolean =>
overlap( overlap(
basis.geometry.y, basis.geometry.y,
basis.geometry.maxY, basis.geometry.maxY,
@ -620,8 +620,8 @@ export class TilingEngine implements Engine {
const closest = candidates.filter( const closest = candidates.filter(
vertical vertical
? (tile) => tile.geometry.y === min ? (tile): boolean => tile.geometry.y === min
: (tile) => tile.geometry.x === min : (tile): boolean => tile.geometry.x === min
); );
return closest.sort((a, b) => b.timestamp - a.timestamp)[0]; return closest.sort((a, b) => b.timestamp - a.timestamp)[0];

View File

@ -54,7 +54,7 @@ export default class CascadeLayout implements WindowsLayout {
public readonly classID = CascadeLayout.id; public readonly classID = CascadeLayout.id;
public get description() { public get description(): string {
return "Cascade [" + CascadeDirection[this.dir] + "]"; return "Cascade [" + CascadeDirection[this.dir] + "]";
} }

View File

@ -57,7 +57,7 @@ export default class SpreadLayout implements WindowsLayout {
return other; return other;
} }
public handleShortcut(_engine: Engine, input: Shortcut) { public handleShortcut(_engine: Engine, input: Shortcut): boolean {
switch (input) { switch (input) {
case Shortcut.Decrease: case Shortcut.Decrease:
// TODO: define arbitrary constants // TODO: define arbitrary constants

View File

@ -54,7 +54,7 @@ export default class StairLayout implements WindowsLayout {
return other; return other;
} }
public handleShortcut(_engine: Engine, input: Shortcut) { public handleShortcut(_engine: Engine, input: Shortcut): boolean {
switch (input) { switch (input) {
case Shortcut.Decrease: case Shortcut.Decrease:
// TODO: define arbitrary constants // TODO: define arbitrary constants

View File

@ -72,7 +72,12 @@ export default class TileLayout implements WindowsLayout {
this.config.tileLayoutGap; this.config.tileLayoutGap;
} }
public adjust(area: Rect, tiles: Window[], basis: Window, delta: RectDelta) { public adjust(
area: Rect,
tiles: Window[],
basis: Window,
delta: RectDelta
): void {
this.parts.adjust(area, tiles, basis, delta); this.parts.adjust(area, tiles, basis, delta);
} }
@ -91,7 +96,7 @@ export default class TileLayout implements WindowsLayout {
return other; return other;
} }
public handleShortcut(engine: Engine, input: Shortcut) { public handleShortcut(engine: Engine, input: Shortcut): boolean {
switch (input) { switch (input) {
case Shortcut.Left: case Shortcut.Left:
this.masterRatio = clip( this.masterRatio = clip(

View File

@ -207,7 +207,7 @@ export default class Window {
* This method is a quick hack created for engine#resizeFloat, thus should * This method is a quick hack created for engine#resizeFloat, thus should
* not be used in other places. * not be used in other places.
*/ */
public forceSetGeometry(geometry: Rect) { public forceSetGeometry(geometry: Rect): void {
this.window.commit(geometry); this.window.commit(geometry);
} }

View File

@ -14,7 +14,7 @@ export default class WindowStore {
this.list = windows || []; this.list = windows || [];
} }
public move(srcWin: Window, destWin: Window, after?: boolean) { public move(srcWin: Window, destWin: Window, after?: boolean): void {
const srcIdx = this.list.indexOf(srcWin); const srcIdx = this.list.indexOf(srcWin);
const destIdx = this.list.indexOf(destWin); const destIdx = this.list.indexOf(destWin);
if (srcIdx === -1 || destIdx === -1) return; if (srcIdx === -1 || destIdx === -1) return;
@ -23,14 +23,14 @@ export default class WindowStore {
this.list.splice(after ? destIdx + 1 : destIdx, 0, srcWin); this.list.splice(after ? destIdx + 1 : destIdx, 0, srcWin);
} }
public setMaster(window: Window) { public setMaster(window: Window): void {
const idx = this.list.indexOf(window); const idx = this.list.indexOf(window);
if (idx === -1) return; if (idx === -1) return;
this.list.splice(idx, 1); this.list.splice(idx, 1);
this.list.splice(0, 0, window); this.list.splice(0, 0, window);
} }
public swap(alpha: Window, beta: Window) { public swap(alpha: Window, beta: Window): void {
const alphaIndex = this.list.indexOf(alpha); const alphaIndex = this.list.indexOf(alpha);
const betaIndex = this.list.indexOf(beta); const betaIndex = this.list.indexOf(beta);
if (alphaIndex < 0 || betaIndex < 0) return; if (alphaIndex < 0 || betaIndex < 0) return;
@ -45,24 +45,24 @@ export default class WindowStore {
return this.list.length; return this.list.length;
} }
public at(idx: number) { public at(idx: number): Window {
return this.list[idx]; return this.list[idx];
} }
public indexOf(window: Window) { public indexOf(window: Window): number {
return this.list.indexOf(window); return this.list.indexOf(window);
} }
public push(window: Window) { public push(window: Window): void {
this.list.push(window); this.list.push(window);
} }
public remove(window: Window) { public remove(window: Window): void {
const idx = this.list.indexOf(window); const idx = this.list.indexOf(window);
if (idx >= 0) this.list.splice(idx, 1); if (idx >= 0) this.list.splice(idx, 1);
} }
public unshift(window: Window) { public unshift(window: Window): void {
this.list.unshift(window); this.list.unshift(window);
} }
//#endregion //#endregion

View File

@ -11,7 +11,10 @@ import Debug from "./util/debug";
* @param qmlObjects objects from QML gui. Required for the interaction with QML, as we cannot access globals. * @param qmlObjects objects from QML gui. Required for the interaction with QML, as we cannot access globals.
* @param kwinApi KWin scripting API. Required for interaction with KWin, as we cannot access globals. * @param kwinApi KWin scripting API. Required for interaction with KWin, as we cannot access globals.
*/ */
export function init(qmlObjects: Bismuth.Qml.Main, kwinScriptingApi: KWin.Api) { export function init(
qmlObjects: Bismuth.Qml.Main,
kwinScriptingApi: KWin.Api
): void {
const config = new ConfigImpl(kwinScriptingApi); const config = new ConfigImpl(kwinScriptingApi);
const debug = new Debug(config); const debug = new Debug(config);

View File

@ -5,10 +5,10 @@
import Rect from "./rect"; import Rect from "./rect";
export function toQRect(rect: Rect) { export function toQRect(rect: Rect): QRect {
return Qt.rect(rect.x, rect.y, rect.width, rect.height); return Qt.rect(rect.x, rect.y, rect.width, rect.height);
} }
export function toRect(qrect: QRect) { export function toRect(qrect: QRect): Rect {
return new Rect(qrect.x, qrect.y, qrect.width, qrect.height); return new Rect(qrect.x, qrect.y, qrect.width, qrect.height);
} }

View File

@ -22,7 +22,7 @@ export class TimersPool {
* Get an instance of timer pool. * Get an instance of timer pool.
* @param scriptRoot where to create QML Timers. Cannot be ommited in the first call. * @param scriptRoot where to create QML Timers. Cannot be ommited in the first call.
*/ */
public static instance(scriptRoot?: object, debug?: Debug) { public static instance(scriptRoot?: object, debug?: Debug): TimersPool {
if (scriptRoot && debug) { if (scriptRoot && debug) {
if (TimersPool._instance) { if (TimersPool._instance) {
return TimersPool._instance; return TimersPool._instance;
@ -63,7 +63,7 @@ export class TimersPool {
this.numTimers = 0; this.numTimers = 0;
} }
public setTimeout(func: () => void, timeout: number) { public setTimeout(func: () => void, timeout: number): void {
if (this.timers.length === 0) { if (this.timers.length === 0) {
this.numTimers++; this.numTimers++;
this.debug.debugObj(() => [ this.debug.debugObj(() => [
@ -76,7 +76,7 @@ export class TimersPool {
this.timers.pop() || this.timers.pop() ||
Qt.createQmlObject("import QtQuick 2.0; Timer {}", this.scriptRoot); Qt.createQmlObject("import QtQuick 2.0; Timer {}", this.scriptRoot);
const callback = () => { const callback = (): void => {
try { try {
timer.triggered.disconnect(callback); timer.triggered.disconnect(callback);
} catch (e) { } catch (e) {
@ -100,6 +100,6 @@ export class TimersPool {
/** /**
* setTimeout from standard JS, but for Qt JS Runtime * setTimeout from standard JS, but for Qt JS Runtime
*/ */
export default function qmlSetTimeout(func: () => void, timeout: number) { export default function qmlSetTimeout(func: () => void, timeout: number): void {
TimersPool.instance().setTimeout(func, timeout); TimersPool.instance().setTimeout(func, timeout);
} }