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: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/338>
This commit is contained in:
committed by
Marge Bot
parent
3f660ee973
commit
fa3f9bcaee
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user