2018-04-30 12:10:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Benjamin Otte
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 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
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-17 14:22:54 +00:00
|
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* GdkDrop:
|
2021-02-17 14:22:54 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkDrop` object represents the target of an ongoing DND operation.
|
2021-02-17 14:22:54 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Possible drop sites get informed about the status of the ongoing drag
|
|
|
|
|
* operation with events of type %GDK_DRAG_ENTER, %GDK_DRAG_LEAVE,
|
|
|
|
|
* %GDK_DRAG_MOTION and %GDK_DROP_START. The `GdkDrop` object can be obtained
|
|
|
|
|
* from these [class@Gdk.Event] types using [method@Gdk.DNDEvent.get_drop].
|
2021-02-17 14:22:54 +00:00
|
|
|
|
*
|
|
|
|
|
* The actual data transfer is initiated from the target side via an async
|
|
|
|
|
* read, using one of the `GdkDrop` methods for this purpose:
|
|
|
|
|
* [method@Gdk.Drop.read_async] or [method@Gdk.Drop.read_value_async].
|
|
|
|
|
*
|
|
|
|
|
* GTK provides a higher level abstraction based on top of these functions,
|
|
|
|
|
* and so they are not normally needed in GTK applications. See the
|
|
|
|
|
* "Drag and Drop" section of the GTK documentation for more information.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2018-06-14 02:58:50 +00:00
|
|
|
|
#include "gdkdropprivate.h"
|
2018-05-23 17:41:54 +00:00
|
|
|
|
|
2018-06-02 04:24:23 +00:00
|
|
|
|
#include "gdkcontentdeserializer.h"
|
2018-04-30 12:10:44 +00:00
|
|
|
|
#include "gdkcontentformats.h"
|
|
|
|
|
#include "gdkcontentprovider.h"
|
|
|
|
|
#include "gdkcontentserializer.h"
|
|
|
|
|
#include "gdkcursor.h"
|
2018-05-23 17:41:54 +00:00
|
|
|
|
#include "gdkdisplay.h"
|
2021-09-24 19:11:00 +00:00
|
|
|
|
#include "gdkdragprivate.h"
|
2018-04-30 12:10:44 +00:00
|
|
|
|
#include "gdkenumtypes.h"
|
|
|
|
|
#include "gdkeventsprivate.h"
|
2022-09-24 03:33:42 +00:00
|
|
|
|
#include <glib/gi18n-lib.h>
|
2018-05-31 19:45:22 +00:00
|
|
|
|
#include "gdkpipeiostreamprivate.h"
|
2018-05-23 17:41:54 +00:00
|
|
|
|
#include "gdksurface.h"
|
2018-04-30 12:10:44 +00:00
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
typedef struct _GdkDropPrivate GdkDropPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GdkDropPrivate {
|
|
|
|
|
GdkDevice *device;
|
|
|
|
|
GdkDrag *drag;
|
|
|
|
|
GdkContentFormats *formats;
|
|
|
|
|
GdkSurface *surface;
|
|
|
|
|
GdkDragAction actions;
|
2020-02-16 05:08:27 +00:00
|
|
|
|
|
|
|
|
|
guint entered : 1; /* TRUE if we got an enter event but not a leave event yet */
|
|
|
|
|
enum {
|
|
|
|
|
GDK_DROP_STATE_NONE, /* pointer is dragging along */
|
|
|
|
|
GDK_DROP_STATE_DROPPING, /* DROP_START has been sent */
|
|
|
|
|
GDK_DROP_STATE_FINISHED /* gdk_drop_finish() has been called */
|
|
|
|
|
} state : 2;
|
2018-07-15 19:41:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
2018-05-14 00:49:33 +00:00
|
|
|
|
PROP_ACTIONS,
|
2018-04-30 12:10:44 +00:00
|
|
|
|
PROP_DEVICE,
|
|
|
|
|
PROP_DISPLAY,
|
2018-05-16 02:49:58 +00:00
|
|
|
|
PROP_DRAG,
|
2018-04-30 12:10:44 +00:00
|
|
|
|
PROP_FORMATS,
|
2018-05-23 16:30:14 +00:00
|
|
|
|
PROP_SURFACE,
|
2018-04-30 12:10:44 +00:00
|
|
|
|
N_PROPERTIES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkDrop, gdk_drop, G_TYPE_OBJECT)
|
2018-04-30 12:10:44 +00:00
|
|
|
|
|
2018-05-14 02:16:25 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_default_status (GdkDrop *self,
|
2020-03-01 17:50:15 +00:00
|
|
|
|
GdkDragAction actions,
|
|
|
|
|
GdkDragAction preferred)
|
2018-05-14 02:16:25 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-31 19:45:22 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_read_local_write_done (GObject *drag,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer stream)
|
|
|
|
|
{
|
|
|
|
|
/* we don't care about the error, we just want to clean up */
|
2018-06-29 17:34:14 +00:00
|
|
|
|
gdk_drag_write_finish (GDK_DRAG (drag), result, NULL);
|
2018-05-31 19:45:22 +00:00
|
|
|
|
|
|
|
|
|
/* XXX: Do we need to close_async() here? */
|
|
|
|
|
g_output_stream_close (stream, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
static void
|
2018-05-07 22:47:26 +00:00
|
|
|
|
gdk_drop_read_local_async (GdkDrop *self,
|
|
|
|
|
GdkContentFormats *formats,
|
|
|
|
|
int io_priority,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-05-31 19:45:22 +00:00
|
|
|
|
GdkContentFormats *content_formats;
|
|
|
|
|
const char *mime_type;
|
2018-05-07 22:47:26 +00:00
|
|
|
|
GTask *task;
|
2018-07-15 20:18:06 +00:00
|
|
|
|
GdkContentProvider *content;
|
2018-05-07 22:47:26 +00:00
|
|
|
|
|
|
|
|
|
task = g_task_new (self, cancellable, callback, user_data);
|
|
|
|
|
g_task_set_priority (task, io_priority);
|
|
|
|
|
g_task_set_source_tag (task, gdk_drop_read_local_async);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
if (priv->drag == NULL)
|
2018-05-31 19:45:22 +00:00
|
|
|
|
{
|
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
2018-09-20 17:01:14 +00:00
|
|
|
|
_("Drag’n’drop from other applications is not supported."));
|
2018-05-31 19:45:22 +00:00
|
|
|
|
g_object_unref (task);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-15 20:18:06 +00:00
|
|
|
|
g_object_get (priv->drag, "content", &content, NULL);
|
|
|
|
|
content_formats = gdk_content_provider_ref_formats (content);
|
2024-05-23 18:39:50 +00:00
|
|
|
|
g_object_unref (content);
|
2018-05-31 19:45:22 +00:00
|
|
|
|
content_formats = gdk_content_formats_union_serialize_mime_types (content_formats);
|
|
|
|
|
mime_type = gdk_content_formats_match_mime_type (content_formats, formats);
|
|
|
|
|
|
|
|
|
|
if (mime_type != NULL)
|
|
|
|
|
{
|
|
|
|
|
GOutputStream *output_stream;
|
|
|
|
|
GIOStream *stream;
|
|
|
|
|
|
|
|
|
|
stream = gdk_pipe_io_stream_new ();
|
|
|
|
|
output_stream = g_io_stream_get_output_stream (stream);
|
2018-07-15 19:41:20 +00:00
|
|
|
|
gdk_drag_write_async (priv->drag,
|
2018-05-31 19:45:22 +00:00
|
|
|
|
mime_type,
|
|
|
|
|
output_stream,
|
|
|
|
|
io_priority,
|
|
|
|
|
cancellable,
|
|
|
|
|
gdk_drop_read_local_write_done,
|
|
|
|
|
g_object_ref (output_stream));
|
|
|
|
|
g_task_set_task_data (task, (gpointer) mime_type, NULL);
|
|
|
|
|
g_task_return_pointer (task, g_object_ref (g_io_stream_get_input_stream (stream)), g_object_unref);
|
|
|
|
|
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
|
_("No compatible formats to transfer contents."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gdk_content_formats_unref (content_formats);
|
2018-05-07 22:47:26 +00:00
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GInputStream *
|
|
|
|
|
gdk_drop_read_local_finish (GdkDrop *self,
|
|
|
|
|
GAsyncResult *result,
|
2019-04-02 11:38:52 +00:00
|
|
|
|
const char **out_mime_type,
|
2018-05-07 22:47:26 +00:00
|
|
|
|
GError **error)
|
2018-04-30 12:10:44 +00:00
|
|
|
|
{
|
2018-05-07 22:47:26 +00:00
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_drop_read_local_async, NULL);
|
|
|
|
|
|
|
|
|
|
if (out_mime_type)
|
|
|
|
|
*out_mime_type = g_task_get_task_data (G_TASK (result));
|
|
|
|
|
|
|
|
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 19:02:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_add_formats (GdkDrop *self,
|
|
|
|
|
GdkContentFormats *formats)
|
|
|
|
|
{
|
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
formats = gdk_content_formats_union_deserialize_gtypes (gdk_content_formats_ref (formats));
|
|
|
|
|
|
|
|
|
|
if (priv->formats)
|
|
|
|
|
{
|
|
|
|
|
formats = gdk_content_formats_union (formats, priv->formats);
|
|
|
|
|
gdk_content_formats_unref (priv->formats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->formats = formats;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_set_property (GObject *gobject,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GdkDrop *self = GDK_DROP (gobject);
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2018-05-14 00:49:33 +00:00
|
|
|
|
case PROP_ACTIONS:
|
|
|
|
|
gdk_drop_set_actions (self, g_value_get_flags (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
case PROP_DEVICE:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
priv->device = g_value_dup_object (value);
|
|
|
|
|
g_assert (priv->device != NULL);
|
|
|
|
|
if (priv->surface)
|
|
|
|
|
g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
|
2018-04-30 12:10:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-05-16 02:49:58 +00:00
|
|
|
|
case PROP_DRAG:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
priv->drag = g_value_dup_object (value);
|
2020-02-16 05:08:27 +00:00
|
|
|
|
if (priv->drag)
|
|
|
|
|
gdk_drop_add_formats (self, gdk_drag_get_formats (priv->drag));
|
2018-05-16 02:49:58 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
case PROP_FORMATS:
|
2020-02-15 19:02:44 +00:00
|
|
|
|
gdk_drop_add_formats (self, g_value_get_boxed (value));
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_assert (priv->formats != NULL);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-05-23 16:30:14 +00:00
|
|
|
|
case PROP_SURFACE:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
priv->surface = g_value_dup_object (value);
|
|
|
|
|
g_assert (priv->surface != NULL);
|
|
|
|
|
if (priv->device)
|
|
|
|
|
g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
|
2018-05-23 16:30:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_drop_get_property (GObject *gobject,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GdkDrop *self = GDK_DROP (gobject);
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2018-05-14 00:49:33 +00:00
|
|
|
|
case PROP_ACTIONS:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_value_set_flags (value, priv->actions);
|
2018-05-14 00:49:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
case PROP_DEVICE:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_value_set_object (value, priv->device);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_DISPLAY:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_value_set_object (value, gdk_device_get_display (priv->device));
|
2018-04-30 12:10:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-05-16 02:49:58 +00:00
|
|
|
|
case PROP_DRAG:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_value_set_object (value, priv->drag);
|
2018-05-16 02:49:58 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
case PROP_FORMATS:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_value_set_boxed (value, priv->formats);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-05-23 16:30:14 +00:00
|
|
|
|
case PROP_SURFACE:
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_value_set_object (value, priv->surface);
|
2018-05-23 16:30:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_drop_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GdkDrop *self = GDK_DROP (object);
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
/* someone forgot to send a LEAVE signal */
|
|
|
|
|
g_warn_if_fail (!priv->entered);
|
2021-06-19 14:49:04 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
/* Should we emit finish() here if necessary?
|
2021-06-19 14:49:04 +00:00
|
|
|
|
* For now that's the backends' job
|
|
|
|
|
*/
|
|
|
|
|
g_warn_if_fail (priv->state != GDK_DROP_STATE_DROPPING);
|
2020-02-16 05:08:27 +00:00
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
g_clear_object (&priv->device);
|
|
|
|
|
g_clear_object (&priv->drag);
|
2020-08-07 00:00:05 +00:00
|
|
|
|
g_clear_object (&priv->surface);
|
|
|
|
|
g_clear_pointer (&priv->formats, gdk_content_formats_unref);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gdk_drop_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_drop_class_init (GdkDropClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
2018-05-14 02:16:25 +00:00
|
|
|
|
klass->status = gdk_drop_default_status;
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
object_class->get_property = gdk_drop_get_property;
|
|
|
|
|
object_class->set_property = gdk_drop_set_property;
|
|
|
|
|
object_class->finalize = gdk_drop_finalize;
|
|
|
|
|
|
2018-05-14 00:49:33 +00:00
|
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
|
* GdkDrop:actions:
|
2018-05-14 00:49:33 +00:00
|
|
|
|
*
|
|
|
|
|
* The possible actions for this drop
|
|
|
|
|
*/
|
|
|
|
|
properties[PROP_ACTIONS] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_flags ("actions", NULL, NULL,
|
2018-05-14 00:49:33 +00:00
|
|
|
|
GDK_TYPE_DRAG_ACTION,
|
|
|
|
|
GDK_ACTION_ALL,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
|
* GdkDrop:device:
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkDevice` performing the drop
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*/
|
|
|
|
|
properties[PROP_DEVICE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("device", NULL, NULL,
|
2018-04-30 12:10:44 +00:00
|
|
|
|
GDK_TYPE_DEVICE,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
|
* GdkDrop:display:
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkDisplay` that the drop belongs to.
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*/
|
|
|
|
|
properties[PROP_DISPLAY] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("display", NULL, NULL,
|
2018-04-30 12:10:44 +00:00
|
|
|
|
GDK_TYPE_DISPLAY,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2018-05-16 02:49:58 +00:00
|
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
|
* GdkDrop:drag:
|
2018-05-16 02:49:58 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkDrag` that initiated this drop
|
2018-05-16 02:49:58 +00:00
|
|
|
|
*/
|
|
|
|
|
properties[PROP_DRAG] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("drag", NULL, NULL,
|
2018-06-29 17:34:14 +00:00
|
|
|
|
GDK_TYPE_DRAG,
|
2018-05-16 02:49:58 +00:00
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
|
* GdkDrop:formats:
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
|
|
|
|
* The possible formats that the drop can provide its data in.
|
|
|
|
|
*/
|
|
|
|
|
properties[PROP_FORMATS] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_boxed ("formats", NULL, NULL,
|
2018-04-30 12:10:44 +00:00
|
|
|
|
GDK_TYPE_CONTENT_FORMATS,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
2018-05-23 16:30:14 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2024-06-03 11:35:00 +00:00
|
|
|
|
* GdkDrop:surface:
|
2018-05-23 16:30:14 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkSurface` the drop happens on
|
2018-05-23 16:30:14 +00:00
|
|
|
|
*/
|
|
|
|
|
properties[PROP_SURFACE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("surface", NULL, NULL,
|
2018-05-23 16:30:14 +00:00
|
|
|
|
GDK_TYPE_SURFACE,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 22:47:26 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_init (GdkDrop *self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
|
* gdk_drop_get_display:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Gets the `GdkDisplay` that @self was created for.
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: (transfer none): a `GdkDisplay`
|
|
|
|
|
*/
|
2018-04-30 12:10:44 +00:00
|
|
|
|
GdkDisplay *
|
|
|
|
|
gdk_drop_get_display (GdkDrop *self)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), NULL);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
return gdk_device_get_display (priv->device);
|
2018-04-30 12:10:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
|
* gdk_drop_get_device:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns the `GdkDevice` performing the drop.
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: (transfer none): The `GdkDevice` performing the drop.
|
|
|
|
|
*/
|
2018-04-30 12:10:44 +00:00
|
|
|
|
GdkDevice *
|
|
|
|
|
gdk_drop_get_device (GdkDrop *self)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), NULL);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
return priv->device;
|
2018-04-30 12:10:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
|
* gdk_drop_get_formats:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-04-30 12:10:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns the `GdkContentFormats` that the drop offers the data
|
2018-04-30 12:10:44 +00:00
|
|
|
|
* to be read in.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: (transfer none): The possible `GdkContentFormats`
|
|
|
|
|
*/
|
2018-04-30 12:10:44 +00:00
|
|
|
|
GdkContentFormats *
|
|
|
|
|
gdk_drop_get_formats (GdkDrop *self)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-04-30 12:10:44 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), NULL);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
return priv->formats;
|
2018-04-30 12:10:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 16:30:14 +00:00
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
|
* gdk_drop_get_surface:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-05-23 16:30:14 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns the `GdkSurface` performing the drop.
|
2018-05-23 16:30:14 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: (transfer none): The `GdkSurface` performing the drop.
|
|
|
|
|
*/
|
2018-05-23 16:30:14 +00:00
|
|
|
|
GdkSurface *
|
|
|
|
|
gdk_drop_get_surface (GdkDrop *self)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-05-23 16:30:14 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), NULL);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
return priv->surface;
|
2018-05-23 16:30:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 00:49:33 +00:00
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
|
* gdk_drop_get_actions:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
|
|
|
|
*
|
|
|
|
|
* Returns the possible actions for this `GdkDrop`.
|
|
|
|
|
*
|
|
|
|
|
* If this value contains multiple actions - i.e.
|
|
|
|
|
* [func@Gdk.DragAction.is_unique] returns %FALSE for the result -
|
|
|
|
|
* [method@Gdk.Drop.finish] must choose the action to use when
|
|
|
|
|
* accepting the drop. This will only happen if you passed
|
|
|
|
|
* %GDK_ACTION_ASK as one of the possible actions in
|
|
|
|
|
* [method@Gdk.Drop.status]. %GDK_ACTION_ASK itself will not
|
2020-01-04 17:06:36 +00:00
|
|
|
|
* be included in the actions returned by this function.
|
2018-05-14 00:49:33 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* This value may change over the lifetime of the [class@Gdk.Drop]
|
|
|
|
|
* both as a response to source side actions as well as to calls to
|
|
|
|
|
* [method@Gdk.Drop.status] or [method@Gdk.Drop.finish]. The source
|
|
|
|
|
* side will not change this value anymore once a drop has started.
|
2018-05-14 00:49:33 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: The possible `GdkDragActions`
|
|
|
|
|
*/
|
2018-05-14 00:49:33 +00:00
|
|
|
|
GdkDragAction
|
|
|
|
|
gdk_drop_get_actions (GdkDrop *self)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-05-14 00:49:33 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), 0);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
return priv->actions;
|
2018-05-14 00:49:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_set_actions (GdkDrop *self,
|
|
|
|
|
GdkDragAction actions)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-05-14 00:49:33 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_DROP (self));
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_return_if_fail (priv->state == GDK_DROP_STATE_NONE);
|
2018-05-14 00:49:33 +00:00
|
|
|
|
g_return_if_fail ((actions & GDK_ACTION_ASK) == 0);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
if (priv->actions == actions)
|
2018-05-14 00:49:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
priv->actions = actions;
|
2018-05-14 00:49:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 02:49:58 +00:00
|
|
|
|
/**
|
2024-06-03 11:36:59 +00:00
|
|
|
|
* gdk_drop_get_drag:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-05-16 02:49:58 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* If this is an in-app drag-and-drop operation, returns the `GdkDrag`
|
2018-05-16 02:49:58 +00:00
|
|
|
|
* that corresponds to this drop.
|
|
|
|
|
*
|
|
|
|
|
* If it is not, %NULL is returned.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: (transfer none) (nullable): the corresponding `GdkDrag`
|
|
|
|
|
*/
|
2018-06-29 17:34:14 +00:00
|
|
|
|
GdkDrag *
|
2018-05-16 02:49:58 +00:00
|
|
|
|
gdk_drop_get_drag (GdkDrop *self)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-05-16 02:49:58 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), 0);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
return priv->drag;
|
2018-05-16 02:49:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 02:16:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_drop_status:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-05-14 02:16:25 +00:00
|
|
|
|
* @actions: Supported actions of the destination, or 0 to indicate
|
|
|
|
|
* that a drop will not be accepted
|
2020-03-01 17:50:15 +00:00
|
|
|
|
* @preferred: A unique action that's a member of @actions indicating the
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* preferred action
|
2018-05-14 02:16:25 +00:00
|
|
|
|
*
|
|
|
|
|
* Selects all actions that are potentially supported by the destination.
|
|
|
|
|
*
|
|
|
|
|
* When calling this function, do not restrict the passed in actions to
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* the ones provided by [method@Gdk.Drop.get_actions]. Those actions may
|
2018-05-14 02:16:25 +00:00
|
|
|
|
* change in the future, even depending on the actions you provide here.
|
|
|
|
|
*
|
2021-06-19 15:01:57 +00:00
|
|
|
|
* The @preferred action is a hint to the drag-and-drop mechanism about which
|
2020-03-01 17:50:15 +00:00
|
|
|
|
* action to use when multiple actions are possible.
|
|
|
|
|
*
|
2018-05-14 02:16:25 +00:00
|
|
|
|
* This function should be called by drag destinations in response to
|
|
|
|
|
* %GDK_DRAG_ENTER or %GDK_DRAG_MOTION events. If the destination does
|
|
|
|
|
* not yet know the exact actions it supports, it should set any possible
|
|
|
|
|
* actions first and then later call this function again.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_status (GdkDrop *self,
|
2020-03-01 17:50:15 +00:00
|
|
|
|
GdkDragAction actions,
|
|
|
|
|
GdkDragAction preferred)
|
2018-05-14 02:16:25 +00:00
|
|
|
|
{
|
2020-02-22 05:53:16 +00:00
|
|
|
|
#ifndef G_DISABLE_CHECKS
|
2020-02-16 05:08:27 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2020-02-22 05:53:16 +00:00
|
|
|
|
#endif
|
2020-02-16 05:08:27 +00:00
|
|
|
|
|
2018-05-14 02:16:25 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_DROP (self));
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_return_if_fail (priv->state != GDK_DROP_STATE_FINISHED);
|
2020-03-01 17:50:15 +00:00
|
|
|
|
g_return_if_fail (gdk_drag_action_is_unique (preferred));
|
|
|
|
|
g_return_if_fail ((preferred & actions) == preferred);
|
2018-05-14 02:16:25 +00:00
|
|
|
|
|
2020-03-01 17:50:15 +00:00
|
|
|
|
GDK_DROP_GET_CLASS (self)->status (self, actions, preferred);
|
2018-05-14 02:16:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 03:45:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_drop_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
|
|
|
|
* @action: the action performed by the destination or 0 if the drop failed
|
2018-05-15 03:45:06 +00:00
|
|
|
|
*
|
|
|
|
|
* Ends the drag operation after a drop.
|
2021-02-21 05:13:57 +00:00
|
|
|
|
*
|
2018-05-15 03:45:06 +00:00
|
|
|
|
* The @action must be a single action selected from the actions
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* available via [method@Gdk.Drop.get_actions].
|
|
|
|
|
*/
|
2018-05-15 03:45:06 +00:00
|
|
|
|
void
|
|
|
|
|
gdk_drop_finish (GdkDrop *self,
|
|
|
|
|
GdkDragAction action)
|
|
|
|
|
{
|
2020-02-16 05:08:27 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2018-05-15 03:45:06 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_DROP (self));
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_return_if_fail (priv->state == GDK_DROP_STATE_DROPPING);
|
2018-05-15 03:45:06 +00:00
|
|
|
|
g_return_if_fail (gdk_drag_action_is_unique (action));
|
|
|
|
|
|
|
|
|
|
GDK_DROP_GET_CLASS (self)->finish (self, action);
|
2020-02-16 05:08:27 +00:00
|
|
|
|
|
|
|
|
|
priv->state = GDK_DROP_STATE_FINISHED;
|
2018-05-15 03:45:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-31 19:45:22 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_read_internal (GdkDrop *self,
|
|
|
|
|
GdkContentFormats *formats,
|
|
|
|
|
int io_priority,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_return_if_fail (priv->state != GDK_DROP_STATE_FINISHED);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
if (priv->drag)
|
2018-05-31 19:45:22 +00:00
|
|
|
|
{
|
|
|
|
|
gdk_drop_read_local_async (self,
|
|
|
|
|
formats,
|
|
|
|
|
io_priority,
|
|
|
|
|
cancellable,
|
|
|
|
|
callback,
|
|
|
|
|
user_data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GDK_DROP_GET_CLASS (self)->read_async (self,
|
|
|
|
|
formats,
|
|
|
|
|
io_priority,
|
|
|
|
|
cancellable,
|
|
|
|
|
callback,
|
|
|
|
|
user_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 22:47:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_drop_read_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
2018-05-07 22:47:26 +00:00
|
|
|
|
* @mime_types: (array zero-terminated=1) (element-type utf8):
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* pointer to an array of mime types
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @io_priority: the I/O priority for the read operation
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @cancellable: (nullable): optional `GCancellable` object
|
2024-07-03 15:57:47 +00:00
|
|
|
|
* @callback: (scope async) (closure user_data): a `GAsyncReadyCallback` to call when
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* the request is satisfied
|
2024-07-03 15:57:47 +00:00
|
|
|
|
* @user_data: the data to pass to @callback
|
2018-05-07 22:47:26 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Asynchronously read the dropped data from a `GdkDrop`
|
2018-05-07 22:47:26 +00:00
|
|
|
|
* in a format that complies with one of the mime types.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_read_async (GdkDrop *self,
|
|
|
|
|
const char **mime_types,
|
|
|
|
|
int io_priority,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GdkContentFormats *formats;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DROP (self));
|
|
|
|
|
g_return_if_fail (mime_types != NULL && mime_types[0] != NULL);
|
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
|
|
formats = gdk_content_formats_new (mime_types, g_strv_length ((char **) mime_types));
|
|
|
|
|
|
2018-05-31 19:45:22 +00:00
|
|
|
|
gdk_drop_read_internal (self, formats, io_priority, cancellable, callback, user_data);
|
2018-05-07 22:47:26 +00:00
|
|
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_drop_read_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
|
|
|
|
* @result: a `GAsyncResult`
|
2023-10-19 14:06:53 +00:00
|
|
|
|
* @out_mime_type: (out) (type utf8) (transfer none): return location for the used mime type
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @error: (nullable): location to store error information on failure
|
2018-05-07 22:47:26 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Finishes an async drop read operation.
|
|
|
|
|
*
|
2021-03-16 18:24:04 +00:00
|
|
|
|
* Note that you must not use blocking read calls on the returned stream
|
|
|
|
|
* in the GTK thread, since some platforms might require communication with
|
|
|
|
|
* GTK to complete the data transfer. You can use async APIs such as
|
|
|
|
|
* g_input_stream_read_bytes_async().
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* See [method@Gdk.Drop.read_async].
|
2018-05-07 22:47:26 +00:00
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): the `GInputStream`
|
2018-05-07 22:47:26 +00:00
|
|
|
|
*/
|
|
|
|
|
GInputStream *
|
|
|
|
|
gdk_drop_read_finish (GdkDrop *self,
|
|
|
|
|
GAsyncResult *result,
|
2019-04-02 11:38:52 +00:00
|
|
|
|
const char **out_mime_type,
|
2018-05-07 22:47:26 +00:00
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GDK_IS_DROP (self), NULL);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (g_async_result_is_tagged (result, gdk_drop_read_local_async))
|
|
|
|
|
{
|
2019-04-02 11:38:52 +00:00
|
|
|
|
return gdk_drop_read_local_finish (self, result, out_mime_type, error);
|
2018-05-07 22:47:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-04-02 11:38:52 +00:00
|
|
|
|
return GDK_DROP_GET_CLASS (self)->read_finish (self, result, out_mime_type, error);
|
2018-05-07 22:47:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-02 04:24:23 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_read_value_done (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GTask *task = data;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
|
|
value = g_task_get_task_data (task);
|
|
|
|
|
|
|
|
|
|
if (!gdk_content_deserialize_finish (result, value, &error))
|
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
else
|
|
|
|
|
g_task_return_pointer (task, value, NULL);
|
|
|
|
|
|
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_drop_read_value_got_stream (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GInputStream *stream;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GTask *task = data;
|
|
|
|
|
const char *mime_type;
|
|
|
|
|
|
2019-04-02 11:38:52 +00:00
|
|
|
|
stream = gdk_drop_read_finish (GDK_DROP (source), result, &mime_type, &error);
|
2018-06-02 04:24:23 +00:00
|
|
|
|
if (stream == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gdk_content_deserialize_async (stream,
|
|
|
|
|
mime_type,
|
|
|
|
|
G_VALUE_TYPE (g_task_get_task_data (task)),
|
|
|
|
|
g_task_get_priority (task),
|
|
|
|
|
g_task_get_cancellable (task),
|
|
|
|
|
gdk_drop_read_value_done,
|
|
|
|
|
task);
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_value (gpointer value)
|
|
|
|
|
{
|
|
|
|
|
g_value_unset (value);
|
2023-03-03 11:41:41 +00:00
|
|
|
|
g_free (value);
|
2018-06-02 04:24:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_drop_read_value_internal (GdkDrop *self,
|
|
|
|
|
GType type,
|
|
|
|
|
gpointer source_tag,
|
|
|
|
|
int io_priority,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-06-02 04:24:23 +00:00
|
|
|
|
GdkContentFormatsBuilder *builder;
|
|
|
|
|
GdkContentFormats *formats;
|
|
|
|
|
GValue *value;
|
|
|
|
|
GTask *task;
|
2024-05-23 18:39:50 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_return_if_fail (priv->state != GDK_DROP_STATE_FINISHED);
|
|
|
|
|
|
2018-06-02 04:24:23 +00:00
|
|
|
|
task = g_task_new (self, cancellable, callback, user_data);
|
|
|
|
|
g_task_set_priority (task, io_priority);
|
|
|
|
|
g_task_set_source_tag (task, source_tag);
|
2023-03-03 11:41:41 +00:00
|
|
|
|
value = g_new0 (GValue, 1);
|
2018-06-02 04:24:23 +00:00
|
|
|
|
g_value_init (value, type);
|
|
|
|
|
g_task_set_task_data (task, value, free_value);
|
|
|
|
|
|
2018-07-15 19:41:20 +00:00
|
|
|
|
if (priv->drag)
|
2018-06-02 04:24:23 +00:00
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
2018-07-15 20:18:06 +00:00
|
|
|
|
gboolean res;
|
2018-06-02 04:24:23 +00:00
|
|
|
|
|
2020-03-02 20:45:42 +00:00
|
|
|
|
res = gdk_content_provider_get_value (gdk_drag_get_content (priv->drag),
|
|
|
|
|
value,
|
|
|
|
|
&error);
|
2018-07-15 20:18:06 +00:00
|
|
|
|
|
|
|
|
|
if (res)
|
2018-06-02 04:24:23 +00:00
|
|
|
|
{
|
|
|
|
|
g_task_return_pointer (task, value, NULL);
|
|
|
|
|
g_object_unref (task);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
|
|
|
|
{
|
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
g_object_unref (task);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* fall through to regular stream transfer */
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder = gdk_content_formats_builder_new ();
|
|
|
|
|
gdk_content_formats_builder_add_gtype (builder, type);
|
|
|
|
|
formats = gdk_content_formats_builder_free_to_formats (builder);
|
|
|
|
|
formats = gdk_content_formats_union_deserialize_mime_types (formats);
|
|
|
|
|
|
|
|
|
|
gdk_drop_read_internal (self,
|
|
|
|
|
formats,
|
|
|
|
|
io_priority,
|
|
|
|
|
cancellable,
|
|
|
|
|
gdk_drop_read_value_got_stream,
|
|
|
|
|
task);
|
|
|
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_drop_read_value_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
|
|
|
|
* @type: a `GType` to read
|
|
|
|
|
* @io_priority: the I/O priority of the request.
|
|
|
|
|
* @cancellable: (nullable): optional `GCancellable` object, %NULL to ignore.
|
2024-07-03 15:57:47 +00:00
|
|
|
|
* @callback: (scope async) (closure user_data): callback to call when the request is satisfied
|
|
|
|
|
* @user_data: the data to pass to callback function
|
2018-06-02 04:24:23 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Asynchronously request the drag operation's contents converted
|
|
|
|
|
* to the given @type.
|
2018-06-02 04:24:23 +00:00
|
|
|
|
*
|
2021-06-19 15:01:57 +00:00
|
|
|
|
* For local drag-and-drop operations that are available in the given
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* `GType`, the value will be copied directly. Otherwise, GDK will
|
|
|
|
|
* try to use [func@Gdk.content_deserialize_async] to convert the data.
|
|
|
|
|
*/
|
2018-06-02 04:24:23 +00:00
|
|
|
|
void
|
|
|
|
|
gdk_drop_read_value_async (GdkDrop *self,
|
|
|
|
|
GType type,
|
|
|
|
|
int io_priority,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GDK_IS_DROP (self));
|
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
|
|
gdk_drop_read_value_internal (self,
|
|
|
|
|
type,
|
|
|
|
|
gdk_drop_read_value_async,
|
|
|
|
|
io_priority,
|
|
|
|
|
cancellable,
|
|
|
|
|
callback,
|
|
|
|
|
user_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_drop_read_value_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @self: a `GdkDrop`
|
|
|
|
|
* @result: a `GAsyncResult`
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @error: a `GError` location to store the error occurring
|
2021-02-21 05:13:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Finishes an async drop read.
|
2018-06-02 04:24:23 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* See [method@Gdk.Drop.read_value_async].
|
2018-06-02 04:24:23 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: (transfer none): a `GValue` containing the result.
|
|
|
|
|
*/
|
2018-06-02 04:24:23 +00:00
|
|
|
|
const GValue *
|
|
|
|
|
gdk_drop_read_value_finish (GdkDrop *self,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_drop_read_value_async, NULL);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 17:41:54 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_drop_do_emit_event (GdkEvent *event,
|
|
|
|
|
gboolean dont_queue)
|
|
|
|
|
{
|
|
|
|
|
if (dont_queue)
|
|
|
|
|
{
|
|
|
|
|
_gdk_event_emit (event);
|
2020-02-15 20:07:24 +00:00
|
|
|
|
gdk_event_unref (event);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_gdk_event_queue_append (gdk_event_get_display (event), event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_emit_enter_event (GdkDrop *self,
|
|
|
|
|
gboolean dont_queue,
|
2020-02-19 02:37:23 +00:00
|
|
|
|
double x,
|
|
|
|
|
double y,
|
2018-05-23 17:41:54 +00:00
|
|
|
|
guint32 time)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
GdkEvent *event;
|
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_warn_if_fail (!priv->entered);
|
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
|
event = gdk_dnd_event_new (GDK_DRAG_ENTER,
|
|
|
|
|
priv->surface,
|
|
|
|
|
priv->device,
|
|
|
|
|
self,
|
|
|
|
|
time,
|
|
|
|
|
0, 0);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
priv->entered = TRUE;
|
|
|
|
|
|
2018-05-23 17:41:54 +00:00
|
|
|
|
gdk_drop_do_emit_event (event, dont_queue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_emit_motion_event (GdkDrop *self,
|
|
|
|
|
gboolean dont_queue,
|
2020-02-14 23:15:38 +00:00
|
|
|
|
double x,
|
|
|
|
|
double y,
|
2018-05-23 17:41:54 +00:00
|
|
|
|
guint32 time)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
GdkEvent *event;
|
2019-12-30 16:58:11 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_warn_if_fail (priv->entered);
|
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
|
event = gdk_dnd_event_new (GDK_DRAG_MOTION,
|
|
|
|
|
priv->surface,
|
|
|
|
|
priv->device,
|
|
|
|
|
self,
|
|
|
|
|
time,
|
|
|
|
|
x, y);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
|
|
|
|
|
gdk_drop_do_emit_event (event, dont_queue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_emit_leave_event (GdkDrop *self,
|
|
|
|
|
gboolean dont_queue,
|
|
|
|
|
guint32 time)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
GdkEvent *event;
|
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_warn_if_fail (priv->entered);
|
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
|
event = gdk_dnd_event_new (GDK_DRAG_LEAVE,
|
|
|
|
|
priv->surface,
|
|
|
|
|
priv->device,
|
|
|
|
|
self,
|
|
|
|
|
time,
|
|
|
|
|
0, 0);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
priv->entered = FALSE;
|
|
|
|
|
|
2018-05-23 17:41:54 +00:00
|
|
|
|
gdk_drop_do_emit_event (event, dont_queue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_drop_emit_drop_event (GdkDrop *self,
|
|
|
|
|
gboolean dont_queue,
|
2020-02-14 23:15:38 +00:00
|
|
|
|
double x,
|
|
|
|
|
double y,
|
2018-05-23 17:41:54 +00:00
|
|
|
|
guint32 time)
|
|
|
|
|
{
|
2018-07-15 19:41:20 +00:00
|
|
|
|
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
GdkEvent *event;
|
2019-12-30 16:58:11 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
g_warn_if_fail (priv->entered);
|
|
|
|
|
g_warn_if_fail (priv->state == GDK_DROP_STATE_NONE);
|
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
|
event = gdk_dnd_event_new (GDK_DROP_START,
|
|
|
|
|
priv->surface,
|
|
|
|
|
priv->device,
|
|
|
|
|
self,
|
|
|
|
|
time,
|
|
|
|
|
x, y);
|
2018-05-23 17:41:54 +00:00
|
|
|
|
|
2020-02-16 05:08:27 +00:00
|
|
|
|
priv->state = GDK_DROP_STATE_DROPPING;
|
|
|
|
|
|
2018-05-23 17:41:54 +00:00
|
|
|
|
gdk_drop_do_emit_event (event, dont_queue);
|
|
|
|
|
}
|