From eaf184b5852825d49c85c683bd7bde96df02baf2 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 9 Nov 2011 11:40:13 -0500 Subject: [PATCH] st-entry: Implement middle click paste https://bugzilla.gnome.org/show_bug.cgi?id=645019 --- src/st/st-entry.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/st/st-entry.c b/src/st/st-entry.c index 000c8ac48..4d0e024d3 100644 --- a/src/st/st-entry.c +++ b/src/st/st-entry.c @@ -541,6 +541,38 @@ st_entry_clipboard_callback (StClipboard *clipboard, clutter_text_insert_text (ctext, text, cursor_pos); } +static gboolean +clutter_text_button_press_event (ClutterActor *actor, + ClutterButtonEvent *event, + gpointer user_data) +{ + GtkSettings *settings = gtk_settings_get_default (); + gboolean primary_paste_enabled; + + g_object_get (settings, + "gtk-enable-primary-paste", &primary_paste_enabled, + NULL); + + if (primary_paste_enabled && event->button == 2) + { + StClipboard *clipboard; + + clipboard = st_clipboard_get_default (); + + /* By the time the clipboard callback is called, + * the rest of the signal handlers will have + * run, making the text cursor to be in the correct + * place. + */ + st_clipboard_get_text (clipboard, + ST_CLIPBOARD_TYPE_PRIMARY, + st_entry_clipboard_callback, + user_data); + } + + return FALSE; +} + static gboolean st_entry_key_press_event (ClutterActor *actor, ClutterKeyEvent *event) @@ -755,6 +787,9 @@ st_entry_init (StEntry *entry) g_signal_connect (priv->entry, "notify::password-char", G_CALLBACK (clutter_text_password_char_cb), entry); + g_signal_connect (priv->entry, "button-press-event", + G_CALLBACK (clutter_text_button_press_event), entry); + priv->spacing = 6.0f; clutter_actor_add_child (CLUTTER_ACTOR (entry), priv->entry);