[gnome-shell] Set the workspace when launching apps



commit bb69afc830a0171a47d744c7eb64d8ffe7a5de5e
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Fri May 1 14:13:51 2009 -0400

    Set the workspace when launching apps
    
    main.js: Add create_app_launch_context() with code from appDisplay;
      additionally set the workspace on the launch context to the current
      workspace so that the application launches on the right workspace
      even if the user switches before the app starts.
    
    appDisplay.js docDisplay.js: Use Main.create_app_launch_context()
    
    http://bugzilla.gnome.org/show_bug.cgi?id=580658 (Reported by Igor Vatavuk)
---
 js/ui/appDisplay.js |   12 ++----------
 js/ui/docDisplay.js |    8 +++++++-
 js/ui/main.js       |   16 ++++++++++++++++
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 3ef58d9..ddf8901 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -5,13 +5,13 @@ const Clutter = imports.gi.Clutter;
 const Pango = imports.gi.Pango;
 const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
-const Gdk = imports.gi.Gdk;
 const Shell = imports.gi.Shell;
 const Lang = imports.lang;
 const Signals = imports.signals;
 
 const GenericDisplay = imports.ui.genericDisplay;
 const GtkUtil = imports.ui.gtkutil;
+const Main = imports.ui.main;
 
 const ENTERED_MENU_COLOR = new Clutter.Color();
 ENTERED_MENU_COLOR.from_pixel(0x00ff0022);
@@ -85,15 +85,7 @@ AppDisplayItem.prototype = {
 
     // Opens an application represented by this display item.
     launch : function() {
-        let global = Shell.Global.get();
-        let screen = global.screen;
-        let display = screen.get_display();
-        let timestamp = display.get_current_time();
-        let context = new Gdk.AppLaunchContext();
-        let icon = this._appInfo.get_icon();
-        context.set_icon(icon);
-        context.set_timestamp(timestamp);
-        this._appInfo.launch([], context);
+        this._appInfo.launch([], Main.create_app_launch_context());
     },
 
     //// Protected method overrides ////
diff --git a/js/ui/docDisplay.js b/js/ui/docDisplay.js
index ee78264..1b5906d 100644
--- a/js/ui/docDisplay.js
+++ b/js/ui/docDisplay.js
@@ -8,6 +8,7 @@ const Shell = imports.gi.Shell;
 const Signals = imports.signals;
 
 const GenericDisplay = imports.ui.genericDisplay;
+const Main = imports.ui.main;
 
 const ITEM_DISPLAY_ICON_MARGIN = 2;
 
@@ -78,7 +79,12 @@ DocDisplayItem.prototype = {
             appExec = appExec.replace(/%/g, "%%");
 
             let appInfo = Gio.app_info_create_from_commandline(appExec, null, 0, null);
-            appInfo.launch([], null, null);
+
+            // The app launch context doesn't work as well as we might like because
+            // it doesn't get the right StartupNotify key from the application's
+            // desktop file. So, we don't get startup notification, the application
+            // doesn't stick to the current workspace, and so forth.
+            appInfo.launch([], Main.create_app_launch_context());
         } else {
             log("Failed to get application info for " + this._docInfo.get_uri());
         }
diff --git a/js/ui/main.js b/js/ui/main.js
index 2db7981..7fcc004 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -1,6 +1,7 @@
 /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
 
 const Clutter = imports.gi.Clutter;
+const Gdk = imports.gi.Gdk;
 const Gio = imports.gi.Gio;
 const Mainloop = imports.mainloop;
 const Meta = imports.gi.Meta;
@@ -166,6 +167,21 @@ function hide_overlay() {
     endModal();
 }
 
+function create_app_launch_context() {
+    let global = Shell.Global.get();
+    let screen = global.screen;
+    let display = screen.get_display();
+
+    let context = new Gdk.AppLaunchContext();
+    context.set_timestamp(display.get_current_time());
+
+    // Make sure that the app is opened on the current workspace even if
+    // the user switches before it seetarts
+    context.set_desktop(screen.get_active_workspace_index());
+
+    return context;
+}
+
 let _shellActors = [];
 
 // For adding an actor that is part of the shell in the normal desktop view



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