summaryrefslogtreecommitdiff
path: root/x.c
diff options
context:
space:
mode:
authorMarcelo Lira <setanta@gmail.com>2025-03-02 03:36:46 -0300
committerMarcelo Lira <setanta@gmail.com>2025-03-02 08:31:10 -0300
commitd0ebad653b810fbdd9420ff172c238a5ec52eb1f (patch)
tree48294e79caba4076fb7287d1e13ecbb508a185a3 /x.c
parent5a7af3b20395d082693124f616b6d586919a97e2 (diff)
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/
Diffstat (limited to 'x.c')
-rw-r--r--x.c41
1 files changed, 38 insertions, 3 deletions
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)
{