From 502f8120815ce4a6b1d40ac1e79e046b0fc59624 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Thu, 14 Oct 2021 22:32:20 -0600 Subject: [PATCH] fix: no crashes in closing transients -- might fix others too; ref #110, #109 --- src/controller/index.ts | 64 +++++++++++++++++++++-------------------- src/driver/window.ts | 5 ++++ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/controller/index.ts b/src/controller/index.ts index 068d6dec..d2dd6d04 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -243,19 +243,17 @@ export class TilingController implements Controller { this.engine.arrange(); // Switch to next window if monocle with config.monocleMinimizeRest - try { - if (!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); - } - } catch { - /* HACK for the HACK: transient modals cause an error with the above workaround, - * so if we catch it here and ignore it, all is well */ - return; + if ( + !window.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); } } @@ -352,25 +350,29 @@ export class TilingController implements Controller { } public onWindowFocused(window: Window): void { - window.timestamp = new Date().getTime(); - this.currentWindow = window; - // Minimize other windows if Monocle and config.monocleMinimizeRest - if ( - this.engine.isLayoutMonocleAndMinimizeRest() && - this.engine.windows.getVisibleTiles(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.getAllTileables(window.surface), - window.surface.workingArea - ); + try { + window.timestamp = new Date().getTime(); + this.currentWindow = window; + // Minimize other windows if Monocle and config.monocleMinimizeRest + if ( + this.engine.isLayoutMonocleAndMinimizeRest() && + this.engine.windows.getVisibleTiles(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.getAllTileables(window.surface), + window.surface.workingArea + ); - this.engine.minimizeOthers(window); + this.engine.minimizeOthers(window); + } + } catch { + return; } } diff --git a/src/driver/window.ts b/src/driver/window.ts index b9af4908..1ba79fad 100644 --- a/src/driver/window.ts +++ b/src/driver/window.ts @@ -20,6 +20,7 @@ export interface DriverWindow { readonly shouldFloat: boolean; readonly screen: number; readonly active: boolean; + readonly isDialog: boolean; surface: DriverSurface; minimized: boolean; shaded: boolean; @@ -261,4 +262,8 @@ export class KWinWindow implements DriverWindow { return new Rect(geometry.x, geometry.y, width, height); } + + public get isDialog(): boolean { + return this.client.dialog; + } }