From 1cbce60c4a653a26b113e85567090300a944864a Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sun, 23 Jan 2022 21:03:42 -0300 Subject: [PATCH] month-view: Port to GTK4 --- src/gui/views/gcal-month-cell.c | 142 +-- src/gui/views/gcal-month-cell.h | 4 +- src/gui/views/gcal-month-cell.ui | 63 +- src/gui/views/gcal-month-popover.c | 712 +++---------- src/gui/views/gcal-month-popover.h | 9 +- src/gui/views/gcal-month-popover.ui | 79 +- src/gui/views/gcal-month-view.c | 1474 +++++++++++++-------------- src/gui/views/gcal-month-view.h | 2 +- src/gui/views/gcal-month-view.ui | 54 +- src/gui/views/gcal-view.c | 2 +- src/theme/Adwaita.css | 8 +- src/utils/gcal-utils.c | 16 +- src/utils/gcal-utils.h | 2 +- 13 files changed, 957 insertions(+), 1610 deletions(-) diff --git a/src/gui/views/gcal-month-cell.c b/src/gui/views/gcal-month-cell.c index 5bb71a2a..c0b6cc3c 100644 --- a/src/gui/views/gcal-month-cell.c +++ b/src/gui/views/gcal-month-cell.c @@ -29,7 +29,7 @@ struct _GcalMonthCell { - GtkEventBox parent; + AdwBin parent; GDateTime *date; guint n_overflow; @@ -46,16 +46,12 @@ struct _GcalMonthCell gboolean different_month; gboolean selected; - /* internal fields */ - gboolean hovered : 1; - gboolean pressed : 1; - GcalContext *context; GcalWeatherInfo *weather_info; }; -G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_EVENT_BOX) +G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, ADW_TYPE_BIN) enum { @@ -82,52 +78,14 @@ static void update_style_flags (GcalMonthCell *self) { g_autoptr (GDateTime) today = NULL; - GtkStyleContext *context; - GtkStateFlags flags; - GtkWidget *widget; - - widget = GTK_WIDGET (self); - flags = gtk_widget_get_state_flags (widget); - - if (self->hovered) - flags |= GTK_STATE_FLAG_PRELIGHT; - else - flags &= ~GTK_STATE_FLAG_PRELIGHT; - - gtk_widget_set_state_flags (widget, flags, TRUE); /* Today */ today = g_date_time_new_now_local (); - context = gtk_widget_get_style_context (GTK_WIDGET (self)); if (gcal_date_time_compare_date (self->date, today) == 0) - gtk_style_context_add_class (context, "today"); + gtk_widget_add_css_class (GTK_WIDGET (self), "today"); else - gtk_style_context_remove_class (context, "today"); -} - -static gboolean -should_propagate_button_event (GtkWidget *widget, - GdkEventButton *event_button) -{ - GcalMonthCell *self; - gdouble x, y; - gint button_height, height; - - self = GCAL_MONTH_CELL (widget); - height = gtk_widget_get_allocated_height (widget); - button_height = gtk_widget_get_allocated_height (self->overflow_button); - - x = event_button->x; - y = event_button->y; - - if (!gcal_translate_child_window_position (widget, event_button->window, x, y, &x, &y)) - return GDK_EVENT_PROPAGATE; - - if (self->n_overflow > 0 && y > height - button_height) - return GDK_EVENT_STOP; - - return GDK_EVENT_PROPAGATE; + gtk_widget_remove_css_class (GTK_WIDGET (self), "today"); } @@ -142,30 +100,6 @@ day_changed_cb (GcalClock *clock, update_style_flags (self); } -static gboolean -enter_notify_event_cb (GtkWidget *widget, - GdkEventCrossing *event_crossing, - GcalMonthCell *self) -{ - self->hovered = TRUE; - - update_style_flags (self); - - return GDK_EVENT_PROPAGATE; -} - -static gboolean -leave_notify_event_cb (GtkWidget *widget, - GdkEventCrossing *event_crossing, - GcalMonthCell *self) -{ - self->hovered = FALSE; - - update_style_flags (self); - - return GDK_EVENT_PROPAGATE; -} - static void overflow_button_clicked_cb (GtkWidget *button, GcalMonthCell *self) @@ -176,6 +110,9 @@ overflow_button_clicked_cb (GtkWidget *button, /* * GtkWidget overrides */ + +#if 0 // TODO: DND + static gboolean gcal_month_cell_drag_motion (GtkWidget *widget, GdkDragContext *context, @@ -297,51 +234,7 @@ gcal_month_cell_drag_leave (GtkWidget *widget, gtk_drag_unhighlight (widget); } -static gboolean -gcal_month_cell_button_press_event (GtkWidget *widget, - GdkEventButton *event_button) -{ - GcalMonthCell *self = GCAL_MONTH_CELL (widget); - - self->pressed = TRUE; - - return should_propagate_button_event (widget, event_button); -} - -static gboolean -gcal_month_cell_button_release_event (GtkWidget *widget, - GdkEventButton *event_button) -{ - GcalMonthCell *self = GCAL_MONTH_CELL (widget); - - if (!self->pressed) - return GDK_EVENT_STOP; - - self->pressed = FALSE; - - return should_propagate_button_event (widget, event_button); -} - -static gboolean -gcal_month_cell_draw (GtkWidget *widget, - cairo_t *cr) -{ - GtkStyleContext *context; - gint width, height; - - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); - context = gtk_widget_get_style_context (widget); - - gtk_render_background (context, cr, 0, 0, width, height); - gtk_render_frame (context, cr, 0, 0, width, height); - - if (gtk_widget_has_focus (widget)) - gtk_render_focus (context, cr, 0, 0, width, height); - - return GTK_WIDGET_CLASS (gcal_month_cell_parent_class)->draw (widget, cr); -} - +#endif /* * GObject overrides @@ -409,12 +302,11 @@ gcal_month_cell_class_init (GcalMonthCellClass *klass) object_class->set_property = gcal_month_cell_set_property; object_class->get_property = gcal_month_cell_get_property; - widget_class->button_press_event = gcal_month_cell_button_press_event; - widget_class->button_release_event = gcal_month_cell_button_release_event; +#if 0 // TODO: DND widget_class->drag_motion = gcal_month_cell_drag_motion; widget_class->drag_drop = gcal_month_cell_drag_drop; widget_class->drag_leave = gcal_month_cell_drag_leave; - widget_class->draw = gcal_month_cell_draw; +#endif signals[SHOW_OVERFLOW] = g_signal_new ("show-overflow", GCAL_TYPE_MONTH_CELL, @@ -442,8 +334,6 @@ gcal_month_cell_class_init (GcalMonthCellClass *klass) gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, temp_label); gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, weather_icon); - gtk_widget_class_bind_template_callback (widget_class, enter_notify_event_cb); - gtk_widget_class_bind_template_callback (widget_class, leave_notify_event_cb); gtk_widget_class_bind_template_callback (widget_class, overflow_button_clicked_cb); gtk_widget_class_set_css_name (widget_class, "monthcell"); @@ -454,12 +344,14 @@ gcal_month_cell_init (GcalMonthCell *self) { gtk_widget_init_template (GTK_WIDGET (self)); +#if 0 // TODO: DND /* Setup the month cell as a drag n' drop destination */ gtk_drag_dest_set (GTK_WIDGET (self), 0, NULL, 0, GDK_ACTION_MOVE); +#endif } GtkWidget* @@ -533,7 +425,7 @@ gcal_month_cell_set_weather (GcalMonthCell *self, icon_name = gcal_weather_info_get_icon_name (info); temp_str = gcal_weather_info_get_temperature (info); - gtk_image_set_from_icon_name (self->weather_icon, icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_image_set_from_icon_name (self->weather_icon, icon_name); gtk_label_set_text (self->temp_label, temp_str); } } @@ -631,8 +523,8 @@ gcal_month_cell_get_content_space (GcalMonthCell *self) g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1); context = gtk_widget_get_style_context (GTK_WIDGET (self)); - gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding); - gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border); + gtk_style_context_get_padding (context, &padding); + gtk_style_context_get_border (context, &border); return gtk_widget_get_allocated_height (GTK_WIDGET (self)) - gcal_month_cell_get_header_height (self) - @@ -650,8 +542,8 @@ gcal_month_cell_get_header_height (GcalMonthCell *self) g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1); context = gtk_widget_get_style_context (GTK_WIDGET (self->header_box)); - gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding); - gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border); + gtk_style_context_get_padding (context, &padding); + gtk_style_context_get_border (context, &border); return gtk_widget_get_allocated_height (self->header_box) + gtk_widget_get_margin_top (self->header_box) + diff --git a/src/gui/views/gcal-month-cell.h b/src/gui/views/gcal-month-cell.h index 6b1dcc83..09a6fe51 100644 --- a/src/gui/views/gcal-month-cell.h +++ b/src/gui/views/gcal-month-cell.h @@ -22,13 +22,13 @@ #include "gcal-context.h" #include "gcal-weather-info.h" -#include +#include G_BEGIN_DECLS #define GCAL_TYPE_MONTH_CELL (gcal_month_cell_get_type()) -G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, GtkEventBox) +G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, AdwBin) 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 89904a41..46291a2c 100644 --- a/src/gui/views/gcal-month-cell.ui +++ b/src/gui/views/gcal-month-cell.ui @@ -1,28 +1,21 @@ -