From 34d24a4cb6494ea5bf29305462a1243ab143dc0c Mon Sep 17 00:00:00 2001 From: Mikhail Zolotukhin Date: Thu, 21 Oct 2021 23:46:57 +0300 Subject: [PATCH] fix: :bug: prevent KWin freeze in various scenarious This removes some hacks and functionality. Those could be added later. --- src/controller/index.ts | 61 +++++++++++------------------------------ src/engine/index.ts | 4 +-- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/src/controller/index.ts b/src/controller/index.ts index 7a1e04d5..165e2765 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -205,12 +205,6 @@ export class ControllerImpl implements Controller { public onCurrentSurfaceChanged(): void { this.log.log(["onCurrentSurfaceChanged", { srf: this.currentSurface }]); this.engine.arrange(); - /* HACK: minimize others and change geometry with Monocle Layout and - * config.monocleMinimizeRest - */ - if (this.currentWindow) { - this.onWindowFocused(this.currentWindow); - } } public onWindowAdded(window: EngineWindow): void { @@ -236,24 +230,21 @@ export class ControllerImpl implements Controller { } public onWindowRemoved(window: EngineWindow): void { - this.log.log(["onWindowRemoved", { window }]); + this.log.log(`[Controller#onWindowRemoved] Window removed: ${window}`); this.engine.unmanage(window); - this.engine.arrange(); - // Switch to next window if monocle with config.monocleMinimizeRest - if ( - !window.isDialog && - !this.currentWindow && - this.engine.isLayoutMonocleAndMinimizeRest() - ) { - this.engine.focusOrder(1, true); - /* HACK: force window to maximize if it isn't already - * This is ultimately to trigger onWindowFocused() at the right time - */ - this.engine.focusOrder(1, true); - this.engine.focusOrder(-1, true); + if (this.engine.isLayoutMonocleAndMinimizeRest()) { + // Switch to the next window if needed + if (!this.currentWindow) { + this.log.log( + `[Controller#onWindowRemoved] Switching to the minimized window` + ); + this.engine.focusOrder(1, true); + } } + + this.engine.arrange(); } public onWindowMoveStart(_window: EngineWindow): void { @@ -353,32 +344,12 @@ export class ControllerImpl implements Controller { } } - public onWindowFocused(window: EngineWindow): void { - try { - window.timestamp = new Date().getTime(); - this.currentWindow = window; - // Minimize other windows if Monocle and config.monocleMinimizeRest - if ( - this.engine.isLayoutMonocleAndMinimizeRest() && - this.engine.windows - .visibleTiledWindowsOn(window.surface) - .includes(window) - ) { - /* If a window hasn't been focused in this layout yet, ensure its geometry - * gets maximized. - */ - this.engine - .currentLayoutOnCurrentSurface() - .apply( - this, - this.engine.windows.tileableWindowsOn(window.surface), - window.surface.workingArea - ); + public onWindowFocused(win: EngineWindow): void { + win.timestamp = new Date().getTime(); - this.engine.minimizeOthers(window); - } - } catch { - return; + // Minimize other windows if Monocle and config.monocleMinimizeRest + if (this.engine.isLayoutMonocleAndMinimizeRest()) { + this.engine.minimizeOthers(win); } } diff --git a/src/engine/index.ts b/src/engine/index.ts index 047cae93..102addbb 100644 --- a/src/engine/index.ts +++ b/src/engine/index.ts @@ -150,7 +150,6 @@ export interface Engine { /** * Minimize all windows on the surface except the given window. - * Used mainly in Monocle mode with config.monocleMinimizeRest */ minimizeOthers(window: EngineWindow): void; @@ -409,7 +408,8 @@ export class EngineImpl implements Engine { this.windows.remove(window); } - /** Focus next or previous window + /** + * Focus next or previous window * @param step direction to step in (1 for forward, -1 for back) * @param includeHidden whether to switch to or skip minimized windows */