[PATCH] Support xterm Ms feature to set clipboard

From: Omar Sandoval <osandov_AT_osandov.com>
Date: Sat, 4 Feb 2017 10:47:36 -0800

This is used by, e.g., tmux.
---
 config.mk |  4 ++--
 st.c      | 22 ++++++++++++++++++++--
 st.info   |  1 +
 3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/config.mk b/config.mk
index c84c5ee..4cf0880 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -14,12 +14,12 @@ X11LIB = /usr/X11R6/lib
 INCS = -I. -I/usr/include -I${X11INC} \
        `pkg-config --cflags fontconfig` \
        `pkg-config --cflags freetype2`
-LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lresolv -lX11 -lutil -lXft \
        `pkg-config --libs fontconfig`  \
        `pkg-config --libs freetype2`
 
 # flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600
+CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
 CFLAGS += -g -std=c99 -pedantic -Wall -Wvariadic-macros -Os ${INCS} ${CPPFLAGS}
 LDFLAGS += -g ${LIBS}
 
diff --git a/st.c b/st.c
index fbcd9e0..3f69a9d 100644
--- a/st.c
+++ b/st.c
_AT_@ -5,6 +5,7 @@
 #include <limits.h>
 #include <locale.h>
 #include <pwd.h>
+#include <resolv.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
_AT_@ -63,8 +64,6 @@ char *argv0;
 #define XK_SWITCH_MOD (1<<13)
 
 /* macros */
-#define MIN(a, b)		((a) < (b) ? (a) : (b))
-#define MAX(a, b)		((a) < (b) ? (b) : (a))
 #define LEN(a)			(sizeof(a) / sizeof(a)[0])
 #define NUMMAXLEN(x)		((int)(sizeof(x) * 2.56 + 0.5) + 1)
 #define DEFAULT(a, b)		(a) = (a) ? (a) : (b)
_AT_@ -2533,6 +2532,25 @@ strhandle(void)
 			if (narg > 1)
 				xsettitle(strescseq.args[1]);
 			return;
+		case 52:
+			if (narg > 2) {
+				char *src, *dst;
+				size_t len;
+
+				src = strescseq.args[2];
+				len = (strlen(src) / 4) * 3;
+				dst = xmalloc(len + 1);
+
+				if (b64_pton(src, (void *)dst, len) != -1) {
+					dst[len] = '\0';
+					xsetsel(dst, CurrentTime);
+					clipcopy(NULL);
+				} else {
+					fprintf(stderr, "erresc: invalid base64\n");
+					free(dst);
+				}
+			}
+			return;
 		case 4: /* color set */
 			if (narg < 3)
 				break;
diff --git a/st.info b/st.info
index 13cc8eb..0b928af 100644
--- a/st.info
+++ b/st.info
_AT_@ -189,6 +189,7 @@ st| simpleterm,
 	Se,
 	Ss,
 	Tc,
+	Ms=\E]52;%p1%s;%p2%s\007,
 
 st-256color| simpleterm with 256 colors,
 	use=st,
-- 
2.11.0
--huq684BweRXVnRxX--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sat Feb 04 2017 - 22:00:17 CET