diff --git a/src/gui/views/gcal-month-cell.c b/src/gui/views/gcal-month-cell.c index 8b46c7e99324b84ff23d4dd2bf356fec6f4881c7..3c45facfede9efcd921b1e62d59f7c16cb8cc248 100644 --- a/src/gui/views/gcal-month-cell.c +++ b/src/gui/views/gcal-month-cell.c @@ -30,11 +30,13 @@ struct _GcalMonthCell { - AdwBin parent; + AdwBreakpointBin parent; GDateTime *date; guint n_overflow; + AdwBreakpoint *breakpoint_narrow; + GtkLabel *day_label; GtkWidget *header_box; GtkLabel *month_name_label; @@ -51,9 +53,11 @@ struct _GcalMonthCell GcalContext *context; GcalWeatherInfo *weather_info; + + GBinding *icon_tooltip_binding; }; -G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, ADW_TYPE_BIN) +G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, ADW_TYPE_BREAKPOINT_BIN) enum { @@ -303,13 +307,34 @@ on_weather_service_weather_changed_cb (GcalWeatherService *weather_service, update_weather (self); } +static void +on_breakpoint_changed_cb (GcalMonthCell *self, + GParamSpec *pspec) +{ + AdwBreakpoint *current_breakpoint = adw_breakpoint_bin_get_current_breakpoint (ADW_BREAKPOINT_BIN (self)); + + if (current_breakpoint == self->breakpoint_narrow) + { + self->icon_tooltip_binding = g_object_bind_property (self->temp_label, "label", + self->weather_icon, "tooltip-text", + G_BINDING_SYNC_CREATE); + } + else + { + g_assert (G_IS_BINDING (self->icon_tooltip_binding)); + + g_clear_pointer (&self->icon_tooltip_binding, g_binding_unbind); + gtk_widget_set_tooltip_text (GTK_WIDGET (self->weather_icon), NULL); + } +} + /* * GObject overrides */ static void -gcal_month_cell_finalize (GObject *object) +gcal_month_cell_dispose (GObject *object) { GcalMonthCell *self = (GcalMonthCell *)object; @@ -319,7 +344,7 @@ gcal_month_cell_finalize (GObject *object) gcal_clear_date_time (&self->date); g_clear_object (&self->context); - G_OBJECT_CLASS (gcal_month_cell_parent_class)->finalize (object); + G_OBJECT_CLASS (gcal_month_cell_parent_class)->dispose (object); } @@ -369,7 +394,7 @@ gcal_month_cell_class_init (GcalMonthCellClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = gcal_month_cell_finalize; + object_class->dispose = gcal_month_cell_dispose; object_class->set_property = gcal_month_cell_set_property; object_class->get_property = gcal_month_cell_get_property; @@ -391,6 +416,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_narrow); 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, month_name_label); @@ -416,6 +442,8 @@ gcal_month_cell_init (GcalMonthCell *self) g_signal_connect (drop_target, "accept", G_CALLBACK (on_drop_target_accept_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)); + + g_signal_connect(self, "notify::current-breakpoint", G_CALLBACK (on_breakpoint_changed_cb), 0); } GtkWidget* diff --git a/src/gui/views/gcal-month-cell.h b/src/gui/views/gcal-month-cell.h index 5f752098f5a48522ab2e309d100364e16f64e4f1..d7aaf0fbbcb446332fdab481212377bb0d9605ab 100644 --- a/src/gui/views/gcal-month-cell.h +++ b/src/gui/views/gcal-month-cell.h @@ -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, AdwBin) +G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, AdwBreakpointBin) GtkWidget* gcal_month_cell_new (void); diff --git a/src/gui/views/gcal-month-cell.ui b/src/gui/views/gcal-month-cell.ui index f5a90466859614e9413021fa24bdef074012a8a0..28ccada48622645129a457482520c8824fc5b995 100644 --- a/src/gui/views/gcal-month-cell.ui +++ b/src/gui/views/gcal-month-cell.ui @@ -1,6 +1,18 @@ -