Guard GTK theme ops when screen/seat missing

This commit is contained in:
2026-06-20 09:51:16 -06:00
parent 6d5f1306bf
commit be33ae30bb
2 changed files with 52 additions and 11 deletions

View File

@@ -199,6 +199,14 @@ get_int_setting (const char *name)
return value;
}
static gboolean
has_default_seat (void)
{
GdkDisplay *display = gdk_display_get_default ();
return display && GDK_IS_SEAT (gdk_display_get_default_seat (display));
}
static void
setup_themes (void)
{
@@ -309,10 +317,13 @@ test_settings_restored_on_disable_and_switch (void)
g_assert_true (theme_gtk3_apply ("layered", THEME_GTK3_VARIANT_PREFER_LIGHT, &error));
g_assert_no_error (error);
g_assert_cmpint (get_int_setting ("gtk-cursor-blink-time"), ==, 333);
g_object_get (gtk_settings_get_default (), "gtk-theme-name", &active_theme_name, NULL);
g_assert_cmpstr (active_theme_name, ==, "child");
g_free (active_theme_name);
active_theme_name = NULL;
if (has_default_seat ())
{
g_object_get (gtk_settings_get_default (), "gtk-theme-name", &active_theme_name, NULL);
g_assert_cmpstr (active_theme_name, ==, "child");
g_free (active_theme_name);
active_theme_name = NULL;
}
g_assert_true (theme_gtk3_apply ("switch", THEME_GTK3_VARIANT_PREFER_LIGHT, &error));
g_assert_no_error (error);
@@ -322,9 +333,12 @@ test_settings_restored_on_disable_and_switch (void)
theme_gtk3_disable ();
g_assert_cmpint (get_int_setting ("gtk-cursor-blink-time"), ==, default_blink);
g_assert_cmpint (get_bool_setting ("gtk-enable-animations"), ==, default_animations);
g_object_get (gtk_settings_get_default (), "gtk-theme-name", &active_theme_name, NULL);
g_assert_cmpstr (active_theme_name, ==, default_theme_name);
g_free (active_theme_name);
if (has_default_seat ())
{
g_object_get (gtk_settings_get_default (), "gtk-theme-name", &active_theme_name, NULL);
g_assert_cmpstr (active_theme_name, ==, default_theme_name);
g_free (active_theme_name);
}
g_free (default_theme_name);
g_assert_false (theme_gtk3_is_active ());
}

View File

@@ -135,8 +135,12 @@ settings_defaults_table (void)
static void
settings_rescan_icon_theme (void)
{
GdkScreen *screen = gdk_screen_get_default ();
GtkIconTheme *icon_theme;
if (!screen)
return;
icon_theme = gtk_icon_theme_get_default ();
if (!icon_theme)
return;
@@ -156,8 +160,13 @@ theme_gtk3_reset_widgets (void)
static void
settings_capture_icon_search_path (void)
{
GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
GdkScreen *screen = gdk_screen_get_default ();
GtkIconTheme *icon_theme;
if (!screen)
return;
icon_theme = gtk_icon_theme_get_default ();
if (!icon_theme || theme_gtk3_settings_state.icon_search_path_captured)
return;
@@ -168,8 +177,13 @@ settings_capture_icon_search_path (void)
static void
settings_append_icon_search_path (const char *path)
{
GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
GdkScreen *screen = gdk_screen_get_default ();
GtkIconTheme *icon_theme;
if (!screen)
return;
icon_theme = gtk_icon_theme_get_default ();
if (!icon_theme || !path || !g_file_test (path, G_FILE_TEST_IS_DIR))
return;
@@ -199,8 +213,13 @@ settings_apply_icon_paths (const char *theme_root)
static void
settings_restore_icon_search_path (void)
{
GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
GdkScreen *screen = gdk_screen_get_default ();
GtkIconTheme *icon_theme;
if (!screen)
return;
icon_theme = gtk_icon_theme_get_default ();
if (!icon_theme || !theme_gtk3_settings_state.icon_search_path_captured)
return;
@@ -394,6 +413,14 @@ settings_theme_link_search_path (const char *theme_root, const char *theme_name)
return ok;
}
static gboolean
settings_default_seat_available (void)
{
GdkDisplay *display = gdk_display_get_default ();
return display && GDK_IS_SEAT (gdk_display_get_default_seat (display));
}
static void
settings_apply_theme_name (const char *theme_root)
{
@@ -404,7 +431,7 @@ settings_apply_theme_name (const char *theme_root)
return;
settings = gtk_settings_get_default ();
if (!settings)
if (!settings || !settings_default_seat_available ())
return;
theme_name = g_path_get_basename (theme_root);