From dee98d1e20171f3aefd308103222f43db41a5691 Mon Sep 17 00:00:00 2001 From: Enzo MAROS Date: Tue, 6 Aug 2024 12:21:47 +0200 Subject: [PATCH] calendar-button: Bind calendar color with paintable When updating the color of the calendar, the corresponding colored dot in the "Calendars" popover does not change. This is due to the fact that GListModel doesn't notify when one child changes internally. Any widget depicting a calendar should watch for changes on the data. To fix this, I used the same code as in GcalEventEditorDialog, which creates a binding between the calendar's color and the paintable inside the image. --- src/gui/gcal-calendar-button.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gui/gcal-calendar-button.c b/src/gui/gcal-calendar-button.c index f02d9e0f..7a733263 100644 --- a/src/gui/gcal-calendar-button.c +++ b/src/gui/gcal-calendar-button.c @@ -50,6 +50,17 @@ static GParamSpec *properties [N_PROPS]; * Auxiliary methods */ +static gboolean +paintable_from_gdk_rgb (GBinding *binding, + const GValue *from_value, + GValue *to_value, + gpointer user_data) +{ + GdkRGBA *rgba = g_value_get_boxed (from_value); + g_value_take_object (to_value, get_circle_paintable_from_color (rgba, 16)); + return TRUE; +} + static GtkWidget* create_row_func (gpointer data, gpointer user_data) @@ -57,7 +68,6 @@ create_row_func (gpointer data, g_autoptr (GdkPaintable) paintable = NULL; GcalCalendar *calendar; GtkWidget *label, *icon, *checkbox, *box, *row; - const GdkRGBA *color; calendar = GCAL_CALENDAR (data); @@ -71,11 +81,16 @@ create_row_func (gpointer data, gtk_widget_set_margin_end (box, 6); /* source color icon */ - color = gcal_calendar_get_color (calendar); - paintable = get_circle_paintable_from_color (color, 16); - icon = gtk_image_new_from_paintable (paintable); - + icon = gtk_image_new (); gtk_widget_add_css_class (icon, "calendar-color-image"); + g_object_bind_property_full (calendar, "color", + icon, "paintable", + G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE, + paintable_from_gdk_rgb, + NULL, + NULL, + NULL); + /* source name label */ label = gtk_label_new (gcal_calendar_get_name (calendar));