color chooser: Fix fallout from floatification

We are using (dddd) variants to store colors in variants,
which is dangerous now that GdkRGBA members are just floats.

Avoid passsing the GdkRGBA members directly to any varargs
functions.
This commit is contained in:
Matthias Clasen 2020-02-21 19:56:44 -05:00
parent 13ed531301
commit 9fa7a47081
2 changed files with 50 additions and 20 deletions

View File

@ -115,6 +115,7 @@ select_swatch (GtkColorChooserWidget *cc,
{
GtkColorChooserWidgetPrivate *priv = gtk_color_chooser_widget_get_instance_private (cc);
GdkRGBA color;
double red, green, blue, alpha;
if (priv->current == swatch)
return;
@ -127,8 +128,12 @@ select_swatch (GtkColorChooserWidget *cc,
gtk_color_swatch_get_rgba (swatch, &color);
red = color.red;
green = color.green;
blue = color.blue;
alpha = color.alpha;
g_settings_set (priv->settings, "selected-color", "(bdddd)",
TRUE, color.red, color.green, color.blue, color.alpha);
TRUE, red, green, blue, alpha);
if (gtk_widget_get_visible (GTK_WIDGET (priv->editor)))
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->editor), &color);
@ -180,8 +185,15 @@ save_custom_colors (GtkColorChooserWidget *cc)
{
child = l->data;
if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color))
g_variant_builder_add (&builder, "(dddd)",
color.red, color.green, color.blue, color.alpha);
{
double red, green, blue, alpha;
red = color.red;
green = color.green;
blue = color.blue;
alpha = color.alpha;
g_variant_builder_add (&builder, "(dddd)", red, green, blue, alpha);
}
}
variant = g_variant_builder_end (&builder);
@ -499,9 +511,14 @@ gtk_color_chooser_widget_activate_color_customize (GtkWidget *widget,
{
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (widget);
GtkColorChooserWidgetPrivate *priv = gtk_color_chooser_widget_get_instance_private (cc);
double red, green, blue, alpha;
GdkRGBA color;
g_variant_get (parameter, "(dddd)", &color.red, &color.green, &color.blue, &color.alpha);
g_variant_get (parameter, "(dddd)", &red, &green, &blue, &alpha);
color.red = red;
color.green = green;
color.blue = blue;
color.alpha = alpha;
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->editor), &color);
@ -517,8 +534,13 @@ gtk_color_chooser_widget_activate_color_select (GtkWidget *widget,
{
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (widget);
GdkRGBA color;
double red, green, blue, alpha;
g_variant_get (parameter, "(dddd)", &color.red, &color.green, &color.blue, &color.alpha);
g_variant_get (parameter, "(dddd)", &red, &green, &blue, &alpha);
color.red = red;
color.green = green;
color.blue = blue;
color.alpha = alpha;
_gtk_color_chooser_color_activated (GTK_COLOR_CHOOSER (cc), &color);
}

View File

@ -167,24 +167,30 @@ static void
activate_color (GtkColorSwatch *swatch)
{
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
double red, green, blue, alpha;
red = priv->color.red;
green = priv->color.green;
blue = priv->color.blue;
alpha = priv->color.alpha;
gtk_widget_activate_action (GTK_WIDGET (swatch),
"color.select", "(dddd)",
priv->color.red,
priv->color.green,
priv->color.blue,
priv->color.alpha);
"color.select", "(dddd)", red, green, blue, alpha);
}
static void
customize_color (GtkColorSwatch *swatch)
{
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
double red, green, blue, alpha;
red = priv->color.red;
green = priv->color.green;
blue = priv->color.blue;
alpha = priv->color.alpha;
gtk_widget_activate_action (GTK_WIDGET (swatch),
"color.customize", "(dddd)",
priv->color.red,
priv->color.green,
priv->color.blue,
priv->color.alpha);
"color.customize", "(dddd)", red, green, blue, alpha);
}
static gboolean
@ -222,17 +228,19 @@ gtk_color_swatch_get_menu_model (GtkColorSwatch *swatch)
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
GMenu *menu, *section;
GMenuItem *item;
double red, green, blue, alpha;
menu = g_menu_new ();
red = priv->color.red;
green = priv->color.green;
blue = priv->color.blue;
alpha = priv->color.alpha;
section = g_menu_new ();
item = g_menu_item_new (_("Customize"), NULL);
g_menu_item_set_action_and_target_value (item, "color.customize",
g_variant_new ("(dddd)",
priv->color.red,
priv->color.green,
priv->color.blue,
priv->color.alpha));
g_variant_new ("(dddd)", red, green, blue, alpha));
g_menu_append_item (section, item);
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));