[gnome-shell-extensions] AutoMoveWindows: new extension



commit ecd7c1754d7d4f0c5f15ca237fc8f6f1b25b28b5
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Feb 19 18:39:38 2011 +0100

    AutoMoveWindows: new extension
    
    Introduce a new extensions that allows to manage your workspaces
    more easily, assigning a specific workspace to each application,
    as soon as it creates a windows, in manner configurable with a
    GSettings key.

 .gitignore                                         |    2 +
 configure.ac                                       |   14 +++--
 extensions/Makefile.am                             |    2 +-
 extensions/auto-move-windows/Makefile.am           |   13 +++++
 extensions/auto-move-windows/extension.js          |   55 ++++++++++++++++++++
 extensions/auto-move-windows/metadata.json.in      |    8 +++
 ...ell.extensions.auto-move-windows.gschema.xml.in |   10 ++++
 extensions/auto-move-windows/stylesheet.css        |    1 +
 po/POTFILES.in                                     |    2 +
 9 files changed, 101 insertions(+), 6 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 3da8fe6..b9428a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@ staging/
 *~
 *.gmo
 metadata.json
+*.gschema.xml
+*.gschema.valid
diff --git a/configure.ac b/configure.ac
index 9240928..3688bf7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,10 +16,12 @@ IT_PROG_INTLTOOL(0.26)
 
 PKG_PROG_PKG_CONFIG([0.22])
 
+GLIB_GSETTINGS
+
 ADDITIONAL_PACKAGES=
 
 dnl keep this in sync with extensions/Makefile.am
-ALL_EXTENSIONS="example alternate-tab xrandr-indicator windowsNavigator"
+ALL_EXTENSIONS="example alternate-tab xrandr-indicator windowsNavigator auto-move-windows"
 AC_ARG_ENABLE([extensions],
 	[AS_HELP_STRING([--enable-extensions],[Space separated list of extensions to enable. Default is that all extensions are built.])],
 	[],
@@ -32,7 +34,7 @@ for e in $enable_extensions; do
 			ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e"
 			ADDITIONAL_PACKAGES="gnome-desktop-3.0 >= 2.91.6"
 			;;
-		alternate-tab|example|windowsNavigator)
+		alternate-tab|example|windowsNavigator|auto-move-windows)
 			ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e"
 			;;
 		*)
@@ -49,13 +51,15 @@ if test "x$ADDITIONAL_PACKAGES" != x; then
 	PKG_CHECK_MODULES(ADDITIONAL, [$ADDITIONAL_PACKAGES])
 fi
 
+dnl Please keep this sorted alphabetically
 AC_CONFIG_FILES([
-  Makefile
-  extensions/Makefile
-  extensions/example/Makefile
   extensions/alternate-tab/Makefile
+  extensions/auto-move-windows/Makefile
+  extensions/example/Makefile
   extensions/windowsNavigator/Makefile
   extensions/xrandr-indicator/Makefile
+  extensions/Makefile
+  Makefile
   po/Makefile.in
 ])
 AC_OUTPUT
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index e2c5fba..0bcbb85 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -1,3 +1,3 @@
-DIST_SUBDIRS = example alternate-tab xrandr-indicator windowsNavigator
+DIST_SUBDIRS = example alternate-tab xrandr-indicator windowsNavigator auto-move-windows
 
 SUBDIRS = $(ENABLED_EXTENSIONS)
diff --git a/extensions/auto-move-windows/Makefile.am b/extensions/auto-move-windows/Makefile.am
new file mode 100644
index 0000000..f002bc9
--- /dev/null
+++ b/extensions/auto-move-windows/Makefile.am
@@ -0,0 +1,13 @@
+EXTENSION_ID = auto-move-windows
+
+include ../../extension.mk
+
+gschemas_in = org.gnome.shell.extensions.auto-move-windows.gschema.xml.in
+
+ INTLTOOL_XML_NOMERGE_RULE@
+
+gsettings_SCHEMAS = $(gschemas_in:.xml.in=.xml)
+
+ GSETTINGS_RULES@
+
+CLEANFILES += $(gschemas_in:.xml.in=.valid) $(gsettings_SCHEMAS)
diff --git a/extensions/auto-move-windows/extension.js b/extensions/auto-move-windows/extension.js
new file mode 100644
index 0000000..48afa75
--- /dev/null
+++ b/extensions/auto-move-windows/extension.js
@@ -0,0 +1,55 @@
+// Start apps on custom workspaces
+
+const Glib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+const Shell = imports.gi.Shell;
+const St = imports.gi.St;
+
+const Main = imports.ui.main;
+
+const SETTINGS_SCHEMA = 'org.gnome.shell.extensions.auto-move-windows';
+const SETTINGS_KEY = 'application-list';
+
+function WindowMover() {
+    this._init();
+}
+
+WindowMover.prototype = {
+    _init: function() {
+	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));
+    },
+
+    _ensureAtLeastWorkspaces: function(num) {
+        for (let j = global.screen.n_workspaces; j <= num; j++) {
+            global.screen.append_new_workspace(false, 0);
+        }
+    },
+
+    _findAndMove: function(display, window) {
+	let spaces = this._settings.get_strv(SETTINGS_KEY);
+
+	let app = this._windowTracker.get_window_app(window);
+	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]);
+		this._ensureAtLeastWorkspaces(workspace_num);
+
+		window.change_workspace_by_index(workspace_num, false, global.get_current_time());
+            }
+        }
+    }
+}
+
+function main(extensionMeta) {
+    new WindowMover();
+}
\ No newline at end of file
diff --git a/extensions/auto-move-windows/metadata.json.in b/extensions/auto-move-windows/metadata.json.in
new file mode 100644
index 0000000..2fd224f
--- /dev/null
+++ b/extensions/auto-move-windows/metadata.json.in
@@ -0,0 +1,8 @@
+{
+ "uuid": "@uuid@",
+ "name": "Auto Move Windows",
+ "description": "Move applications to specific workspaces when they create windows",
+ "shell-version": [ "@shell_current@" ],
+ "localedir": "@LOCALEDIR@",
+ "original-author": "alessandro crismani gmail com",
+}
diff --git a/extensions/auto-move-windows/org.gnome.shell.extensions.auto-move-windows.gschema.xml.in b/extensions/auto-move-windows/org.gnome.shell.extensions.auto-move-windows.gschema.xml.in
new file mode 100644
index 0000000..59753dc
--- /dev/null
+++ b/extensions/auto-move-windows/org.gnome.shell.extensions.auto-move-windows.gschema.xml.in
@@ -0,0 +1,10 @@
+<schemalist gettext-domain="gnome-shell-extensions">
+  <schema id="org.gnome.shell.extensions.auto-move-windows" path="/org/gnome/shell/extensions/auto-move-windows/">
+    <key name="application-list" type="as">
+      <!-- FIXME: should be a(su), when JS supports more of GVariant -->
+      <default>[ ]</default>
+      <_summary>Application and workspace list</_summary>
+      <_description>A list of strings, each containing an application id (desktop file name), followed by a colon and the workspace number</_description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/extensions/auto-move-windows/stylesheet.css b/extensions/auto-move-windows/stylesheet.css
new file mode 100644
index 0000000..25134b6
--- /dev/null
+++ b/extensions/auto-move-windows/stylesheet.css
@@ -0,0 +1 @@
+/* This extensions requires no special styling */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c7acdd3..9d6ae8a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,3 +2,5 @@ extensions/example/extension.js
 extensions/windowsNavigator/extension.js
 extensions/xrandr-indicator/extension.js
 extensions/alternate-tab/extension.js
+extensions/auto-move-windows/extension.js
+extensions/auto-move-windows/org.gnome.shell.extensions.auto-move-windows.gschema.in
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]