1
0
Fork 0

Updating 44/vertical-workspaces to version 37+20231208 [0d82192].

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-24 19:42:07 +01:00
parent 975b88c6bb
commit 07381ac119
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
37 changed files with 9559 additions and 4338 deletions

View file

@ -9,30 +9,23 @@
'use strict';
const { GLib, Gio, Meta, St, Shell } = imports.gi;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Settings = Me.imports.lib.settings;
const _Util = Me.imports.lib.util;
let Me;
let opt;
// gettext
const _ = Settings._;
const shellVersion = Settings.shellVersion;
const ModifierType = imports.gi.Clutter.ModifierType;
let windowSearchProvider;
let _enableTimeoutId = 0;
let _;
// prefix helps to eliminate results from other search providers
// so it needs to be something less common
// needs to be accessible from vw module
var prefix = 'wq//';
let opt;
const PREFIX = 'wq//';
const Action = {
NONE: 0,
@ -42,66 +35,77 @@ const Action = {
MOVE_ALL_TO_WS: 4,
};
function getOverviewSearchResult() {
return Main.overview._overview.controls._searchController._searchResults;
}
var WindowSearchProviderModule = class {
// export for other modules
static _PREFIX = PREFIX;
constructor(me) {
Me = me;
opt = Me.opt;
_ = Me.gettext;
function update(reset = false) {
opt = Me.imports.lib.settings.opt;
if (!reset && opt.WINDOW_SEARCH_PROVIDER_ENABLED && !windowSearchProvider) {
enable();
} else if (reset || !opt.WINDOW_SEARCH_PROVIDER_ENABLED) {
disable();
this._firstActivation = true;
this.moduleEnabled = false;
// export for other modules
this._windowSearchProvider = null;
this._enableTimeoutId = 0;
}
cleanGlobals() {
Me = null;
opt = null;
_ = null;
}
}
function enable() {
// delay because Fedora had problem to register a new provider soon after Shell restarts
_enableTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
2000,
() => {
if (!windowSearchProvider) {
windowSearchProvider = new WindowSearchProvider(opt);
getOverviewSearchResult()._registerProvider(
windowSearchProvider
);
}
_enableTimeoutId = 0;
return GLib.SOURCE_REMOVE;
update(reset) {
this.moduleEnabled = opt.get('windowSearchProviderModule');
reset = reset || !this.moduleEnabled;
if (reset && !this._firstActivation) {
this._disableModule();
} else if (!reset) {
this._firstActivation = false;
this._activateModule();
}
);
}
if (reset && this._firstActivation)
console.debug(' WindowSearchProviderModule - Keeping untouched');
}
function disable() {
if (windowSearchProvider) {
getOverviewSearchResult()._unregisterProvider(
windowSearchProvider
_activateModule() {
// delay because Fedora had problem to register a new provider soon after Shell restarts
this._enableTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
2000,
() => {
if (!this._windowSearchProvider) {
this._windowSearchProvider = new WindowSearchProvider(opt);
this._getOverviewSearchResult()._registerProvider(this._windowSearchProvider);
}
this._enableTimeoutId = 0;
return GLib.SOURCE_REMOVE;
}
);
windowSearchProvider = null;
console.debug(' WindowSearchProviderModule - Activated');
}
if (_enableTimeoutId) {
GLib.source_remove(_enableTimeoutId);
_enableTimeoutId = 0;
_disableModule() {
if (this._windowSearchProvider) {
this._getOverviewSearchResult()._unregisterProvider(this._windowSearchProvider);
this._windowSearchProvider = null;
}
if (this._enableTimeoutId) {
GLib.source_remove(this._enableTimeoutId);
this._enableTimeoutId = 0;
}
console.debug(' WindowSearchProviderModule - Disabled');
}
}
function makeResult(window, i) {
const app = Shell.WindowTracker.get_default().get_window_app(window);
const appName = app ? app.get_name() : 'Unknown';
const windowTitle = window.get_title();
const wsIndex = window.get_workspace().index();
return {
'id': i,
// convert all accented chars to their basic form and lower case for search
'name': `${wsIndex + 1}: ${windowTitle} ${appName}`.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(),
appName,
windowTitle,
window,
};
}
_getOverviewSearchResult() {
return Main.overview._overview.controls._searchController._searchResults;
}
};
const closeSelectedRegex = /^\/x!$/;
const closeAllResultsRegex = /^\/xa!$/;
@ -110,15 +114,22 @@ const moveAllToWsRegex = /^\/ma[0-9]+$/;
const WindowSearchProvider = class WindowSearchProvider {
constructor() {
this.id = `open-windows@${Me.metadata.uuid}`;
this.appInfo = Gio.AppInfo.create_from_commandline('true', _('Open Windows'), null);
this.appInfo.get_description = () => _('List of open windows');
this.appInfo.get_name = () => _('Open Windows');
this.appInfo.get_id = () => this.id;
this.appInfo.get_icon = () => Gio.icon_new_for_string('focus-windows-symbolic');
this.appInfo.should_show = () => true;
this.id = 'open-windows';
const appSystem = Shell.AppSystem.get_default();
// use arbitrary app to get complete appInfo object
let appInfo = appSystem.lookup_app('com.matjakeman.ExtensionManager.desktop')?.get_app_info();
if (!appInfo)
appInfo = appSystem.lookup_app('org.gnome.Extensions.desktop')?.get_app_info();
if (!appInfo)
appInfo = Gio.AppInfo.create_from_commandline('true', _('Open Windows'), null);
appInfo.get_description = () => _('Search open windows');
appInfo.get_name = () => _('Open Windows');
appInfo.get_id = () => this.id;
appInfo.get_icon = () => Gio.icon_new_for_string('focus-windows-symbolic');
appInfo.should_show = () => true;
this.canLaunchSearch = true;
this.appInfo = appInfo;
this.canLaunchSearch = false;
this.isRemoteProvider = false;
this.action = 0;
@ -128,7 +139,7 @@ const WindowSearchProvider = class WindowSearchProvider {
// do not modify original terms
let termsCopy = [...terms];
// search for terms without prefix
termsCopy[0] = termsCopy[0].replace(prefix, '');
termsCopy[0] = termsCopy[0].replace(PREFIX, '');
/* if (gOptions.get('searchWindowsCommands')) {
this.action = 0;
@ -167,9 +178,9 @@ const WindowSearchProvider = class WindowSearchProvider {
let m;
for (let key in candidates) {
if (opt.SEARCH_FUZZY)
m = _Util.fuzzyMatch(term, candidates[key].name);
m = Me.Util.fuzzyMatch(term, candidates[key].name);
else
m = _Util.strictMatch(term, candidates[key].name);
m = Me.Util.strictMatch(term, candidates[key].name);
if (m !== -1)
results.push({ weight: m, id: key });
@ -178,7 +189,19 @@ const WindowSearchProvider = class WindowSearchProvider {
results.sort((a, b) => a.weight > b.weight);
const currentWs = global.workspace_manager.get_active_workspace_index();
// prefer current workspace
results.sort((a, b) => (this.windows[a.id].window.get_workspace().index() !== currentWs) && (this.windows[b.id].window.get_workspace().index() === currentWs));
switch (opt.WINDOW_SEARCH_ORDER) {
case 1: // MRU - current ws first
results.sort((a, b) => (this.windows[a.id].window.get_workspace().index() !== currentWs) && (this.windows[b.id].window.get_workspace().index() === currentWs));
break;
case 2: // MRU - by workspace
results.sort((a, b) => this.windows[a.id].window.get_workspace().index() > this.windows[b.id].window.get_workspace().index());
break;
case 3: // Stable sequence - by workspace
results.sort((a, b) => this.windows[a.id].window.get_stable_sequence() > this.windows[b.id].window.get_stable_sequence());
results.sort((a, b) => this.windows[a.id].window.get_workspace().index() > this.windows[b.id].window.get_workspace().index());
break;
}
results.sort((a, b) => (_terms !== ' ') && (a.weight > 0 && b.weight === 0));
this.resultIds = results.map(item => item.id);
@ -187,7 +210,7 @@ const WindowSearchProvider = class WindowSearchProvider {
getResultMetas(resultIds, callback = null) {
const metas = resultIds.map(id => this.getResultMeta(id));
if (shellVersion >= 43)
if (Me.shellVersion >= 43)
return new Promise(resolve => resolve(metas));
else
callback(metas);
@ -210,12 +233,29 @@ const WindowSearchProvider = class WindowSearchProvider {
};
}
makeResult(window, i) {
const app = Shell.WindowTracker.get_default().get_window_app(window);
const appName = app ? app.get_name() : 'Unknown';
const windowTitle = window.get_title();
const wsIndex = window.get_workspace().index();
return {
'id': i,
// convert all accented chars to their basic form and lower case for search
'name': `${wsIndex + 1}: ${windowTitle} ${appName}`.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(),
appName,
windowTitle,
window,
};
}
launchSearch(/* terms, timeStamp*/) {
}
activateResult(resultId/* , terms, timeStamp*/) {
const isCtrlPressed = _Util.isCtrlPressed();
const isShiftPressed = _Util.isShiftPressed();
const isCtrlPressed = Me.Util.isCtrlPressed();
const isShiftPressed = Me.Util.isShiftPressed();
this.action = 0;
this.targetWs = 0;
@ -276,15 +316,16 @@ const WindowSearchProvider = class WindowSearchProvider {
this.windows = windows = {};
global.display.get_tab_list(Meta.TabList.NORMAL, null).filter(w => w.get_workspace() !== null).map(
(v, i) => {
windows[`${i}-${v.get_id()}`] = makeResult(v, `${i}-${v.get_id()}`);
windows[`${i}-${v.get_id()}`] = this.makeResult(v, `${i}-${v.get_id()}`);
return windows[`${i}-${v.get_id()}`];
}
);
if (shellVersion >= 43)
if (Me.shellVersion >= 43)
return new Promise(resolve => resolve(this._getResultSet(terms)));
else
callback(this._getResultSet(terms));
return null;
}
@ -293,13 +334,15 @@ const WindowSearchProvider = class WindowSearchProvider {
return results;
}
getSubsearchResultSet(previousResults, terms, callback/* , cancellable*/) {
// if we return previous results, quick typers get non-actual results
callback(this._getResultSet(terms));
getSubsearchResultSet(previousResults, terms, callback) {
if (Me.shellVersion < 43) {
this.getSubsearchResultSet42(terms, callback);
return null;
}
return this.getInitialResultSet(terms);
}
/* createResultObject(resultMeta) {
const app = Shell.WindowTracker.get_default().get_window_app(resultMeta.id);
return new AppIcon(app);
}*/
getSubsearchResultSet42(terms, callback) {
callback(this._getResultSet(terms));
}
};