diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-08-16 05:04:54 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-08-19 03:29:11 +0200 |
commit | 61ff6e97c57f62ee3ad4ffc2166e433bc060e7cb (patch) | |
tree | 64c032ebdd040809d1b7e822e627e199a9c2476e /src/interface-gtk | |
parent | 94b041ec331427fd63cdae3e943efe825d1bbf14 (diff) | |
download | sciteco-61ff6e97c57f62ee3ad4ffc2166e433bc060e7cb.tar.gz |
Integrated clipboard support
* mapped to different registers beginning with "~"
* on supported platforms accessing the clipboard is as easy as
X~ or G~.
Naturally this also allows clipboards to be pasted in
string arguments/insertions (^EQ~).
* Currently, Gtk+, PDCurses and ncurses/XTerm are supported.
For XTerm clipboard support, users must set 0,256ED to enable
it since we cannot check for XTerm window ops programmatically
(at least without libX11).
* When clipboard regs exist, the clipboard can also be deemed functional.
This allows macros to fall back to xclip(1) if necessary.
* EOL handling has been moved into a new file eol.c and eol.h.
EOL translation no longer depends on GIOChannels but can be
memory-backed as well.
Diffstat (limited to 'src/interface-gtk')
-rw-r--r-- | src/interface-gtk/interface-gtk.cpp | 74 | ||||
-rw-r--r-- | src/interface-gtk/interface-gtk.h | 6 |
2 files changed, 79 insertions, 1 deletions
diff --git a/src/interface-gtk/interface-gtk.cpp b/src/interface-gtk/interface-gtk.cpp index 49c3154..4ef0b38 100644 --- a/src/interface-gtk/interface-gtk.cpp +++ b/src/interface-gtk/interface-gtk.cpp @@ -211,6 +211,17 @@ InterfaceGtk::main_impl(int &argc, char **&argv) gtk_init(&argc, &argv); /* + * Register clipboard registers. + * Unfortunately, we cannot find out which + * clipboards/selections are supported on this system, + * so we register only some default ones. + */ + QRegisters::globals.insert(new QRegisterClipboard()); + QRegisters::globals.insert(new QRegisterClipboard("P")); + QRegisters::globals.insert(new QRegisterClipboard("S")); + QRegisters::globals.insert(new QRegisterClipboard("C")); + + /* * The event queue is initialized now, so we can * pass it as user data to C-linkage callbacks. */ @@ -381,7 +392,7 @@ void InterfaceGtk::refresh_info(void) { GtkStyleContext *style = gtk_widget_get_style_context(info_bar_widget); - const gchar *info_type_str; + const gchar *info_type_str = PACKAGE; gchar *info_current_temp = g_strdup(info_current); gchar *info_current_canon; GIcon *icon; @@ -523,6 +534,67 @@ InterfaceGtk::cmdline_update_impl(const Cmdline *cmdline) gdk_threads_leave(); } +static GdkAtom +get_selection_by_name(const gchar *name) +{ + /* + * We can use gdk_atom_intern() to support arbitrary X11 selection + * names. However, since we cannot find out which selections are + * registered, we are only providing QRegisters for the three default + * selections. + * Checking them here avoids expensive X server roundtrips. + */ + switch (*name) { + case '\0': return GDK_NONE; + case 'P': return GDK_SELECTION_PRIMARY; + case 'S': return GDK_SELECTION_SECONDARY; + case 'C': return GDK_SELECTION_CLIPBOARD; + default: break; + } + + return gdk_atom_intern(name, FALSE); +} + +void +InterfaceGtk::set_clipboard(const gchar *name, const gchar *str, gssize str_len) +{ + GtkClipboard *clipboard; + + gdk_threads_enter(); + + clipboard = gtk_clipboard_get(get_selection_by_name(name)); + + /* + * NOTE: function has compatible semantics for str_len < 0. + */ + gtk_clipboard_set_text(clipboard, str, str_len); + + gdk_threads_leave(); +} + +gchar * +InterfaceGtk::get_clipboard(const gchar *name, gsize *str_len) +{ + GtkClipboard *clipboard; + gchar *str; + + gdk_threads_enter(); + + clipboard = gtk_clipboard_get(get_selection_by_name(name)); + /* + * Could return NULL for an empty clipboard. + * NOTE: This converts to UTF8 and we loose the ability + * to get clipboard with embedded nulls. + */ + str = gtk_clipboard_wait_for_text(clipboard); + + gdk_threads_leave(); + + if (str_len) + *str_len = str ? strlen(str) : 0; + return str; +} + void InterfaceGtk::popup_add_impl(PopupEntryType type, const gchar *name, bool highlight) diff --git a/src/interface-gtk/interface-gtk.h b/src/interface-gtk/interface-gtk.h index 80692f9..0145ff4 100644 --- a/src/interface-gtk/interface-gtk.h +++ b/src/interface-gtk/interface-gtk.h @@ -131,6 +131,12 @@ public: /* implementation of Interface::cmdline_update() */ void cmdline_update_impl(const Cmdline *cmdline); + /* override of Interface::set_clipboard() */ + void set_clipboard(const gchar *name, + const gchar *str = NULL, gssize str_len = -1); + /* override of Interface::get_clipboard() */ + gchar *get_clipboard(const gchar *name, gsize *str_len = NULL); + /* implementation of Interface::popup_add() */ void popup_add_impl(PopupEntryType type, const gchar *name, bool highlight = false); |