workspace-indicator: Handle active indication in thumbnail

Meta.Workspace has had an `active` property for a while now, so
we can use a property binding instead of tracking the active
workspace ourselves.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/316>
This commit is contained in:
Florian Müllner
2024-02-27 21:20:45 +01:00
parent b55e7a4dc8
commit a2ffb1238f
@@ -111,6 +111,13 @@ class WorkspaceLayout extends Clutter.LayoutManager {
}
class WorkspaceThumbnail extends St.Button {
static [GObject.properties] = {
'active': GObject.ParamSpec.boolean(
'active', '', '',
GObject.ParamFlags.READWRITE,
false),
};
static {
GObject.registerClass(this);
}
@@ -143,6 +150,10 @@ class WorkspaceThumbnail extends St.Button {
let workspaceManager = global.workspace_manager;
this._workspace = workspaceManager.get_workspace_by_index(index);
this._workspace.bind_property('active',
this, 'active',
GObject.BindingFlags.SYNC_CREATE);
this._workspace.connectObject(
'window-added', (ws, window) => this._addWindow(window),
'window-removed', (ws, window) => this._removeWindow(window),
@@ -155,6 +166,18 @@ class WorkspaceThumbnail extends St.Button {
this._onRestacked();
}
get active() {
return this.has_style_class_name('active');
}
set active(active) {
if (active)
this.add_style_class_name('active');
else
this.remove_style_class_name('active');
this.notify('active');
}
acceptDrop(source) {
if (!source.metaWindow)
return false;
@@ -360,7 +383,6 @@ export class WorkspaceIndicator extends PanelMenu.Button {
this._currentWorkspace = global.workspace_manager.get_active_workspace_index();
this._updateMenuOrnament();
this._updateActiveThumbnail();
this._statusLabel.set_text(this._getStatusText());
}
@@ -379,16 +401,6 @@ export class WorkspaceIndicator extends PanelMenu.Button {
}
}
_updateActiveThumbnail() {
let thumbs = this._thumbnailsBox.get_children();
for (let i = 0; i < thumbs.length; i++) {
if (i === this._currentWorkspace)
thumbs[i].add_style_class_name('active');
else
thumbs[i].remove_style_class_name('active');
}
}
_getStatusText() {
const {nWorkspaces} = global.workspace_manager;
const current = this._currentWorkspace + 1;
@@ -436,7 +448,6 @@ export class WorkspaceIndicator extends PanelMenu.Button {
let thumb = new WorkspaceThumbnail(i);
this._thumbnailsBox.add_child(thumb);
}
this._updateActiveThumbnail();
}
_activate(index) {