Hello,
thanks for your reply.
Quote:
You are passing a pointer to g_object_set. The colour selection stores this pointer directly as its current colour (rather than setting up a duplicate pointer with the same contents).
Are you sure about this? In
gtk+-3.4.0/gtk/deprecated/gtkcolorsel.c (just to make sure we're talking about the same widget), I found this code in
gtk_color_selection_set_current_rgba:
Code:
priv->color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
priv->color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
priv->color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
priv->color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
It's the only time where the function uses rgba - it clearly doesn't save the pointer. Also, assuming that the function would save the pointer, this wouldn't work (because rgba only exists on the stack, so it will get lost if the function ends), would it?
Code:
GtkColorSelection some_function(void) {
GdkRGBA rgba;
/* fill rgba */
return g_object_new(GTK_TYPE_COLOR_SELECTION, "current-rgba", &rgba, NULL);
}
At least, this example also doesn't work (it's the same as in my post above, just using another GdkRGBA, rgba2, for the get part - the second output is still 1,00000-1,000000-1,00000).
Code:
colsel = g_object_new(GTK_TYPE_COLOR_SELECTION, NULL);
GdkRGBA rgba;
rgba.red = 0.1;
rgba.green = 0.2;
rgba.blue = 0.3;
rgba.alpha = 0.4;
g_print("%lf-%lf-%lf\n", rgba.red, rgba.green, rgba.blue);
g_object_set(colsel, "current-rgba", &rgba, NULL);
GdkRGBA rgba2;
rgba2.red = 1;
rgba2.green = 1;
rgba2.blue = 1;
g_object_get(colsel, "current-rgba", &rgba2, NULL);
g_print("%lf-%lf-%lf\n", rgba2.red, rgba2.green, rgba2.blue);