2014-05-29 03:55:53 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* 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 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkclipboardprivate.h"
|
|
|
|
|
2017-11-22 09:44:30 +00:00
|
|
|
#include "gdkcontentdeserializer.h"
|
2014-05-29 03:55:53 +00:00
|
|
|
#include "gdkcontentformats.h"
|
2017-11-24 05:17:37 +00:00
|
|
|
#include "gdkcontentproviderimpl.h"
|
|
|
|
#include "gdkcontentproviderprivate.h"
|
2017-11-24 10:15:51 +00:00
|
|
|
#include "gdkcontentserializer.h"
|
2014-05-29 03:55:53 +00:00
|
|
|
#include "gdkdisplay.h"
|
2017-11-24 05:17:37 +00:00
|
|
|
#include "gdkintl.h"
|
2017-11-24 09:13:23 +00:00
|
|
|
#include "gdkpipeiostreamprivate.h"
|
2017-12-02 13:38:57 +00:00
|
|
|
#include "gdktexture.h"
|
2014-05-29 03:55:53 +00:00
|
|
|
|
2017-12-05 07:09:54 +00:00
|
|
|
#include <gobject/gvaluecollector.h>
|
|
|
|
|
2017-12-04 23:58:30 +00:00
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkClipboard:
|
2017-12-04 23:58:30 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The `GdkClipboard` object represents data shared between applications or
|
|
|
|
* inside an application.
|
2017-12-05 00:06:02 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* To get a `GdkClipboard` object, use [method@Gdk.Display.get_clipboard] or
|
|
|
|
* [method@Gdk.Display.get_primary_clipboard]. You can find out about the data
|
|
|
|
* that is currently available in a clipboard using
|
|
|
|
* [method@Gdk.Clipboard.get_formats].
|
2017-12-05 00:06:02 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* To make text or image data available in a clipboard, use
|
|
|
|
* [method@Gdk.Clipboard.set_text] or [method@Gdk.Clipboard.set_texture].
|
|
|
|
* For other data, you can use [method@Gdk.Clipboard.set_content], which
|
|
|
|
* takes a [class@Gdk.ContentProvider] object.
|
2017-12-26 19:39:24 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* To read textual or image data from a clipboard, use
|
|
|
|
* [method@Gdk.Clipboard.read_text_async] or
|
|
|
|
* [method@Gdk.Clipboard.read_texture_async]. For other data, use
|
|
|
|
* [method@Gdk.Clipboard.read_async], which provides a `GInputStream` object.
|
2017-12-26 19:39:24 +00:00
|
|
|
*/
|
|
|
|
|
2014-05-29 03:55:53 +00:00
|
|
|
typedef struct _GdkClipboardPrivate GdkClipboardPrivate;
|
|
|
|
|
|
|
|
struct _GdkClipboardPrivate
|
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
GdkContentFormats *formats;
|
2017-11-24 05:17:37 +00:00
|
|
|
GdkContentProvider *content;
|
2014-05-29 03:55:53 +00:00
|
|
|
|
|
|
|
guint local : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_DISPLAY,
|
|
|
|
PROP_FORMATS,
|
|
|
|
PROP_LOCAL,
|
2017-11-24 05:17:37 +00:00
|
|
|
PROP_CONTENT,
|
2014-05-29 03:55:53 +00:00
|
|
|
N_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CHANGED,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GdkClipboard, gdk_clipboard, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_clipboard_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkClipboard *clipboard = GDK_CLIPBOARD (gobject);
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
priv->display = g_value_get_object (value);
|
|
|
|
g_assert (priv->display != NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_clipboard_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkClipboard *clipboard = GDK_CLIPBOARD (gobject);
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, priv->display);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_FORMATS:
|
|
|
|
g_value_set_boxed (value, priv->formats);
|
|
|
|
break;
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
case PROP_CONTENT:
|
|
|
|
g_value_set_object (value, priv->content);
|
|
|
|
break;
|
|
|
|
|
2014-05-29 03:55:53 +00:00
|
|
|
case PROP_LOCAL:
|
|
|
|
g_value_set_boolean (value, priv->local);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_clipboard_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GdkClipboard *clipboard = GDK_CLIPBOARD (object);
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->formats, gdk_content_formats_unref);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gdk_clipboard_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2017-11-24 19:42:40 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_content_changed_cb (GdkContentProvider *provider,
|
|
|
|
GdkClipboard *clipboard);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_clipboard_real_claim (GdkClipboard *clipboard,
|
|
|
|
GdkContentFormats *formats,
|
|
|
|
gboolean local,
|
|
|
|
GdkContentProvider *content)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (clipboard));
|
|
|
|
|
|
|
|
gdk_content_formats_unref (priv->formats);
|
|
|
|
gdk_content_formats_ref (formats);
|
|
|
|
formats = gdk_content_formats_union_deserialize_gtypes (formats);
|
|
|
|
priv->formats = formats;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_FORMATS]);
|
|
|
|
if (priv->local != local)
|
|
|
|
{
|
|
|
|
priv->local = local;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_LOCAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->content != content)
|
|
|
|
{
|
|
|
|
GdkContentProvider *old_content = priv->content;
|
|
|
|
|
|
|
|
if (content)
|
|
|
|
priv->content = g_object_ref (content);
|
|
|
|
else
|
|
|
|
priv->content = NULL;
|
|
|
|
|
|
|
|
if (old_content)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (old_content,
|
|
|
|
gdk_clipboard_content_changed_cb,
|
|
|
|
clipboard);
|
|
|
|
gdk_content_provider_detach_clipboard (old_content, clipboard);
|
|
|
|
g_object_unref (old_content);
|
|
|
|
}
|
|
|
|
if (content)
|
|
|
|
{
|
|
|
|
gdk_content_provider_attach_clipboard (content, clipboard);
|
|
|
|
g_signal_connect (content,
|
|
|
|
"content-changed",
|
|
|
|
G_CALLBACK (gdk_clipboard_content_changed_cb),
|
|
|
|
clipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_CONTENT]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (clipboard));
|
|
|
|
|
|
|
|
g_signal_emit (clipboard, signals[CHANGED], 0);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:23:36 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_store_default_async (GdkClipboard *clipboard,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
GTask *task;
|
|
|
|
|
|
|
|
task = g_task_new (clipboard, cancellable, callback, user_data);
|
|
|
|
g_task_set_priority (task, io_priority);
|
|
|
|
g_task_set_source_tag (task, gdk_clipboard_store_default_async);
|
|
|
|
|
|
|
|
if (priv->local)
|
|
|
|
{
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("This clipboard cannot store data."));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_task_return_boolean (task, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_clipboard_store_default_finish (GdkClipboard *clipboard,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, clipboard), FALSE);
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_store_default_async, FALSE);
|
|
|
|
|
|
|
|
return g_task_propagate_boolean (G_TASK (result), error);
|
|
|
|
}
|
|
|
|
|
2017-11-24 09:13:23 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_read_local_write_done (GObject *clipboard,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer stream)
|
|
|
|
{
|
|
|
|
/* we don't care about the error, we just want to clean up */
|
|
|
|
gdk_clipboard_write_finish (GDK_CLIPBOARD (clipboard), result, NULL);
|
|
|
|
|
|
|
|
/* XXX: Do we need to close_async() here? */
|
|
|
|
g_output_stream_close (stream, NULL, NULL);
|
|
|
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
}
|
|
|
|
|
2017-11-22 08:25:35 +00:00
|
|
|
static void
|
2017-11-24 05:17:37 +00:00
|
|
|
gdk_clipboard_read_local_async (GdkClipboard *clipboard,
|
|
|
|
GdkContentFormats *formats,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2017-11-22 08:25:35 +00:00
|
|
|
{
|
2017-11-24 05:17:37 +00:00
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
2017-11-24 09:13:23 +00:00
|
|
|
GdkContentFormats *content_formats;
|
|
|
|
const char *mime_type;
|
2017-11-22 08:25:35 +00:00
|
|
|
GTask *task;
|
|
|
|
|
|
|
|
task = g_task_new (clipboard, cancellable, callback, user_data);
|
|
|
|
g_task_set_priority (task, io_priority);
|
2017-11-24 05:17:37 +00:00
|
|
|
g_task_set_source_tag (task, gdk_clipboard_read_local_async);
|
2017-11-22 08:25:35 +00:00
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
if (priv->content == NULL)
|
|
|
|
{
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
|
|
|
_("Cannot read from empty clipboard."));
|
2017-11-24 09:13:23 +00:00
|
|
|
g_object_unref (task);
|
|
|
|
return;
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
2017-11-24 09:13:23 +00:00
|
|
|
|
|
|
|
content_formats = gdk_content_provider_ref_formats (priv->content);
|
2017-11-24 10:15:51 +00:00
|
|
|
content_formats = gdk_content_formats_union_serialize_mime_types (content_formats);
|
2017-11-24 10:34:19 +00:00
|
|
|
mime_type = gdk_content_formats_match_mime_type (content_formats, formats);
|
2017-11-24 09:13:23 +00:00
|
|
|
|
2017-11-24 10:34:19 +00:00
|
|
|
if (mime_type != NULL)
|
2017-11-24 09:13:23 +00:00
|
|
|
{
|
|
|
|
GOutputStream *output_stream;
|
|
|
|
GIOStream *stream;
|
|
|
|
|
|
|
|
stream = gdk_pipe_io_stream_new ();
|
|
|
|
output_stream = g_io_stream_get_output_stream (stream);
|
|
|
|
gdk_clipboard_write_async (clipboard,
|
|
|
|
mime_type,
|
|
|
|
output_stream,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
gdk_clipboard_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);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
2017-11-24 10:15:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("No compatible formats to transfer clipboard contents."));
|
|
|
|
}
|
2017-11-24 05:17:37 +00:00
|
|
|
|
2017-11-24 09:13:23 +00:00
|
|
|
gdk_content_formats_unref (content_formats);
|
2017-11-22 08:25:35 +00:00
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
2017-11-20 01:06:21 +00:00
|
|
|
static GInputStream *
|
2017-11-24 05:17:37 +00:00
|
|
|
gdk_clipboard_read_local_finish (GdkClipboard *clipboard,
|
|
|
|
GAsyncResult *result,
|
2019-04-02 11:37:54 +00:00
|
|
|
const char **out_mime_type,
|
2017-11-24 05:17:37 +00:00
|
|
|
GError **error)
|
2017-11-20 01:06:21 +00:00
|
|
|
{
|
2017-11-24 05:17:37 +00:00
|
|
|
g_return_val_if_fail (g_task_is_valid (result, clipboard), NULL);
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_read_local_async, NULL);
|
|
|
|
|
|
|
|
if (out_mime_type)
|
2017-11-24 09:13:23 +00:00
|
|
|
*out_mime_type = g_task_get_task_data (G_TASK (result));
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
2017-11-20 01:06:21 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 03:55:53 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_class_init (GdkClipboardClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
object_class->get_property = gdk_clipboard_get_property;
|
|
|
|
object_class->set_property = gdk_clipboard_set_property;
|
|
|
|
object_class->finalize = gdk_clipboard_finalize;
|
|
|
|
|
2017-11-24 19:42:40 +00:00
|
|
|
class->claim = gdk_clipboard_real_claim;
|
2017-11-29 22:23:36 +00:00
|
|
|
class->store_async = gdk_clipboard_store_default_async;
|
|
|
|
class->store_finish = gdk_clipboard_store_default_finish;
|
2017-11-24 05:17:37 +00:00
|
|
|
class->read_async = gdk_clipboard_read_local_async;
|
|
|
|
class->read_finish = gdk_clipboard_read_local_finish;
|
2017-11-20 01:06:21 +00:00
|
|
|
|
2014-05-29 03:55:53 +00:00
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* GdkClipboard:display: (attributes org.gtk.Property.get=gdk_clipboard_get_display)
|
2014-05-29 03:55:53 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The `GdkDisplay` that the clipboard belongs to.
|
2014-05-29 03:55:53 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_DISPLAY] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("display", NULL, NULL,
|
2014-05-29 03:55:53 +00:00
|
|
|
GDK_TYPE_DISPLAY,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* GdkClipboard:formats: (attributes org.gtk.Property.get=gdk_clipboard_get_formats)
|
2014-05-29 03:55:53 +00:00
|
|
|
*
|
|
|
|
* The possible formats that the clipboard can provide its data in.
|
|
|
|
*/
|
|
|
|
properties[PROP_FORMATS] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boxed ("formats", NULL, NULL,
|
2014-05-29 03:55:53 +00:00
|
|
|
GDK_TYPE_CONTENT_FORMATS,
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* GdkClipboard:local: (attributes org.gtk.Property.get=gdk_clipboard_is_local)
|
2014-05-29 03:55:53 +00:00
|
|
|
*
|
|
|
|
* %TRUE if the contents of the clipboard are owned by this process.
|
|
|
|
*/
|
|
|
|
properties[PROP_LOCAL] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("local", NULL, NULL,
|
2014-05-29 03:55:53 +00:00
|
|
|
TRUE,
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* GdkClipboard:content: (attributes org.gtk.Property.get=gdk_clipboard_get_content)
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The `GdkContentProvider` or %NULL if the clipboard is empty or contents are
|
2017-11-24 05:17:37 +00:00
|
|
|
* provided otherwise.
|
|
|
|
*/
|
|
|
|
properties[PROP_CONTENT] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("content", NULL, NULL,
|
2017-11-24 05:17:37 +00:00
|
|
|
GDK_TYPE_CONTENT_PROVIDER,
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2017-12-26 19:03:30 +00:00
|
|
|
/**
|
|
|
|
* GdkClipboard::changed:
|
|
|
|
* @clipboard: the object on which the signal was emitted
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Emitted when the clipboard changes ownership.
|
2017-12-26 19:03:30 +00:00
|
|
|
*/
|
2014-05-29 03:55:53 +00:00
|
|
|
signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GdkClipboardClass, changed),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_clipboard_init (GdkClipboard *clipboard)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
priv->formats = gdk_content_formats_new (NULL, 0);
|
2017-11-19 18:18:22 +00:00
|
|
|
priv->local = TRUE;
|
2014-05-29 03:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* gdk_clipboard_get_display: (attributes org.gtk.Method.get_property=display)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2014-05-29 03:55:53 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Gets the `GdkDisplay` that the clipboard was created for.
|
2014-05-29 03:55:53 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: (transfer none): a `GdkDisplay`
|
|
|
|
*/
|
2014-05-29 03:55:53 +00:00
|
|
|
GdkDisplay *
|
|
|
|
gdk_clipboard_get_display (GdkClipboard *clipboard)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), NULL);
|
|
|
|
|
|
|
|
return priv->display;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* gdk_clipboard_get_formats: (attributes org.gtk.Method.get_property=formats)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2014-05-29 03:55:53 +00:00
|
|
|
*
|
|
|
|
* Gets the formats that the clipboard can provide its current contents in.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The formats of the clipboard
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2014-05-29 03:55:53 +00:00
|
|
|
GdkContentFormats *
|
|
|
|
gdk_clipboard_get_formats (GdkClipboard *clipboard)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), NULL);
|
|
|
|
|
|
|
|
return priv->formats;
|
|
|
|
}
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* gdk_clipboard_is_local: (attributes org.gtk.Method.get_property=local)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
*
|
|
|
|
* Returns if the clipboard is local.
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* A clipboard is considered local if it was last claimed
|
|
|
|
* by the running application.
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Note that [method@Gdk.Clipboard.get_content] may return %NULL
|
|
|
|
* even on a local clipboard. In this case the clipboard is empty.
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the clipboard is local
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-24 05:17:37 +00:00
|
|
|
gboolean
|
|
|
|
gdk_clipboard_is_local (GdkClipboard *clipboard)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), FALSE);
|
|
|
|
|
|
|
|
return priv->local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-24 14:10:45 +00:00
|
|
|
* gdk_clipboard_get_content: (attributes org.gtk.Method.get_property=content)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
*
|
|
|
|
* Returns the `GdkContentProvider` currently set on @clipboard.
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* If the @clipboard is empty or its contents are not owned by the
|
|
|
|
* current process, %NULL will be returned.
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2021-05-18 21:05:26 +00:00
|
|
|
* Returns: (transfer none) (nullable): The content of a clipboard
|
|
|
|
* if the clipboard does not maintain any content
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-24 05:17:37 +00:00
|
|
|
GdkContentProvider *
|
|
|
|
gdk_clipboard_get_content (GdkClipboard *clipboard)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), NULL);
|
|
|
|
|
|
|
|
return priv->content;
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:23:36 +00:00
|
|
|
/**
|
|
|
|
* gdk_clipboard_store_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2021-05-22 18:43:11 +00:00
|
|
|
* @io_priority: the I/O priority of the request
|
|
|
|
* @cancellable: (nullable): optional `GCancellable` object
|
2017-11-29 22:23:36 +00:00
|
|
|
* @callback: (scope async): callback to call when the request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Asynchronously instructs the @clipboard to store its contents remotely.
|
|
|
|
*
|
|
|
|
* If the clipboard is not local, this function does nothing but report success.
|
|
|
|
*
|
|
|
|
* The @callback must call [method@Gdk.Clipboard.store_finish].
|
2017-11-29 22:23:36 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The purpose of this call is to preserve clipboard contents beyond the
|
|
|
|
* lifetime of an application, so this function is typically called on
|
|
|
|
* exit. Depending on the platform, the functionality may not be available
|
|
|
|
* unless a "clipboard manager" is running.
|
|
|
|
*
|
|
|
|
* This function is called automatically when a [class@Gtk.Application] is
|
|
|
|
* shut down, so you likely don't need to call it.
|
|
|
|
*/
|
2017-11-29 22:23:36 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_store_async (GdkClipboard *clipboard,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
if (priv->local)
|
|
|
|
{
|
2021-04-16 03:22:27 +00:00
|
|
|
GDK_CLIPBOARD_GET_CLASS (clipboard)->store_async (clipboard,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2017-11-29 22:23:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-16 03:22:27 +00:00
|
|
|
gdk_clipboard_store_default_async (clipboard,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2017-11-29 22:23:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_store_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @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 asynchronous clipboard store.
|
2017-11-29 22:23:36 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* See [method@Gdk.Clipboard.store_async].
|
2017-11-29 22:23:36 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if storing was successful.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-29 22:23:36 +00:00
|
|
|
gboolean
|
|
|
|
gdk_clipboard_store_finish (GdkClipboard *clipboard,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
/* don't check priv->local here because it might have changed while the
|
|
|
|
* read was ongoing */
|
|
|
|
if (g_async_result_is_tagged (result, gdk_clipboard_store_default_async))
|
|
|
|
{
|
|
|
|
return gdk_clipboard_store_default_finish (clipboard, result, error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return GDK_CLIPBOARD_GET_CLASS (clipboard)->store_finish (clipboard, result, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 08:25:35 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_read_internal (GdkClipboard *clipboard,
|
|
|
|
GdkContentFormats *formats,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2017-11-20 01:06:21 +00:00
|
|
|
{
|
2017-11-24 05:17:37 +00:00
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
|
|
|
|
if (priv->local)
|
|
|
|
{
|
2018-05-31 19:29:02 +00:00
|
|
|
gdk_clipboard_read_local_async (clipboard,
|
|
|
|
formats,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-31 19:29:02 +00:00
|
|
|
GDK_CLIPBOARD_GET_CLASS (clipboard)->read_async (clipboard,
|
|
|
|
formats,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
2017-11-22 08:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_read_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2021-08-20 12:57:27 +00:00
|
|
|
* @mime_types: (array zero-terminated=1): a %NULL-terminated array of mime types to choose from
|
2021-02-21 05:13:57 +00:00
|
|
|
* @io_priority: the I/O priority of the request
|
2021-05-22 18:43:11 +00:00
|
|
|
* @cancellable: (nullable): optional `GCancellable` object
|
2017-11-22 08:25:35 +00:00
|
|
|
* @callback: (scope async): callback to call when the request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously requests an input stream to read the @clipboard's
|
2021-02-21 05:13:57 +00:00
|
|
|
* contents from.
|
|
|
|
*
|
|
|
|
* When the operation is finished @callback will be called. You must then
|
|
|
|
* call [method@Gdk.Clipboard.read_finish] to get the result of the operation.
|
2017-11-22 08:25:35 +00:00
|
|
|
*
|
|
|
|
* The clipboard will choose the most suitable mime type from the given list
|
2021-02-21 05:13:57 +00:00
|
|
|
* to fulfill the request, preferring the ones listed first.
|
|
|
|
*/
|
2017-11-22 08:25:35 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_read_async (GdkClipboard *clipboard,
|
|
|
|
const char **mime_types,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GdkContentFormats *formats;
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (mime_types != NULL && mime_types[0] != NULL);
|
2017-11-29 22:23:36 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
2017-11-22 08:25:35 +00:00
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
formats = gdk_content_formats_new (mime_types, g_strv_length ((char **) mime_types));
|
|
|
|
|
|
|
|
gdk_clipboard_read_internal (clipboard, formats, io_priority, cancellable, callback, user_data);
|
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
}
|
2017-11-20 01:06:21 +00:00
|
|
|
|
2017-11-22 08:25:35 +00:00
|
|
|
/**
|
|
|
|
* gdk_clipboard_read_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @result: a `GAsyncResult`
|
2021-05-22 18:43:11 +00:00
|
|
|
* @out_mime_type: (out) (optional) (transfer none): location to store
|
2021-05-18 21:05:26 +00:00
|
|
|
* the chosen mime type
|
|
|
|
* @error: a `GError` location to store the error occurring
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* Finishes an asynchronous clipboard read.
|
2017-11-22 08:25:35 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* See [method@Gdk.Clipboard.read_async].
|
2017-11-22 08:25:35 +00:00
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (transfer full) (nullable): a `GInputStream`
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-22 08:25:35 +00:00
|
|
|
GInputStream *
|
|
|
|
gdk_clipboard_read_finish (GdkClipboard *clipboard,
|
|
|
|
GAsyncResult *result,
|
2019-04-02 11:37:54 +00:00
|
|
|
const char **out_mime_type,
|
2017-11-22 08:25:35 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2017-11-20 01:06:21 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), NULL);
|
2017-11-22 08:25:35 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2017-11-20 01:06:21 +00:00
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
/* don't check priv->local here because it might have changed while the
|
|
|
|
* read was ongoing */
|
|
|
|
if (g_async_result_is_tagged (result, gdk_clipboard_read_local_async))
|
|
|
|
{
|
2019-04-02 11:37:54 +00:00
|
|
|
return gdk_clipboard_read_local_finish (clipboard, result, out_mime_type, error);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-02 11:37:54 +00:00
|
|
|
return GDK_CLIPBOARD_GET_CLASS (clipboard)->read_finish (clipboard, result, out_mime_type, error);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
2017-11-20 01:06:21 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 09:44:30 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_read_value_done (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GTask *task = data;
|
|
|
|
GError *error = NULL;
|
2017-11-24 05:07:09 +00:00
|
|
|
GValue *value;
|
2017-11-22 09:44:30 +00:00
|
|
|
|
2017-11-24 05:07:09 +00:00
|
|
|
value = g_task_get_task_data (task);
|
|
|
|
|
|
|
|
if (!gdk_content_deserialize_finish (result, value, &error))
|
2017-11-22 09:44:30 +00:00
|
|
|
g_task_return_error (task, error);
|
|
|
|
else
|
2017-11-24 05:07:09 +00:00
|
|
|
g_task_return_pointer (task, value, NULL);
|
2017-11-22 09:44:30 +00:00
|
|
|
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_clipboard_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:37:54 +00:00
|
|
|
stream = gdk_clipboard_read_finish (GDK_CLIPBOARD (source), result, &mime_type, &error);
|
2017-11-22 09:44:30 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_content_deserialize_async (stream,
|
|
|
|
mime_type,
|
2017-11-24 05:07:09 +00:00
|
|
|
G_VALUE_TYPE (g_task_get_task_data (task)),
|
2017-11-22 09:44:30 +00:00
|
|
|
g_task_get_priority (task),
|
|
|
|
g_task_get_cancellable (task),
|
|
|
|
gdk_clipboard_read_value_done,
|
|
|
|
task);
|
|
|
|
g_object_unref (stream);
|
|
|
|
}
|
|
|
|
|
2017-11-24 05:07:09 +00:00
|
|
|
static void
|
|
|
|
free_value (gpointer value)
|
|
|
|
{
|
|
|
|
g_value_unset (value);
|
|
|
|
g_slice_free (GValue, value);
|
|
|
|
}
|
|
|
|
|
2017-11-22 12:21:25 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
|
|
|
|
GType type,
|
|
|
|
gpointer source_tag,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2017-11-24 05:17:37 +00:00
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
2017-11-22 12:21:25 +00:00
|
|
|
GdkContentFormatsBuilder *builder;
|
|
|
|
GdkContentFormats *formats;
|
2017-11-24 05:07:09 +00:00
|
|
|
GValue *value;
|
2017-11-22 12:21:25 +00:00
|
|
|
GTask *task;
|
2017-11-24 05:17:37 +00:00
|
|
|
|
2017-11-22 12:21:25 +00:00
|
|
|
task = g_task_new (clipboard, cancellable, callback, user_data);
|
|
|
|
g_task_set_priority (task, io_priority);
|
|
|
|
g_task_set_source_tag (task, source_tag);
|
2017-11-24 05:07:09 +00:00
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
g_value_init (value, type);
|
|
|
|
g_task_set_task_data (task, value, free_value);
|
2017-11-22 12:21:25 +00:00
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
if (priv->local)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (priv->content == NULL)
|
|
|
|
{
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
|
|
|
_("Cannot read from empty clipboard."));
|
|
|
|
g_object_unref (task);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gdk_content_provider_get_value (priv->content, value, &error))
|
|
|
|
{
|
|
|
|
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);
|
Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.
The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.
A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.
For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.
For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.
https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-01 16:43:15 +00:00
|
|
|
formats = gdk_content_formats_builder_free_to_formats (builder);
|
2017-11-24 05:17:37 +00:00
|
|
|
formats = gdk_content_formats_union_deserialize_mime_types (formats);
|
|
|
|
|
2017-11-22 12:21:25 +00:00
|
|
|
gdk_clipboard_read_internal (clipboard,
|
|
|
|
formats,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
gdk_clipboard_read_value_got_stream,
|
|
|
|
task);
|
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
}
|
|
|
|
|
2017-11-22 09:44:30 +00:00
|
|
|
/**
|
|
|
|
* gdk_clipboard_read_value_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @type: a `GType` to read
|
|
|
|
* @io_priority: the I/O priority of the request
|
2021-05-20 03:39:18 +00:00
|
|
|
* @cancellable: (nullable): optional `GCancellable` object
|
2017-11-22 09:44:30 +00:00
|
|
|
* @callback: (scope async): callback to call when the request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously request the @clipboard contents converted to the given
|
2021-02-21 05:13:57 +00:00
|
|
|
* @type.
|
2017-11-22 09:44:30 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* When the operation is finished @callback will be called. You must then call
|
|
|
|
* [method@Gdk.Clipboard.read_value_finish] to get the resulting `GValue`.
|
|
|
|
*
|
|
|
|
* For local clipboard contents that are available in the given `GType`,
|
|
|
|
* the value will be copied directly. Otherwise, GDK will try to use
|
|
|
|
* [func@content_deserialize_async] to convert the clipboard's data.
|
|
|
|
*/
|
2017-11-22 09:44:30 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_read_value_async (GdkClipboard *clipboard,
|
|
|
|
GType type,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2017-11-22 12:21:25 +00:00
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
g_return_if_fail (callback != NULL);
|
2017-11-22 09:44:30 +00:00
|
|
|
|
2017-11-22 12:21:25 +00:00
|
|
|
gdk_clipboard_read_value_internal (clipboard,
|
|
|
|
type,
|
|
|
|
gdk_clipboard_read_value_async,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2017-11-22 09:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_read_value_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @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 asynchronous clipboard read.
|
2017-11-22 09:44:30 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* See [method@Gdk.Clipboard.read_value_async].
|
2017-11-22 09:44:30 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Returns: (transfer none): a `GValue` containing the result.
|
|
|
|
*/
|
2017-11-22 09:44:30 +00:00
|
|
|
const GValue *
|
|
|
|
gdk_clipboard_read_value_finish (GdkClipboard *clipboard,
|
2017-12-05 07:52:48 +00:00
|
|
|
GAsyncResult *result,
|
2017-11-22 09:44:30 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2017-12-05 07:52:48 +00:00
|
|
|
g_return_val_if_fail (g_task_is_valid (result, clipboard), NULL);
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_read_value_async, NULL);
|
2017-11-22 12:21:25 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2017-11-22 09:44:30 +00:00
|
|
|
|
2017-12-05 07:52:48 +00:00
|
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
2017-11-22 09:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 12:21:25 +00:00
|
|
|
/**
|
2017-12-02 13:38:57 +00:00
|
|
|
* gdk_clipboard_read_texture_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @cancellable: (nullable): optional `GCancellable` object, %NULL to ignore.
|
2017-11-22 12:21:25 +00:00
|
|
|
* @callback: (scope async): callback to call when the request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Asynchronously request the @clipboard contents converted to a `GdkPixbuf`.
|
|
|
|
*
|
|
|
|
* When the operation is finished @callback will be called. You must then
|
|
|
|
* call [method@Gdk.Clipboard.read_texture_finish] to get the result.
|
2017-11-22 12:21:25 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
|
2021-05-25 11:33:55 +00:00
|
|
|
* Use that function or [method@Gdk.Clipboard.read_async] directly if you
|
2021-02-21 05:13:57 +00:00
|
|
|
* need more control over the operation.
|
|
|
|
*/
|
2017-11-22 12:21:25 +00:00
|
|
|
void
|
2017-12-02 13:38:57 +00:00
|
|
|
gdk_clipboard_read_texture_async (GdkClipboard *clipboard,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2017-11-22 12:21:25 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
gdk_clipboard_read_value_internal (clipboard,
|
2017-12-02 13:38:57 +00:00
|
|
|
GDK_TYPE_TEXTURE,
|
|
|
|
gdk_clipboard_read_texture_async,
|
2017-11-22 12:21:25 +00:00
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 13:38:57 +00:00
|
|
|
* gdk_clipboard_read_texture_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @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 asynchronous clipboard read.
|
2017-11-22 12:21:25 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* See [method@Gdk.Clipboard.read_texture_async].
|
2017-11-22 12:21:25 +00:00
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (transfer full) (nullable): a new `GdkTexture`
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-12-02 13:38:57 +00:00
|
|
|
GdkTexture *
|
|
|
|
gdk_clipboard_read_texture_finish (GdkClipboard *clipboard,
|
2017-12-05 07:52:48 +00:00
|
|
|
GAsyncResult *result,
|
2017-12-02 13:38:57 +00:00
|
|
|
GError **error)
|
2017-11-22 12:21:25 +00:00
|
|
|
{
|
|
|
|
const GValue *value;
|
|
|
|
|
2017-12-05 07:52:48 +00:00
|
|
|
g_return_val_if_fail (g_task_is_valid (result, clipboard), NULL);
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_read_texture_async, NULL);
|
2017-11-22 12:21:25 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2017-12-05 07:52:48 +00:00
|
|
|
value = g_task_propagate_pointer (G_TASK (result), error);
|
2017-11-22 12:21:25 +00:00
|
|
|
if (!value)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_value_dup_object (value);
|
|
|
|
}
|
|
|
|
|
2017-11-22 13:19:02 +00:00
|
|
|
/**
|
|
|
|
* gdk_clipboard_read_text_async:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2021-05-22 18:43:11 +00:00
|
|
|
* @cancellable: (nullable): optional `GCancellable` object
|
2017-11-22 13:19:02 +00:00
|
|
|
* @callback: (scope async): callback to call when the request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously request the @clipboard contents converted to a string.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* When the operation is finished @callback will be called. You must then
|
|
|
|
* call [method@Gdk.Clipboard.read_text_finish] to get the result.
|
|
|
|
*
|
|
|
|
* This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
|
|
|
|
* Use that function or [method@Gdk.Clipboard.read_async] directly if you
|
|
|
|
* need more control over the operation.
|
|
|
|
*/
|
2017-11-22 13:19:02 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_read_text_async (GdkClipboard *clipboard,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
gdk_clipboard_read_value_internal (clipboard,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
gdk_clipboard_read_text_async,
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_read_text_finish:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @result: a `GAsyncResult`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @error: a `GError` location to store the error occurring
|
2017-11-22 13:19:02 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Finishes an asynchronous clipboard read.
|
2017-11-22 13:19:02 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* See [method@Gdk.Clipboard.read_text_async].
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (transfer full) (nullable): a new string
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-22 13:19:02 +00:00
|
|
|
char *
|
|
|
|
gdk_clipboard_read_text_finish (GdkClipboard *clipboard,
|
2017-12-05 07:52:48 +00:00
|
|
|
GAsyncResult *result,
|
2017-11-22 13:19:02 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
const GValue *value;
|
|
|
|
|
2017-12-05 07:52:48 +00:00
|
|
|
g_return_val_if_fail (g_task_is_valid (result, clipboard), NULL);
|
2017-12-05 11:02:20 +00:00
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_read_text_async, NULL);
|
2017-11-22 13:19:02 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2017-12-05 07:52:48 +00:00
|
|
|
value = g_task_propagate_pointer (G_TASK (result), error);
|
2017-11-22 13:19:02 +00:00
|
|
|
if (!value)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_value_dup_string (value);
|
|
|
|
}
|
|
|
|
|
2014-05-29 03:55:53 +00:00
|
|
|
GdkClipboard *
|
|
|
|
gdk_clipboard_new (GdkDisplay *display)
|
|
|
|
{
|
|
|
|
return g_object_new (GDK_TYPE_CLIPBOARD,
|
|
|
|
"display", display,
|
|
|
|
NULL);
|
|
|
|
}
|
2017-11-19 18:18:22 +00:00
|
|
|
|
2017-11-24 09:13:23 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_write_done (GObject *content,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer task)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (gdk_content_provider_write_mime_type_finish (GDK_CONTENT_PROVIDER (content), result, &error))
|
|
|
|
g_task_return_boolean (task, TRUE);
|
|
|
|
else
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
2017-11-24 10:15:51 +00:00
|
|
|
static void
|
|
|
|
gdk_clipboard_write_serialize_done (GObject *content,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer task)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (gdk_content_serialize_finish (result, &error))
|
|
|
|
g_task_return_boolean (task, TRUE);
|
|
|
|
else
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
2018-09-03 22:36:56 +00:00
|
|
|
|
2017-11-24 09:13:23 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_write_async (GdkClipboard *clipboard,
|
|
|
|
const char *mime_type,
|
|
|
|
GOutputStream *stream,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
2017-11-24 10:15:51 +00:00
|
|
|
GdkContentFormats *formats, *mime_formats;
|
2017-11-24 09:13:23 +00:00
|
|
|
GTask *task;
|
2017-11-24 10:15:51 +00:00
|
|
|
GType gtype;
|
2017-11-24 09:13:23 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (priv->local);
|
|
|
|
g_return_if_fail (mime_type != NULL);
|
|
|
|
g_return_if_fail (mime_type == g_intern_string (mime_type));
|
|
|
|
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
|
|
|
task = g_task_new (clipboard, cancellable, callback, user_data);
|
|
|
|
g_task_set_priority (task, io_priority);
|
|
|
|
g_task_set_source_tag (task, gdk_clipboard_write_async);
|
|
|
|
|
|
|
|
if (priv->content == NULL)
|
|
|
|
{
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
|
|
|
_("Cannot read from empty clipboard."));
|
|
|
|
g_object_unref (task);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
formats = gdk_content_provider_ref_formats (priv->content);
|
|
|
|
if (gdk_content_formats_contain_mime_type (formats, mime_type))
|
|
|
|
{
|
|
|
|
gdk_content_provider_write_mime_type_async (priv->content,
|
|
|
|
mime_type,
|
|
|
|
stream,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
gdk_clipboard_write_done,
|
|
|
|
task);
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
mime_formats = gdk_content_formats_new ((const char *[2]) { mime_type, NULL }, 1);
|
2017-11-24 10:15:51 +00:00
|
|
|
mime_formats = gdk_content_formats_union_serialize_gtypes (mime_formats);
|
2017-11-24 10:34:19 +00:00
|
|
|
gtype = gdk_content_formats_match_gtype (formats, mime_formats);
|
|
|
|
if (gtype != G_TYPE_INVALID)
|
2017-11-24 10:15:51 +00:00
|
|
|
{
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_assert (gtype != G_TYPE_INVALID);
|
|
|
|
|
|
|
|
g_value_init (&value, gtype);
|
|
|
|
if (gdk_content_provider_get_value (priv->content, &value, &error))
|
|
|
|
{
|
|
|
|
gdk_content_serialize_async (stream,
|
|
|
|
mime_type,
|
|
|
|
&value,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
gdk_clipboard_write_serialize_done,
|
|
|
|
g_object_ref (task));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("No compatible formats to transfer clipboard contents."));
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_content_formats_unref (mime_formats);
|
2017-11-24 09:13:23 +00:00
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_clipboard_write_finish (GdkClipboard *clipboard,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, clipboard), FALSE);
|
|
|
|
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_write_async, FALSE);
|
|
|
|
|
|
|
|
return g_task_propagate_boolean (G_TASK (result), error);
|
|
|
|
}
|
|
|
|
|
2017-11-24 19:42:40 +00:00
|
|
|
static gboolean
|
2017-11-24 05:17:37 +00:00
|
|
|
gdk_clipboard_claim (GdkClipboard *clipboard,
|
|
|
|
GdkContentFormats *formats,
|
|
|
|
gboolean local,
|
|
|
|
GdkContentProvider *content)
|
2017-11-19 18:18:22 +00:00
|
|
|
{
|
2017-11-24 19:42:40 +00:00
|
|
|
return GDK_CLIPBOARD_GET_CLASS (clipboard)->claim (clipboard, formats, local, content);
|
2017-11-19 18:18:22 +00:00
|
|
|
}
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_clipboard_content_changed_cb (GdkContentProvider *provider,
|
|
|
|
GdkClipboard *clipboard)
|
|
|
|
{
|
|
|
|
GdkContentFormats *formats;
|
|
|
|
|
|
|
|
formats = gdk_content_provider_ref_formats (provider);
|
2017-11-24 10:15:51 +00:00
|
|
|
formats = gdk_content_formats_union_serialize_mime_types (formats);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
gdk_clipboard_claim (clipboard, formats, TRUE, provider);
|
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_clipboard_claim_remote (GdkClipboard *clipboard,
|
|
|
|
GdkContentFormats *formats)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (formats != NULL);
|
|
|
|
|
|
|
|
gdk_clipboard_claim (clipboard, formats, FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_set_content:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2021-05-19 11:24:34 +00:00
|
|
|
* @provider: (transfer none) (nullable): the new contents of @clipboard
|
2021-05-18 21:05:26 +00:00
|
|
|
* or %NULL to clear the clipboard
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Sets a new content provider on @clipboard.
|
|
|
|
*
|
|
|
|
* The clipboard will claim the `GdkDisplay`'s resources and advertise
|
|
|
|
* these new contents to other applications.
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2017-11-24 19:42:40 +00:00
|
|
|
* In the rare case of a failure, this function will return %FALSE. The
|
|
|
|
* clipboard will then continue reporting its old contents and ignore
|
|
|
|
* @provider.
|
|
|
|
*
|
2017-11-24 05:17:37 +00:00
|
|
|
* If the contents are read by either an external application or the
|
|
|
|
* @clipboard's read functions, @clipboard will select the best format to
|
|
|
|
* transfer the contents and then request that format from @provider.
|
2017-11-24 19:42:40 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if setting the clipboard succeeded
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-24 19:42:40 +00:00
|
|
|
gboolean
|
2017-11-24 05:17:37 +00:00
|
|
|
gdk_clipboard_set_content (GdkClipboard *clipboard,
|
|
|
|
GdkContentProvider *provider)
|
|
|
|
{
|
|
|
|
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
|
|
|
|
GdkContentFormats *formats;
|
2017-11-24 19:42:40 +00:00
|
|
|
gboolean result;
|
2017-11-24 05:17:37 +00:00
|
|
|
|
2017-11-24 19:42:40 +00:00
|
|
|
g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), FALSE);
|
|
|
|
g_return_val_if_fail (provider == NULL || GDK_IS_CONTENT_PROVIDER (provider), FALSE);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
if (provider)
|
|
|
|
{
|
|
|
|
if (priv->content == provider)
|
2017-11-24 19:42:40 +00:00
|
|
|
return TRUE;
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
formats = gdk_content_provider_ref_formats (provider);
|
2017-11-24 10:15:51 +00:00
|
|
|
formats = gdk_content_formats_union_serialize_mime_types (formats);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (priv->content == NULL && priv->local)
|
2017-11-24 19:42:40 +00:00
|
|
|
return TRUE;
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
formats = gdk_content_formats_new (NULL, 0);
|
|
|
|
}
|
|
|
|
|
2017-11-24 19:42:40 +00:00
|
|
|
result = gdk_clipboard_claim (clipboard, formats, TRUE, provider);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
2017-11-24 19:42:40 +00:00
|
|
|
|
|
|
|
return result;
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-05 07:09:54 +00:00
|
|
|
* gdk_clipboard_set:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2017-12-05 07:09:54 +00:00
|
|
|
* @type: type of value to set
|
|
|
|
* @...: value contents conforming to @type
|
2017-12-05 03:06:20 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Sets the clipboard to contain the value collected from the given varargs.
|
2021-11-01 12:54:07 +00:00
|
|
|
*
|
2021-08-22 18:49:12 +00:00
|
|
|
* Values should be passed the same way they are passed to other value
|
|
|
|
* collecting APIs, such as [`method@GObject.Object.set`] or
|
2021-11-01 12:54:07 +00:00
|
|
|
* [`func@GObject.signal_emit`].
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
|
|
|
* ```c
|
2021-08-22 18:49:12 +00:00
|
|
|
* gdk_clipboard_set (clipboard, GTK_TYPE_STRING, "Hello World");
|
2021-11-01 12:54:07 +00:00
|
|
|
*
|
2021-08-22 18:49:12 +00:00
|
|
|
* gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture);
|
2021-02-21 05:13:57 +00:00
|
|
|
* ```
|
|
|
|
*/
|
2017-12-05 03:06:20 +00:00
|
|
|
void
|
2021-02-21 05:13:57 +00:00
|
|
|
gdk_clipboard_set (GdkClipboard *clipboard,
|
|
|
|
GType type,
|
2017-12-05 07:09:54 +00:00
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
|
|
|
|
va_start (args, type);
|
|
|
|
gdk_clipboard_set_valist (clipboard, type, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_set_valist: (skip)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2017-12-05 07:09:54 +00:00
|
|
|
* @type: type of value to set
|
|
|
|
* @args: varargs containing the value of @type
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* Sets the clipboard to contain the value collected from the given @args.
|
|
|
|
*/
|
2017-12-05 07:09:54 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_set_valist (GdkClipboard *clipboard,
|
|
|
|
GType type,
|
|
|
|
va_list args)
|
2017-11-24 05:17:37 +00:00
|
|
|
{
|
|
|
|
GValue value = G_VALUE_INIT;
|
2017-12-05 07:09:54 +00:00
|
|
|
char *error;
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
|
2017-12-05 07:09:54 +00:00
|
|
|
G_VALUE_COLLECT_INIT (&value, type,
|
|
|
|
args, G_VALUE_NOCOPY_CONTENTS,
|
|
|
|
&error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("%s: %s", G_STRLOC, error);
|
|
|
|
g_free (error);
|
|
|
|
/* we purposely leak the value here, it might not be
|
2020-06-18 07:47:16 +00:00
|
|
|
* in a sane state if an error condition occurred
|
2017-12-05 07:09:54 +00:00
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_clipboard_set_value (clipboard, &value);
|
2017-11-24 05:17:37 +00:00
|
|
|
g_value_unset (&value);
|
2017-12-05 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_set_value: (rename-to gdk_clipboard_set)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @value: a `GValue` to set
|
2017-12-05 07:09:54 +00:00
|
|
|
*
|
|
|
|
* Sets the @clipboard to contain the given @value.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-12-05 07:09:54 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_set_value (GdkClipboard *clipboard,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
|
|
|
GdkContentProvider *provider;
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
g_return_if_fail (G_IS_VALUE (value));
|
|
|
|
|
|
|
|
provider = gdk_content_provider_new_for_value (value);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
gdk_clipboard_set_content (clipboard, provider);
|
|
|
|
g_object_unref (provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-05 07:09:54 +00:00
|
|
|
* gdk_clipboard_set_text: (skip)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
2017-12-05 07:09:54 +00:00
|
|
|
* @text: Text to put into the clipboard
|
|
|
|
*
|
|
|
|
* Puts the given @text into the clipboard.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-12-05 07:09:54 +00:00
|
|
|
void
|
|
|
|
gdk_clipboard_set_text (GdkClipboard *clipboard,
|
|
|
|
const char *text)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
|
|
|
|
|
|
|
gdk_clipboard_set (clipboard, G_TYPE_STRING, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_clipboard_set_texture: (skip)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @clipboard: a `GdkClipboard`
|
|
|
|
* @texture: a `GdkTexture` to put into the clipboard
|
2017-11-24 05:17:37 +00:00
|
|
|
*
|
2017-12-02 13:38:57 +00:00
|
|
|
* Puts the given @texture into the clipboard.
|
2021-02-21 05:13:57 +00:00
|
|
|
*/
|
2017-11-24 05:17:37 +00:00
|
|
|
void
|
2017-12-02 13:38:57 +00:00
|
|
|
gdk_clipboard_set_texture (GdkClipboard *clipboard,
|
|
|
|
GdkTexture *texture)
|
2017-11-24 05:17:37 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
2017-12-02 13:38:57 +00:00
|
|
|
g_return_if_fail (GDK_IS_TEXTURE (texture));
|
2017-11-24 05:17:37 +00:00
|
|
|
|
2017-12-05 07:09:54 +00:00
|
|
|
gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, texture);
|
2017-11-24 05:17:37 +00:00
|
|
|
}
|