[gnome-shell-extensions/wip/fmuellner/fix-auto-move: 9/12] auto-move-windows: Cache app configuration in map
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/fmuellner/fix-auto-move: 9/12] auto-move-windows: Cache app configuration in map
- Date: Thu, 18 Jan 2018 12:27:13 +0000 (UTC)
commit 0721ed6504ee8af37804b5d5fdc05f3e63799905
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Dec 21 21:13:13 2017 +0100
auto-move-windows: Cache app configuration in map
While reading the configuration, processing it and iterating over the
configured apps to find a match isn't terribly expensive, but caching
the configuration in a map does save a bit of work, and makes for much
cleaner code in findAndMove().
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/33
extensions/auto-move-windows/extension.js | 45 +++++++++++++++++--------------
1 file changed, 25 insertions(+), 20 deletions(-)
---
diff --git a/extensions/auto-move-windows/extension.js b/extensions/auto-move-windows/extension.js
index d759f07..92ce7b1 100644
--- a/extensions/auto-move-windows/extension.js
+++ b/extensions/auto-move-windows/extension.js
@@ -10,18 +10,27 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
-const SETTINGS_KEY = 'application-list';
-
-let settings;
-
class WindowMover {
constructor() {
- this._settings = settings;
+ this._settings = Convenience.getSettings();
this._windowTracker = Shell.WindowTracker.get_default();
+ this._appConfigs = new Map();
let display = global.screen.get_display();
// Connect after so the handler from ShellWindowTracker has already run
this._windowCreatedId = display.connect_after('window-created', this._findAndMove.bind(this));
+
+ this._settings.connect('changed', this._updateAppConfigs.bind(this));
+ this._updateAppConfigs();
+ }
+
+ _updateAppConfigs() {
+ this._appConfigs.clear();
+
+ this._settings.get_strv('application-list').forEach(v => {
+ let [appId, num] = v.split(':');
+ this._appConfigs.set(appId, parseInt(num) - 1);
+ });
}
destroy() {
@@ -29,6 +38,11 @@ class WindowMover {
global.screen.get_display().disconnect(this._windowCreatedId);
this._windowCreatedId = 0;
}
+
+ if (this._settings) {
+ this._settings.run_dispose();
+ this._settings = null;
+ }
}
_ensureAtLeastWorkspaces(num, window) {
@@ -42,8 +56,6 @@ class WindowMover {
if (window.skip_taskbar)
return;
- let spaces = this._settings.get_strv(SETTINGS_KEY);
-
let app = this._windowTracker.get_window_app(window);
if (!app) {
if (!noRecurse) {
@@ -56,18 +68,12 @@ class WindowMover {
log ('Cannot find application for window');
return;
}
- let app_id = app.get_id();
- for (let i = 0; i < spaces.length; i++) {
- let appsToSpace = spaces[i].split(":");
- // Match application id
- if (appsToSpace[0] == app_id) {
- let workspaceNum = parseInt(appsToSpace[1]) - 1;
-
- if (workspaceNum >= global.screen.n_workspaces)
- this._ensureAtLeastWorkspaces(workspace_num, window);
-
- window.change_workspace_by_index(workspaceNum, false);
- }
+ let workspaceNum = this._appConfigs.get(app.get_id());
+ if (workspaceNum !== undefined) {
+ if (workspaceNum >= global.screen.n_workspaces)
+ this._ensureAtLeastWorkspaces(workspaceNum, window);
+
+ window.change_workspace_by_index(workspaceNum, false);
}
}
};
@@ -77,7 +83,6 @@ let winMover;
function init() {
Convenience.initTranslations();
- settings = Convenience.getSettings();
}
function myCheckWorkspaces() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]