[gnome-shell-extensions] AutoMoveWindows: override Main._checkWorkspace
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] AutoMoveWindows: override Main._checkWorkspace
- Date: Wed, 23 Feb 2011 18:08:48 +0000 (UTC)
commit 4e12738df297a12de005708d47339b8f0b7e89df
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Wed Feb 23 18:33:35 2011 +0100
AutoMoveWindows: override Main._checkWorkspace
Modify workspace management to only remove empty workspaces at end,
which is more consistent with a fixed workspace layout.
Also, some whitespace cleanup.
Patch provided by Thomas Bouffon <thomas bouffon gmail com>
extensions/auto-move-windows/extension.js | 97 ++++++++++++++++++++---------
1 files changed, 68 insertions(+), 29 deletions(-)
---
diff --git a/extensions/auto-move-windows/extension.js b/extensions/auto-move-windows/extension.js
index 658e62f..f12931c 100644
--- a/extensions/auto-move-windows/extension.js
+++ b/extensions/auto-move-windows/extension.js
@@ -1,3 +1,4 @@
+// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
// Start apps on custom workspaces
const Glib = imports.gi.GLib;
@@ -18,53 +19,91 @@ function WindowMover() {
WindowMover.prototype = {
_init: function() {
- this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
- this._windowTracker = Shell.WindowTracker.get_default();
+ this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
+ this._windowTracker = Shell.WindowTracker.get_default();
- let display = global.screen.get_display();
- // Connect after so the handler from ShellWindowTracker has already run
- display.connect_after('window-created', Lang.bind(this, this._findAndMove));
+ let display = global.screen.get_display();
+ // Connect after so the handler from ShellWindowTracker has already run
+ display.connect_after('window-created', Lang.bind(this, this._findAndMove));
},
- _ensureAtLeastWorkspaces: function(num) {
+ _ensureAtLeastWorkspaces: function(num, window) {
for (let j = global.screen.n_workspaces; j <= num; j++) {
+ window.change_workspace_by_index(j-1, false, global.get_current_time());
global.screen.append_new_workspace(false, 0);
}
},
_findAndMove: function(display, window, noRecurse) {
- if (!this._windowTracker.is_window_interesting(window))
- return;
-
- let spaces = this._settings.get_strv(SETTINGS_KEY);
-
- let app = this._windowTracker.get_window_app(window);
- if (!app) {
- if (!noRecurse) {
- // window is not tracked yet
- Mainloop.idle_add(Lang.bind(this, function() {
- this._findAndMove(display, window, true);
- return false;
- }));
- } else
- log ('Cannot find application for window');
- return;
- }
- let app_id = app.get_id();
+ if (!this._windowTracker.is_window_interesting(window))
+ return;
+
+ let spaces = this._settings.get_strv(SETTINGS_KEY);
+
+ let app = this._windowTracker.get_window_app(window);
+ if (!app) {
+ if (!noRecurse) {
+ // window is not tracked yet
+ Mainloop.idle_add(Lang.bind(this, function() {
+ this._findAndMove(display, window, true);
+ return false;
+ }));
+ } else
+ log ('Cannot find application for window');
+ return;
+ }
+ let app_id = app.get_id();
for ( let j = 0 ; j < spaces.length; j++ ) {
let apps_to_space = spaces[j].split(":");
// Match application id
if (apps_to_space[0] == app_id) {
- let workspace_num = parseInt(apps_to_space[1]) - 1;
- // FIXME: does not work with automatic management of workspaces
- // this._ensureAtLeastWorkspaces(workspace_num);
+ let workspace_num = parseInt(apps_to_space[1]) - 1;
+
+ if (workspace_num >= global.screen.n_workspaces)
+ this._ensureAtLeastWorkspaces(workspace_num, window);
- window.change_workspace_by_index(workspace_num, false, global.get_current_time());
+ window.change_workspace_by_index(workspace_num, false, global.get_current_time());
}
}
}
}
function main(extensionMeta) {
+ Main._checkWorkspaces = function() {
+ let i;
+ let emptyWorkspaces = new Array(Main._workspaces.length);
+
+ for (i = 0; i < Main._workspaces.length; i++)
+ emptyWorkspaces[i] = true;
+
+ let windows = global.get_window_actors();
+ for (i = 0; i < windows.length; i++) {
+ let win = windows[i];
+
+ if (win.get_meta_window().is_on_all_workspaces())
+ continue;
+
+ let workspaceIndex = win.get_workspace();
+ emptyWorkspaces[workspaceIndex] = false;
+ }
+
+ // If we don't have an empty workspace at the end, add one
+ if (!emptyWorkspaces[emptyWorkspaces.length -1]) {
+ global.screen.append_new_workspace(false, global.get_current_time());
+ emptyWorkspaces.push(false);
+ }
+
+ // Delete other empty workspaces; do it from the end to avoid index changes
+ for (i = emptyWorkspaces.length - 2; i >= 0; i--) {
+ if (emptyWorkspaces[i])
+ global.screen.remove_workspace(Main._workspaces[i], global.get_current_time());
+ else
+ break;
+ }
+ Main._checkWorkspacesId = 0;
+ return false;
+
+ };
+
new WindowMover();
-}
\ No newline at end of file
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]