From fa3f9bcaeea1a4c167b121f7efdbfb0e101703a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 24 Sep 2024 20:31:06 +0200 Subject: [PATCH] window-list: Save and restore positions as runtime state While it doesn't make sense for window list positions to be truly persistent like dash items, some persistence is desirable. Otherwise any manually set position is lost when the extension is disabled, for example when locking the screen. To address this, serialize the positions as runtime state on drop, and restore them when populating the list. Part-of: --- extensions/window-list/extension.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js index b5be15e6..885bb5ac 100644 --- a/extensions/window-list/extension.js +++ b/extensions/window-list/extension.js @@ -35,6 +35,8 @@ const DRAG_RESIZE_DURATION = 400; const DRAG_PROXIMITY_THRESHOLD = 30; +const SAVED_POSITIONS_KEY = 'window-list-positions'; + const GroupingMode = { NEVER: 0, AUTO: 1, @@ -1095,6 +1097,8 @@ class WindowList extends St.Widget { for (let i = 0; i < apps.length; i++) this._addApp(apps[i], false); } + + this._restorePositions(); } _updateKeyboardAnchor() { @@ -1243,9 +1247,33 @@ class WindowList extends St.Widget { this._clearDragPlaceholder(); + this._savePositions(); + return true; } + _getPositionStateKey() { + return `${SAVED_POSITIONS_KEY}:${this._monitor.index}`; + } + + _savePositions() { + const buttons = this._windowList.get_children() + .filter(b => b instanceof BaseButton); + global.set_runtime_state(this._getPositionStateKey(), + new GLib.Variant('as', buttons.map(b => b.id))); + } + + _restorePositions() { + const positions = global.get_runtime_state('as', + this._getPositionStateKey())?.deepUnpack() ?? []; + + for (const button of this._windowList.get_children()) { + const pos = positions.indexOf(button.id); + if (pos > -1) + this._windowList.set_child_at_index(button, pos); + } + } + _monitorItemDrag() { DND.addDragMonitor(this._itemDragMonitor); }