app-system: Map wmclass to ID rather than apps
This makes the refcounting and memory management easier to understand.
This commit is contained in:
parent
76eca409a3
commit
2daa0d057b
@ -43,7 +43,7 @@ struct _ShellAppSystemPrivate {
|
||||
GHashTable *running_apps;
|
||||
GHashTable *visible_id_to_app;
|
||||
GHashTable *id_to_app;
|
||||
GHashTable *startup_wm_class_to_app;
|
||||
GHashTable *startup_wm_class_to_id;
|
||||
|
||||
GSList *known_vendor_prefixes;
|
||||
};
|
||||
@ -94,9 +94,7 @@ shell_app_system_init (ShellAppSystem *self)
|
||||
/* All the objects in this hash table are owned by id_to_app */
|
||||
priv->visible_id_to_app = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
||||
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);
|
||||
|
||||
/* We want to track NoDisplay apps, so we add INCLUDE_NODISPLAY. We'll
|
||||
* filter NoDisplay apps out when showing them to the user. */
|
||||
@ -117,7 +115,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->visible_id_to_app);
|
||||
g_hash_table_destroy (priv->startup_wm_class_to_app);
|
||||
g_hash_table_destroy (priv->startup_wm_class_to_id);
|
||||
|
||||
g_slist_free_full (priv->known_vendor_prefixes, g_free);
|
||||
priv->known_vendor_prefixes = NULL;
|
||||
@ -353,7 +351,7 @@ on_apps_tree_changed_cb (GMenuTree *tree,
|
||||
old_startup_wm_class = g_desktop_app_info_get_startup_wm_class (old_info);
|
||||
|
||||
if (old_startup_wm_class)
|
||||
g_hash_table_remove (self->priv->startup_wm_class_to_app, old_startup_wm_class);
|
||||
g_hash_table_remove (self->priv->startup_wm_class_to_id, old_startup_wm_class);
|
||||
|
||||
_shell_app_set_app_info (app, info);
|
||||
g_object_ref (app); /* Extra ref, removed in _replace below */
|
||||
@ -371,8 +369,8 @@ on_apps_tree_changed_cb (GMenuTree *tree,
|
||||
|
||||
startup_wm_class = g_desktop_app_info_get_startup_wm_class (info);
|
||||
if (startup_wm_class)
|
||||
g_hash_table_replace (self->priv->startup_wm_class_to_app,
|
||||
(char*)startup_wm_class, g_object_ref (app));
|
||||
g_hash_table_replace (self->priv->startup_wm_class_to_id,
|
||||
(char*)startup_wm_class, (char*)id);
|
||||
}
|
||||
/* Now iterate over the apps again; we need to unreference any apps
|
||||
* which have been removed. The JS code may still be holding a
|
||||
@ -568,10 +566,16 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user