[gnome-calendar/wip/pandusonu/week-view] event-widget: properly draw dnd icon
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/pandusonu/week-view] event-widget: properly draw dnd icon
- Date: Tue, 17 Jan 2017 13:25:10 +0000 (UTC)
commit 4974e03216f24cea0edfd24a7faa593670923dda
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Jan 17 11:04:18 2017 -0200
event-widget: properly draw dnd icon
Instead of using a pixbuf and relying on the underlying GdkWindow,
simply perform a custom draw() over a manually created cairo context
and avoid nasty crashes.
src/gcal-event-widget.c | 35 +++++++++++++++++++++++------------
1 files changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index bf193b3..e4d6309 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -40,9 +40,6 @@ struct _GcalEventWidget
GcalEvent *event;
- /* Drag n' Drop icon */
- GdkPixbuf *dnd_pixbuf;
-
GtkOrientation orientation;
GdkWindow *event_window;
@@ -290,7 +287,6 @@ gcal_event_widget_finalize (GObject *object)
/* releasing properties */
g_clear_pointer (&self->css_class, g_free);
- g_clear_object (&self->dnd_pixbuf);
g_clear_object (&self->event);
G_OBJECT_CLASS (gcal_event_widget_parent_class)->finalize (object);
@@ -678,13 +674,30 @@ gcal_event_widget_button_release_event (GtkWidget *widget,
return FALSE;
}
+static cairo_surface_t*
+get_dnd_icon (GtkWidget *widget)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ /* Make it transparent */
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ cr = cairo_create (surface);
+
+ gtk_widget_draw (widget, cr);
+
+ return surface;
+}
+
static void
gcal_event_widget_drag_begin (GtkWidget *widget,
GdkDragContext *context)
{
GcalEventWidget *self = GCAL_EVENT_WIDGET (widget);
-
- g_clear_object (&self->dnd_pixbuf);
+ cairo_surface_t *surface;
if (self->read_only)
{
@@ -693,13 +706,11 @@ gcal_event_widget_drag_begin (GtkWidget *widget,
}
/* Setup the drag n' drop icon */
- self->dnd_pixbuf = gdk_pixbuf_get_from_window (self->event_window,
- 0,
- 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
+ surface = get_dnd_icon (widget);
+
+ gtk_drag_set_icon_surface (context, surface);
- gtk_drag_set_icon_pixbuf (context, self->dnd_pixbuf, 0, 0);
+ g_clear_pointer (&surface, cairo_surface_destroy);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]