From d0ebad653b810fbdd9420ff172c238a5ec52eb1f Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Sun, 2 Mar 2025 03:36:46 -0300 Subject: CSI 22, 23 This patch adds support for CSI escape sequences 22 and 23, which save and restore window title (for instance nvim does this when opening and closing). https://st.suckless.org/patches/csi_22_23/ --- x.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'x.c') diff --git a/x.c b/x.c index 6b55d05..80b5d12 100644 --- a/x.c +++ b/x.c @@ -64,6 +64,9 @@ static void ttysend(const Arg *); /* config.h for applying patches and the configuration. */ #include "config.h" +/* size of title stack */ +#define TITLESTACKSIZE 8 + /* XEMBED messages */ #define XEMBED_FOCUS_IN 4 #define XEMBED_FOCUS_OUT 5 @@ -224,6 +227,8 @@ static DC dc; static XWindow xw; static XSelection xsel; static TermWindow win; +static int tstki; /* title stack index */ +static char *titlestack[TITLESTACKSIZE]; /* title stack */ /* Font Ring Cache */ enum { @@ -1752,10 +1757,30 @@ xseticontitle(char *p) } void -xsettitle(char *p) +xfreetitlestack(void) { - XTextProperty prop; - DEFAULT(p, opt_title); + for (int i = 0; i < LEN(titlestack); i++) { + free(titlestack[i]); + titlestack[i] = NULL; + } +} + +void +xsettitle(char *p, int pop) +{ + XTextProperty prop; + + free(titlestack[tstki]); + if (pop) { + titlestack[tstki] = NULL; + tstki = (tstki - 1 + TITLESTACKSIZE) % TITLESTACKSIZE; + p = titlestack[tstki] ? titlestack[tstki] : opt_title; + } else if (p) { + titlestack[tstki] = xstrdup(p); + } else { + titlestack[tstki] = NULL; + p = opt_title; + } if (p[0] == '\0') p = opt_title; @@ -1768,6 +1793,16 @@ xsettitle(char *p) XFree(prop.value); } +void +xpushtitle(void) +{ + int tstkin = (tstki + 1) % TITLESTACKSIZE; + + free(titlestack[tstkin]); + titlestack[tstkin] = titlestack[tstki] ? xstrdup(titlestack[tstki]) : NULL; + tstki = tstkin; +} + int xstartdraw(void) { -- cgit v1.2.3