From 42902085e59962aafba7554ed43845e771b945de Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 9 Aug 2020 17:36:41 -0400 Subject: [PATCH] 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. --- demos/gtk-demo/dnd.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c index 70ea875c1c..1aff3b1bcd 100644 --- a/demos/gtk-demo/dnd.c +++ b/demos/gtk-demo/dnd.c @@ -153,6 +153,30 @@ click_done (GtkGesture *gesture) 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 canvas_item_init (CanvasItem *item) { @@ -180,7 +204,11 @@ canvas_item_init (CanvasItem *item) gtk_widget_set_name (item->label, id); g_free (id); - gdk_rgba_parse (&rgba, "yellow"); + if (theme_is_dark ()) + gdk_rgba_parse (&rgba, "blue"); + else + gdk_rgba_parse (&rgba, "yellow"); + set_color (item, &rgba); item->angle = 0;