summaryrefslogtreecommitdiffstats
path: root/extensions/44/vertical-workspaces/lib/util.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-08 16:02:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-08 16:02:53 +0000
commit4d8b071804d73b7a733f2b7696fde40caf8800bb (patch)
tree86aefc1c0ea9c596bab0ecbc0c054a2378d6cd13 /extensions/44/vertical-workspaces/lib/util.js
parentUpdating 44/no-overview to version 44 [68db01d]. (diff)
downloadgnome-shell-extensions-extra-4d8b071804d73b7a733f2b7696fde40caf8800bb.tar.xz
gnome-shell-extensions-extra-4d8b071804d73b7a733f2b7696fde40caf8800bb.zip
Updating 44/vertical-workspaces to version 37+20231208 [0d82192].
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/44/vertical-workspaces/lib/util.js')
-rw-r--r--extensions/44/vertical-workspaces/lib/util.js199
1 files changed, 99 insertions, 100 deletions
diff --git a/extensions/44/vertical-workspaces/lib/util.js b/extensions/44/vertical-workspaces/lib/util.js
index 5f5c069..9bc4365 100644
--- a/extensions/44/vertical-workspaces/lib/util.js
+++ b/extensions/44/vertical-workspaces/lib/util.js
@@ -10,16 +10,27 @@
'use strict';
+const Clutter = imports.gi.Clutter;
+const Meta = imports.gi.Meta;
const Gi = imports._gi;
-const { Shell, Meta, Clutter } = imports.gi;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Shell = imports.gi.Shell;
-const Config = imports.misc.config;
-const Main = imports.ui.main;
+const Main = imports.ui.main;
-const ExtensionUtils = imports.misc.extensionUtils;
-const Me = ExtensionUtils.getCurrentExtension();
+let Me;
-var shellVersion = parseFloat(Config.PACKAGE_VERSION);
+let _installedExtensions;
+
+function init(me) {
+ Me = me;
+}
+
+function cleanGlobals() {
+ Me = null;
+ _installedExtensions = null;
+}
var Overrides = class {
constructor() {
@@ -27,8 +38,13 @@ var Overrides = class {
}
addOverride(name, prototype, overrideList) {
+ const backup = this.overrideProto(prototype, overrideList, name);
+ // don't update originals when override's just refreshing, keep initial content
+ let originals = this._overrides[name]?.originals;
+ if (!originals)
+ originals = backup;
this._overrides[name] = {
- originals: this.overrideProto(prototype, overrideList),
+ originals,
prototype,
};
}
@@ -38,15 +54,15 @@ var Overrides = class {
if (!override)
return false;
- this.overrideProto(override.prototype, override.originals);
- this._overrides[name] = undefined;
+ this.overrideProto(override.prototype, override.originals, name);
+ delete this._overrides[name];
return true;
}
removeAll() {
for (let name in this._overrides) {
this.removeOverride(name);
- this._overrides[name] = undefined;
+ delete this._overrides[name];
}
}
@@ -54,13 +70,17 @@ var Overrides = class {
proto[Gi.hook_up_vfunc_symbol](symbol, func);
}
- overrideProto(proto, overrides) {
+ overrideProto(proto, overrides, name) {
const backup = {};
-
+ const originals = this._overrides[name]?.originals;
for (let symbol in overrides) {
if (symbol.startsWith('after_')) {
const actualSymbol = symbol.slice('after_'.length);
- const fn = proto[actualSymbol];
+ let fn;
+ if (originals && originals[actualSymbol])
+ fn = originals[actualSymbol];
+ else
+ fn = proto[actualSymbol];
const afterFn = overrides[symbol];
proto[actualSymbol] = function (...args) {
args = Array.prototype.slice.call(args);
@@ -72,11 +92,11 @@ var Overrides = class {
} else {
backup[symbol] = proto[symbol];
if (symbol.startsWith('vfunc')) {
- if (shellVersion < 42)
+ if (Me.shellVersion < 42)
this.hookVfunc(proto, symbol.slice(6), overrides[symbol]);
else
this.hookVfunc(proto[Gi.gobject_prototype_symbol], symbol.slice(6), overrides[symbol]);
- } else {
+ } else if (overrides[symbol] !== null) {
proto[symbol] = overrides[symbol];
}
}
@@ -85,87 +105,21 @@ var Overrides = class {
}
};
-function getOverviewTranslations(opt, dash, tmbBox, searchEntryBin) {
- // const tmbBox = Main.overview._overview._controls._thumbnailsBox;
- let searchTranslationY = 0;
- if (searchEntryBin.visible) {
- const offset = (dash.visible && (!opt.DASH_VERTICAL ? dash.height + 12 : 0)) +
- (opt.WS_TMB_TOP ? tmbBox.height + 12 : 0);
- searchTranslationY = -searchEntryBin.height - offset - 30;
- }
-
- let tmbTranslationX = 0;
- let tmbTranslationY = 0;
- let offset;
- if (tmbBox.visible) {
- switch (opt.WS_TMB_POSITION) {
- case 3: // left
- offset = 10 + (dash?.visible && opt.DASH_LEFT ? dash.width : 0);
- tmbTranslationX = -tmbBox.width - offset;
- tmbTranslationY = 0;
- break;
- case 1: // right
- offset = 10 + (dash?.visible && opt.DASH_RIGHT ? dash.width : 0);
- tmbTranslationX = tmbBox.width + offset;
- tmbTranslationY = 0;
- break;
- case 0: // top
- offset = 10 + (dash?.visible && opt.DASH_TOP ? dash.height : 0) + Main.panel.height;
- tmbTranslationX = 0;
- tmbTranslationY = -tmbBox.height - offset;
- break;
- case 2: // bottom
- offset = 10 + (dash?.visible && opt.DASH_BOTTOM ? dash.height : 0) + Main.panel.height; // just for case the panel is at bottom
- tmbTranslationX = 0;
- tmbTranslationY = tmbBox.height + offset;
- break;
- }
- }
-
- let dashTranslationX = 0;
- let dashTranslationY = 0;
- let position = opt.DASH_POSITION;
- // if DtD replaced the original Dash, read its position
- if (dashIsDashToDock())
- position = dash._position;
-
- if (dash?.visible) {
- switch (position) {
- case 0: // top
- dashTranslationX = 0;
- dashTranslationY = -dash.height - dash.margin_bottom - Main.panel.height;
- break;
- case 1: // right
- dashTranslationX = dash.width;
- dashTranslationY = 0;
- break;
- case 2: // bottom
- dashTranslationX = 0;
- dashTranslationY = dash.height + dash.margin_bottom + Main.panel.height;
- break;
- case 3: // left
- dashTranslationX = -dash.width;
- dashTranslationY = 0;
- break;
- }
- }
-
- return [tmbTranslationX, tmbTranslationY, dashTranslationX, dashTranslationY, searchTranslationY];
-}
-
-function openPreferences() {
+function openPreferences(metadata) {
+ if (!metadata)
+ metadata = Me.metadata;
const windows = global.display.get_tab_list(Meta.TabList.NORMAL_ALL, null);
let tracker = Shell.WindowTracker.get_default();
let metaWin, isVW = null;
for (let win of windows) {
const app = tracker.get_window_app(win);
- if (win.get_title().includes(Me.metadata.name) && app.get_name() === 'Extensions') {
+ if (win.get_title()?.includes(metadata.name) && app.get_name() === 'Extensions') {
// this is our existing window
metaWin = win;
isVW = true;
break;
- } else if (win.wm_class.includes('org.gnome.Shell.Extensions')) {
+ } else if (win.wm_class?.includes('org.gnome.Shell.Extensions')) {
// this is prefs window of another extension
metaWin = win;
isVW = false;
@@ -182,17 +136,20 @@ function openPreferences() {
}
if (!metaWin || (metaWin && !isVW)) {
- try {
- Main.extensionManager.openExtensionPrefs(Me.metadata.uuid, '', {});
- } catch (e) {
- log(e);
- }
+ GLib.idle_add(GLib.PRIORITY_LOW, () => {
+ try {
+ Main.extensionManager.openExtensionPrefs(metadata.uuid, '', {});
+ } catch (e) {
+ console.error(e);
+ }
+ });
}
}
function activateSearchProvider(prefix = '') {
const searchEntry = Main.overview.searchEntry;
- if (!searchEntry.get_text() || !searchEntry.get_text().startsWith(prefix)) {
+ const searchEntryText = searchEntry.get_text();
+ if (!searchEntryText || (searchEntryText && !searchEntry.get_text().startsWith(prefix))) {
prefix = `${prefix} `;
const position = prefix.length;
searchEntry.set_text(prefix);
@@ -220,9 +177,16 @@ function reorderWorkspace(direction = 0) {
global.workspace_manager.reorder_workspace(activeWs, targetIdx);
}
+function activateKeyboardForWorkspaceView() {
+ Main.ctrlAltTabManager._items.forEach(i => {
+ if (i.sortGroup === 1 && i.name === 'Windows')
+ Main.ctrlAltTabManager.focusGroup(i);
+ });
+}
+
function exposeWindows(adjustment, activateKeyboard) {
// expose windows for static overview modes
- if (!adjustment.value && !Main.overview._animationInProgress) {
+ if (!adjustment.value/* && !Main.overview._animationInProgress*/) {
if (adjustment.value === 0) {
adjustment.value = 0;
adjustment.ease(1, {
@@ -330,13 +294,48 @@ function isMoreRelevant(stringA, stringB, pattern) {
return !aAny && bAny;
}
-function getEnabledExtensions(uuid = '') {
- let extensions = [];
- Main.extensionManager._extensions.forEach(e => {
- if (e.state === 1 && e.uuid.includes(uuid))
- extensions.push(e);
- });
- return extensions;
+function getEnabledExtensions(pattern = '') {
+ let result = [];
+ // extensionManager is unreliable at startup (if not all extensions were loaded)
+ // but gsettings key can contain removed extensions...
+ // therefore we have to look into filesystem, what's really installed
+ if (!_installedExtensions) {
+ const extensionFiles = [...collectFromDatadirs('extensions', true)];
+ _installedExtensions = extensionFiles.map(({ info }) => {
+ let fileType = info.get_file_type();
+ if (fileType !== Gio.FileType.DIRECTORY)
+ return null;
+ const uuid = info.get_name();
+ return uuid;
+ });
+ }
+ const enabled = Main.extensionManager._enabledExtensions;
+ result = _installedExtensions.filter(ext => enabled.includes(ext));
+ return result.filter(uuid => uuid !== null && uuid.includes(pattern));
+}
+
+function* collectFromDatadirs(subdir, includeUserDir) {
+ let dataDirs = GLib.get_system_data_dirs();
+ if (includeUserDir)
+ dataDirs.unshift(GLib.get_user_data_dir());
+
+ for (let i = 0; i < dataDirs.length; i++) {
+ let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', subdir]);
+ let dir = Gio.File.new_for_path(path);
+
+ let fileEnum;
+ try {
+ fileEnum = dir.enumerate_children('standard::name,standard::type',
+ Gio.FileQueryInfoFlags.NONE, null);
+ } catch (e) {
+ fileEnum = null;
+ }
+ if (fileEnum !== null) {
+ let info;
+ while ((info = fileEnum.next_file(null)))
+ yield { dir: fileEnum.get_child(info), info };
+ }
+ }
}
function getScrollDirection(event) {