[gnome-shell] AppWell: If an application is running, activate an existing window



commit 92e9bc85a1832bdbd35c565b8961d9b7b9ab7e60
Author: Colin Walters <walters verbum org>
Date:   Sat Jul 4 17:13:13 2009 -0400

    AppWell: If an application is running, activate an existing window
    
    Instead of relaunching, pick the first window and activate

 js/ui/appDisplay.js     |   17 +++++++++++++----
 src/shell-app-monitor.c |   31 +++++++++++++++++++++++++++----
 src/shell-app-monitor.h |    2 +-
 3 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 0fbad13..372c364 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -467,8 +467,7 @@ WellDisplayItem.prototype = {
             }));
         this.actor._delegate = this;
         this.actor.connect('button-release-event', Lang.bind(this, function (b, e) {
-            this.launch();
-            this.emit('activated');
+            this._handleActivate();
         }));
 
         let draggable = DND.makeDraggable(this.actor);
@@ -480,7 +479,7 @@ WellDisplayItem.prototype = {
 
         this.actor.append(iconBox, Big.BoxPackFlags.NONE);
 
-        let count = Shell.AppMonitor.get_default().get_window_count(appInfo.appId);
+        this._windows = Shell.AppMonitor.get_default().get_windows_for_app(appInfo.appId)
 
         let nameBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
                                     x_align: Big.BoxAlignment.CENTER });
@@ -492,7 +491,7 @@ WellDisplayItem.prototype = {
                                         line_wrap_mode: Pango.WrapMode.WORD_CHAR,
                                         text: appInfo.name });
         nameBox.append(this._name, Big.BoxPackFlags.EXPAND);
-        if (count > 0) {
+        if (this._windows.length > 0) {
             let runningBox = new Big.Box({ /* border_color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
                                            border: 1,
                                            padding: 1 */ });
@@ -503,6 +502,16 @@ WellDisplayItem.prototype = {
         }
     },
 
+    _handleActivate: function () {
+        if (this._windows.length == 0)
+            this.launch();
+        else {
+            let first = this._windows[0];
+            first.activate(Clutter.get_current_event_time());
+        }
+        this.emit('activated');
+    },
+
     // Opens an application represented by this display item.
     launch : function() {
         this.appInfo.launch();
diff --git a/src/shell-app-monitor.c b/src/shell-app-monitor.c
index f099610..7a021d9 100644
--- a/src/shell-app-monitor.c
+++ b/src/shell-app-monitor.c
@@ -377,11 +377,34 @@ load_initial_windows (ShellAppMonitor *monitor)
     }
 }
 
-guint
-shell_app_monitor_get_window_count (ShellAppMonitor *self,
-                                    const char      *appid)
+/**
+ * shell_app_monitor_get_windows_for_app:
+ * @self:
+ * @appid: Find windows for this id
+ *
+ * Returns: (transfer container) (element-type MetaWindow): List of #MetaWindow corresponding to appid
+ */
+GSList *
+shell_app_monitor_get_windows_for_app (ShellAppMonitor *self,
+                                       const char      *appid)
 {
-  return GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
+  GHashTableIter iter;
+  gpointer key, value;
+  GSList *ret = NULL;
+
+  g_hash_table_iter_init (&iter, self->window_to_appid);
+
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+      MetaWindow *window = key;
+      const char *id = value;
+
+      if (strcmp (id, appid) != 0)
+        continue;
+
+      ret = g_slist_prepend (ret, window);
+    }
+  return ret;
 }
 
 static void
diff --git a/src/shell-app-monitor.h b/src/shell-app-monitor.h
index 073691b..7ed68d0 100644
--- a/src/shell-app-monitor.h
+++ b/src/shell-app-monitor.h
@@ -44,7 +44,7 @@ GSList *shell_app_monitor_get_most_used_apps (ShellAppMonitor *monitor,
                                               int              activity,
                                               gint             number);
 
-guint shell_app_monitor_get_window_count (ShellAppMonitor *monitor, const char *appid);
+GSList *shell_app_monitor_get_windows_for_app (ShellAppMonitor *monitor, const char *appid);
 
 /* Get whatever's running right now */
 GList *shell_app_monitor_get_running_app_ids (ShellAppMonitor *monitor);



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