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
+70 -69
View File
@@ -1,18 +1,7 @@
using Gtk 4.0;
using Adw 1;
template $GcalMonthCell: Adw.BreakpointBin {
Adw.Breakpoint breakpoint_narrow {
condition ("max-width: 120sp")
setters {
weather_icon.halign: end;
weather_icon.hexpand: true;
weather_icon.margin-start: 6;
temp_label.visible: false;
}
}
template $GcalMonthCell: Widget {
accessibility {
labelled-by: day_label;
has-popup: true;
@@ -20,74 +9,86 @@ template $GcalMonthCell: Adw.BreakpointBin {
}
accessible-role: grid_cell;
width-request: 50;
height-request: 50;
hexpand: true;
vexpand: true;
focusable: true;
Overlay overlay {
[overlay]
Box header_box {
valign: start;
spacing: 6;
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;
Adw.BreakpointBin breakpoint_bin {
width-request: 50;
height-request: 50;
Label day_label {
styles [
"day-label",
"numeric",
]
}
Adw.Breakpoint breakpoint_narrow {
condition ("max-width: 120sp")
Image weather_icon {
pixel-size: 16;
margin-start: 12;
accessible-role: presentation;
styles [
"dimmed",
]
}
Label temp_label {
styles [
"dimmed",
"temp-label",
]
setters {
weather_icon.halign: end;
weather_icon.hexpand: true;
weather_icon.margin-start: 6;
temp_label.visible: false;
}
}
[overlay]
Button overflow_button {
accessible-role: toggle_button;
valign: end;
sensitive: false;
clicked => $overflow_button_clicked_cb(template) not-swapped;
tooltip-text: _("All Events");
margin-top: 1;
margin-start: 1;
margin-bottom: 2;
margin-end: 2;
child: Overlay overlay {
[overlay]
Box header_box {
valign: start;
spacing: 6;
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;
accessibility {
has-popup: true;
labelled-by: overflow_inscription;
}
Label day_label {
styles [
"day-label",
"numeric",
]
}
styles [
"flat",
"overflow",
]
Image weather_icon {
pixel-size: 16;
margin-start: 12;
accessible-role: presentation;
Box {
Inscription overflow_inscription {
text-overflow: ellipsize_end;
styles [
"dimmed",
]
}
Label temp_label {
styles [
"dimmed",
"temp-label",
]
}
}
}
[overlay]
Button overflow_button {
accessible-role: toggle_button;
valign: end;
sensitive: false;
clicked => $overflow_button_clicked_cb(template) not-swapped;
tooltip-text: _("All Events");
margin-top: 1;
margin-start: 1;
margin-bottom: 2;
margin-end: 2;
accessibility {
has-popup: true;
labelled-by: overflow_inscription;
}
styles [
"flat",
"overflow",
]
Box {
Inscription overflow_inscription {
text-overflow: ellipsize_end;
}
}
}
};
}
}
+12 -6
View File
@@ -30,7 +30,7 @@
struct _GcalMonthCell
{
AdwBreakpointBin parent;
GtkWidget parent;
GDateTime *date;
guint n_overflow;
@@ -41,6 +41,7 @@ struct _GcalMonthCell
GtkWidget *header_box;
GtkImage *weather_icon;
GtkLabel *temp_label;
GtkWidget *breakpoint_bin;
GtkWidget *overflow_button;
GtkInscription *overflow_inscription;
@@ -56,7 +57,7 @@ struct _GcalMonthCell
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
{
@@ -324,10 +325,10 @@ on_weather_service_weather_changed_cb (GcalWeatherService *weather_service,
}
static void
on_breakpoint_changed_cb (GcalMonthCell *self,
GParamSpec *pspec)
on_breakpoint_changed_cb (GcalMonthCell *self)
{
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)
{
@@ -357,6 +358,7 @@ gcal_month_cell_dispose (GObject *object)
gcal_clear_date_time (&self->date);
g_clear_object (&self->context);
g_clear_pointer (&self->breakpoint_bin, gtk_widget_unparent);
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_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, day_label);
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_set_css_name (widget_class, "monthcell");
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
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);
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*
+1 -1
View File
@@ -27,7 +27,7 @@ G_BEGIN_DECLS
#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);