[gtk+] dnd: Add gdk_drag_context_get_display()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] dnd: Add gdk_drag_context_get_display()
- Date: Sun, 10 Dec 2017 00:59:45 +0000 (UTC)
commit 0d31eb8670e6a2fad43b6edf816f60a4fc8ace49
Author: Benjamin Otte <otte redhat com>
Date: Tue Dec 5 17:30:58 2017 +0100
dnd: Add gdk_drag_context_get_display()
Also turn it into a readable, construct-only property.
Every GDK object should have this. (Apart from GdkDisplay, obviously.)
docs/reference/gdk/gdk4-sections.txt | 1 +
gdk/broadway/gdkdnd-broadway.c | 2 +-
gdk/gdkdnd.c | 83 ++++++++++++++++++++++++++++++++++
gdk/gdkdnd.h | 2 +
gdk/quartz/gdkdnd-quartz.c | 2 +-
gdk/wayland/gdkdnd-wayland.c | 10 +++--
gdk/win32/gdkdnd-win32.c | 5 +-
gdk/x11/gdkdnd-x11.c | 23 +++-------
8 files changed, 103 insertions(+), 25 deletions(-)
---
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 63b09bb..d167c2b 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -860,6 +860,7 @@ GdkDragAction
gdk_drag_status
gdk_drag_drop_succeeded
+gdk_drag_context_get_display
gdk_drag_context_get_actions
gdk_drag_context_get_suggested_action
gdk_drag_context_get_selected_action
diff --git a/gdk/broadway/gdkdnd-broadway.c b/gdk/broadway/gdkdnd-broadway.c
index 264da5e..cbc1860 100644
--- a/gdk/broadway/gdkdnd-broadway.c
+++ b/gdk/broadway/gdkdnd-broadway.c
@@ -96,8 +96,8 @@ _gdk_broadway_window_drag_begin (GdkWindow *window,
g_return_val_if_fail (GDK_WINDOW_IS_BROADWAY (window), NULL);
new_context = g_object_new (GDK_TYPE_BROADWAY_DRAG_CONTEXT,
+ "display", gdk_window_get_display (window),
NULL);
- new_context->display = gdk_window_get_display (window);
return new_context;
}
diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c
index 5bf0ab3..ead7bdf 100644
--- a/gdk/gdkdnd.c
+++ b/gdk/gdkdnd.c
@@ -47,6 +47,12 @@ static struct {
};
enum {
+ PROP_0,
+ PROP_DISPLAY,
+ N_PROPERTIES
+};
+
+enum {
CANCEL,
DROP_PERFORMED,
DND_FINISHED,
@@ -54,6 +60,7 @@ enum {
N_SIGNALS
};
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
static guint signals[N_SIGNALS] = { 0 };
static GList *contexts = NULL;
@@ -74,6 +81,20 @@ static GList *contexts = NULL;
*/
/**
+ * gdk_drag_context_get_display:
+ * @context: a #GdkDragContext
+ *
+ * Gets the #GdkDisplay that the drag context was created for.
+ *
+ * Returns: (transfer none): a #GdkDisplay
+ **/
+GdkDisplay *
+gdk_drag_context_get_display (GdkDragContext *context)
+{
+ return context->display;
+}
+
+/**
* gdk_drag_context_get_formats:
* @context: a #GdkDragContext
*
@@ -231,6 +252,47 @@ gdk_drag_context_init (GdkDragContext *context)
}
static void
+gdk_drag_context_set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDragContext *context = GDK_DRAG_CONTEXT (gobject);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ context->display = g_value_get_object (value);
+ g_assert (context->display != NULL);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_drag_context_get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDragContext *context = GDK_DRAG_CONTEXT (gobject);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ g_value_set_object (value, context->display);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
gdk_drag_context_finalize (GObject *object)
{
GdkDragContext *context = GDK_DRAG_CONTEXT (object);
@@ -252,9 +314,28 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->get_property = gdk_drag_context_get_property;
+ object_class->set_property = gdk_drag_context_set_property;
object_class->finalize = gdk_drag_context_finalize;
/**
+ * GdkDragContext:display:
+ *
+ * The #GdkDisplay that the drag context belongs to.
+ *
+ * Since: 3.94
+ */
+ properties[PROP_DISPLAY] =
+ g_param_spec_object ("display",
+ "Display",
+ "Display owning this clipboard",
+ GDK_TYPE_DISPLAY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
* GdkDragContext::cancel:
* @context: The object on which the signal is emitted
* @reason: The reason the context was cancelled
@@ -342,6 +423,8 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__FLAGS,
G_TYPE_NONE, 1, GDK_TYPE_DRAG_ACTION);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
/*
diff --git a/gdk/gdkdnd.h b/gdk/gdkdnd.h
index d7eac34..85f8fa0 100644
--- a/gdk/gdkdnd.h
+++ b/gdk/gdkdnd.h
@@ -83,6 +83,8 @@ typedef enum {
GDK_AVAILABLE_IN_ALL
GType gdk_drag_context_get_type (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_94
+GdkDisplay * gdk_drag_context_get_display (GdkDragContext *context);
GDK_AVAILABLE_IN_ALL
void gdk_drag_context_set_device (GdkDragContext *context,
GdkDevice *device);
diff --git a/gdk/quartz/gdkdnd-quartz.c b/gdk/quartz/gdkdnd-quartz.c
index ee18704..fc9c338 100644
--- a/gdk/quartz/gdkdnd-quartz.c
+++ b/gdk/quartz/gdkdnd-quartz.c
@@ -43,8 +43,8 @@ _gdk_quartz_window_drag_begin (GdkWindow *window,
/* Create fake context */
_gdk_quartz_drag_source_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT,
+ "display", display,
NULL);
- _gdk_quartz_drag_source_context->display = gdk_window_get_display (window);
_gdk_quartz_drag_source_context->is_source = TRUE;
_gdk_quartz_drag_source_context->source_window = window;
diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c
index c676f25..a7281b8 100644
--- a/gdk/wayland/gdkdnd-wayland.c
+++ b/gdk/wayland/gdkdnd-wayland.c
@@ -513,9 +513,10 @@ _gdk_wayland_window_drag_begin (GdkWindow *window,
const char *const *mimetypes;
gsize i, n_mimetypes;
- context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
+ context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
+ "display", gdk_window_get_display (window),
+ NULL);
context = GDK_DRAG_CONTEXT (context_wayland);
- context->display = gdk_window_get_display (window);
context->source_window = g_object_ref (window);
context->is_source = TRUE;
context->formats = gdk_content_formats_ref (formats);
@@ -544,9 +545,10 @@ _gdk_wayland_drop_context_new (GdkDisplay *display,
GdkWaylandDragContext *context_wayland;
GdkDragContext *context;
- context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
+ context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
+ "display", display,
+ NULL);
context = GDK_DRAG_CONTEXT (context_wayland);
- context->display = display;
context->is_source = FALSE;
context->formats = gdk_content_formats_new (NULL, 0);
diff --git a/gdk/win32/gdkdnd-win32.c b/gdk/win32/gdkdnd-win32.c
index ea4deb0..fbf5af6 100644
--- a/gdk/win32/gdkdnd-win32.c
+++ b/gdk/win32/gdkdnd-win32.c
@@ -238,9 +238,10 @@ gdk_drag_context_new (GdkDisplay *display)
GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
GdkDragContext *context;
- context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT, NULL);
+ context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT,
+ "display", display,
+ NULL);
context = GDK_DRAG_CONTEXT(context_win32);
- context->display = display;
gdk_drag_context_set_device (context, gdk_seat_get_pointer (gdk_display_get_default_seat (display)));
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index 5b3947e..85a98c5 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -1134,19 +1134,6 @@ send_client_message_async_cb (Window window,
g_object_unref (context);
}
-
-static GdkDisplay *
-gdk_drag_context_get_display (GdkDragContext *context)
-{
- if (context->source_window)
- return GDK_WINDOW_DISPLAY (context->source_window);
- else if (context->dest_window)
- return GDK_WINDOW_DISPLAY (context->dest_window);
-
- g_assert_not_reached ();
- return NULL;
-}
-
static void
send_client_message_async (GdkDragContext *context,
Window window,
@@ -1672,10 +1659,11 @@ xdnd_enter_filter (GdkXEvent *xev,
display_x11->current_dest_drag = NULL;
}
- context_x11 = (GdkX11DragContext *)g_object_new (GDK_TYPE_X11_DRAG_CONTEXT, NULL);
+ context_x11 = g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
+ "display", display,
+ NULL);
context = (GdkDragContext *)context_x11;
- context->display = display;
context->protocol = GDK_DRAG_PROTO_XDND;
context_x11->version = version;
@@ -1984,9 +1972,10 @@ _gdk_x11_window_drag_begin (GdkWindow *window,
{
GdkDragContext *context;
- context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT, NULL);
+ context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
+ "display", gdk_window_get_display (window),
+ NULL);
- context->display = gdk_window_get_display (window);
context->is_source = TRUE;
context->source_window = window;
g_object_ref (window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]