2010-12-18 20:38:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-18 20:38:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkdndprivate.h"
|
|
|
|
|
|
|
|
#include "gdkinternals.h"
|
|
|
|
#include "gdkproperty.h"
|
|
|
|
#include "gdkprivate-wayland.h"
|
2017-11-20 03:42:43 +00:00
|
|
|
#include "gdkcontentformats.h"
|
2010-12-18 20:38:49 +00:00
|
|
|
#include "gdkdisplay-wayland.h"
|
2017-12-10 00:05:37 +00:00
|
|
|
#include "gdkintl.h"
|
2016-01-13 20:00:34 +00:00
|
|
|
#include "gdkseat-wayland.h"
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2015-11-19 19:26:11 +00:00
|
|
|
#include "gdkdeviceprivate.h"
|
|
|
|
|
2017-12-10 00:05:37 +00:00
|
|
|
#include <glib-unix.h>
|
|
|
|
#include <gio/gunixinputstream.h>
|
|
|
|
#include <gio/gunixoutputstream.h>
|
2010-12-18 20:38:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define GDK_TYPE_WAYLAND_DRAG_CONTEXT (gdk_wayland_drag_context_get_type ())
|
|
|
|
#define GDK_WAYLAND_DRAG_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_DRAG_CONTEXT, GdkWaylandDragContext))
|
|
|
|
#define GDK_WAYLAND_DRAG_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WAYLAND_DRAG_CONTEXT, GdkWaylandDragContextClass))
|
|
|
|
#define GDK_IS_WAYLAND_DRAG_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WAYLAND_DRAG_CONTEXT))
|
|
|
|
#define GDK_IS_WAYLAND_DRAG_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WAYLAND_DRAG_CONTEXT))
|
|
|
|
#define GDK_WAYLAND_DRAG_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WAYLAND_DRAG_CONTEXT, GdkWaylandDragContextClass))
|
|
|
|
|
|
|
|
typedef struct _GdkWaylandDragContext GdkWaylandDragContext;
|
|
|
|
typedef struct _GdkWaylandDragContextClass GdkWaylandDragContextClass;
|
|
|
|
|
|
|
|
struct _GdkWaylandDragContext
|
|
|
|
{
|
|
|
|
GdkDragContext context;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *dnd_surface;
|
|
|
|
struct wl_surface *dnd_wl_surface;
|
2014-08-21 19:30:22 +00:00
|
|
|
struct wl_data_source *data_source;
|
2018-05-06 00:06:53 +00:00
|
|
|
struct wl_data_offer *offer;
|
2016-01-13 20:00:34 +00:00
|
|
|
GdkDragAction selected_action;
|
2014-08-21 18:20:37 +00:00
|
|
|
uint32_t serial;
|
2015-12-08 02:53:38 +00:00
|
|
|
gint hot_x;
|
|
|
|
gint hot_y;
|
2010-12-18 20:38:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GdkWaylandDragContextClass
|
|
|
|
{
|
|
|
|
GdkDragContextClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GList *contexts;
|
|
|
|
|
2014-09-06 00:41:06 +00:00
|
|
|
GType gdk_wayland_drag_context_get_type (void);
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
G_DEFINE_TYPE (GdkWaylandDragContext, gdk_wayland_drag_context, GDK_TYPE_DRAG_CONTEXT)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_finalize (GObject *object)
|
|
|
|
{
|
2014-08-21 18:20:37 +00:00
|
|
|
GdkWaylandDragContext *wayland_context = GDK_WAYLAND_DRAG_CONTEXT (object);
|
2010-12-18 20:38:49 +00:00
|
|
|
GdkDragContext *context = GDK_DRAG_CONTEXT (object);
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *dnd_surface;
|
2010-12-18 20:38:49 +00:00
|
|
|
|
|
|
|
contexts = g_list_remove (contexts, context);
|
|
|
|
|
2015-08-03 06:26:39 +00:00
|
|
|
if (context->is_source)
|
|
|
|
{
|
2016-01-13 20:00:34 +00:00
|
|
|
gdk_drag_context_set_cursor (context, NULL);
|
2015-08-03 06:26:39 +00:00
|
|
|
}
|
2014-08-21 19:30:22 +00:00
|
|
|
|
2018-05-06 15:06:57 +00:00
|
|
|
g_clear_pointer (&wayland_context->data_source, (GDestroyNotify) wl_data_source_destroy);
|
|
|
|
g_clear_pointer (&wayland_context->offer, (GDestroyNotify) wl_data_offer_destroy);
|
2014-08-21 18:20:37 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
dnd_surface = wayland_context->dnd_surface;
|
2014-08-21 18:20:37 +00:00
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
G_OBJECT_CLASS (gdk_wayland_drag_context_parent_class)->finalize (object);
|
2016-01-08 16:22:47 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (dnd_surface)
|
|
|
|
gdk_surface_destroy (dnd_surface);
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 20:00:34 +00:00
|
|
|
static inline uint32_t
|
|
|
|
gdk_to_wl_actions (GdkDragAction action)
|
|
|
|
{
|
|
|
|
uint32_t dnd_actions = 0;
|
|
|
|
|
2018-05-08 11:56:08 +00:00
|
|
|
if (action & (GDK_ACTION_COPY | GDK_ACTION_LINK))
|
2016-01-13 20:00:34 +00:00
|
|
|
dnd_actions |= WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
|
|
|
|
if (action & GDK_ACTION_MOVE)
|
|
|
|
dnd_actions |= WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE;
|
|
|
|
if (action & GDK_ACTION_ASK)
|
|
|
|
dnd_actions |= WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
|
|
|
|
|
|
|
|
return dnd_actions;
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_drag_abort (GdkDragContext *context,
|
|
|
|
guint32 time)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_drag_drop (GdkDragContext *context,
|
|
|
|
guint32 time)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 18:20:37 +00:00
|
|
|
gdk_wayland_drag_context_init (GdkWaylandDragContext *context_wayland)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2014-08-21 18:20:37 +00:00
|
|
|
GdkDragContext *context;
|
|
|
|
|
|
|
|
context = GDK_DRAG_CONTEXT (context_wayland);
|
2010-12-18 20:38:49 +00:00
|
|
|
contexts = g_list_prepend (contexts, context);
|
2014-08-21 18:20:37 +00:00
|
|
|
|
|
|
|
context->action = GDK_ACTION_COPY;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
static GdkSurface *
|
2018-03-20 11:05:26 +00:00
|
|
|
gdk_wayland_drag_context_get_drag_surface (GdkDragContext *context)
|
2015-12-02 04:33:53 +00:00
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
return GDK_WAYLAND_DRAG_CONTEXT (context)->dnd_surface;
|
2015-12-02 04:33:53 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 02:53:38 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_set_hotspot (GdkDragContext *context,
|
|
|
|
gint hot_x,
|
|
|
|
gint hot_y)
|
|
|
|
{
|
2015-12-08 10:19:33 +00:00
|
|
|
GdkWaylandDragContext *context_wayland = GDK_WAYLAND_DRAG_CONTEXT (context);
|
|
|
|
gint prev_hot_x = context_wayland->hot_x;
|
|
|
|
gint prev_hot_y = context_wayland->hot_y;
|
|
|
|
const GdkRectangle damage_rect = { .width = 1, .height = 1 };
|
|
|
|
|
|
|
|
context_wayland->hot_x = hot_x;
|
|
|
|
context_wayland->hot_y = hot_y;
|
|
|
|
|
|
|
|
if (prev_hot_x == hot_x && prev_hot_y == hot_y)
|
|
|
|
return;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
_gdk_wayland_surface_offset_next_wl_buffer (context_wayland->dnd_surface,
|
2015-12-08 10:19:33 +00:00
|
|
|
-hot_x, -hot_y);
|
2018-03-21 03:07:37 +00:00
|
|
|
gdk_surface_invalidate_rect (context_wayland->dnd_surface, &damage_rect);
|
2015-12-08 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 20:00:34 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_set_cursor (GdkDragContext *context,
|
|
|
|
GdkCursor *cursor)
|
|
|
|
{
|
|
|
|
GdkDevice *device = gdk_drag_context_get_device (context);
|
|
|
|
|
|
|
|
gdk_wayland_seat_set_global_cursor (gdk_device_get_seat (device), cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_action_changed (GdkDragContext *context,
|
|
|
|
GdkDragAction action)
|
|
|
|
{
|
|
|
|
GdkCursor *cursor;
|
|
|
|
|
2016-04-26 07:31:33 +00:00
|
|
|
cursor = gdk_drag_get_cursor (context, action);
|
2016-01-13 20:00:34 +00:00
|
|
|
gdk_drag_context_set_cursor (context, cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_drop_performed (GdkDragContext *context,
|
|
|
|
guint32 time_)
|
|
|
|
{
|
|
|
|
gdk_drag_context_set_cursor (context, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-15 16:02:14 +00:00
|
|
|
gdk_wayland_drag_context_cancel (GdkDragContext *context,
|
|
|
|
GdkDragCancelReason reason)
|
2016-01-13 20:00:34 +00:00
|
|
|
{
|
|
|
|
gdk_drag_context_set_cursor (context, NULL);
|
|
|
|
}
|
|
|
|
|
2016-03-16 20:49:21 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_drop_done (GdkDragContext *context,
|
|
|
|
gboolean success)
|
|
|
|
{
|
|
|
|
GdkWaylandDragContext *context_wayland = GDK_WAYLAND_DRAG_CONTEXT (context);
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
if (context_wayland->dnd_surface)
|
|
|
|
gdk_surface_hide (context_wayland->dnd_surface);
|
2016-03-16 20:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_drag_context_class_init (GdkWaylandDragContextClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GdkDragContextClass *context_class = GDK_DRAG_CONTEXT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gdk_wayland_drag_context_finalize;
|
|
|
|
|
|
|
|
context_class->drag_abort = gdk_wayland_drag_context_drag_abort;
|
|
|
|
context_class->drag_drop = gdk_wayland_drag_context_drag_drop;
|
2018-03-20 11:05:26 +00:00
|
|
|
context_class->get_drag_surface = gdk_wayland_drag_context_get_drag_surface;
|
2015-12-08 02:53:38 +00:00
|
|
|
context_class->set_hotspot = gdk_wayland_drag_context_set_hotspot;
|
2016-03-16 20:49:21 +00:00
|
|
|
context_class->drop_done = gdk_wayland_drag_context_drop_done;
|
2016-01-13 20:00:34 +00:00
|
|
|
context_class->set_cursor = gdk_wayland_drag_context_set_cursor;
|
|
|
|
context_class->action_changed = gdk_wayland_drag_context_action_changed;
|
|
|
|
context_class->drop_performed = gdk_wayland_drag_context_drop_performed;
|
|
|
|
context_class->cancel = gdk_wayland_drag_context_cancel;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-20 14:14:10 +00:00
|
|
|
_gdk_wayland_surface_register_dnd (GdkSurface *surface)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
static GdkSurface *
|
2018-03-20 14:14:10 +00:00
|
|
|
create_dnd_surface (GdkDisplay *display)
|
2014-08-21 19:30:22 +00:00
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2014-08-21 19:30:22 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = gdk_surface_new_popup (display, &(GdkRectangle) { 0, 0, 100, 100 });
|
2014-08-21 19:30:22 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_surface_set_type_hint (surface, GDK_SURFACE_TYPE_HINT_DND);
|
2016-11-06 15:22:21 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
return surface;
|
2014-08-21 19:30:22 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
GdkDragContext *
|
2018-03-20 14:14:10 +00:00
|
|
|
_gdk_wayland_surface_drag_begin (GdkSurface *surface,
|
2017-12-13 14:03:53 +00:00
|
|
|
GdkDevice *device,
|
|
|
|
GdkContentProvider *content,
|
|
|
|
GdkDragAction actions,
|
|
|
|
gint dx,
|
|
|
|
gint dy)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2014-08-21 19:30:22 +00:00
|
|
|
GdkWaylandDragContext *context_wayland;
|
2010-12-18 20:38:49 +00:00
|
|
|
GdkDragContext *context;
|
2017-12-11 00:45:31 +00:00
|
|
|
GdkWaylandDisplay *display_wayland;
|
2017-11-20 03:42:43 +00:00
|
|
|
const char *const *mimetypes;
|
|
|
|
gsize i, n_mimetypes;
|
2014-08-21 19:30:22 +00:00
|
|
|
|
2017-12-11 00:45:31 +00:00
|
|
|
display_wayland = GDK_WAYLAND_DISPLAY (gdk_device_get_display (device));
|
|
|
|
|
2017-12-05 16:30:58 +00:00
|
|
|
context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
|
2018-04-27 10:32:17 +00:00
|
|
|
"device", device,
|
2017-12-13 14:03:53 +00:00
|
|
|
"content", content,
|
2017-12-05 16:30:58 +00:00
|
|
|
NULL);
|
2014-08-21 19:30:22 +00:00
|
|
|
context = GDK_DRAG_CONTEXT (context_wayland);
|
2018-03-20 14:14:10 +00:00
|
|
|
context->source_surface = g_object_ref (surface);
|
2013-11-19 23:55:26 +00:00
|
|
|
context->is_source = TRUE;
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
context_wayland->dnd_surface = create_dnd_surface (gdk_surface_get_display (surface));
|
|
|
|
context_wayland->dnd_wl_surface = gdk_wayland_surface_get_wl_surface (context_wayland->dnd_surface);
|
2018-05-30 02:04:39 +00:00
|
|
|
context_wayland->data_source = gdk_wayland_selection_get_data_source (surface);
|
2014-08-21 19:30:22 +00:00
|
|
|
|
2018-05-07 15:31:26 +00:00
|
|
|
mimetypes = gdk_content_formats_get_mime_types (gdk_drag_context_get_formats (context), &n_mimetypes);
|
2017-11-20 03:42:43 +00:00
|
|
|
for (i = 0; i < n_mimetypes; i++)
|
2015-06-25 12:52:47 +00:00
|
|
|
{
|
2017-11-20 03:42:43 +00:00
|
|
|
wl_data_source_offer (context_wayland->data_source, mimetypes[i]);
|
2015-06-25 12:52:47 +00:00
|
|
|
}
|
2014-08-21 19:30:22 +00:00
|
|
|
|
2017-12-11 00:45:31 +00:00
|
|
|
if (display_wayland->data_device_manager_version >=
|
|
|
|
WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION)
|
|
|
|
{
|
|
|
|
wl_data_source_set_actions (context_wayland->data_source,
|
|
|
|
gdk_to_wl_actions (actions));
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_data_device_start_drag (gdk_wayland_device_get_data_device (device),
|
|
|
|
context_wayland->data_source,
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_wayland_surface_get_wl_surface (surface),
|
|
|
|
context_wayland->dnd_wl_surface,
|
2017-12-11 00:45:31 +00:00
|
|
|
_gdk_wayland_display_get_serial (display_wayland));
|
|
|
|
|
|
|
|
gdk_seat_ungrab (gdk_device_get_seat (device));
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
return context;
|
|
|
|
}
|
2014-08-21 18:20:37 +00:00
|
|
|
|
|
|
|
void
|
2018-03-20 11:05:26 +00:00
|
|
|
_gdk_wayland_drag_context_set_source_surface (GdkDragContext *context,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface)
|
2014-08-21 18:20:37 +00:00
|
|
|
{
|
2018-03-20 11:05:26 +00:00
|
|
|
if (context->source_surface)
|
|
|
|
g_object_unref (context->source_surface);
|
2014-08-21 18:20:37 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
context->source_surface = surface ? g_object_ref (surface) : NULL;
|
2014-08-21 18:20:37 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 19:30:22 +00:00
|
|
|
GdkDragContext *
|
|
|
|
gdk_wayland_drag_context_lookup_by_data_source (struct wl_data_source *source)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = contexts; l; l = l->next)
|
|
|
|
{
|
|
|
|
GdkWaylandDragContext *wayland_context = l->data;
|
|
|
|
|
|
|
|
if (wayland_context->data_source == source)
|
|
|
|
return l->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|