From 0616261a9455574fc26b452343b6bf9b8e0400b1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 9 Nov 2011 11:19:47 -0500 Subject: [PATCH] st-clipboard: Add the ability to choose the clipboard type https://bugzilla.gnome.org/show_bug.cgi?id=645019 --- js/ui/shellEntry.js | 6 +++--- src/st/st-clipboard.c | 24 +++++++++++++++++++----- src/st/st-clipboard.h | 7 +++++++ src/st/st-entry.c | 13 ++++++++++--- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/js/ui/shellEntry.js b/js/ui/shellEntry.js index 18fe7d199..6952a3e20 100644 --- a/js/ui/shellEntry.js +++ b/js/ui/shellEntry.js @@ -90,7 +90,7 @@ const EntryMenu = new Lang.Class({ }, _updatePasteItem: function() { - this._clipboard.get_text(Lang.bind(this, + this._clipboard.get_text(St.ClipboardType.CLIPBOARD, Lang.bind(this, function(clipboard, text) { this._pasteItem.setSensitive(text && text != ''); })); @@ -106,11 +106,11 @@ const EntryMenu = new Lang.Class({ _onCopyActivated: function() { let selection = this._entry.clutter_text.get_selection(); - this._clipboard.set_text(selection); + this._clipboard.set_text(St.ClipboardType.CLIPBOARD, selection); }, _onPasteActivated: function() { - this._clipboard.get_text(Lang.bind(this, + this._clipboard.get_text(St.ClipboardType.CLIPBOARD, Lang.bind(this, function(clipboard, text) { if (!text) return; diff --git a/src/st/st-clipboard.c b/src/st/st-clipboard.c index 6d98c959d..c4458e208 100644 --- a/src/st/st-clipboard.c +++ b/src/st/st-clipboard.c @@ -55,6 +55,7 @@ struct _EventFilterData gpointer user_data; }; +static Atom __atom_primary = None; static Atom __atom_clip = None; static Atom __utf8_string = None; static Atom __atom_targets = None; @@ -197,6 +198,9 @@ st_clipboard_init (StClipboard *self) dpy = clutter_x11_get_default_display (); /* Only create once */ + if (__atom_primary == None) + __atom_primary = XInternAtom (dpy, "PRIMARY", 0); + if (__atom_clip == None) __atom_clip = XInternAtom (dpy, "CLIPBOARD", 0); @@ -298,9 +302,16 @@ st_clipboard_get_default (void) return default_clipboard; } +static Atom +atom_for_clipboard_type (StClipboardType type) +{ + return type == ST_CLIPBOARD_TYPE_CLIPBOARD ? __atom_clip : __atom_primary; +} + /** * st_clipboard_get_text: * @clipboard: A #StCliboard + * @type: The type of clipboard data you want * @callback: (scope async): function to be called when the text is retreived * @user_data: data to be passed to the callback * @@ -310,6 +321,7 @@ st_clipboard_get_default (void) */ void st_clipboard_get_text (StClipboard *clipboard, + StClipboardType type, StClipboardCallbackFunc callback, gpointer user_data) { @@ -333,7 +345,7 @@ st_clipboard_get_text (StClipboard *clipboard, clutter_x11_trap_x_errors (); /* safety on */ XConvertSelection (dpy, - __atom_clip, + atom_for_clipboard_type (type), __utf8_string, __utf8_string, clipboard->priv->clipboard_window, CurrentTime); @@ -344,14 +356,15 @@ st_clipboard_get_text (StClipboard *clipboard, /** * st_clipboard_set_text: * @clipboard: A #StClipboard + * @type: The type of clipboard that you want to set * @text: text to copy to the clipboard * * Sets text as the current contents of the clipboard. - * */ void -st_clipboard_set_text (StClipboard *clipboard, - const gchar *text) +st_clipboard_set_text (StClipboard *clipboard, + StClipboardType type, + const gchar *text) { StClipboardPrivate *priv; Display *dpy; @@ -370,7 +383,8 @@ st_clipboard_set_text (StClipboard *clipboard, clutter_x11_trap_x_errors (); - XSetSelectionOwner (dpy, __atom_clip, priv->clipboard_window, CurrentTime); + XSetSelectionOwner (dpy, atom_for_clipboard_type (type), priv->clipboard_window, CurrentTime); + XSync (dpy, FALSE); clutter_x11_untrap_x_errors (); diff --git a/src/st/st-clipboard.h b/src/st/st-clipboard.h index 20759d43d..ca45499e1 100644 --- a/src/st/st-clipboard.h +++ b/src/st/st-clipboard.h @@ -72,6 +72,11 @@ struct _StClipboardClass GObjectClass parent_class; }; +typedef enum { + ST_CLIPBOARD_TYPE_PRIMARY, + ST_CLIPBOARD_TYPE_CLIPBOARD +} StClipboardType; + /** * StClipboardCallbackFunc: * @clipboard: A #StClipboard @@ -89,9 +94,11 @@ GType st_clipboard_get_type (void); StClipboard* st_clipboard_get_default (void); void st_clipboard_get_text (StClipboard *clipboard, + StClipboardType type, StClipboardCallbackFunc callback, gpointer user_data); void st_clipboard_set_text (StClipboard *clipboard, + StClipboardType type, const gchar *text); G_END_DECLS diff --git a/src/st/st-entry.c b/src/st/st-entry.c index 4cd1da6fa..000c8ac48 100644 --- a/src/st/st-entry.c +++ b/src/st/st-entry.c @@ -559,7 +559,10 @@ st_entry_key_press_event (ClutterActor *actor, clipboard = st_clipboard_get_default (); - st_clipboard_get_text (clipboard, st_entry_clipboard_callback, actor); + st_clipboard_get_text (clipboard, + ST_CLIPBOARD_TYPE_CLIPBOARD, + st_entry_clipboard_callback, + actor); return TRUE; } @@ -576,7 +579,9 @@ st_entry_key_press_event (ClutterActor *actor, text = clutter_text_get_selection ((ClutterText*) priv->entry); if (text && strlen (text)) - st_clipboard_set_text (clipboard, text); + st_clipboard_set_text (clipboard, + ST_CLIPBOARD_TYPE_CLIPBOARD, + text); return TRUE; } @@ -595,7 +600,9 @@ st_entry_key_press_event (ClutterActor *actor, if (text && strlen (text)) { - st_clipboard_set_text (clipboard, text); + st_clipboard_set_text (clipboard, + ST_CLIPBOARD_TYPE_CLIPBOARD, + text); /* now delete the text */ clutter_text_delete_selection ((ClutterText *) priv->entry);