repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 91cc921f88027032ea9dbf01896fa54b73cb2740:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 91cc921f88027032ea9dbf01896fa54b73cb2740
Author: Emanuele Giaquinta 
Date:   Sat Apr 26 14:07:36 2014 +0000

    Add bindings to interact with the CLIPBOARD selection.

diff --git a/Changes b/Changes
index 65cee9b2aee4652ff68423df653906532a0fc290..
index ..93e6765b5d571aaf8f5fa956302b8c0085931ef3 100644
--- a/Changes
+++ b/Changes
@@ -42,6 +42,8 @@ TODO IMPL: recalc bg always on bg colour change
 	  and holding the scrollbar up or down button, gentoo bug #493992.
 	- increase the maximum length of a command sequence to 32k bytes,
           to allow longer OSC sequences (previous limit was 2k).
+        - new Ctrl-Meta-c and Ctrl-Meta-v bindings to interact with
+          the CLIPBOARD selection.
         - new extension: selection-to-clipboard.

 9.19 Sun Oct 27 17:16:07 CET 2013
diff --git a/doc/rxvt.1.pod b/doc/rxvt.1.pod
index 70d50ca4bd92110b18cf155244cc128d4fbbaa7c..
index ..87042cd06279ccd60e926df2e786be116e60ea5b 100644
--- a/doc/rxvt.1.pod
+++ b/doc/rxvt.1.pod
@@ -1378,6 +1378,12 @@ B modifier) to be inserted as if it had been typed on the keyboard.
 Pressing B causes the value of the PRIMARY selection to be
 inserted too.

+rxvt-unicode also provides the bindings B and
+ to interact with the CLIPBOARD selection. The first
+binding causes the value of the internal selection to be copied to the
+CLIPBOARD selection, while the second binding causes the value of the
+CLIPBOARD selection to be inserted.
+
 =back

 =head1 CHANGING FONTS
diff --git a/src/command.C b/src/command.C
index db20b871634f85b980fd394c1b5058e1a8fc09cc..
index ..153f0e1a4375aee746c982837b65b1bc007c01f6 100644
--- a/src/command.C
+++ b/src/command.C
@@ -402,6 +402,15 @@ map_function_key (KeySym keysym)
   return param;
 }

+static inline wchar_t *
+rxvt_wcsdup (const wchar_t *str, int len)
+{
+  wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t));
+  memcpy (r, str, len * sizeof (wchar_t));
+  r[len] = 0;
+  return r;
+}
+
 void ecb_cold
 rxvt_term::key_press (XKeyEvent &ev)
 {
@@ -580,6 +589,21 @@ rxvt_term::key_press (XKeyEvent &ev)
             }
         }

+      if (ctrl && meta && (keysym == XK_c || keysym == XK_v))
+        {
+          if (keysym == XK_v)
+            selection_request (ev.time, Sel_Clipboard);
+          else if (selection.len > 0)
+            {
+              free (selection.clip_text);
+              selection.clip_text = rxvt_wcsdup (selection.text, selection.len);
+              selection.clip_len = selection.len;
+              selection_grab (CurrentTime, true);
+            }
+
+          return;
+        }
+
 #if ENABLE_FRILLS || ISO_14755
       // ISO 14755 support
       if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51))

-----END OF PAGE-----