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
8bd7db9227
commit
6050ca6e0c
@ -43,7 +43,7 @@ struct _ShellAppSystemPrivate {
|
|||||||
GHashTable *running_apps;
|
GHashTable *running_apps;
|
||||||
GHashTable *visible_id_to_app;
|
GHashTable *visible_id_to_app;
|
||||||
GHashTable *id_to_app;
|
GHashTable *id_to_app;
|
||||||
GHashTable *startup_wm_class_to_app;
|
GHashTable *startup_wm_class_to_id;
|
||||||
|
|
||||||
GSList *known_vendor_prefixes;
|
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 */
|
/* 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->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,
|
priv->startup_wm_class_to_id = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
NULL,
|
|
||||||
(GDestroyNotify)g_object_unref);
|
|
||||||
|
|
||||||
/* We want to track NoDisplay apps, so we add INCLUDE_NODISPLAY. We'll
|
/* We want to track NoDisplay apps, so we add INCLUDE_NODISPLAY. We'll
|
||||||
* filter NoDisplay apps out when showing them to the user. */
|
* 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->running_apps);
|
||||||
g_hash_table_destroy (priv->id_to_app);
|
g_hash_table_destroy (priv->id_to_app);
|
||||||
g_hash_table_destroy (priv->visible_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);
|
g_slist_free_full (priv->known_vendor_prefixes, g_free);
|
||||||
priv->known_vendor_prefixes = NULL;
|
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);
|
old_startup_wm_class = g_desktop_app_info_get_startup_wm_class (old_info);
|
||||||
|
|
||||||
if (old_startup_wm_class)
|
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);
|
_shell_app_set_app_info (app, info);
|
||||||
g_object_ref (app); /* Extra ref, removed in _replace below */
|
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);
|
startup_wm_class = g_desktop_app_info_get_startup_wm_class (info);
|
||||||
if (startup_wm_class)
|
if (startup_wm_class)
|
||||||
g_hash_table_replace (self->priv->startup_wm_class_to_app,
|
g_hash_table_replace (self->priv->startup_wm_class_to_id,
|
||||||
(char*)startup_wm_class, g_object_ref (app));
|
(char*)startup_wm_class, (char*)id);
|
||||||
}
|
}
|
||||||
/* Now iterate over the apps again; we need to unreference any apps
|
/* Now iterate over the apps again; we need to unreference any apps
|
||||||
* which have been removed. The JS code may still be holding a
|
* 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,
|
shell_app_system_lookup_startup_wmclass (ShellAppSystem *system,
|
||||||
const char *wmclass)
|
const char *wmclass)
|
||||||
{
|
{
|
||||||
|
const char *id;
|
||||||
|
|
||||||
if (wmclass == NULL)
|
if (wmclass == NULL)
|
||||||
return 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
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user