diff --git a/lib/extension/tree.js b/lib/extension/tree.js index 7d2c169..a9a18ba 100644 --- a/lib/extension/tree.js +++ b/lib/extension/tree.js @@ -363,7 +363,9 @@ export class Node extends GObject.Object { // 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.childNodes[node.index]; + + parentNode.childNodes.splice(node.index, 1); refNode.parentNode = null; } if (!refNode) { @@ -709,6 +711,28 @@ export class Tree extends Node { global.window_group.remove_child(existingWsNode.actorBin); this.removeChild(existingWsNode); + + let workspaces = this.nodeWorkpaces; + workspaces.forEach((wsNode) => { + // Extract the current integer index from "ws{n}" + let currentIndex = parseInt(wsNode.nodeValue.replace("ws", "")); + + // If the workspace was after the deleted one, shift it down + if (currentIndex > wsIndex) { + let newIndex = currentIndex - 1; + wsNode._data = `ws${newIndex}`; + + // Also update the IDs of the Monitor children + wsNode.childNodes.forEach((child) => { + if (child.nodeType === NODE_TYPES.MONITOR) { + // Monitor node values look like "mo{m}ws{n}" + let parts = child.nodeValue.split("ws"); + child._data = `${parts[0]}ws${newIndex}`; + } + }); + } + }); + return true; } @@ -1295,8 +1319,7 @@ export class Tree extends Node { let metaWin = w.nodeValue; try { this.extWm.move(metaWin, w.renderRect); - } catch (e) { - } + } catch (e) {} } else { Logger.debug(`ignoring apply for ${w.renderRect.width}x${w.renderRect.height}`); } @@ -1407,17 +1430,19 @@ export class Tree extends Node { } // Skip windows whose actors were destroyed mid-render - tiledChildren.filter((c) => c.isNodeValid()).forEach((child, index) => { - // A monitor can contain a window or container child - if (node.layout === LAYOUT_TYPES.HSPLIT || node.layout === LAYOUT_TYPES.VSPLIT) { - this.processSplit(node, child, params, index); - } else if (node.layout === LAYOUT_TYPES.STACKED) { - this.processStacked(node, child, params, index); - } else if (node.layout === LAYOUT_TYPES.TABBED) { - this.processTabbed(node, child, params, index); - } - this.processNode(child); - }); + tiledChildren + .filter((c) => c.isNodeValid()) + .forEach((child, index) => { + // A monitor can contain a window or container child + if (node.layout === LAYOUT_TYPES.HSPLIT || node.layout === LAYOUT_TYPES.VSPLIT) { + this.processSplit(node, child, params, index); + } else if (node.layout === LAYOUT_TYPES.STACKED) { + this.processStacked(node, child, params, index); + } else if (node.layout === LAYOUT_TYPES.TABBED) { + this.processTabbed(node, child, params, index); + } + this.processNode(child); + }); } if (node.isWindow()) { @@ -1558,8 +1583,7 @@ export class Tree extends Node { if (child.actor?.border) { borderWidth = child.actor.border.get_theme_node().get_border_width(St.Side.TOP); } - } catch (e) { - } + } catch (e) {} // Make adjustments to the gaps let adjust = 4 * Utils.dpi(); @@ -1584,8 +1608,7 @@ export class Tree extends Node { if (child.tab && !decoration.contains(child.tab)) { try { decoration.add_child(child.tab); - } catch (e) { - } + } catch (e) {} } }