Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tiling): Windows launching onto window that isn't focused #1171

Merged
merged 4 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/auto_tiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
Expand Down Expand Up @@ -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');
Expand Down
20 changes: 17 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class Ext extends Ecs.System<ExtEvent> {
injections: Array<Injection> = 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<string, [SignalID, any]> = new Map();

Expand Down Expand Up @@ -792,8 +792,11 @@ export class Ext extends Ecs.System<ExtEvent> {
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) {
Expand Down Expand Up @@ -1067,6 +1070,17 @@ export class Ext extends Ecs.System<ExtEvent> {
}
}

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) {
Expand Down