Skip to content

Commit 475b49d

Browse files
committed
fix: Focus handling improvements to fix inconsistencies in stack add / remove
1 parent 9616931 commit 475b49d

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

src/auto_tiler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,13 @@ export class AutoTiler {
655655
return Err('ignoring focus');
656656
}
657657

658-
if (!ext.prev_focused) {
658+
const prev = ext.prev_focused[0]
659+
660+
if (!prev) {
659661
return Err('no window has been previously focused');
660662
}
661663

662-
let onto = ext.windows.get(ext.prev_focused);
664+
let onto = ext.windows.get(prev);
663665

664666
if (!onto) {
665667
return Err('no focus window');

src/extension.ts

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,8 @@ export class Ext extends Ecs.System<ExtEvent> {
150150
/** Functions replaced in GNOME */
151151
injections: Array<Injection> = new Array();
152152

153-
/** The last window that was focused */
154-
last_focused: Entity | null = null;
155-
156153
/** The window that was focused before the last window */
157-
prev_focused: Entity | null = null;
154+
prev_focused: [null | Entity, null | Entity] = [null, null];
158155

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

@@ -629,11 +626,7 @@ export class Ext extends Ecs.System<ExtEvent> {
629626
}
630627

631628
focus_window(): Window.ShellWindow | null {
632-
let focused = this.get_window(display.get_focus_window())
633-
if (!focused && this.last_focused) {
634-
focused = this.windows.get(this.last_focused);
635-
}
636-
return focused;
629+
return this.get_window(display.get_focus_window())
637630
}
638631

639632
stack_select(
@@ -723,7 +716,7 @@ export class Ext extends Ecs.System<ExtEvent> {
723716

724717
on_active_workspace_changed() {
725718
this.exit_modes();
726-
this.last_focused = null;
719+
this.prev_focused = [null, null]
727720
this.restack()
728721
}
729722

@@ -738,20 +731,16 @@ export class Ext extends Ecs.System<ExtEvent> {
738731
}
739732
});
740733

741-
if (this.last_focused == win) {
742-
this.last_focused = null;
734+
if (this.auto_tiler) {
735+
const entity = this.auto_tiler.attached.get(win);
736+
if (entity) {
737+
const fork = this.auto_tiler.forest.forks.get(entity);
738+
if (fork?.right?.is_window(win)) {
739+
const entity = fork.right.inner.kind === 3
740+
? fork.right.inner.entities[0]
741+
: fork.right.inner.entity;
743742

744-
if (this.auto_tiler) {
745-
const entity = this.auto_tiler.attached.get(win);
746-
if (entity) {
747-
const fork = this.auto_tiler.forest.forks.get(entity);
748-
if (fork?.right?.is_window(win)) {
749-
const entity = fork.right.inner.kind === 3
750-
? fork.right.inner.entities[0]
751-
: fork.right.inner.entity;
752-
753-
this.windows.with(entity, (sibling) => sibling.activate())
754-
}
743+
this.windows.with(entity, (sibling) => sibling.activate())
755744
}
756745
}
757746
}
@@ -782,16 +771,8 @@ export class Ext extends Ecs.System<ExtEvent> {
782771
this.exception_add(win)
783772
}
784773

785-
// Keep the last-focused window from being shifted too quickly. 300ms debounce
786-
if (this.focus_trigger === null) {
787-
this.focus_trigger = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 300, () => {
788-
this.focus_trigger = null;
789-
return false;
790-
});
791-
792-
this.prev_focused = this.last_focused;
793-
this.last_focused = win.entity;
794-
}
774+
this.prev_focused[0] = this.prev_focused[1];
775+
this.prev_focused[1] = win.entity;
795776

796777
// Update the active tab in the stack.
797778
if (null !== this.auto_tiler && null !== win.stack) {
@@ -801,9 +782,9 @@ export class Ext extends Ecs.System<ExtEvent> {
801782

802783
this.show_border_on_focused();
803784

804-
if (this.auto_tiler && this.prev_focused !== null) {
805-
let prev = this.windows.get(this.prev_focused);
806-
let is_attached = this.auto_tiler.attached.contains(this.prev_focused);
785+
if (this.auto_tiler && this.prev_focused[0] !== null) {
786+
let prev = this.windows.get(this.prev_focused[0]);
787+
let is_attached = this.auto_tiler.attached.contains(this.prev_focused[0]);
807788

808789
if (prev && prev !== win && is_attached && prev.actor_exists() && prev.name(this) !== win.name(this)) {
809790
if (prev.rect().contains(win.rect())) {
@@ -1848,7 +1829,7 @@ export class Ext extends Ecs.System<ExtEvent> {
18481829
// Bind show desktop and remove the active hint
18491830
this.connect(workspace_manager, 'showing-desktop-changed', () => {
18501831
this.hide_all_borders();
1851-
this.last_focused = null
1832+
this.prev_focused = [null, null]
18521833
});
18531834

18541835
St.ThemeContext.get_for_stage(global.stage)

0 commit comments

Comments
 (0)