st-clipboard: Add the ability to choose the clipboard type

https://bugzilla.gnome.org/show_bug.cgi?id=645019
This commit is contained in:
Jasper St. Pierre 2011-11-09 11:19:47 -05:00
parent d2c45f428f
commit 0616261a94
4 changed files with 39 additions and 11 deletions

View File

@ -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;

View File

@ -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,13 +356,14 @@ 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,
StClipboardType type,
const gchar *text)
{
StClipboardPrivate *priv;
@ -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 ();

View File

@ -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

View File

@ -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);