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 Gtk 4.0;
using Adw 1; using Adw 1;
template $GcalMonthCell: Adw.BreakpointBin { template $GcalMonthCell: Widget {
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;
}
}
accessibility { accessibility {
labelled-by: day_label; labelled-by: day_label;
has-popup: true; has-popup: true;
@@ -20,74 +9,86 @@ template $GcalMonthCell: Adw.BreakpointBin {
} }
accessible-role: grid_cell; accessible-role: grid_cell;
width-request: 50;
height-request: 50;
hexpand: true;
vexpand: true;
focusable: true; focusable: true;
Overlay overlay { Adw.BreakpointBin breakpoint_bin {
[overlay] width-request: 50;
Box header_box { height-request: 50;
valign: start;
spacing: 6;
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;
Label day_label { Adw.Breakpoint breakpoint_narrow {
styles [ condition ("max-width: 120sp")
"day-label",
"numeric",
]
}
Image weather_icon { setters {
pixel-size: 16; weather_icon.halign: end;
margin-start: 12; weather_icon.hexpand: true;
accessible-role: presentation; weather_icon.margin-start: 6;
temp_label.visible: false;
styles [
"dimmed",
]
}
Label temp_label {
styles [
"dimmed",
"temp-label",
]
} }
} }
[overlay] child: Overlay overlay {
Button overflow_button { [overlay]
accessible-role: toggle_button; Box header_box {
valign: end; valign: start;
sensitive: false; spacing: 6;
clicked => $overflow_button_clicked_cb(template) not-swapped; margin-top: 6;
tooltip-text: _("All Events"); margin-bottom: 6;
margin-top: 1; margin-start: 6;
margin-start: 1; margin-end: 6;
margin-bottom: 2;
margin-end: 2;
accessibility { Label day_label {
has-popup: true; styles [
labelled-by: overflow_inscription; "day-label",
} "numeric",
]
}
styles [ Image weather_icon {
"flat", pixel-size: 16;
"overflow", margin-start: 12;
] accessible-role: presentation;
Box { styles [
Inscription overflow_inscription { "dimmed",
text-overflow: ellipsize_end; ]
}
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 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);