gtk-demo: Dark theme support for dnd demo

Add minimal dark theme support to the dnd demo,
by picking suitable default colors for our items.
This commit is contained in:
Matthias Clasen 2020-08-09 17:36:41 -04:00
parent 230107cd84
commit 42902085e5

View File

@ -153,6 +153,30 @@ click_done (GtkGesture *gesture)
gtk_widget_insert_after (item, canvas, last_child); gtk_widget_insert_after (item, canvas, last_child);
} }
static gboolean
theme_is_dark (void)
{
GtkSettings *settings;
char *theme;
gboolean prefer_dark;
gboolean dark;
settings = gtk_settings_get_default ();
g_object_get (settings,
"gtk-theme-name", &theme,
"gtk-application-prefer-dark-theme", &prefer_dark,
NULL);
if ((strcmp (theme, "Adwaita") == 0 && prefer_dark) || strcmp (theme, "HighContrastInverse") == 0)
dark = TRUE;
else
dark = FALSE;
g_free (theme);
return dark;
}
static void static void
canvas_item_init (CanvasItem *item) canvas_item_init (CanvasItem *item)
{ {
@ -180,7 +204,11 @@ canvas_item_init (CanvasItem *item)
gtk_widget_set_name (item->label, id); gtk_widget_set_name (item->label, id);
g_free (id); g_free (id);
if (theme_is_dark ())
gdk_rgba_parse (&rgba, "blue");
else
gdk_rgba_parse (&rgba, "yellow"); gdk_rgba_parse (&rgba, "yellow");
set_color (item, &rgba); set_color (item, &rgba);
item->angle = 0; item->angle = 0;