Skip to content

Commit ce75e3f

Browse files
Add "auto unstack" switch
1 parent b5accce commit ce75e3f

File tree

7 files changed

+503
-432
lines changed

7 files changed

+503
-432
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**

schemas/org.gnome.shell.extensions.pop-shell.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
<summary>Hide the outer gap when a tree contains only one window</summary>
6565
</key>
6666

67+
<key type="b" name="auto-unstack">
68+
<default>false</default>
69+
<summary>Destroy a window stack when it contains only one window</summary>
70+
</key>
71+
6772
<key type="b" name="snap-to-grid">
6873
<default>false</default>
6974
<summary>Snaps windows to the tiling grid on drop</summary>

src/auto_tiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const Me = imports.misc.extensionUtils.getCurrentExtension();
22

33
import * as ecs from 'ecs';
4+
import * as geom from 'geom';
45
import * as lib from 'lib';
56
import * as log from 'log';
67
import * as node from 'node';
78
import * as result from 'result';
89
import * as stack from 'stack';
9-
import * as geom from 'geom';
1010
import * as tiling from 'tiling';
1111

1212
import type { Entity } from 'ecs';
@@ -232,9 +232,9 @@ export class AutoTiler {
232232
}
233233

234234
/** Detaches the window from a tiling branch, if it is attached to one. */
235-
detach_window(ext: Ext, win: Entity) {
235+
detach_window(ext: Ext, win: Entity, destroy_stack: boolean = true) {
236236
this.attached.take_with(win, (prev_fork: Entity) => {
237-
const reflow_fork = this.forest.detach(ext, prev_fork, win);
237+
const reflow_fork = this.forest.detach(ext, prev_fork, win, destroy_stack);
238238

239239
if (reflow_fork) {
240240
const fork = reflow_fork[1];

src/forest.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
33

44
import * as arena from 'arena';
55
import * as Ecs from 'ecs';
6+
import * as Fork from 'fork';
7+
import * as geom from 'geom';
68
import * as Lib from 'lib';
79
import * as log from 'log';
810
import * as movement from 'movement';
9-
import * as Rect from 'rectangle';
1011
import * as Node from 'node';
11-
import * as Fork from 'fork';
12-
import * as geom from 'geom';
12+
import * as Rect from 'rectangle';
1313

1414
import type { Entity } from 'ecs';
15-
import type { Rectangle } from './rectangle';
16-
import type { ShellWindow } from './window';
1715
import type { Ext } from './extension';
16+
import type { Rectangle } from './rectangle';
1817
import { Stack } from './stack';
18+
import type { ShellWindow } from './window';
1919

2020
const { Arena } = arena;
2121
const { Meta } = imports.gi;
@@ -350,7 +350,7 @@ export class Forest extends Ecs.World {
350350
}
351351

352352
/** Detaches an entity from the a fork, re-arranging the fork's tree as necessary */
353-
detach(ext: Ext, fork_entity: Entity, window: Entity): [Entity, Fork.Fork] | null {
353+
detach(ext: Ext, fork_entity: Entity, window: Entity, destroy_stack: boolean = false): [Entity, Fork.Fork] | null {
354354
const fork = this.forks.get(fork_entity);
355355
if (!fork) return null;
356356

@@ -387,8 +387,11 @@ export class Forest extends Ecs.World {
387387
ext,
388388
fork.left.inner as Node.NodeStack,
389389
window,
390-
() => {
391-
if (fork.right) {
390+
destroy_stack,
391+
(window: undefined | Entity) => {
392+
if (window)
393+
fork.left = Node.Node.window(window);
394+
else if (fork.right) {
392395
fork.left = fork.right
393396
fork.right = null
394397
if (parent) {
@@ -428,9 +431,14 @@ export class Forest extends Ecs.World {
428431
ext,
429432
fork.right.inner as Node.NodeStack,
430433
window,
431-
() => {
432-
fork.right = null
434+
destroy_stack,
435+
(window) => {
436+
if (window)
437+
fork.right = Node.Node.window(window);
438+
else {
439+
fork.right = null;
433440
this.reassign_to_parent(fork, fork.left)
441+
}
434442
},
435443
);
436444
}
@@ -714,7 +722,7 @@ export class Forest extends Ecs.World {
714722
}
715723

716724
/** Removes window from stack, destroying the stack if it was the last window. */
717-
private remove_from_stack(ext: Ext, stack: Node.NodeStack, window: Entity, on_last: () => void) {
725+
private remove_from_stack(ext: Ext, stack: Node.NodeStack, window: Entity, destroy_stack: boolean, on_last: (win?: Entity) => void) {
718726
if (stack.entities.length === 1) {
719727
this.stacks.remove(stack.idx)?.destroy();
720728
on_last();
@@ -723,6 +731,10 @@ export class Forest extends Ecs.World {
723731
if (s) {
724732
Node.stack_remove(this, stack, window)
725733
}
734+
if (destroy_stack && stack.entities.length === 1) {
735+
on_last(stack.entities[0])
736+
this.stacks.remove(stack.idx)?.destroy()
737+
}
726738
}
727739

728740
const win = ext.windows.get(window);

0 commit comments

Comments
 (0)