[gnome-shell-extensions/gnome-3-26] 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/gnome-3-26] auto-move-windows: Cache app configuration in map
- Date: Thu, 18 Jan 2018 12:50:21 +0000 (UTC)
commit caab9465f484ffa530da6dcd651e5e7ef0b4dc6e
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 8915747..d45c730 100644
--- a/extensions/auto-move-windows/extension.js
+++ b/extensions/auto-move-windows/extension.js
@@ -11,20 +11,29 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
-const SETTINGS_KEY = 'application-list';
-
-let settings;
-
const WindowMover = new Lang.Class({
Name: 'AutoMoveWindows.WindowMover',
_init: function() {
- 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', Lang.bind(this, this._findAndMove));
+
+ this._settings.connect('changed', this._updateAppConfigs.bind(this));
+ this._updateAppConfigs();
+ },
+
+ _updateAppConfigs: function() {
+ this._appConfigs.clear();
+
+ this._settings.get_strv('application-list').forEach(v => {
+ let [appId, num] = v.split(':');
+ this._appConfigs.set(appId, parseInt(num) - 1);
+ });
},
destroy: function() {
@@ -32,6 +41,11 @@ const WindowMover = new Lang.Class({
global.screen.get_display().disconnect(this._windowCreatedId);
this._windowCreatedId = 0;
}
+
+ if (this._settings) {
+ this._settings.run_dispose();
+ this._settings = null;
+ }
},
_ensureAtLeastWorkspaces: function(num, window) {
@@ -45,8 +59,6 @@ const WindowMover = new Lang.Class({
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) {
@@ -59,18 +71,12 @@ const WindowMover = new Lang.Class({
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);
}
}
});
@@ -80,7 +86,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]