commit 5c223b38668f0316a724adb5c1b8c18b5e571e9c
Author: Ashish Kumar Yadav <[email protected]>
Date:   Sun Aug 1 19:52:28 2021 +0530

    [st][patch][csi_22_23] New patch for CSI escape sequences 22 and 23

diff --git a/st.suckless.org/patches/csi_22_23/index.md 
b/st.suckless.org/patches/csi_22_23/index.md
new file mode 100644
index 00000000..7bb6bb09
--- /dev/null
+++ b/st.suckless.org/patches/csi_22_23/index.md
@@ -0,0 +1,15 @@
+CSI 22, 23
+==========
+
+Description
+-----------
+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).
+
+Download
+--------
+* [st-csi\_22\_23-0.8.4.diff](st-csi_22_23-0.8.4.diff)
+
+Authors
+-------
+* Ashish Kumar Yadav - <[email protected]>
diff --git a/st.suckless.org/patches/csi_22_23/st-csi_22_23-0.8.4.diff 
b/st.suckless.org/patches/csi_22_23/st-csi_22_23-0.8.4.diff
new file mode 100644
index 00000000..893a2c53
--- /dev/null
+++ b/st.suckless.org/patches/csi_22_23/st-csi_22_23-0.8.4.diff
@@ -0,0 +1,186 @@
+From b53d1edf59c34792ca284c783afcc0eff1f0ae07 Mon Sep 17 00:00:00 2001
+From: Ashish Kumar Yadav <[email protected]>
+Date: Sun, 1 Aug 2021 19:35:08 +0530
+Subject: [PATCH] Implement support for CSI 22 and 23
+
+This patch implements title stack into st.
+---
+ st.c  | 34 +++++++++++++++++++++++++++++++---
+ win.h |  4 +++-
+ x.c   | 43 +++++++++++++++++++++++++++++++++++++++----
+ 3 files changed, 73 insertions(+), 8 deletions(-)
+
+diff --git a/st.c b/st.c
+index 76b7e0d..9581b6f 100644
+--- a/st.c
++++ b/st.c
+@@ -1806,6 +1806,33 @@ csihandle(void)
+                       goto unknown;
+               }
+               break;
++       case 't': /* title stack operations */
++               switch (csiescseq.arg[0]) {
++               case 22: /* pust current title on stack */
++                       switch (csiescseq.arg[1]) {
++                       case 0:
++                       case 1:
++                       case 2:
++                               xpushtitle();
++                               break;
++                       default:
++                               goto unknown;
++                       }
++                       break;
++               case 23: /* pop last title from stack */
++                       switch (csiescseq.arg[1]) {
++                       case 0:
++                       case 1:
++                       case 2:
++                               xsettitle(NULL, 1);
++                               break;
++                       default:
++                               goto unknown;
++                       }
++                       break;
++               default:
++                       goto unknown;
++               }
+       }
+ }
+ 
+@@ -1856,7 +1883,7 @@ strhandle(void)
+               case 1:
+               case 2:
+                       if (narg > 1)
+-                              xsettitle(strescseq.args[1]);
++                              xsettitle(strescseq.args[1], 0);
+                       return;
+               case 52:
+                       if (narg > 2 && allowwindowops) {
+@@ -1892,7 +1919,7 @@ strhandle(void)
+               }
+               break;
+       case 'k': /* old title set compatibility */
+-              xsettitle(strescseq.args[0]);
++              xsettitle(strescseq.args[0], 0);
+               return;
+       case 'P': /* DCS -- Device Control String */
+       case '_': /* APC -- Application Program Command */
+@@ -2264,6 +2291,7 @@ eschandle(uchar ascii)
+               break;
+       case 'c': /* RIS -- Reset to initial state */
+               treset();
++              xfreetitlestack();
+               resettitle();
+               xloadcols();
+               break;
+@@ -2546,7 +2574,7 @@ tresize(int col, int row)
+ void
+ resettitle(void)
+ {
+-      xsettitle(NULL);
++      xsettitle(NULL, 0);
+ }
+ 
+ void
+diff --git a/win.h b/win.h
+index a6ef1b9..e24337e 100644
+--- a/win.h
++++ b/win.h
+@@ -30,7 +30,9 @@ void xdrawline(Line, int, int, int);
+ void xfinishdraw(void);
+ void xloadcols(void);
+ int xsetcolorname(int, const char *);
+-void xsettitle(char *);
++void xfreetitlestack(void);
++void xsettitle(char *, int);
++void xpushtitle(void);
+ int xsetcursor(int);
+ void xsetmode(int, unsigned int);
+ void xsetpointermotion(int);
+diff --git a/x.c b/x.c
+index 210f184..6184a11 100644
+--- a/x.c
++++ b/x.c
+@@ -63,6 +63,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
+@@ -116,6 +119,11 @@ typedef struct {
+       struct timespec tclick2;
+ } XSelection;
+ 
++typedef struct {
++      int i;
++      char *titles[TITLESTACKSIZE];
++} XTitleStack;
++
+ /* Font structure */
+ #define Font Font_
+ typedef struct {
+@@ -219,6 +227,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
+ static DC dc;
+ static XWindow xw;
+ static XSelection xsel;
++static XTitleStack tstack;
+ static TermWindow win;
+ 
+ /* Font Ring Cache */
+@@ -1580,18 +1589,44 @@ xsetenv(void)
+ }
+ 
+ void
+-xsettitle(char *p)
++xfreetitlestack(void)
++{
++      for (int i = 0; i < TITLESTACKSIZE; i++) {
++              free(tstack.titles[i]);
++              tstack.titles[i] = NULL;
++      }
++}
++
++void
++xsettitle(char *p, int pop)
+ {
+       XTextProperty prop;
+-      DEFAULT(p, opt_title);
+ 
+-      Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
+-                      &prop);
++      free(tstack.titles[tstack.i]);
++
++      if (pop) {
++              tstack.titles[tstack.i] = NULL;
++              tstack.i = (tstack.i - 1 + TITLESTACKSIZE) % TITLESTACKSIZE;
++              p = tstack.titles[tstack.i];
++      } else {
++              DEFAULT(p, opt_title);
++              tstack.titles[tstack.i] = strdup(p);
++      }
++
++      Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, &prop);
+       XSetWMName(xw.dpy, xw.win, &prop);
+       XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
+       XFree(prop.value);
+ }
+ 
++void
++xpushtitle(void)
++{
++      tstack.i = (tstack.i + 1) % TITLESTACKSIZE;
++      free(tstack.titles[tstack.i]);
++      tstack.titles[tstack.i] = NULL;
++}
++
+ int
+ xstartdraw(void)
+ {
+-- 
+2.32.0
+


Reply via email to