clipboard: Add gdk_clipboard_claim_remote()

This allows the remote clipboard to take over. The X11 clipboard already
does that.
This commit is contained in:
Benjamin Otte 2017-11-19 19:18:22 +01:00
parent 4728dd0a9e
commit a5ab9a9671
3 changed files with 29 additions and 0 deletions

View File

@ -188,6 +188,7 @@ gdk_clipboard_init (GdkClipboard *clipboard)
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
priv->formats = gdk_content_formats_new (NULL, 0);
priv->local = TRUE;
}
/**
@ -233,3 +234,24 @@ gdk_clipboard_new (GdkDisplay *display)
"display", display,
NULL);
}
void
gdk_clipboard_claim_remote (GdkClipboard *clipboard,
GdkContentFormats *formats)
{
GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
g_return_if_fail (formats != NULL);
gdk_content_formats_unref (priv->formats);
priv->formats = gdk_content_formats_ref (formats);
g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_FORMATS]);
if (priv->local)
{
priv->local = FALSE;
g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_LOCAL]);
}
g_signal_emit (clipboard, signals[CHANGED], 0);
}

View File

@ -45,6 +45,8 @@ struct _GdkClipboardClass
GdkClipboard * gdk_clipboard_new (GdkDisplay *display);
void gdk_clipboard_claim_remote (GdkClipboard *clipboard,
GdkContentFormats *formats);
G_END_DECLS

View File

@ -115,9 +115,14 @@ gdk_x11_clipboard_request_targets_finish (GObject *source_object,
{
gdk_content_formats_builder_add_mime_type (builder, gdk_x11_get_xatom_name_for_display (display , atoms[i]));
}
gdk_content_formats_builder_add_formats (builder, gdk_clipboard_get_formats (GDK_CLIPBOARD (cb)));
formats = gdk_content_formats_builder_free (builder);
GDK_NOTE(CLIPBOARD, char *s = gdk_content_formats_to_string (formats); g_printerr ("%s: got formats: %s\n", cb->selection, s); g_free (s));
/* union with previously loaded formats */
gdk_clipboard_claim_remote (GDK_CLIPBOARD (cb), formats);
gdk_content_formats_unref (formats);
g_input_stream_read_bytes_async (stream,
SELECTION_MAX_SIZE (display),
G_PRIORITY_DEFAULT,