Because gtk_style_context_get_background_color is deprected since version gtk v3.16 I want to read out the following style-property: GTK_STYLE_PROPERTY_BACKGROUND_COLOR
Currrently my code looks like that:
GdkRGBA *color;
...
GValue value = G_VALUE_INIT;
gtk_style_context_get_property (context,GTK_STYLE_PROPERTY_BACKGROUND_COLOR, state, &value);
color = g_value_get_object (&value);
However it seems like I am doing it wrong. During runtime I only get the following GLib-GObject-CRITICAL:
(thunar:6564): GLib-GObject-CRITICAL **: g_value_get_object: assertion 'G_VALUE_HOLDS_OBJECT (value)' failed
So how I can make use of gtk properties which are holding more complex datatypes ?
EDIT: Here the complete solution which now works for me:
GtkStateFlags state;
GdkRGBA *color;
GtkStyleContext *context = gtk_widget_get_style_context (widget);
// get the color
gtk_style_context_get (context, GTK_STATE_FLAG_SELECTED, GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &color, NULL);
// do something with the color
gdk_cairo_set_source_rgba (cr, color);
// dont forget to free it afterwards !! (Otherwise segfaults may occur)
gdk_rgba_free (color);