[hackers] [st] Making the copy and pasting consistent. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Sat, 13 Apr 2013 08:50:56 +0200

commit 4018b2c5075c1cab603ca137ef5f6d68b9cee483
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Sat Apr 13 08:48:17 2013 +0200

    Making the copy and pasting consistent.
    
    The copying and pasting in the terminald and GUI world is flawed. Due to the
    discussion on the mailinglist it seems that sending '
' is what GUIs expect
    and ' ' what terminal applications want. St now implements that behaviour.

diff --git a/st.c b/st.c
index 93058b9..49a9770 100644
--- a/st.c
+++ b/st.c
_AT_@ -788,9 +788,18 @@ selcopy(void) {
                                 memcpy(ptr, p, size);
                                 ptr += size;
                         }
- /*
 at the end of every selected line except for the last one */
+
+ /*
+ * Copy and pasting of line endings is inconsistent
+ * in the inconsistent terminal and GUI world.
+ * The best solution seems like to produce '
' when
+ * something is copied from st and convert '
' to
+ * ' ', when something to be pasted is received by
+ * st.
+ * FIXME: Fix the computer world.
+ */
                         if(is_selected && y < sel.e.y)
- *ptr++ = ' ';
+ *ptr++ = '
';
                 }
                 *ptr = 0;
         }
_AT_@ -801,7 +810,7 @@ void
 selnotify(XEvent *e) {
         ulong nitems, ofs, rem;
         int format;
- uchar *data;
+ uchar *data, *last, *repl;
         Atom type;
 
         ofs = 0;
_AT_@ -812,7 +821,25 @@ selnotify(XEvent *e) {
                         fprintf(stderr, "Clipboard allocation failed
");
                         return;
                 }
- ttywrite((const char *) data, nitems * format / 8);
+
+ /*
+ * As seen in selcopy:
+ * Line endings are inconsistent in the terminal and GUI world
+ * copy and pasting. When receiving some selection data,
+ * replace all '
' with ' '.
+ * FIXME: Fix the computer world.
+ */
+ repl = data;
+ last = data + nitems * format / 8;
+ while((repl = memchr(repl, '
', last - repl))) {
+ *repl++ = ' ';
+ }
+
+ last = data + nitems * format / 8;
+ repl = data;
+
+
+ ttywrite((const char *)data, nitems * format / 8);
                 XFree(data);
                 /* number of 32-bit chunks returned */
                 ofs += nitems * format / 32;
Received on Sat Apr 13 2013 - 08:50:56 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 13 2013 - 09:00:20 CEST