From a635ca51edeb59630769b1cd9298e12601a2acda Mon Sep 17 00:00:00 2001 From: ARAKHNID Date: Fri, 2 Oct 2026 10:06:11 -0500 Subject: [PATCH] gui/views/week-view: Add shortcuts for zooming in/out It's possible to change the density of the week view, but only through pinch-zooming or Ctrl+scroll wheel. This means it can't be done with only the keyboard, and since neither of these methods are documented, it's not discoverable either. This adds shortcuts for zooming the view in and out, and documents them in the shortcuts dialog to make them discoverable. Helps #1556 Part-of: --- src/gui/shortcuts-dialog.blp | 10 ++++++++++ src/gui/views/gcal-week-view.blp | 22 ++++++++++++++++++++++ src/gui/views/gcal-week-view.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/gui/shortcuts-dialog.blp b/src/gui/shortcuts-dialog.blp index 774b219f..d11dd3b8 100644 --- a/src/gui/shortcuts-dialog.blp +++ b/src/gui/shortcuts-dialog.blp @@ -78,6 +78,16 @@ Adw.ShortcutsDialog shortcuts_dialog { title: C_("shortcut dialog", "Previous View"); accelerator: "Page_Up"; } + + Adw.ShortcutsItem { + title: C_("shortcut dialog", "Zoom In"); + accelerator: "plus"; + } + + Adw.ShortcutsItem { + title: C_("shortcut dialog", "Zoom Out"); + accelerator: "minus"; + } } Adw.ShortcutsSection { diff --git a/src/gui/views/gcal-week-view.blp b/src/gui/views/gcal-week-view.blp index 5d83e19d..77ddf87a 100644 --- a/src/gui/views/gcal-week-view.blp +++ b/src/gui/views/gcal-week-view.blp @@ -3,6 +3,28 @@ using Gtk 4.0; template $GcalWeekView: Box { orientation: vertical; + ShortcutController { + Shortcut { + trigger: "plus"; + action: "action(week-view.zoom-in)"; + } + + Shortcut { + trigger: "minus"; + action: "action(week-view.zoom-out)"; + } + + Shortcut { + trigger: "KP_Add"; + action: "action(week-view.zoom-in)"; + } + + Shortcut { + trigger: "KP_Subtract"; + action: "action(week-view.zoom-out)"; + } + } + styles [ "week-view", ] diff --git a/src/gui/views/gcal-week-view.c b/src/gui/views/gcal-week-view.c index d9ac663c..84b4bccd 100644 --- a/src/gui/views/gcal-week-view.c +++ b/src/gui/views/gcal-week-view.c @@ -388,6 +388,32 @@ stack_visible_child_changed_cb (AdwViewStack *stack, g_clear_signal_handler (&self->stack_page_changed_id, stack); } +static void +zoom_in_activated_cb (GtkWidget *widget, + const char *action_name, + GVariant *param) +{ + GcalWeekView *self = GCAL_WEEK_VIEW (widget); + gdouble view_center_y = gtk_widget_get_height (self->scrolled_window) / 2.0; + + begin_zoom (self, view_center_y); + apply_zoom (self, view_center_y, 1.1); + save_zoom_level (self); +} + +static void +zoom_out_activated_cb (GtkWidget *widget, + const char *action_name, + GVariant *param) + +{ + GcalWeekView *self = GCAL_WEEK_VIEW (widget); + gdouble view_center_y = gtk_widget_get_height (self->scrolled_window) / 2.0; + + begin_zoom (self, view_center_y); + apply_zoom (self, view_center_y, 0.9); + save_zoom_level (self); +} /* GcalView implementation */ static GDateTime* @@ -624,6 +650,9 @@ gcal_week_view_class_init (GcalWeekViewClass *klass) gtk_widget_class_bind_template_callback (widget_class, on_zoom_gesture_end_cb); gtk_widget_class_set_css_name (widget_class, "calendar-view"); + + gtk_widget_class_install_action (widget_class, "week-view.zoom-in", NULL, zoom_in_activated_cb); + gtk_widget_class_install_action (widget_class, "week-view.zoom-out", NULL, zoom_out_activated_cb); } static void