From a58bdbfbd4f0dc8e045171182bf9ce7d8c381ea6 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 6 Nov 2019 00:40:17 +0100 Subject: [PATCH] st: Add StClipboard method to set arbitrary clipboard content This complements the current text-based API. https://gitlab.gnome.org/GNOME/mutter/issues/789 https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/810 --- src/st/st-clipboard.c | 39 +++++++++++++++++++++++++++++++-------- src/st/st-clipboard.h | 5 +++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/st/st-clipboard.c b/src/st/st-clipboard.c index b2d8e7f94..1dcd1e75f 100644 --- a/src/st/st-clipboard.c +++ b/src/st/st-clipboard.c @@ -194,6 +194,36 @@ st_clipboard_get_text (StClipboard *clipboard, data); } +/** + * st_clipboard_set_content: + * @clipboard: A #StClipboard + * @type: The type of clipboard that you want to set + * @mimetype: content mimetype + * @bytes: content data + * + * Sets the clipboard content. + **/ +void +st_clipboard_set_content (StClipboard *clipboard, + StClipboardType type, + const gchar *mimetype, + GBytes *bytes) +{ + MetaSelectionType selection_type; + MetaSelectionSource *source; + + g_return_if_fail (ST_IS_CLIPBOARD (clipboard)); + g_return_if_fail (meta_selection != NULL); + g_return_if_fail (bytes != NULL); + + if (!convert_type (type, &selection_type)) + return; + + source = meta_selection_source_memory_new (mimetype, bytes); + meta_selection_set_owner (meta_selection, selection_type, source); + g_object_unref (source); +} + /** * st_clipboard_set_text: * @clipboard: A #StClipboard @@ -207,22 +237,15 @@ st_clipboard_set_text (StClipboard *clipboard, StClipboardType type, const gchar *text) { - MetaSelectionType selection_type; - MetaSelectionSource *source; GBytes *bytes; g_return_if_fail (ST_IS_CLIPBOARD (clipboard)); g_return_if_fail (meta_selection != NULL); g_return_if_fail (text != NULL); - if (!convert_type (type, &selection_type)) - return; - bytes = g_bytes_new_take (g_strdup (text), strlen (text)); - source = meta_selection_source_memory_new ("text/plain;charset=utf-8", bytes); + st_clipboard_set_content (clipboard, type, "text/plain;charset=utf-8", bytes); g_bytes_unref (bytes); - - meta_selection_set_owner (meta_selection, selection_type, source); } void diff --git a/src/st/st-clipboard.h b/src/st/st-clipboard.h index 86e67e1ee..60e384601 100644 --- a/src/st/st-clipboard.h +++ b/src/st/st-clipboard.h @@ -73,6 +73,11 @@ void st_clipboard_set_text (StClipboard *clipboard, StClipboardType type, const gchar *text); +void st_clipboard_set_content (StClipboard *clipboard, + StClipboardType type, + const gchar *mimetype, + GBytes *bytes); + void st_clipboard_set_selection (MetaSelection *selection); G_END_DECLS