Skip to content

Commit 6df2541

Browse files
committed
fix: Stack swapping fixes
1 parent 3847079 commit 6df2541

File tree

6 files changed

+64
-42
lines changed

6 files changed

+64
-42
lines changed

src/auto_tiler.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ export class AutoTiler {
4848

4949
if (!a_fork || !b_fork) return;
5050

51-
function stack_detach(ext: Ext, win: ShellWindow): null | number {
52-
const win_stack = win.stack;
53-
if (win.stack !== null) ext.auto_tiler
54-
?.forest.stacks.get(win.stack)
55-
?.deactivate(win);
56-
return win_stack;
57-
}
51+
const a_stack = a_win.stack, b_stack = b_win.stack;
5852

59-
const a_stack = stack_detach(ext, a_win);
60-
const b_stack = stack_detach(ext, b_win);
53+
if (ext.auto_tiler) {
54+
if (a_win.stack !== null) ext.auto_tiler.forest.stacks.get(a_win.stack)?.deactivate(a_win);
55+
if (b_win.stack !== null) ext.auto_tiler.forest.stacks.get(b_win.stack)?.deactivate(b_win);
56+
}
6157

62-
a_fork.replace_window(ext, a_win, b_win);
58+
const a_fn = a_fork.replace_window(ext, a_win, b_win);
6359
this.attached.insert(b, a_ent);
64-
a_win.stack = b_stack;
6560
this.tile(ext, a_fork, a_fork.area);
6661

67-
b_fork.replace_window(ext, b_win, a_win);
62+
const b_fn = b_fork.replace_window(ext, b_win, a_win);
6863
this.attached.insert(a, b_ent);
69-
b_win.stack = a_stack;
7064
this.tile(ext, b_fork, b_fork.area);
65+
66+
if (a_fn) a_fn();
67+
if (b_fn) b_fn();
68+
69+
a_win.stack = b_stack;
70+
b_win.stack = a_stack;
7171
}
7272

7373
update_toplevel(ext: Ext, fork: Fork, monitor: number, smart_gaps: boolean) {

src/fork.ts

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,39 +118,57 @@ export class Fork {
118118
}
119119

120120
/** Replaces the association of a window in a fork with another */
121-
replace_window(ext: Ext, a: ShellWindow, b: ShellWindow): boolean {
122-
if (!this.right) return false;
123-
121+
replace_window(ext: Ext, a: ShellWindow, b: ShellWindow): null | (() => void) {
124122
switch (this.left.inner.kind) {
125123
case 2:
126-
if (Ecs.entity_eq(this.left.inner.entity, a.entity)) {
127-
this.left.inner.entity = b.entity;
128-
} else if (this.right.inner.kind === 2) {
129-
this.right.inner.entity = b.entity;
130-
} else if (this.right.inner.kind === 3) {
131-
const idx = node.stack_find(this.right.inner, a.entity);
132-
if (idx === null) return false;
133-
node.stack_replace(ext, this.right.inner, idx, b.entity);
134-
this.right.inner.entities[idx] = b.entity;
124+
const inner = this.left.inner;
125+
if (Ecs.entity_eq(inner.entity, a.entity)) {
126+
return () => {
127+
inner.entity = b.entity;
128+
}
129+
} else if (this.right) {
130+
const inner = this.right.inner;
131+
if (inner.kind === 2) {
132+
return () => {
133+
inner.entity = b.entity;
134+
};
135+
} else if (inner.kind === 3) {
136+
const idx = node.stack_find(inner, a.entity);
137+
if (idx === null) return null;
138+
139+
return () => {
140+
node.stack_replace(ext, inner, idx, b);
141+
inner.entities[idx] = b.entity;
142+
};
143+
}
135144
}
136145

137146
break
138147
case 3:
139-
let idx = node.stack_find(this.left.inner, a.entity);
148+
const inner_s = this.left.inner as node.NodeStack;
149+
let idx = node.stack_find(inner_s, a.entity);
140150
if (idx !== null) {
141-
node.stack_replace(ext, this.left.inner, idx, b.entity);
142-
this.left.inner.entities[idx] = b.entity;
143-
} else if (this.right.inner.kind === 2) {
144-
this.right.inner.entity = b.entity;
145-
} else if (this.right.inner.kind === 3) {
146-
const idx = node.stack_find(this.right.inner, a.entity);
147-
if (idx === null) return false;
148-
node.stack_replace(ext, this.right.inner, idx, b.entity);
149-
this.right.inner.entities[idx] = b.entity;
151+
const id = idx;
152+
return () => {
153+
node.stack_replace(ext, inner_s, id, b);
154+
inner_s.entities[id] = b.entity;
155+
}
156+
} else if (this.right) {
157+
const inner = this.right.inner;
158+
if (inner.kind === 2) {
159+
return () => inner.entity = b.entity;
160+
} else if (inner.kind === 3) {
161+
const idx = node.stack_find(inner, a.entity);
162+
if (idx === null) return null;
163+
return () => {
164+
node.stack_replace(ext, inner, idx, b);
165+
inner.entities[idx] = b.entity;
166+
};
167+
}
150168
}
151169
}
152170

153-
return true;
171+
return null;
154172
}
155173

156174
/** Sets a new area for this fork */

src/node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Entity } from 'ecs';
88
import type { Ext } from 'extension';
99
import type { Rectangle } from 'rectangle';
1010
import type { Stack } from 'stack';
11+
import { ShellWindow } from './window';
1112

1213
/** A node is either a fork a window */
1314
export enum NodeKind {
@@ -116,14 +117,13 @@ export function stack_move_right(ext: Ext, forest: Forest, node: NodeStack, enti
116117
return moved;
117118
}
118119

119-
export function stack_replace(ext: Ext, node: NodeStack, from: number, window: Entity) {
120+
export function stack_replace(ext: Ext, node: NodeStack, from: number, window: ShellWindow) {
120121
if (!ext.auto_tiler) return;
121122

122123
const stack = ext.auto_tiler.forest.stacks.get(node.idx);
123124
if (!stack) return;
124125

125-
const win = ext.windows.get(window);
126-
if (win) stack.replace(from, win)
126+
stack.replace(from, window)
127127
}
128128

129129
/** Removes a window from a stack */

src/stack.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export class Stack {
237237
const c = this.components[idx];
238238
if (c) {
239239
for (const s of c.signals) c.meta.disconnect(s);
240-
c.meta.get_compositor_private()?.show();
240+
241+
const actor = window.meta.get_compositor_private();
241242

242243
if (this.active_meta === c.meta) {
243244
if (this.active_signal) this.active_meta.disconnect(this.active_signal);
@@ -246,9 +247,9 @@ export class Stack {
246247
this.update_positions(window.meta.get_frame_rect());
247248
});
248249
this.active = window.entity;
249-
window.meta.get_compositor_private()?.show();
250+
actor?.show();
250251
} else {
251-
window.meta.get_compositor_private()?.hide();
252+
actor?.hide();
252253
}
253254

254255
c.meta = window.meta;

src/tiling.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ export class Tiler {
628628
ext.size_signals_unblock(meta);
629629
ext.add_tag(meta_entity, Tags.Tiled);
630630
});
631+
632+
ext.active_hint?.track_window(ext, meta, false);
631633
}
632634
}
633635

src/window.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export class ShellWindow {
175175
ext.tween_signals.delete(entity_string);
176176
if (ext.active_hint?.is_tracking(this.entity)) {
177177
ext.active_hint.track_window(ext, this);
178+
ext.active_hint.show();
178179
}
179180
};
180181

0 commit comments

Comments
 (0)