month-view: Port to GTK4
This commit is contained in:
+17
-125
@@ -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) +
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
#include "gcal-context.h"
|
||||
#include "gcal-weather-info.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <adwaita.h>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GcalMonthCell" parent="GtkEventBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="expand">True</property>
|
||||
<signal name="enter-notify-event" handler="enter_notify_event_cb" object="GcalMonthCell" swapped="no" />
|
||||
<signal name="leave-notify-event" handler="leave_notify_event_cb" object="GcalMonthCell" swapped="no" />
|
||||
<template class="GcalMonthCell" parent="AdwBin">
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="focusable">True</property>
|
||||
<child>
|
||||
<object class="GtkOverlay" id="overlay">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
|
||||
<child type="overlay">
|
||||
<object class="GtkBox" id="header_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="margin">6</property>
|
||||
<property name="margin-bottom">0</property>
|
||||
<property name="margin-top">6</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin-end">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="day_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<style>
|
||||
<class name="day-label" />
|
||||
</style>
|
||||
@@ -32,8 +25,6 @@
|
||||
<!-- Weather forecast -->
|
||||
<child>
|
||||
<object class="GtkImage" id="weather_icon">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="pixel_size">16</property>
|
||||
<property name="margin-start">12</property>
|
||||
<style>
|
||||
@@ -44,8 +35,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="temp_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<style>
|
||||
<class name="dim-label" />
|
||||
<class name="temp-label" />
|
||||
@@ -55,38 +44,18 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- HACK: in Gtk3, insensitive widgets receive no events. We "fix" this
|
||||
limitation by adding an always-sensitive GtkEventBox above the event,
|
||||
and when the event is insensitive, the event box's event window is
|
||||
above it -->
|
||||
<child type="overlay">
|
||||
<object class="GtkEventBox" id="button_event_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="above-child" bind-source="overflow_button" bind-property="sensitive" bind-flags="default|invert-boolean|sync-create" />
|
||||
<signal name="enter-notify-event" handler="enter_notify_event_cb" object="GcalMonthCell" swapped="no" />
|
||||
<signal name="leave-notify-event" handler="leave_notify_event_cb" object="GcalMonthCell" swapped="no" />
|
||||
<object class="GtkButton" id="overflow_button">
|
||||
<property name="valign">end</property>
|
||||
<signal name="clicked" handler="overflow_button_clicked_cb" object="GcalMonthCell" swapped="no" />
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
<child>
|
||||
<object class="GtkButton" id="overflow_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="valign">end</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="clicked" handler="overflow_button_clicked_cb" object="GcalMonthCell" swapped="no" />
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="overflow_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="ellipsize">end</property>
|
||||
</object>
|
||||
</child>
|
||||
<object class="GtkLabel" id="overflow_label">
|
||||
<property name="ellipsize">end</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
+151
-561
@@ -24,59 +24,41 @@
|
||||
#include "gcal-month-popover.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#include <dazzle.h>
|
||||
#include <adwaita.h>
|
||||
|
||||
#define RATIO_TO_RELATIVE 1.25
|
||||
#define MIN_WIDTH 250
|
||||
|
||||
struct _GcalMonthPopover
|
||||
{
|
||||
GtkWindow parent;
|
||||
GtkWidget parent;
|
||||
|
||||
GtkLabel *day_label;
|
||||
GtkWidget *listbox;
|
||||
GtkRevealer *revealer;
|
||||
GtkWidget *scrolled_window;
|
||||
|
||||
GtkWidget *relative_to;
|
||||
GtkWindow *transient_for;
|
||||
GtkListBox *listbox;
|
||||
GtkWidget *main_box;
|
||||
|
||||
GcalContext *context;
|
||||
|
||||
DzlAnimation *opacity_animation;
|
||||
DzlAnimation *position_animation;
|
||||
DzlAnimation *size_animation;
|
||||
|
||||
gulong delete_event_handler;
|
||||
gulong configure_event_handler;
|
||||
gulong size_allocate_handler;
|
||||
|
||||
/* Positioning flags - range from [0, 1] */
|
||||
gdouble x_ratio;
|
||||
gdouble y_ratio;
|
||||
|
||||
GDateTime *date;
|
||||
AdwAnimation *animation;
|
||||
};
|
||||
|
||||
static void event_activated_cb (GcalEventWidget *event_widget,
|
||||
GcalMonthPopover *self);
|
||||
|
||||
G_DEFINE_TYPE (GcalMonthPopover, gcal_month_popover, GTK_TYPE_WINDOW)
|
||||
G_DEFINE_TYPE (GcalMonthPopover, gcal_month_popover, GTK_TYPE_WIDGET)
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONTEXT,
|
||||
PROP_RELATIVE_TO,
|
||||
PROP_X,
|
||||
PROP_Y,
|
||||
N_PROPS
|
||||
N_PROPS,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
EVENT_ACTIVATED,
|
||||
LAST_SIGNAL
|
||||
LAST_SIGNAL,
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
@@ -87,227 +69,20 @@ static GParamSpec *properties [N_PROPS] = { NULL, };
|
||||
* Auxiliary functions
|
||||
*/
|
||||
|
||||
static void
|
||||
adjust_margin (GcalMonthPopover *self,
|
||||
GdkRectangle *area)
|
||||
{
|
||||
GtkStyleContext *style_context;
|
||||
GtkBorder margin;
|
||||
|
||||
style_context = gtk_widget_get_style_context (gtk_bin_get_child (GTK_BIN (self)));
|
||||
gtk_style_context_get_margin (style_context,
|
||||
gtk_style_context_get_state (style_context),
|
||||
&margin);
|
||||
|
||||
area->x -= margin.right;
|
||||
area->y -= margin.top;
|
||||
area->width += margin.right + margin.left;
|
||||
area->height += margin.top + margin.bottom;
|
||||
}
|
||||
|
||||
static void
|
||||
animate_opacity (GcalMonthPopover *self,
|
||||
gdouble target)
|
||||
{
|
||||
DzlAnimation *animation;
|
||||
|
||||
if (self->opacity_animation)
|
||||
dzl_animation_stop (self->opacity_animation);
|
||||
|
||||
/* Animate the opacity */
|
||||
animation = dzl_object_animate (self,
|
||||
DZL_ANIMATION_EASE_IN_OUT_CUBIC,
|
||||
250,
|
||||
gtk_widget_get_frame_clock (GTK_WIDGET (self)),
|
||||
"opacity", target,
|
||||
NULL);
|
||||
dzl_set_weak_pointer (&self->opacity_animation, animation);
|
||||
}
|
||||
|
||||
static void
|
||||
animate_position (GcalMonthPopover *self,
|
||||
gdouble x_ratio,
|
||||
gdouble y_ratio)
|
||||
{
|
||||
DzlAnimation *animation;
|
||||
|
||||
if (self->position_animation)
|
||||
dzl_animation_stop (self->position_animation);
|
||||
|
||||
/* Animate the opacity */
|
||||
animation = dzl_object_animate (self,
|
||||
DZL_ANIMATION_EASE_IN_OUT_CUBIC,
|
||||
200,
|
||||
gtk_widget_get_frame_clock (GTK_WIDGET (self)),
|
||||
"x", x_ratio,
|
||||
"y", y_ratio,
|
||||
NULL);
|
||||
dzl_set_weak_pointer (&self->position_animation, animation);
|
||||
}
|
||||
|
||||
static void
|
||||
animate_size (GcalMonthPopover *self,
|
||||
gint target_width,
|
||||
gint target_height)
|
||||
{
|
||||
DzlAnimation *animation;
|
||||
|
||||
if (self->size_animation)
|
||||
dzl_animation_stop (self->size_animation);
|
||||
|
||||
/* Animate the size */
|
||||
animation = dzl_object_animate (self,
|
||||
DZL_ANIMATION_EASE_IN_OUT_CUBIC,
|
||||
200,
|
||||
gtk_widget_get_frame_clock (GTK_WIDGET (self)),
|
||||
"width-request", target_width,
|
||||
"height-request", target_height,
|
||||
NULL);
|
||||
dzl_set_weak_pointer (&self->size_animation, animation);
|
||||
}
|
||||
|
||||
static void
|
||||
update_maximum_height (GcalMonthPopover *self)
|
||||
{
|
||||
GdkWindow *window;
|
||||
gint clip_height;
|
||||
|
||||
clip_height = 3000;
|
||||
window = gtk_widget_get_window (GTK_WIDGET (self->relative_to));
|
||||
|
||||
if (window)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
GdkMonitor *monitor;
|
||||
|
||||
display = gtk_widget_get_display (GTK_WIDGET (self));
|
||||
monitor = gdk_display_get_monitor_at_window (display, window);
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
GdkRectangle workarea;
|
||||
|
||||
gdk_monitor_get_workarea (monitor, &workarea);
|
||||
|
||||
clip_height = workarea.height / 2;
|
||||
}
|
||||
}
|
||||
|
||||
g_object_set (self->scrolled_window,
|
||||
"max-content-height", clip_height,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
update_position (GcalMonthPopover *self)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
GtkWidget *toplevel;
|
||||
GdkWindow *window;
|
||||
gint diff_w;
|
||||
gint diff_h;
|
||||
gint x;
|
||||
gint y;
|
||||
|
||||
if (!gtk_widget_get_realized (GTK_WIDGET (self)))
|
||||
return;
|
||||
|
||||
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->relative_to));
|
||||
window = gtk_widget_get_window (toplevel);
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self->relative_to), &alloc);
|
||||
|
||||
alloc.x = 0;
|
||||
alloc.y = 0;
|
||||
|
||||
gtk_widget_translate_coordinates (GTK_WIDGET (self->relative_to), toplevel, 0, 0, &alloc.x, &alloc.y);
|
||||
|
||||
gdk_window_get_position (window, &x, &y);
|
||||
alloc.x += x;
|
||||
alloc.y += y;
|
||||
|
||||
adjust_margin (self, &alloc);
|
||||
|
||||
diff_w = (RATIO_TO_RELATIVE - 1) * alloc.width * (1.0 - self->x_ratio);
|
||||
diff_h = (RATIO_TO_RELATIVE - 1) * alloc.height * (1.0 - self->y_ratio);
|
||||
|
||||
/* Animate the margins, not the (x, y) position) */
|
||||
gtk_widget_set_margin_top (gtk_bin_get_child (GTK_BIN (self)), diff_h / 2);
|
||||
|
||||
if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
|
||||
gtk_widget_set_margin_end (gtk_bin_get_child (GTK_BIN (self)), diff_w / 2);
|
||||
else
|
||||
gtk_widget_set_margin_start (gtk_bin_get_child (GTK_BIN (self)), diff_w / 2);
|
||||
}
|
||||
|
||||
static void
|
||||
reposition_popover (GcalMonthPopover *self,
|
||||
gboolean animate)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
GtkWidget *toplevel;
|
||||
GdkWindow *window;
|
||||
gint diff_w;
|
||||
gint diff_h;
|
||||
gint x;
|
||||
gint y;
|
||||
|
||||
if (!gtk_widget_get_realized (GTK_WIDGET (self)))
|
||||
return;
|
||||
|
||||
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->relative_to));
|
||||
window = gtk_widget_get_window (toplevel);
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self->relative_to), &alloc);
|
||||
|
||||
alloc.x = 0;
|
||||
alloc.y = 0;
|
||||
|
||||
gtk_widget_translate_coordinates (GTK_WIDGET (self->relative_to), toplevel, 0, 0, &alloc.x, &alloc.y);
|
||||
|
||||
gdk_window_get_position (window, &x, &y);
|
||||
alloc.x += x;
|
||||
alloc.y += y;
|
||||
|
||||
adjust_margin (self, &alloc);
|
||||
update_maximum_height (self);
|
||||
|
||||
diff_w = (RATIO_TO_RELATIVE - 1) * alloc.width;
|
||||
diff_h = (RATIO_TO_RELATIVE - 1) * alloc.height;
|
||||
|
||||
gtk_window_move (GTK_WINDOW (self), alloc.x - diff_w / 2, alloc.y - diff_h / 2);
|
||||
|
||||
alloc.width = MAX (MIN_WIDTH, alloc.width);
|
||||
|
||||
if (animate)
|
||||
{
|
||||
gtk_widget_set_size_request (GTK_WIDGET (self), alloc.width, alloc.height);
|
||||
|
||||
animate_position (self, 1.0, 1.0);
|
||||
animate_size (self, alloc.width * RATIO_TO_RELATIVE, alloc.height * RATIO_TO_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_set_size_request (GTK_WIDGET (self), alloc.width * RATIO_TO_RELATIVE, alloc.height * RATIO_TO_RELATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_event_list (GcalMonthPopover *self)
|
||||
{
|
||||
g_autoptr (GDateTime) start_dt = NULL;
|
||||
g_autoptr (GDateTime) end_dt = NULL;
|
||||
g_autoptr (GPtrArray) events = NULL;
|
||||
GtkWidget *child;
|
||||
guint i;
|
||||
|
||||
gtk_container_foreach (GTK_CONTAINER (self->listbox), (GtkCallback) gtk_widget_destroy, NULL);
|
||||
while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->listbox))) != NULL)
|
||||
gtk_list_box_remove (self->listbox, child);
|
||||
|
||||
if (!gtk_widget_get_realized (GTK_WIDGET (self)) ||
|
||||
!gtk_widget_get_visible (GTK_WIDGET (self)) ||
|
||||
!self->date)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!self->date)
|
||||
return;
|
||||
|
||||
start_dt = g_date_time_new_local (g_date_time_get_year (self->date),
|
||||
g_date_time_get_month (self->date),
|
||||
@@ -324,6 +99,7 @@ update_event_list (GcalMonthPopover *self)
|
||||
g_autoptr (GTimeZone) tz = NULL;
|
||||
GtkWidget *event_widget;
|
||||
GcalEvent *event;
|
||||
GtkWidget *row;
|
||||
|
||||
event = g_ptr_array_index (events, i);
|
||||
|
||||
@@ -344,7 +120,11 @@ update_event_list (GcalMonthPopover *self)
|
||||
gcal_event_widget_set_date_start (GCAL_EVENT_WIDGET (event_widget), event_start);
|
||||
gcal_event_widget_set_date_end (GCAL_EVENT_WIDGET (event_widget), event_end);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (self->listbox), event_widget);
|
||||
row = gtk_list_box_row_new ();
|
||||
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), event_widget);
|
||||
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
|
||||
|
||||
gtk_list_box_append (self->listbox, row);
|
||||
|
||||
g_signal_connect_object (event_widget,
|
||||
"activate",
|
||||
@@ -352,8 +132,40 @@ update_event_list (GcalMonthPopover *self)
|
||||
self,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_show_all (self->listbox);
|
||||
static inline gdouble
|
||||
lerp (gdouble from,
|
||||
gdouble to,
|
||||
gdouble progress)
|
||||
{
|
||||
return from * (1.0 - progress) + to * progress;
|
||||
}
|
||||
|
||||
static GskTransform*
|
||||
create_transform (GcalMonthPopover *self,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
graphene_point_t offset;
|
||||
GskTransform *transform;
|
||||
gdouble progress;
|
||||
gdouble scale;
|
||||
|
||||
progress = adw_animation_get_value (self->animation);
|
||||
|
||||
transform = gsk_transform_new ();
|
||||
|
||||
graphene_point_init (&offset, width / 2.0, height / 2.0);
|
||||
transform = gsk_transform_translate (transform, &offset);
|
||||
|
||||
scale = lerp (0.75, 1.0, progress);
|
||||
transform = gsk_transform_scale (transform, scale, scale);
|
||||
|
||||
graphene_point_init (&offset, -width / 2.0, -height / 2.0);
|
||||
transform = gsk_transform_translate (transform, &offset);
|
||||
|
||||
return g_steal_pointer (&transform);
|
||||
}
|
||||
|
||||
|
||||
@@ -369,8 +181,8 @@ sort_func (GtkListBoxRow *a,
|
||||
GcalEventWidget *event_a;
|
||||
GcalEventWidget *event_b;
|
||||
|
||||
event_a = GCAL_EVENT_WIDGET (gtk_bin_get_child (GTK_BIN (a)));
|
||||
event_b = GCAL_EVENT_WIDGET (gtk_bin_get_child (GTK_BIN (b)));
|
||||
event_a = GCAL_EVENT_WIDGET (gtk_list_box_row_get_child (a));
|
||||
event_b = GCAL_EVENT_WIDGET (gtk_list_box_row_get_child (b));
|
||||
|
||||
return gcal_event_widget_sort_events (event_a, event_b);
|
||||
}
|
||||
@@ -380,6 +192,24 @@ sort_func (GtkListBoxRow *a,
|
||||
* Callbacks
|
||||
*/
|
||||
|
||||
static void
|
||||
animation_cb (gdouble value,
|
||||
gpointer user_data)
|
||||
{
|
||||
GcalMonthPopover *self = GCAL_MONTH_POPOVER (user_data);
|
||||
|
||||
gtk_widget_set_opacity (GTK_WIDGET (self->main_box), value);
|
||||
gtk_widget_queue_allocate (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
on_animation_done_cb (AdwAnimation *animation,
|
||||
GcalMonthPopover *self)
|
||||
{
|
||||
if (adw_animation_get_value (animation) == 0.0)
|
||||
gtk_widget_hide (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
event_activated_cb (GcalEventWidget *event_widget,
|
||||
GcalMonthPopover *self)
|
||||
@@ -397,197 +227,80 @@ static void
|
||||
new_event_button_clicked_cb (GtkWidget *button,
|
||||
GcalMonthPopover *self)
|
||||
{
|
||||
GActionMap *map;
|
||||
GAction *action;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
map = G_ACTION_MAP (g_application_get_default ());
|
||||
action = g_action_map_lookup_action (map, "new");
|
||||
|
||||
gcal_month_popover_popdown (self);
|
||||
|
||||
g_action_activate (action, NULL);
|
||||
gtk_widget_activate_action (GTK_WIDGET (self), "win.new-event", NULL);
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
revealer_notify_child_revealed_cb (GcalMonthPopover *self,
|
||||
GParamSpec *pspec,
|
||||
GtkRevealer *revealer)
|
||||
{
|
||||
if (!gtk_revealer_get_reveal_child (self->revealer))
|
||||
gtk_widget_hide (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
transient_for_configure_event_cb (GcalMonthPopover *self,
|
||||
GdkEvent *event,
|
||||
GtkWindow *toplevel)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (self));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
transient_for_delete_event_cb (GcalMonthPopover *self,
|
||||
GdkEvent *event,
|
||||
GtkWindow *toplevel)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (self));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
transient_for_size_allocate_cb (GcalMonthPopover *self,
|
||||
GtkAllocation *allocation,
|
||||
GtkWindow *toplevel)
|
||||
{
|
||||
reposition_popover (self, FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GtkWidget overrides
|
||||
*/
|
||||
|
||||
static void
|
||||
gcal_month_popover_destroy (GtkWidget *widget)
|
||||
gcal_month_popover_measure (GtkWidget *widget,
|
||||
GtkOrientation orientation,
|
||||
gint for_size,
|
||||
gint *minimum,
|
||||
gint *natural,
|
||||
gint *minimum_baseline,
|
||||
gint *natural_baseline)
|
||||
{
|
||||
GcalMonthPopover *self = (GcalMonthPopover *)widget;
|
||||
GtkWidget *child;
|
||||
|
||||
if (self->transient_for)
|
||||
for (child = gtk_widget_get_first_child (widget);
|
||||
child;
|
||||
child = gtk_widget_get_next_sibling (child))
|
||||
{
|
||||
g_signal_handler_disconnect (self->transient_for, self->size_allocate_handler);
|
||||
g_signal_handler_disconnect (self->transient_for, self->configure_event_handler);
|
||||
g_signal_handler_disconnect (self->transient_for, self->delete_event_handler);
|
||||
gint child_min_baseline = -1;
|
||||
gint child_nat_baseline = -1;
|
||||
gint child_min = 0;
|
||||
gint child_nat = 0;
|
||||
|
||||
self->size_allocate_handler = 0;
|
||||
self->configure_event_handler = 0;
|
||||
self->delete_event_handler = 0;
|
||||
if (!gtk_widget_should_layout (child))
|
||||
continue;
|
||||
|
||||
self->transient_for = NULL;
|
||||
gtk_widget_measure (child,
|
||||
orientation,
|
||||
for_size,
|
||||
&child_min,
|
||||
&child_nat,
|
||||
&child_min_baseline,
|
||||
&child_nat_baseline);
|
||||
|
||||
*minimum = MAX (*minimum, child_min);
|
||||
*natural = MAX (*natural, child_nat);
|
||||
|
||||
if (child_min_baseline > -1)
|
||||
*minimum_baseline = MAX (*minimum_baseline, child_min_baseline);
|
||||
if (child_nat_baseline > -1)
|
||||
*natural_baseline = MAX (*natural_baseline, child_nat_baseline);
|
||||
}
|
||||
|
||||
if (self->opacity_animation)
|
||||
{
|
||||
dzl_animation_stop (self->opacity_animation);
|
||||
dzl_clear_weak_pointer (&self->opacity_animation);
|
||||
}
|
||||
|
||||
if (self->position_animation)
|
||||
{
|
||||
dzl_animation_stop (self->position_animation);
|
||||
dzl_clear_weak_pointer (&self->position_animation);
|
||||
}
|
||||
|
||||
if (self->size_animation)
|
||||
{
|
||||
dzl_animation_stop (self->size_animation);
|
||||
dzl_clear_weak_pointer (&self->size_animation);
|
||||
}
|
||||
|
||||
gcal_month_popover_set_relative_to (self, NULL);
|
||||
|
||||
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->destroy (widget);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_month_popover_focus_out_event (GtkWidget *widget,
|
||||
GdkEventFocus *event_focus)
|
||||
{
|
||||
gcal_month_popover_popdown (GCAL_MONTH_POPOVER (widget));
|
||||
|
||||
return GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->focus_out_event (widget, event_focus);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_popover_hide (GtkWidget *widget)
|
||||
gcal_month_popover_size_allocate (GtkWidget *widget,
|
||||
gint width,
|
||||
gint height,
|
||||
gint baseline)
|
||||
{
|
||||
GcalMonthPopover *self = (GcalMonthPopover *)widget;
|
||||
GcalMonthPopover *self = GCAL_MONTH_POPOVER (widget);
|
||||
g_autoptr (GskTransform) transform = NULL;
|
||||
GtkWidget *child;
|
||||
|
||||
if (self->transient_for)
|
||||
gtk_window_group_remove_window (gtk_window_get_group (self->transient_for), GTK_WINDOW (self));
|
||||
transform = create_transform (self, width, height);
|
||||
|
||||
g_signal_handler_disconnect (self->transient_for, self->delete_event_handler);
|
||||
g_signal_handler_disconnect (self->transient_for, self->size_allocate_handler);
|
||||
g_signal_handler_disconnect (self->transient_for, self->configure_event_handler);
|
||||
|
||||
self->delete_event_handler = 0;
|
||||
self->size_allocate_handler = 0;
|
||||
self->configure_event_handler = 0;
|
||||
|
||||
self->transient_for = NULL;
|
||||
|
||||
gcal_month_popover_popdown (self);
|
||||
|
||||
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->hide (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_popover_show (GtkWidget *widget)
|
||||
{
|
||||
GcalMonthPopover *self = (GcalMonthPopover *)widget;
|
||||
|
||||
if (self->relative_to)
|
||||
for (child = gtk_widget_get_first_child (widget);
|
||||
child;
|
||||
child = gtk_widget_get_next_sibling (child))
|
||||
{
|
||||
GtkWidget *toplevel;
|
||||
if (!gtk_widget_should_layout (child))
|
||||
continue;
|
||||
|
||||
toplevel = gtk_widget_get_ancestor (GTK_WIDGET (self->relative_to), GTK_TYPE_WINDOW);
|
||||
|
||||
if (GTK_IS_WINDOW (toplevel))
|
||||
{
|
||||
self->transient_for = GTK_WINDOW (toplevel);
|
||||
|
||||
gtk_window_group_add_window (gtk_window_get_group (self->transient_for), GTK_WINDOW (self));
|
||||
|
||||
self->delete_event_handler =
|
||||
g_signal_connect_object (toplevel,
|
||||
"delete-event",
|
||||
G_CALLBACK (transient_for_delete_event_cb),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
self->size_allocate_handler =
|
||||
g_signal_connect_object (toplevel,
|
||||
"size-allocate",
|
||||
G_CALLBACK (transient_for_size_allocate_cb),
|
||||
self,
|
||||
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
|
||||
|
||||
self->configure_event_handler =
|
||||
g_signal_connect_object (toplevel,
|
||||
"configure-event",
|
||||
G_CALLBACK (transient_for_configure_event_cb),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (self), self->transient_for);
|
||||
|
||||
reposition_popover (self, FALSE);
|
||||
}
|
||||
gtk_widget_allocate (child, width, height, baseline, gsk_transform_ref (transform));
|
||||
}
|
||||
|
||||
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->show (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_popover_realize (GtkWidget *widget)
|
||||
{
|
||||
GcalMonthPopover *self = (GcalMonthPopover *)widget;
|
||||
GdkScreen *screen;
|
||||
GdkVisual *visual;
|
||||
|
||||
screen = gtk_widget_get_screen (widget);
|
||||
visual = gdk_screen_get_rgba_visual (screen);
|
||||
|
||||
if (visual)
|
||||
gtk_widget_set_visual (widget, visual);
|
||||
|
||||
GTK_WIDGET_CLASS (gcal_month_popover_parent_class)->realize (widget);
|
||||
|
||||
reposition_popover (self, TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -609,18 +322,6 @@ gcal_month_popover_get_property (GObject *object,
|
||||
g_value_set_object (value, self->context);
|
||||
break;
|
||||
|
||||
case PROP_RELATIVE_TO:
|
||||
g_value_set_object (value, self->relative_to);
|
||||
break;
|
||||
|
||||
case PROP_X:
|
||||
g_value_set_double (value, self->x_ratio);
|
||||
break;
|
||||
|
||||
case PROP_Y:
|
||||
g_value_set_double (value, self->y_ratio);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
@@ -640,40 +341,33 @@ gcal_month_popover_set_property (GObject *object,
|
||||
self->context = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_RELATIVE_TO:
|
||||
gcal_month_popover_set_relative_to (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_X:
|
||||
self->x_ratio = g_value_get_double (value);
|
||||
update_position (self);
|
||||
break;
|
||||
|
||||
|
||||
case PROP_Y:
|
||||
self->y_ratio = g_value_get_double (value);
|
||||
update_position (self);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_popover_dispose (GObject *object)
|
||||
{
|
||||
GcalMonthPopover *self = (GcalMonthPopover *)object;
|
||||
|
||||
g_clear_pointer (&self->main_box, gtk_widget_unparent);
|
||||
|
||||
G_OBJECT_CLASS (gcal_month_popover_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_popover_class_init (GcalMonthPopoverClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->dispose = gcal_month_popover_dispose;
|
||||
object_class->get_property = gcal_month_popover_get_property;
|
||||
object_class->set_property = gcal_month_popover_set_property;
|
||||
|
||||
widget_class->destroy = gcal_month_popover_destroy;
|
||||
widget_class->focus_out_event = gcal_month_popover_focus_out_event;
|
||||
widget_class->hide = gcal_month_popover_hide;
|
||||
widget_class->show = gcal_month_popover_show;
|
||||
widget_class->realize = gcal_month_popover_realize;
|
||||
widget_class->measure = gcal_month_popover_measure;
|
||||
widget_class->size_allocate = gcal_month_popover_size_allocate;
|
||||
|
||||
properties [PROP_CONTEXT] = g_param_spec_object ("context",
|
||||
"Context",
|
||||
@@ -681,28 +375,6 @@ gcal_month_popover_class_init (GcalMonthPopoverClass *klass)
|
||||
GCAL_TYPE_CONTEXT,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties [PROP_RELATIVE_TO] = g_param_spec_object ("relative-to",
|
||||
"Relative To",
|
||||
"The widget to be relative to",
|
||||
GTK_TYPE_WIDGET,
|
||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_X] = g_param_spec_double ("x",
|
||||
"X Percent position",
|
||||
"X Percent position",
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_Y] = g_param_spec_double ("y",
|
||||
"Y Percent position",
|
||||
"Y Percent position",
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
|
||||
signals[EVENT_ACTIVATED] = g_signal_new ("event-activated",
|
||||
@@ -720,8 +392,7 @@ gcal_month_popover_class_init (GcalMonthPopoverClass *klass)
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, day_label);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, listbox);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, revealer);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, scrolled_window);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalMonthPopover, main_box);
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, "monthpopover");
|
||||
}
|
||||
@@ -731,133 +402,52 @@ gcal_month_popover_init (GcalMonthPopover *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
gtk_window_set_type_hint (GTK_WINDOW (self), GDK_WINDOW_TYPE_HINT_COMBO);
|
||||
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
|
||||
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
|
||||
gtk_window_set_skip_pager_hint (GTK_WINDOW (self), TRUE);
|
||||
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (self), TRUE);
|
||||
|
||||
g_signal_connect_object (self->revealer,
|
||||
"notify::child-revealed",
|
||||
G_CALLBACK (revealer_notify_child_revealed_cb),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
gtk_list_box_set_sort_func (GTK_LIST_BOX (self->listbox), sort_func, NULL, NULL);
|
||||
|
||||
self->animation = adw_timed_animation_new (GTK_WIDGET (self),
|
||||
0.0,
|
||||
1.0,
|
||||
250,
|
||||
adw_callback_animation_target_new (animation_cb, self, NULL));
|
||||
g_signal_connect (self->animation, "done", G_CALLBACK (on_animation_done_cb), self);
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gcal_month_popover_new (void)
|
||||
{
|
||||
return g_object_new (GCAL_TYPE_MONTH_POPOVER,
|
||||
"type", GTK_WINDOW_POPUP,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gcal_month_popover_set_relative_to (GcalMonthPopover *self,
|
||||
GtkWidget *relative_to)
|
||||
{
|
||||
g_return_if_fail (GCAL_MONTH_POPOVER (self));
|
||||
g_return_if_fail (!relative_to || GTK_IS_WIDGET (relative_to));
|
||||
|
||||
if (self->relative_to == relative_to)
|
||||
return;
|
||||
|
||||
if (self->relative_to)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (self->relative_to, gtk_widget_destroyed, &self->relative_to);
|
||||
self->relative_to = NULL;
|
||||
}
|
||||
|
||||
if (relative_to)
|
||||
{
|
||||
self->relative_to = relative_to;
|
||||
g_signal_connect (self->relative_to,
|
||||
"destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed),
|
||||
&self->relative_to);
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RELATIVE_TO]);
|
||||
return g_object_new (GCAL_TYPE_MONTH_POPOVER, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gcal_month_popover_popup (GcalMonthPopover *self)
|
||||
{
|
||||
gint duration = 250;
|
||||
|
||||
g_return_if_fail (GCAL_IS_MONTH_POPOVER (self));
|
||||
|
||||
if (self->relative_to)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
GdkDisplay *display;
|
||||
GdkMonitor *monitor;
|
||||
GdkWindow *window;
|
||||
gint min_height;
|
||||
gint nat_height;
|
||||
|
||||
display = gtk_widget_get_display (GTK_WIDGET (self->relative_to));
|
||||
window = gtk_widget_get_window (GTK_WIDGET (self->relative_to));
|
||||
monitor = gdk_display_get_monitor_at_window (display, window);
|
||||
|
||||
gtk_widget_get_preferred_height (GTK_WIDGET (self), &min_height, &nat_height);
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
|
||||
duration = dzl_animation_calculate_duration (monitor, alloc.height, nat_height);
|
||||
}
|
||||
GCAL_ENTRY;
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (self));
|
||||
|
||||
gtk_revealer_set_transition_duration (self->revealer, duration);
|
||||
gtk_revealer_set_reveal_child (self->revealer, TRUE);
|
||||
adw_timed_animation_set_reverse (ADW_TIMED_ANIMATION (self->animation), FALSE);
|
||||
adw_timed_animation_set_easing (ADW_TIMED_ANIMATION (self->animation), ADW_EASE_OUT_EXPO);
|
||||
adw_animation_play (self->animation);
|
||||
|
||||
update_event_list (self);
|
||||
|
||||
gtk_widget_grab_focus (GTK_WIDGET (self));
|
||||
|
||||
/* Animations */
|
||||
animate_opacity (self, 1.0);
|
||||
reposition_popover (self, TRUE);
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_month_popover_popdown (GcalMonthPopover *self)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
GdkDisplay *display;
|
||||
GdkMonitor *monitor;
|
||||
GdkWindow *window;
|
||||
guint duration;
|
||||
|
||||
g_return_if_fail (GCAL_IS_MONTH_POPOVER (self));
|
||||
|
||||
if (!gtk_widget_get_realized (GTK_WIDGET (self)))
|
||||
return;
|
||||
GCAL_ENTRY;
|
||||
|
||||
display = gtk_widget_get_display (GTK_WIDGET (self->relative_to));
|
||||
window = gtk_widget_get_window (GTK_WIDGET (self->relative_to));
|
||||
monitor = gdk_display_get_monitor_at_window (display, window);
|
||||
adw_timed_animation_set_reverse (ADW_TIMED_ANIMATION (self->animation), TRUE);
|
||||
adw_timed_animation_set_easing (ADW_TIMED_ANIMATION (self->animation), ADW_EASE_IN_EXPO);
|
||||
adw_animation_play (self->animation);
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
|
||||
duration = dzl_animation_calculate_duration (monitor, alloc.height, 0);
|
||||
|
||||
gtk_revealer_set_transition_duration (self->revealer, duration);
|
||||
gtk_revealer_set_reveal_child (self->revealer, FALSE);
|
||||
|
||||
/* Animations */
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self->relative_to), &alloc);
|
||||
gtk_widget_translate_coordinates (self->relative_to,
|
||||
gtk_widget_get_toplevel (self->relative_to), 0, 0, &alloc.x, &alloc.y);
|
||||
adjust_margin (self, &alloc);
|
||||
|
||||
alloc.width = MAX (MIN_WIDTH, alloc.width);
|
||||
|
||||
animate_opacity (self, 0.0);
|
||||
animate_position (self, 0.0, 0.0);
|
||||
animate_size (self, alloc.width, alloc.height);
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
GDateTime*
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GCAL_MONTH_POPOVER_H
|
||||
#define GCAL_MONTH_POPOVER_H
|
||||
#pragma once
|
||||
|
||||
#include "gcal-manager.h"
|
||||
|
||||
@@ -26,8 +25,7 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_MONTH_POPOVER (gcal_month_popover_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalMonthPopover, gcal_month_popover, GCAL, MONTH_POPOVER, GtkWindow)
|
||||
G_DECLARE_FINAL_TYPE (GcalMonthPopover, gcal_month_popover, GCAL, MONTH_POPOVER, GtkWidget)
|
||||
|
||||
GtkWidget* gcal_month_popover_new (void);
|
||||
|
||||
@@ -45,6 +43,3 @@ void gcal_month_popover_set_date (GcalMonthPopov
|
||||
GDateTime *date);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* GCAL_MONTH_POPOVER_H */
|
||||
|
||||
|
||||
@@ -1,95 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GcalMonthPopover" parent="GtkWindow">
|
||||
<property name="modal">false</property>
|
||||
<property name="opacity">0.0</property>
|
||||
<property name="destroy-with-parent">true</property>
|
||||
<template class="GcalMonthPopover" parent="GtkWidget">
|
||||
<property name="visible">False</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">true</property>
|
||||
<object class="GtkBox" id="main_box">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">12</property>
|
||||
<style>
|
||||
<class name="card" />
|
||||
<class name="view" />
|
||||
</style>
|
||||
|
||||
<!-- Day label & close button-->
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">true</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="day_label">
|
||||
<property name="visible">true</property>
|
||||
<property name="label">12</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<property name="hexpand">true</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="2.25" />
|
||||
</attributes>
|
||||
<style>
|
||||
<class name="large-title" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="visible">true</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="icon-name">window-close-symbolic</property>
|
||||
<signal name="clicked" handler="close_button_clicked_cb" object="GcalMonthPopover" swapped="yes" />
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">true</property>
|
||||
<property name="icon-name">window-close-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
<class name="circular" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Event list revealer -->
|
||||
<!-- Event list -->
|
||||
<child>
|
||||
<object class="GtkRevealer" id="revealer">
|
||||
<property name="reveal-child">false</property>
|
||||
<property name="transition-duration">200</property>
|
||||
<property name="transition-type">slide-down</property>
|
||||
<property name="visible">true</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="top_box">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="visible">true</property>
|
||||
<child>
|
||||
<object class="DzlElasticBin" id="elastic">
|
||||
<property name="visible">true</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolled_window">
|
||||
<property name="hscrollbar-policy">never</property>
|
||||
<property name="propagate-natural-height">true</property>
|
||||
<property name="visible">true</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="listbox">
|
||||
<property name="visible">true</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<style>
|
||||
<class name="background" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<object class="GtkListBox" id="listbox">
|
||||
<property name="vexpand">True</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<style>
|
||||
<class name="calendar-list" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- New Event button -->
|
||||
<child>
|
||||
<object class="GtkButton" id="new_event_button">
|
||||
<property name="visible">true</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="label" translatable="yes">New Event…</property>
|
||||
<signal name="clicked" handler="new_event_button_clicked_cb" object="GcalMonthPopover" swapped="no" />
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
+702
-772
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_MONTH_VIEW (gcal_month_view_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalMonthView, gcal_month_view, GCAL, MONTH_VIEW, GtkContainer)
|
||||
G_DECLARE_FINAL_TYPE (GcalMonthView, gcal_month_view, GCAL, MONTH_VIEW, GtkWidget)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -1,20 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GcalMonthView" parent="GtkContainer">
|
||||
<template class="GcalMonthView" parent="GtkWidget">
|
||||
|
||||
<child>
|
||||
<object class="GtkGestureClick">
|
||||
<property name="button">1</property>
|
||||
<signal name="pressed" handler="on_click_gesture_pressed_cb" object="GcalMonthView" swapped="no" />
|
||||
<signal name="released" handler="on_click_gesture_released_cb" object="GcalMonthView" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEventControllerMotion" id="motion_controller">
|
||||
<property name="propagation-phase">none</property>
|
||||
<signal name="motion" handler="on_motion_controller_motion_cb" object="GcalMonthView" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEventControllerKey">
|
||||
<signal name="key-pressed" handler="on_key_controller_key_pressed_cb" object="GcalMonthView" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEventControllerScroll">
|
||||
<property name="flags">vertical</property>
|
||||
<signal name="scroll" handler="on_scroll_controller_scrolled_cb" object="GcalMonthView" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Header -->
|
||||
<child type="header">
|
||||
<object class="GtkBox">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">true</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="month_label">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -24,8 +47,6 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="year_label">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">1.0</property>
|
||||
<style>
|
||||
@@ -38,15 +59,12 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">true</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin-end">6</property>
|
||||
<property name="margin-bottom">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_0">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -57,8 +75,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_1">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -69,8 +85,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_2">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -81,8 +95,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_3">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -93,8 +105,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_4">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -105,8 +115,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_5">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -117,8 +125,6 @@
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_6">
|
||||
<property name="visible">true</property>
|
||||
<property name="can_focus">false</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<style>
|
||||
@@ -135,8 +141,6 @@
|
||||
<!-- Grid -->
|
||||
<child type="grid">
|
||||
<object class="GtkGrid" id="grid">
|
||||
<property name="visible">true</property>
|
||||
<property name="can-focus">false</property>
|
||||
<property name="row-homogeneous">true</property>
|
||||
<property name="column-homogeneous">true</property>
|
||||
</object>
|
||||
|
||||
@@ -40,7 +40,7 @@ gcal_view_default_init (GcalViewInterface *iface)
|
||||
g_object_interface_install_property (iface,
|
||||
g_param_spec_boxed ("active-date",
|
||||
"The active date",
|
||||
"The active/selecetd date in the view",
|
||||
"The active/selected date in the view",
|
||||
G_TYPE_DATE_TIME,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ label.secondary-label {
|
||||
}
|
||||
|
||||
calendar-view {
|
||||
padding: 6px;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
@@ -429,7 +428,6 @@ monthcell {
|
||||
border: solid 1px alpha(@borders, 0.3);
|
||||
border-width: 1px 0 0 1px;
|
||||
background: transparent;
|
||||
padding: 1px 3px 0 3px;
|
||||
transition: background-color 200ms;
|
||||
}
|
||||
|
||||
@@ -474,14 +472,10 @@ monthcell button {
|
||||
* Month popover
|
||||
*/
|
||||
|
||||
monthpopover { background: transparent; }
|
||||
|
||||
monthpopover > box {
|
||||
margin: 4px;
|
||||
border: 1px solid @borders;
|
||||
box-shadow: 0px 0px 2px @wm_shadow;
|
||||
padding: 12px;
|
||||
background: @theme_bg_color;
|
||||
background-color: @popover_bg_color;
|
||||
}
|
||||
|
||||
.notes-section box > textview {
|
||||
|
||||
@@ -877,7 +877,7 @@ get_alarm_trigger_minutes (GcalEvent *event,
|
||||
/**
|
||||
* should_change_date_for_scroll:
|
||||
* @scroll_value: the current scroll value
|
||||
* @scroll_event: the #GdkEventScroll that is being parsed
|
||||
* @scroll_event: the #GdkEvent that is being parsed
|
||||
*
|
||||
* Utility function to check if the date should change based
|
||||
* on the scroll. The date is changed when the user scrolls
|
||||
@@ -887,12 +887,14 @@ get_alarm_trigger_minutes (GcalEvent *event,
|
||||
* Returns: %TRUE if the date should change, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
should_change_date_for_scroll (gdouble *scroll_value,
|
||||
GdkEventScroll *scroll_event)
|
||||
should_change_date_for_scroll (gdouble *scroll_value,
|
||||
GdkEvent *scroll_event)
|
||||
{
|
||||
gdouble delta_y;
|
||||
gdouble dx, dy;
|
||||
|
||||
switch (scroll_event->direction)
|
||||
g_return_val_if_fail (gdk_event_get_event_type (scroll_event) == GDK_SCROLL, FALSE);
|
||||
|
||||
switch (gdk_scroll_event_get_direction (scroll_event))
|
||||
{
|
||||
case GDK_SCROLL_DOWN:
|
||||
*scroll_value = SCROLL_HARDNESS;
|
||||
@@ -903,8 +905,8 @@ should_change_date_for_scroll (gdouble *scroll_value,
|
||||
break;
|
||||
|
||||
case GDK_SCROLL_SMOOTH:
|
||||
gdk_event_get_scroll_deltas ((GdkEvent*) scroll_event, NULL, &delta_y);
|
||||
*scroll_value += delta_y;
|
||||
gdk_scroll_event_get_deltas (scroll_event, &dx, &dy);
|
||||
*scroll_value += dy;
|
||||
break;
|
||||
|
||||
/* Ignore horizontal scrolling for now */
|
||||
|
||||
@@ -106,7 +106,7 @@ gint get_alarm_trigger_minutes (GcalEvent
|
||||
ECalComponentAlarm *alarm);
|
||||
|
||||
gboolean should_change_date_for_scroll (gdouble *scroll_value,
|
||||
GdkEventScroll *scroll_event);
|
||||
GdkEvent *scroll_event);
|
||||
|
||||
gboolean is_source_enabled (ESource *source);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user