Skip to content

Commit

Permalink
Added support for GNOME 45.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlynxZhou committed Oct 10, 2023
1 parent c098387 commit 99eb28d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
61 changes: 37 additions & 24 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,50 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

/* exported init, enable, disable */

import { ThumbnailsBox } from "resource:///org/gnome/shell/ui/workspaceThumbnail.js";
import {
ThumbnailsBox
} from "resource:///org/gnome/shell/ui/workspaceThumbnail.js";
import {
InjectionManager
} from "resource:///org/gnome/shell/extensions/extension.js";

export default class AlwaysShowWorkspaceThumbnails {
constructor() {
this._injectionManager = new InjectionManager();
}

enable() {
ThumbnailsBox.prototype._updateShouldShowOrig =
ThumbnailsBox.prototype._updateShouldShow;
// NOTE: Don't use arrow expressions for the function used to inject, we
// want it to use the calling context, but arrow expressions will bind this
// extension object to it. Also the document is wrong, it says it will
// change `this` for you, but actually not.

// Just set true, so we can always show ThumbnailsBox.
ThumbnailsBox.prototype._updateShouldShow = function () {
/*
const { nWorkspaces } = global.workspace_manager;
const shouldShow = this._settings.get_boolean('dynamic-workspaces')
? nWorkspaces > NUM_WORKSPACES_THRESHOLD
: nWorkspaces > 1;
*/
this._injectionManager.overrideMethod(
ThumbnailsBox.prototype,
"_updateShouldShow",
() => {
return function () {
const {nWorkspaces} = global.workspace_manager;
// AZ: If dynamic, don't check the number, always show it.
// const shouldShow = this._settings.get_boolean("dynamic-workspaces")
// ? nWorkspaces > NUM_WORKSPACES_THRESHOLD
// : nWorkspaces > 1;
const shouldShow = this._settings.get_boolean("dynamic-workspaces") ||
nWorkspaces > 1;

// if (this._shouldShow === shouldShow)
if (this._shouldShow === true) return;
if (this._shouldShow === shouldShow) {
return;
}

// this._shouldShow = shouldShow;
this._shouldShow = true;
this.notify("should-show");
};
this._shouldShow = shouldShow;
this.notify("should-show");
};
}
);
}

disable() {
if (ThumbnailsBox.prototype._updateShouldShowOrig instanceof Function) {
ThumbnailsBox.prototype._updateShouldShow =
ThumbnailsBox.prototype._updateShouldShowOrig;
ThumbnailsBox.prototype._updateShouldShowOrig = undefined;
}
this._injectionManager.clear();
}
}
};
1 change: 1 addition & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"description": "Always show workspace thumbnails even there is only one workspace.",
"uuid": "[email protected]",
"url": "https://github.com/AlynxZhou/gnome-shell-extension-always-show-workspace-thumbnails/",
"version": 6,
"shell-version": ["45"]
}

0 comments on commit 99eb28d

Please sign in to comment.