views/month-view: Check if focused widget is month cell

This fixes an issue where pressing Shift + Up/Down while focused on the
overflow button will result in a bail out when asserting the focused
widget has a month cell ancestor:

```
GcalMonthView:ERROR:../src/gui/views/gcal-month-view.c:1002:on_key_controller_key_pressed_cb: assertion failed: (GCAL_IS_MONTH_CELL (month_cell))
Bail out! GcalMonthView:ERROR:../src/gui/views/gcal-month-view.c:1002:on_key_controller_key_pressed_cb: assertion failed: (GCAL_IS_MONTH_CELL (month_cell))
```

When navigating between month cells with a keyboard, focus is set
on respective month cells, so checking whether the ancestor
is a month cell or not is not only unnecessary, it also causes
bugs like the assertion above.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/720>
This commit is contained in:
Zoey Ahmed
2026-03-11 08:55:09 -04:00
committed by Hari Rana
parent b18e2b68bd
commit f99678aea9
+8 -11
View File
@@ -968,16 +968,15 @@ on_key_controller_key_pressed_cb (GtkEventControllerKey *event_controller,
GcalMonthView *self)
{
GDateTime *date = NULL;
GtkWidget *focused_widget, *month_cell;
GtkWidget *focused_widget;
GtkRoot *root;
root = gtk_widget_get_root (GTK_WIDGET (self));
focused_widget = gtk_root_get_focus (root);
month_cell = gtk_widget_get_ancestor (focused_widget, GCAL_TYPE_MONTH_CELL);
self->state = state;
if (month_cell && (state & GDK_SHIFT_MASK))
if (GCAL_IS_MONTH_CELL (focused_widget) && (state & GDK_SHIFT_MASK))
{
if (keyval == GDK_KEY_Escape)
{
@@ -990,19 +989,18 @@ on_key_controller_key_pressed_cb (GtkEventControllerKey *event_controller,
if (!self->selection.start)
{
date = gcal_month_cell_get_date (GCAL_MONTH_CELL (month_cell));
date = gcal_month_cell_get_date (GCAL_MONTH_CELL (focused_widget));
self->selection.start = g_date_time_ref (date);
update_selection_range (self);
}
focused_widget = gtk_root_get_focus (root);
month_cell = gtk_widget_get_ancestor (focused_widget, GCAL_TYPE_MONTH_CELL);
g_assert (GCAL_IS_MONTH_CELL (month_cell));
g_assert (GCAL_IS_MONTH_CELL (focused_widget));
gcal_clear_date_time (&self->selection.end);
date = gcal_month_cell_get_date (GCAL_MONTH_CELL (month_cell));
date = gcal_month_cell_get_date (GCAL_MONTH_CELL (focused_widget));
self->selection.end = g_date_time_ref (date);
update_selection_range (self);
@@ -1018,14 +1016,13 @@ on_key_controller_key_released_cb (GtkEventControllerKey *event_controller,
GdkModifierType state,
GcalMonthView *self)
{
GtkWidget *focused_widget, *month_cell;
GtkWidget *focused_widget;
GtkRoot *root;
root = gtk_widget_get_root (GTK_WIDGET (self));
focused_widget = gtk_root_get_focus (root);
month_cell = gtk_widget_get_ancestor (focused_widget, GCAL_TYPE_MONTH_CELL);
if (month_cell)
if (GCAL_IS_MONTH_CELL (focused_widget))
{
switch (keyval)
{
@@ -1035,7 +1032,7 @@ on_key_controller_key_released_cb (GtkEventControllerKey *event_controller,
if (!self->selection.end)
break;
gtk_widget_activate (month_cell);
gtk_widget_activate (focused_widget);
break;
default:
break;