Skip to content

Commit e06dcb8

Browse files
committed
fix(tiling): Windows launching onto window that isn't focused
1 parent eab2b78 commit e06dcb8

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/auto_tiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ export class AutoTiler {
656656
return Err('ignoring focus');
657657
}
658658

659-
const prev = ext.prev_focused[1]
659+
const prev = ext.previously_focused(win)
660660

661661
if (!prev) {
662662
return Err('no window has been previously focused');

src/extension.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class Ext extends Ecs.System<ExtEvent> {
152152
injections: Array<Injection> = new Array();
153153

154154
/** The window that was focused before the last window */
155-
prev_focused: [null | Entity, null | Entity] = [null, null];
155+
private prev_focused: [null | Entity, null | Entity] = [null, null];
156156

157157
tween_signals: Map<string, [SignalID, any]> = new Map();
158158

@@ -789,8 +789,11 @@ export class Ext extends Ecs.System<ExtEvent> {
789789
this.exception_add(win)
790790
}
791791

792-
this.prev_focused[0] = this.prev_focused[1];
793-
this.prev_focused[1] = win.entity;
792+
// Track history of focused windows, but do not permit duplicates.
793+
if (this.prev_focused[1] !== win.entity) {
794+
this.prev_focused[0] = this.prev_focused[1];
795+
this.prev_focused[1] = win.entity;
796+
}
794797

795798
// Update the active tab in the stack.
796799
if (null !== this.auto_tiler && null !== win.stack) {
@@ -1063,6 +1066,17 @@ export class Ext extends Ecs.System<ExtEvent> {
10631066
this.tiler.snap(this, win);
10641067
}
10651068
}
1069+
1070+
previously_focused(active: Window.ShellWindow): null | Ecs.Entity {
1071+
for (const id of [1, 0]) {
1072+
const prev = this.prev_focused[id]
1073+
if (prev && ! Ecs.entity_eq(active.entity, prev)) {
1074+
return prev;
1075+
}
1076+
}
1077+
1078+
return null
1079+
}
10661080

10671081
movement_is_valid(win: Window.ShellWindow, movement: movement.Movement) {
10681082
if ((movement & Movement.SHRINK) !== 0) {

0 commit comments

Comments
 (0)