From 3dce4414a88d85a5b9fe53758a9810da4f203d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20G=C3=B6llnitz?= Date: Wed, 4 Jun 2025 03:05:54 +0200 Subject: [PATCH] enums+window: make GcalWindowView iterators order and length agnostic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, iterators over the GcalWindowView enum relied on knowing the first and last enum value. But we know, without knowing which is the first, that an enum in C will assign 0 to its first value if not otherwise specified. And with the trick of a new end value similar to N_PROPS, we can determine the amount of available window views without relying on know which it is. Signed-off-by: Markus Göllnitz Part-of: --- src/gcal-enums.h | 2 ++ src/gui/gcal-window.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gcal-enums.h b/src/gcal-enums.h index df71a6e5..b9b14c2e 100644 --- a/src/gcal-enums.h +++ b/src/gcal-enums.h @@ -42,6 +42,8 @@ typedef enum { GCAL_WINDOW_VIEW_WEEK, GCAL_WINDOW_VIEW_MONTH, + + GCAL_WINDOW_VIEW_N_VIEWS, } GcalWindowView; typedef enum diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c index 09c31fe2..79372807 100644 --- a/src/gui/gcal-window.c +++ b/src/gui/gcal-window.c @@ -261,7 +261,7 @@ update_active_date (GcalWindow *window, gcal_set_date_time (&window->active_date, new_date); - for (i = GCAL_WINDOW_VIEW_WEEK; i <= GCAL_WINDOW_VIEW_MONTH; i++) + for (i = 0; i < GCAL_WINDOW_VIEW_N_VIEWS; i++) gcal_view_set_date (GCAL_VIEW (window->views[i]), new_date); gcal_view_set_date (GCAL_VIEW (window->agenda_view), new_date); gcal_view_set_date (GCAL_VIEW (window->date_chooser), new_date); @@ -452,7 +452,7 @@ on_view_action_activated (GSimpleAction *action, else if (view == -2) view = --(window->active_view); - window->active_view = CLAMP (view, GCAL_WINDOW_VIEW_WEEK, GCAL_WINDOW_VIEW_MONTH); + window->active_view = CLAMP (view, 0, GCAL_WINDOW_VIEW_N_VIEWS - 1); adw_view_stack_set_visible_child (window->views_stack, window->views[window->active_view]); g_object_notify_by_pspec (G_OBJECT (user_data), properties[PROP_ACTIVE_VIEW]);