diff --git a/src/auto_tiler.ts b/src/auto_tiler.ts index b1eeb919..7d233e13 100644 --- a/src/auto_tiler.ts +++ b/src/auto_tiler.ts @@ -202,6 +202,7 @@ export class AutoTiler { log.debug(`attach to workspace: ${result.value}`) this.attach_to_workspace(ext, win, ext.workspace_id(win)); } else { + log.debug(`attaching to window ${win.entity}`) this.attach_to_window(ext, result.value, win, { auto: 0 }) } } @@ -656,7 +657,7 @@ export class AutoTiler { return Err('ignoring focus'); } - const prev = ext.prev_focused[1] + const prev = ext.previously_focused(win) if (!prev) { return Err('no window has been previously focused'); @@ -684,9 +685,9 @@ export class AutoTiler { return Err('focused window is not attached'); } - return onto.meta.get_monitor() == win.meta.get_monitor() && onto.workspace_id() == win.workspace_id() + return onto.workspace_id() == win.workspace_id() ? Ok(onto) - : Err('window is not on the same monitor or workspace'); + : Err('window is not on the same workspace'); } private toggle_orientation_(ext: Ext, focused: ShellWindow): Result { diff --git a/src/extension.ts b/src/extension.ts index c1af4d43..21672a80 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -152,7 +152,7 @@ export class Ext extends Ecs.System { injections: Array = new Array(); /** The window that was focused before the last window */ - prev_focused: [null | Entity, null | Entity] = [null, null]; + private prev_focused: [null | Entity, null | Entity] = [null, null]; tween_signals: Map = new Map(); @@ -792,8 +792,11 @@ export class Ext extends Ecs.System { this.exception_add(win) } - this.prev_focused[0] = this.prev_focused[1]; - this.prev_focused[1] = win.entity; + // Track history of focused windows, but do not permit duplicates. + if (this.prev_focused[1] !== win.entity) { + this.prev_focused[0] = this.prev_focused[1]; + this.prev_focused[1] = win.entity; + } // Update the active tab in the stack. if (null !== this.auto_tiler && null !== win.stack) { @@ -1067,6 +1070,17 @@ export class Ext extends Ecs.System { } } + previously_focused(active: Window.ShellWindow): null | Ecs.Entity { + for (const id of [1, 0]) { + const prev = this.prev_focused[id] + if (prev && ! Ecs.entity_eq(active.entity, prev)) { + return prev; + } + } + + return null + } + movement_is_valid(win: Window.ShellWindow, movement: movement.Movement) { if ((movement & Movement.SHRINK) !== 0) { if ((movement & Movement.DOWN) !== 0) { @@ -2021,7 +2035,7 @@ export class Ext extends Ecs.System { let actor = window.meta.get_compositor_private(); if (actor) { if (!window.meta.minimized) { - tiler.auto_tile(this, window, false); + tiler.auto_tile(this, window, true); } } }