From 3d7197d3cd72d4315ea018e5d034743195e0da6d Mon Sep 17 00:00:00 2001 From: Hari Rana Date: Sun, 4 May 2025 17:26:38 -0400 Subject: [PATCH] gui/window: Set parent widget as last focus when event widget is unfocusable When selecting an event with a pointer, the keyboard-focused widget was being set instead of the last focus widget, which was then refocused after the event popover closed. This patch fixes that bug by only setting the parent widget as the last focus widget if the event widget itself is unfocusable, like in the agenda view. The `GtkWidget:focus-on-click` property is already enabled, so it takes care of refocusing the event widget if it's focusable. Commit https://gitlab.gnome.org/GNOME/gnome-calendar/-/commit/a3fb57939a307f5b661cc2f205e562f43a0a31fa technically fixed https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/915, but this patch solidifies the commit. Closes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/915 --- src/gui/gcal-window.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c index ddee83bf..db8b3586 100644 --- a/src/gui/gcal-window.c +++ b/src/gui/gcal-window.c @@ -772,6 +772,18 @@ day_selected (GcalWindow *self) update_active_date (self, gcal_view_get_date (GCAL_VIEW (self->date_chooser))); } +static GtkWidget* +find_first_focusable_widget (GtkWidget *widget) +{ + GtkWidget *aux = widget; + + while (aux && !gtk_widget_get_focusable (aux)) + aux = gtk_widget_get_parent (aux); + + g_assert (GTK_IS_WIDGET (aux)); + return aux; +} + static void event_activated (GcalView *view, GcalEventWidget *event_widget, @@ -779,7 +791,7 @@ event_activated (GcalView *view, { GcalWindow *self = GCAL_WINDOW (user_data); - g_set_weak_pointer (&self->last_focused_widget, gtk_root_get_focus (GTK_ROOT (self))); + g_set_weak_pointer (&self->last_focused_widget, find_first_focusable_widget (GTK_WIDGET (event_widget))); gcal_event_widget_show_preview (event_widget, event_preview_cb, user_data); }