[gnome-shell/wip/desktop-file-index: 14/14] app-system: Add back StartupWMClass matching



commit 4c1848e458e7fdb57d4244132369f4a8e4c945cf
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Sep 26 17:19:21 2013 -0400

    app-system: Add back StartupWMClass matching
    
    While unfortunate that we still have to scan all apps with get_all(),
    support for this feature will be short-lived, so hopefully we can drop
    it in the future as new apps adapt to the desktop file / app ID
    recommendations.
    
    For now, simply scan all desktop IDs.

 src/shell-app-system.c |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index d9b0daa..e53c881 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -40,7 +40,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 struct _ShellAppSystemPrivate {
   GHashTable *running_apps;
   GHashTable *id_to_app;
-  GHashTable *startup_wm_class_to_app;
+  GHashTable *startup_wm_class_to_id;
 };
 
 static void shell_app_system_finalize (GObject *object);
@@ -72,11 +72,33 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
 }
 
 static void
+scan_startup_wm_class_to_id (ShellAppSystem *self)
+{
+  ShellAppSystemPrivate *priv = self->priv;
+  GList *apps, *l;
+
+  g_hash_table_remove_all (priv->startup_wm_class_to_id);
+
+  apps = g_app_info_get_all ();
+  for (l = apps; l != NULL; l = l->next)
+    {
+      GAppInfo *info = l->data;
+      g_hash_table_insert (priv->startup_wm_class_to_id,
+                           (char *) g_desktop_app_info_get_startup_wm_class (G_DESKTOP_APP_INFO (info)),
+                           (char *) g_app_info_get_id (info));
+    }
+
+  g_list_free_full (apps, g_object_unref);
+}
+
+static void
 installed_changed (GAppInfoMonitor *monitor,
                    gpointer         user_data)
 {
   ShellAppSystem *self = user_data;
 
+  scan_startup_wm_class_to_id (self);
+
   g_signal_emit (self, signals[INSTALLED_CHANGED], 0, NULL);
 }
 
@@ -95,9 +117,7 @@ shell_app_system_init (ShellAppSystem *self)
                                            NULL,
                                            (GDestroyNotify)g_object_unref);
 
-  priv->startup_wm_class_to_app = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                         NULL,
-                                                         (GDestroyNotify)g_object_unref);
+  priv->startup_wm_class_to_id = g_hash_table_new (g_str_hash, g_str_equal);
 
   monitor = g_app_info_monitor_get ();
   g_signal_connect (monitor, "changed", G_CALLBACK (installed_changed), self);
@@ -112,7 +132,7 @@ shell_app_system_finalize (GObject *object)
 
   g_hash_table_destroy (priv->running_apps);
   g_hash_table_destroy (priv->id_to_app);
-  g_hash_table_destroy (priv->startup_wm_class_to_app);
+  g_hash_table_destroy (priv->startup_wm_class_to_id);
 
   G_OBJECT_CLASS (shell_app_system_parent_class)->finalize (object);
 }
@@ -260,10 +280,15 @@ ShellApp *
 shell_app_system_lookup_startup_wmclass (ShellAppSystem *system,
                                          const char     *wmclass)
 {
+  const char *id;
   if (wmclass == NULL)
     return NULL;
 
-  return g_hash_table_lookup (system->priv->startup_wm_class_to_app, wmclass);
+  id = g_hash_table_lookup (system->priv->startup_wm_class_to_id, wmclass);
+  if (id == NULL)
+    return NULL;
+
+  return shell_app_system_lookup_app (system, id);
 }
 
 void


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