shell/tray-manager: Only create resources when needed

NaTrayManager in particular is deeply tied to X11. We currently assume
that X11 support is always available, but that is already not true
anymore - Xwayland startup is now asynchronous.

It will be even less true once we handle Xwayland crashes gracefully.

Start addressing that by not creating the corresponding resources once
and assume they exist for the lifetime of Shell.TrayManager, but make
sure they exist when actually needed.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/2308
This commit is contained in:
Florian Müllner 2020-03-04 23:12:29 +01:00 committed by Florian Müllner
parent f4ea9074d0
commit 07bbcb1b48

View File

@ -58,6 +58,8 @@ static guint shell_tray_manager_signals [LAST_SIGNAL] = { 0 };
static const ClutterColor default_color = { 0x00, 0x00, 0x00, 0xff }; static const ClutterColor default_color = { 0x00, 0x00, 0x00, 0xff };
static void shell_tray_manager_release_resources (ShellTrayManager *manager);
static void na_tray_icon_added (NaTrayManager *na_manager, GtkWidget *child, gpointer manager); static void na_tray_icon_added (NaTrayManager *na_manager, GtkWidget *child, gpointer manager);
static void na_tray_icon_removed (NaTrayManager *na_manager, GtkWidget *child, gpointer manager); static void na_tray_icon_removed (NaTrayManager *na_manager, GtkWidget *child, gpointer manager);
@ -125,16 +127,7 @@ shell_tray_manager_init (ShellTrayManager *manager)
{ {
manager->priv = shell_tray_manager_get_instance_private (manager); manager->priv = shell_tray_manager_get_instance_private (manager);
manager->priv->na_manager = na_tray_manager_new ();
manager->priv->icons = g_hash_table_new_full (NULL, NULL,
NULL, free_tray_icon);
manager->priv->bg_color = default_color; manager->priv->bg_color = default_color;
g_signal_connect (manager->priv->na_manager, "tray-icon-added",
G_CALLBACK (na_tray_icon_added), manager);
g_signal_connect (manager->priv->na_manager, "tray-icon-removed",
G_CALLBACK (na_tray_icon_removed), manager);
} }
static void static void
@ -142,8 +135,7 @@ shell_tray_manager_finalize (GObject *object)
{ {
ShellTrayManager *manager = SHELL_TRAY_MANAGER (object); ShellTrayManager *manager = SHELL_TRAY_MANAGER (object);
g_object_unref (manager->priv->na_manager); shell_tray_manager_release_resources (manager);
g_hash_table_destroy (manager->priv->icons);
G_OBJECT_CLASS (shell_tray_manager_parent_class)->finalize (object); G_OBJECT_CLASS (shell_tray_manager_parent_class)->finalize (object);
} }
@ -193,6 +185,30 @@ shell_tray_manager_new (void)
return g_object_new (SHELL_TYPE_TRAY_MANAGER, NULL); return g_object_new (SHELL_TYPE_TRAY_MANAGER, NULL);
} }
static void
shell_tray_manager_ensure_resources (ShellTrayManager *manager)
{
if (manager->priv->na_manager != NULL)
return;
manager->priv->icons = g_hash_table_new_full (NULL, NULL,
NULL, free_tray_icon);
manager->priv->na_manager = na_tray_manager_new ();
g_signal_connect (manager->priv->na_manager, "tray-icon-added",
G_CALLBACK (na_tray_icon_added), manager);
g_signal_connect (manager->priv->na_manager, "tray-icon-removed",
G_CALLBACK (na_tray_icon_removed), manager);
}
static void
shell_tray_manager_release_resources (ShellTrayManager *manager)
{
g_clear_object (&manager->priv->na_manager);
g_clear_pointer (&manager->priv->icons, g_hash_table_destroy);
}
static void static void
shell_tray_manager_style_changed (StWidget *theme_widget, shell_tray_manager_style_changed (StWidget *theme_widget,
gpointer user_data) gpointer user_data)
@ -212,6 +228,8 @@ void
shell_tray_manager_manage_screen (ShellTrayManager *manager, shell_tray_manager_manage_screen (ShellTrayManager *manager,
StWidget *theme_widget) StWidget *theme_widget)
{ {
shell_tray_manager_ensure_resources (manager);
na_tray_manager_manage_screen (manager->priv->na_manager); na_tray_manager_manage_screen (manager->priv->na_manager);
g_signal_connect_object (theme_widget, "style-changed", g_signal_connect_object (theme_widget, "style-changed",