views/month-cell: Inherit GtkWidget

AdwBreakpointBin, the parent, cannot set focus to itself. Instead
of focusing GtkOverlay, a child widget, we should instead inherit
GtkWidget to allow focusing that instead.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/564>
This commit is contained in:
Hari Rana
2026-03-03 18:35:17 -05:00
parent b592f15b26
commit 80adbd0d23
3 changed files with 83 additions and 76 deletions
+16 -15
View File
@@ -1,7 +1,20 @@
using Gtk 4.0; using Gtk 4.0;
using Adw 1; using Adw 1;
template $GcalMonthCell: Adw.BreakpointBin { template $GcalMonthCell: Widget {
accessibility {
labelled-by: day_label;
has-popup: true;
selected: false;
}
accessible-role: grid_cell;
focusable: true;
Adw.BreakpointBin breakpoint_bin {
width-request: 50;
height-request: 50;
Adw.Breakpoint breakpoint_narrow { Adw.Breakpoint breakpoint_narrow {
condition ("max-width: 120sp") condition ("max-width: 120sp")
@@ -13,20 +26,7 @@ template $GcalMonthCell: Adw.BreakpointBin {
} }
} }
accessibility { child: Overlay overlay {
labelled-by: day_label;
has-popup: true;
selected: false;
}
accessible-role: grid_cell;
width-request: 50;
height-request: 50;
hexpand: true;
vexpand: true;
focusable: true;
Overlay overlay {
[overlay] [overlay]
Box header_box { Box header_box {
valign: start; valign: start;
@@ -89,5 +89,6 @@ template $GcalMonthCell: Adw.BreakpointBin {
} }
} }
} }
};
} }
} }
+12 -6
View File
@@ -30,7 +30,7 @@
struct _GcalMonthCell struct _GcalMonthCell
{ {
AdwBreakpointBin parent; GtkWidget parent;
GDateTime *date; GDateTime *date;
guint n_overflow; guint n_overflow;
@@ -41,6 +41,7 @@ struct _GcalMonthCell
GtkWidget *header_box; GtkWidget *header_box;
GtkImage *weather_icon; GtkImage *weather_icon;
GtkLabel *temp_label; GtkLabel *temp_label;
GtkWidget *breakpoint_bin;
GtkWidget *overflow_button; GtkWidget *overflow_button;
GtkInscription *overflow_inscription; GtkInscription *overflow_inscription;
@@ -56,7 +57,7 @@ struct _GcalMonthCell
GBinding *icon_tooltip_binding; GBinding *icon_tooltip_binding;
}; };
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, ADW_TYPE_BREAKPOINT_BIN) G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_WIDGET)
enum enum
{ {
@@ -324,10 +325,10 @@ on_weather_service_weather_changed_cb (GcalWeatherService *weather_service,
} }
static void static void
on_breakpoint_changed_cb (GcalMonthCell *self, on_breakpoint_changed_cb (GcalMonthCell *self)
GParamSpec *pspec)
{ {
AdwBreakpoint *current_breakpoint = adw_breakpoint_bin_get_current_breakpoint (ADW_BREAKPOINT_BIN (self)); AdwBreakpoint *current_breakpoint =
adw_breakpoint_bin_get_current_breakpoint (ADW_BREAKPOINT_BIN (self->breakpoint_bin));
if (current_breakpoint == self->breakpoint_narrow) if (current_breakpoint == self->breakpoint_narrow)
{ {
@@ -357,6 +358,7 @@ gcal_month_cell_dispose (GObject *object)
gcal_clear_date_time (&self->date); gcal_clear_date_time (&self->date);
g_clear_object (&self->context); g_clear_object (&self->context);
g_clear_pointer (&self->breakpoint_bin, gtk_widget_unparent);
G_OBJECT_CLASS (gcal_month_cell_parent_class)->dispose (object); G_OBJECT_CLASS (gcal_month_cell_parent_class)->dispose (object);
} }
@@ -430,6 +432,7 @@ gcal_month_cell_class_init (GcalMonthCellClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-month-cell.ui"); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/views/gcal-month-cell.ui");
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, breakpoint_bin);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, breakpoint_narrow); gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, breakpoint_narrow);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, day_label); gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, day_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, header_box); gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, header_box);
@@ -442,6 +445,8 @@ gcal_month_cell_class_init (GcalMonthCellClass *klass)
gtk_widget_class_bind_template_callback (widget_class, overflow_button_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, overflow_button_clicked_cb);
gtk_widget_class_set_css_name (widget_class, "monthcell"); gtk_widget_class_set_css_name (widget_class, "monthcell");
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
} }
static void static void
@@ -456,7 +461,8 @@ gcal_month_cell_init (GcalMonthCell *self)
g_signal_connect (drop_target, "drop", G_CALLBACK (on_drop_target_drop_cb), self); g_signal_connect (drop_target, "drop", G_CALLBACK (on_drop_target_drop_cb), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drop_target)); gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drop_target));
g_signal_connect(self, "notify::current-breakpoint", G_CALLBACK (on_breakpoint_changed_cb), 0); g_signal_connect_swapped (self->breakpoint_bin,
"notify::current-breakpoint", G_CALLBACK (on_breakpoint_changed_cb), self);
} }
GtkWidget* GtkWidget*
+1 -1
View File
@@ -27,7 +27,7 @@ G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_CELL (gcal_month_cell_get_type()) #define GCAL_TYPE_MONTH_CELL (gcal_month_cell_get_type())
G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, AdwBreakpointBin) G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, GtkWidget)
GtkWidget* gcal_month_cell_new (void); GtkWidget* gcal_month_cell_new (void);