From 5aec783a85872f65e39997ac6c62e642aeeeecf2 Mon Sep 17 00:00:00 2001 From: Hari Rana Date: Fri, 18 Sep 2026 07:18:08 -0400 Subject: [PATCH] common/date-chooser: Use `GcalMultiChoice::user-changed` At the moment `gcal_date_chooser_set_date()` is automatically setting the day to 1, which is undesirable behavior for a method that is designed to "just" set the date. By connecting to `GcalMultiChoice::explicitly-changed`, we can simply have the day set to 1 to accompanying callbacks. Currently, `multi_choice_changed()` is invoked 50 times at startup. By using `GcalMultiChoice::explicitly-changed`, `multi_choice_changed()` is only invoked 10 times. This is still more than ideal, but it's a significant drop. Fixes: https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1639 Part-of: --- src/gui/common/gcal-date-chooser.blp | 8 +++++--- src/gui/common/gcal-date-chooser.c | 26 +++++++++----------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/gui/common/gcal-date-chooser.blp b/src/gui/common/gcal-date-chooser.blp index 66e5448f..9d8a6a98 100644 --- a/src/gui/common/gcal-date-chooser.blp +++ b/src/gui/common/gcal-date-chooser.blp @@ -16,7 +16,7 @@ template $GcalDateChooser: Adw.Bin { previous-button-tooltip: _("Previous Month"); next-button-tooltip: _("Next Month"); visible: bind $get_split_choice_visible(template.show-heading, template.split-month-year) as ; - notify::value => $split_multi_choice_changed() swapped; + user-changed => $on_split_multi_choice_user_changed() swapped; layout { column: 0; @@ -33,7 +33,7 @@ template $GcalDateChooser: Adw.Bin { category: _("Year"); previous-button-tooltip: _("Previous Year"); next-button-tooltip: _("Next Year"); - notify::value => $split_multi_choice_changed() swapped; + user-changed => $on_split_multi_choice_user_changed() swapped; layout { column: 1; @@ -53,7 +53,7 @@ template $GcalDateChooser: Adw.Bin { category: _("Month"); previous-button-tooltip: _("Previous Month"); next-button-tooltip: _("Next Month"); - notify::value => $combined_multi_choice_changed() swapped; + user-changed => $on_combined_multi_choice_user_changed() swapped; layout { column: 0; @@ -92,6 +92,7 @@ Popover popover { previous-button-tooltip: bind month_choice.previous-button-tooltip; next-button-tooltip: bind month_choice.next-button-tooltip; string-list: bind month_choice.string-list; + user-changed => $on_split_multi_choice_user_changed() swapped; } $GcalMultiChoice { @@ -102,6 +103,7 @@ Popover popover { previous-button-tooltip: bind year_choice.previous-button-tooltip; next-button-tooltip: bind year_choice.next-button-tooltip; string-list: bind year_choice.string-list; + user-changed => $on_split_multi_choice_user_changed() swapped; } styles [ diff --git a/src/gui/common/gcal-date-chooser.c b/src/gui/common/gcal-date-chooser.c index ba72fb91..394823ef 100644 --- a/src/gui/common/gcal-date-chooser.c +++ b/src/gui/common/gcal-date-chooser.c @@ -600,9 +600,6 @@ gcal_date_chooser_set_date (GcalView *view, g_date_time_get_ymd (self->date, &y1, &m1, &d1); g_date_time_get_ymd (date, &y2, &m2, &d2); - if (y1 != y2 || m1 != m2) - d2 = 1; - gcal_set_date_time (&self->date, date); if (y1 != y2 || m1 != m2 || d1 != d2) @@ -871,30 +868,25 @@ multi_choice_changed (GcalDateChooser *self, } static void -combined_multi_choice_changed (GcalDateChooser *self) +on_combined_multi_choice_user_changed (GcalDateChooser *self) { - gint year, month, day, value; + int year, month, value; value = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->combined_choice)); - decode_combined_choice_value (value, &year, &month, &day); + decode_combined_choice_value (value, &year, &month, NULL); - multi_choice_changed (self, year, month, day); + multi_choice_changed (self, year, month, 1); } static void -split_multi_choice_changed (GcalDateChooser *self) +on_split_multi_choice_user_changed (GcalDateChooser *self) { - gint year, month, day; + int year, month; year = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->year_choice)); month = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->month_choice)) + 1; - day = g_date_time_get_day_of_month (self->date); - - /* Make sure the day is valid at that month */ - day = MIN (day, month_length[leap (year)][month]); - - multi_choice_changed (self, year, month, day); + multi_choice_changed (self, year, month, 1); } static gboolean @@ -1028,10 +1020,10 @@ gcal_date_chooser_class_init (GcalDateChooserClass *class) gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, grid); gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, gizmo); - gtk_widget_class_bind_template_callback (widget_class, combined_multi_choice_changed); + gtk_widget_class_bind_template_callback (widget_class, on_combined_multi_choice_user_changed); gtk_widget_class_bind_template_callback (widget_class, get_combined_choice_visible); gtk_widget_class_bind_template_callback (widget_class, get_split_choice_visible); - gtk_widget_class_bind_template_callback (widget_class, split_multi_choice_changed); + gtk_widget_class_bind_template_callback (widget_class, on_split_multi_choice_user_changed); gtk_widget_class_set_css_name (widget_class, "datechooser"); }