mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-06-21 13:29:25 +00:00
Guard GTK3 theme tests for headless Xwayland
This commit is contained in:
@@ -34,12 +34,18 @@ struct session *lastact_sess;
|
|||||||
struct zoitechatprefs prefs;
|
struct zoitechatprefs prefs;
|
||||||
|
|
||||||
static gboolean gtk_available;
|
static gboolean gtk_available;
|
||||||
|
static gboolean gtk_has_default_seat;
|
||||||
static char *temp_root;
|
static char *temp_root;
|
||||||
static char *xdg_data_home;
|
static char *xdg_data_home;
|
||||||
|
static char *themes_root;
|
||||||
static char *theme_parent_root;
|
static char *theme_parent_root;
|
||||||
static char *theme_child_root;
|
static char *theme_child_root;
|
||||||
static char *theme_switch_root;
|
static char *theme_switch_root;
|
||||||
|
|
||||||
|
static const char *theme_parent_name = "zoitechat-test-parent";
|
||||||
|
static const char *theme_child_name = "zoitechat-test-child";
|
||||||
|
static const char *theme_switch_name = "zoitechat-test-switch";
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
theme_policy_system_prefers_dark (void)
|
theme_policy_system_prefers_dark (void)
|
||||||
{
|
{
|
||||||
@@ -181,6 +187,20 @@ zoitechat_gtk3_theme_build_inheritance_chain (const char *theme_root)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
test_display_has_default_seat (void)
|
||||||
|
{
|
||||||
|
GdkDisplay *display;
|
||||||
|
GdkSeat *seat;
|
||||||
|
|
||||||
|
display = gdk_display_get_default ();
|
||||||
|
if (!GDK_IS_DISPLAY (display))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
seat = gdk_display_get_default_seat (display);
|
||||||
|
return GDK_IS_SEAT (seat);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
get_bool_setting (const char *name)
|
get_bool_setting (const char *name)
|
||||||
{
|
{
|
||||||
@@ -215,12 +235,16 @@ setup_themes (void)
|
|||||||
temp_root = g_dir_make_tmp ("zoitechat-theme-gtk3-settings-XXXXXX", NULL);
|
temp_root = g_dir_make_tmp ("zoitechat-theme-gtk3-settings-XXXXXX", NULL);
|
||||||
g_assert_nonnull (temp_root);
|
g_assert_nonnull (temp_root);
|
||||||
xdg_data_home = g_build_filename (temp_root, "data", NULL);
|
xdg_data_home = g_build_filename (temp_root, "data", NULL);
|
||||||
g_assert_cmpint (g_mkdir_with_parents (xdg_data_home, 0700), ==, 0);
|
themes_root = g_build_filename (xdg_data_home, "themes", NULL);
|
||||||
|
g_assert_cmpint (g_mkdir_with_parents (themes_root, 0700), ==, 0);
|
||||||
g_setenv ("XDG_DATA_HOME", xdg_data_home, TRUE);
|
g_setenv ("XDG_DATA_HOME", xdg_data_home, TRUE);
|
||||||
|
g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
|
||||||
|
g_setenv ("NO_AT_BRIDGE", "1", TRUE);
|
||||||
|
g_unsetenv ("GTK_THEME");
|
||||||
|
|
||||||
theme_parent_root = g_build_filename (temp_root, "parent", NULL);
|
theme_parent_root = g_build_filename (themes_root, theme_parent_name, NULL);
|
||||||
theme_child_root = g_build_filename (temp_root, "child", NULL);
|
theme_child_root = g_build_filename (themes_root, theme_child_name, NULL);
|
||||||
theme_switch_root = g_build_filename (temp_root, "switch", NULL);
|
theme_switch_root = g_build_filename (themes_root, theme_switch_name, NULL);
|
||||||
g_assert_cmpint (g_mkdir_with_parents (theme_parent_root, 0700), ==, 0);
|
g_assert_cmpint (g_mkdir_with_parents (theme_parent_root, 0700), ==, 0);
|
||||||
g_assert_cmpint (g_mkdir_with_parents (theme_child_root, 0700), ==, 0);
|
g_assert_cmpint (g_mkdir_with_parents (theme_child_root, 0700), ==, 0);
|
||||||
g_assert_cmpint (g_mkdir_with_parents (theme_switch_root, 0700), ==, 0);
|
g_assert_cmpint (g_mkdir_with_parents (theme_switch_root, 0700), ==, 0);
|
||||||
@@ -248,13 +272,13 @@ setup_themes (void)
|
|||||||
"gtk-cursor-blink-time=444\n");
|
"gtk-cursor-blink-time=444\n");
|
||||||
|
|
||||||
path = g_build_filename (theme_parent_root, "index.theme", NULL);
|
path = g_build_filename (theme_parent_root, "index.theme", NULL);
|
||||||
write_file (path, "[Desktop Entry]\nName=parent\n");
|
write_file (path, "[Desktop Entry]\nName=zoitechat-test-parent\n");
|
||||||
g_free (path);
|
g_free (path);
|
||||||
path = g_build_filename (theme_child_root, "index.theme", NULL);
|
path = g_build_filename (theme_child_root, "index.theme", NULL);
|
||||||
write_file (path, "[Desktop Entry]\nName=child\nInherits=parent\n");
|
write_file (path, "[Desktop Entry]\nName=zoitechat-test-child\nInherits=zoitechat-test-parent\n");
|
||||||
g_free (path);
|
g_free (path);
|
||||||
path = g_build_filename (theme_switch_root, "index.theme", NULL);
|
path = g_build_filename (theme_switch_root, "index.theme", NULL);
|
||||||
write_file (path, "[Desktop Entry]\nName=switch\n");
|
write_file (path, "[Desktop Entry]\nName=zoitechat-test-switch\n");
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,11 +290,13 @@ teardown_themes (void)
|
|||||||
g_free (theme_parent_root);
|
g_free (theme_parent_root);
|
||||||
g_free (theme_child_root);
|
g_free (theme_child_root);
|
||||||
g_free (theme_switch_root);
|
g_free (theme_switch_root);
|
||||||
|
g_free (themes_root);
|
||||||
g_free (xdg_data_home);
|
g_free (xdg_data_home);
|
||||||
g_free (temp_root);
|
g_free (temp_root);
|
||||||
theme_parent_root = NULL;
|
theme_parent_root = NULL;
|
||||||
theme_child_root = NULL;
|
theme_child_root = NULL;
|
||||||
theme_switch_root = NULL;
|
theme_switch_root = NULL;
|
||||||
|
themes_root = NULL;
|
||||||
xdg_data_home = NULL;
|
xdg_data_home = NULL;
|
||||||
temp_root = NULL;
|
temp_root = NULL;
|
||||||
}
|
}
|
||||||
@@ -351,6 +377,7 @@ main (int argc, char **argv)
|
|||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
setup_themes ();
|
setup_themes ();
|
||||||
gtk_available = gtk_init_check (&argc, &argv);
|
gtk_available = gtk_init_check (&argc, &argv);
|
||||||
|
gtk_has_default_seat = gtk_available && test_display_has_default_seat ();
|
||||||
|
|
||||||
g_test_add_func ("/theme/gtk3/settings_layer_precedence", test_settings_layer_precedence);
|
g_test_add_func ("/theme/gtk3/settings_layer_precedence", test_settings_layer_precedence);
|
||||||
g_test_add_func ("/theme/gtk3/settings_restored_on_disable_and_switch", test_settings_restored_on_disable_and_switch);
|
g_test_add_func ("/theme/gtk3/settings_restored_on_disable_and_switch", test_settings_restored_on_disable_and_switch);
|
||||||
@@ -359,6 +386,8 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
if (!gtk_available)
|
if (!gtk_available)
|
||||||
g_test_message ("Skipping GTK3 settings tests because GTK initialization failed");
|
g_test_message ("Skipping GTK3 settings tests because GTK initialization failed");
|
||||||
|
else if (!gtk_has_default_seat)
|
||||||
|
g_test_message ("Skipping gtk-theme-name assertions because GTK display has no default GdkSeat");
|
||||||
|
|
||||||
rc = g_test_run ();
|
rc = g_test_run ();
|
||||||
theme_gtk3_disable ();
|
theme_gtk3_disable ();
|
||||||
|
|||||||
@@ -151,8 +151,12 @@ settings_rescan_icon_theme (void)
|
|||||||
static void
|
static void
|
||||||
theme_gtk3_reset_widgets (void)
|
theme_gtk3_reset_widgets (void)
|
||||||
{
|
{
|
||||||
GdkScreen *screen = gdk_screen_get_default ();
|
GdkScreen *screen;
|
||||||
|
|
||||||
|
if (!theme_gtk3_display_has_default_seat ())
|
||||||
|
return;
|
||||||
|
|
||||||
|
screen = gdk_screen_get_default ();
|
||||||
if (screen)
|
if (screen)
|
||||||
gtk_style_context_reset_widgets (screen);
|
gtk_style_context_reset_widgets (screen);
|
||||||
}
|
}
|
||||||
@@ -430,6 +434,9 @@ settings_apply_theme_name (const char *theme_root)
|
|||||||
if (!theme_root)
|
if (!theme_root)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!theme_gtk3_display_has_default_seat ())
|
||||||
|
return;
|
||||||
|
|
||||||
settings = gtk_settings_get_default ();
|
settings = gtk_settings_get_default ();
|
||||||
if (!settings || !settings_default_seat_available ())
|
if (!settings || !settings_default_seat_available ())
|
||||||
return;
|
return;
|
||||||
@@ -760,9 +767,12 @@ settings_apply_from_file (const char *theme_root, const char *css_dir)
|
|||||||
static void
|
static void
|
||||||
theme_gtk3_remove_provider (void)
|
theme_gtk3_remove_provider (void)
|
||||||
{
|
{
|
||||||
GdkScreen *screen = gdk_screen_get_default ();
|
GdkScreen *screen = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
|
if (theme_gtk3_display_has_default_seat ())
|
||||||
|
screen = gdk_screen_get_default ();
|
||||||
|
|
||||||
if (screen && theme_gtk3_providers_variant)
|
if (screen && theme_gtk3_providers_variant)
|
||||||
{
|
{
|
||||||
for (i = 0; i < theme_gtk3_providers_variant->len; i++)
|
for (i = 0; i < theme_gtk3_providers_variant->len; i++)
|
||||||
@@ -817,7 +827,10 @@ load_css_with_variant (ZoitechatGtk3Theme *theme, ThemeGtk3Variant variant, GErr
|
|||||||
theme_gtk3_providers_base = g_ptr_array_new_with_free_func (g_object_unref);
|
theme_gtk3_providers_base = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
theme_gtk3_providers_variant = g_ptr_array_new_with_free_func (g_object_unref);
|
theme_gtk3_providers_variant = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
|
|
||||||
|
screen = NULL;
|
||||||
|
if (theme_gtk3_display_has_default_seat ())
|
||||||
screen = gdk_screen_get_default ();
|
screen = gdk_screen_get_default ();
|
||||||
|
|
||||||
for (i = 0; i < chain->len; i++)
|
for (i = 0; i < chain->len; i++)
|
||||||
{
|
{
|
||||||
const char *theme_root = g_ptr_array_index (chain, i);
|
const char *theme_root = g_ptr_array_index (chain, i);
|
||||||
|
|||||||
Reference in New Issue
Block a user