Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
54 changes: 42 additions & 12 deletions lib/extension/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,20 @@ export class Node extends GObject.Object {
node.decoration = null;
}

let refNode;
if (this.contains(node)) {
// Since contains() tries to find node on all descendants,
// detach only from the immediate parent
let parentNode = node.parentNode;
refNode = parentNode.childNodes.splice(node.index, 1);
refNode.parentNode = null;
}
if (!refNode) {
// Detach this very node from its immediate parent. contains() matches by
// value: for a detached node whose window had another node there, index
// was null and splice(null, 1) dropped the parent's first child instead.
let parentNode = node.parentNode;
let index = parentNode ? parentNode.childNodes.indexOf(node) : -1;
if (index >= 0) {
parentNode.childNodes.splice(index, 1);
} else if (!this.contains(node)) {
throw `NodeNotFound ${node}`;
} else {
Logger.warn(`detaching a node its parent did not hold: ${node.nodeValue}`);
}
return refNode;
node.parentNode = null;
return node;
}

/**
Expand Down Expand Up @@ -620,6 +622,10 @@ export class Queue extends GObject.Object {
dequeue() {
return this._elements.shift();
}

has(predicate) {
return this._elements.some(predicate);
}
}

export class Tree extends Node {
Expand Down Expand Up @@ -1062,7 +1068,7 @@ export class Tree extends Node {
monitorDirection
);
if (targetMonitor < 0) return targetMonitor;
let monWs = `mo${targetMonitor}ws${nodeWindow.nodeValue.get_workspace().index()}`;
let monWs = this.extWm.monWsKey(targetMonitor, nodeWindow.nodeValue.get_workspace().index());
monitorNode = this.findNode(monWs);
return monitorNode;
}
Expand Down Expand Up @@ -1127,6 +1133,7 @@ export class Tree extends Node {

// Push down the Meta.Window into a new Container
let currentIndex = node.index;
if (currentIndex === null) return;
let container = new St.Bin();
let newConNode = new Node(NODE_TYPES.CON, container);
newConNode.settings = this.settings;
Expand All @@ -1138,8 +1145,13 @@ export class Tree extends Node {
newConNode.percent = node.percent;
newConNode.parentNode = parentNode;
parentNode.childNodes[currentIndex] = newConNode;
this.createNode(container, node.nodeType, node.nodeValue);
// Move the window's own node into the container. A new node lost its
// mode (a window being dragged turned back to TILE) and state, and the
// old one, detached but still referenced (drag-and-drop target...), was
// re-attached later as a second node of the same window.
newConNode.childNodes.push(node);
node.parentNode = newConNode;
node.percent = 0.0;
this.attachNode = newConNode;
}

Expand Down Expand Up @@ -1273,6 +1285,7 @@ export class Tree extends Node {

render(from) {
Logger.debug(`render tree ${from ? "from " + from : ""}`);
this.removeDuplicateWindows();
this.processNode(this);
this.apply(this);
this.cleanTree();
Expand All @@ -1283,6 +1296,23 @@ export class Tree extends Node {
Logger.debug(`*********************************************`);
}

/**
* A window must have a single node. A second one was moved to its own,
* stale tile at each render while findNode() returned the first: the
* window sat on the wrong monitor and both nodes fought over it.
*/
removeDuplicateWindows() {
const seen = new Set();
this.getNodeByType(NODE_TYPES.WINDOW).forEach((w) => {
if (!seen.has(w.nodeValue)) {
seen.add(w.nodeValue);
return;
}
Logger.warn(`dropping a second node of ${w.nodeValue.get_wm_class()}`);
w.parentNode.removeChild(w);
});
}

apply(node) {
if (!node) return;
let tiledChildren = node
Expand Down
Loading