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

Add "auto unstack" switch #1657

Open
wants to merge 9 commits into
base: master_jammy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions schemas/org.gnome.shell.extensions.pop-shell.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<summary>Hide the outer gap when a tree contains only one window</summary>
</key>

<key type="b" name="auto-unstack">
<default>false</default>
<summary>Destroy stacks when separated by the mouse</summary>
</key>

<key type="b" name="snap-to-grid">
<default>false</default>
<summary>Snaps windows to the tiling grid on drop</summary>
Expand Down
6 changes: 3 additions & 3 deletions src/auto_tiler.ts
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is me trying to move the imports back to their rightful place

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const Me = imports.misc.extensionUtils.getCurrentExtension();

import * as ecs from 'ecs';
import * as geom from 'geom';
import * as lib from 'lib';
import * as log from 'log';
import * as node from 'node';
import * as result from 'result';
import * as stack from 'stack';
import * as geom from 'geom';
import * as tiling from 'tiling';

import type { Entity } from 'ecs';
Expand Down Expand Up @@ -232,9 +232,9 @@ export class AutoTiler {
}

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

if (reflow_fork) {
const fork = reflow_fork[1];
Expand Down
34 changes: 23 additions & 11 deletions src/forest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();

import * as arena from 'arena';
import * as Ecs from 'ecs';
import * as Fork from 'fork';
import * as geom from 'geom';
import * as Lib from 'lib';
import * as log from 'log';
import * as movement from 'movement';
import * as Rect from 'rectangle';
import * as Node from 'node';
import * as Fork from 'fork';
import * as geom from 'geom';
import * as Rect from 'rectangle';

import type { Entity } from 'ecs';
import type { Rectangle } from './rectangle';
import type { ShellWindow } from './window';
import type { Ext } from './extension';
import type { Rectangle } from './rectangle';
import { Stack } from './stack';
import type { ShellWindow } from './window';

const { Arena } = arena;
const { Meta } = imports.gi;
Expand Down Expand Up @@ -350,7 +350,7 @@ export class Forest extends Ecs.World {
}

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

Expand Down Expand Up @@ -387,8 +387,11 @@ export class Forest extends Ecs.World {
ext,
fork.left.inner as Node.NodeStack,
window,
() => {
if (fork.right) {
destroy_stack,
(window: undefined | Entity) => {
if (window)
fork.left = Node.Node.window(window);
else if (fork.right) {
fork.left = fork.right
fork.right = null
if (parent) {
Expand Down Expand Up @@ -428,9 +431,14 @@ export class Forest extends Ecs.World {
ext,
fork.right.inner as Node.NodeStack,
window,
() => {
fork.right = null
destroy_stack,
(window) => {
if (window)
fork.right = Node.Node.window(window);
else {
fork.right = null;
this.reassign_to_parent(fork, fork.left)
}
},
);
}
Expand Down Expand Up @@ -714,7 +722,7 @@ export class Forest extends Ecs.World {
}

/** Removes window from stack, destroying the stack if it was the last window. */
private remove_from_stack(ext: Ext, stack: Node.NodeStack, window: Entity, on_last: () => void) {
private remove_from_stack(ext: Ext, stack: Node.NodeStack, window: Entity, destroy_stack: boolean, on_last: (win?: Entity) => void) {
if (stack.entities.length === 1) {
this.stacks.remove(stack.idx)?.destroy();
on_last();
Expand All @@ -723,6 +731,10 @@ export class Forest extends Ecs.World {
if (s) {
Node.stack_remove(this, stack, window)
}
if (destroy_stack && stack.entities.length === 1) {
on_last(stack.entities[0])
this.stacks.remove(stack.idx)?.destroy()
}
}

const win = ext.windows.get(window);
Expand Down
Loading