sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-csi_22_23-0.8.4.diff (4524B)


      1 From 49342f1039b41d2c95dde3f9cc26efbdc85d0272 Mon Sep 17 00:00:00 2001
      2 From: Ashish Kumar Yadav <ashishkumar.yadav@students.iiserpune.ac.in>
      3 Date: Wed, 11 Aug 2021 20:24:07 +0530
      4 Subject: [PATCH] Implement support for CSI 22 and 23
      5 
      6 This patch implements title stack into st.
      7 ---
      8  st.c    | 34 +++++++++++++++++++++++++++++++---
      9  st.info |  4 ++--
     10  win.h   |  4 +++-
     11  x.c     | 44 +++++++++++++++++++++++++++++++++++++++-----
     12  4 files changed, 75 insertions(+), 11 deletions(-)
     13 
     14 diff --git a/st.c b/st.c
     15 index 76b7e0d..092b93c 100644
     16 --- a/st.c
     17 +++ b/st.c
     18 @@ -1806,6 +1806,33 @@ csihandle(void)
     19  			goto unknown;
     20  		}
     21  		break;
     22 +	case 't': /* title stack operations */
     23 +		switch (csiescseq.arg[0]) {
     24 +		case 22: /* pust current title on stack */
     25 +			switch (csiescseq.arg[1]) {
     26 +			case 0:
     27 +			case 1:
     28 +			case 2:
     29 +				xpushtitle();
     30 +				break;
     31 +			default:
     32 +				goto unknown;
     33 +			}
     34 +			break;
     35 +		case 23: /* pop last title from stack */
     36 +			switch (csiescseq.arg[1]) {
     37 +			case 0:
     38 +			case 1:
     39 +			case 2:
     40 +				xsettitle(NULL, 1);
     41 +				break;
     42 +			default:
     43 +				goto unknown;
     44 +			}
     45 +			break;
     46 +		default:
     47 +			goto unknown;
     48 +		}
     49  	}
     50  }
     51  
     52 @@ -1856,7 +1883,7 @@ strhandle(void)
     53  		case 1:
     54  		case 2:
     55  			if (narg > 1)
     56 -				xsettitle(strescseq.args[1]);
     57 +				xsettitle(strescseq.args[1], 0);
     58  			return;
     59  		case 52:
     60  			if (narg > 2 && allowwindowops) {
     61 @@ -1892,7 +1919,7 @@ strhandle(void)
     62  		}
     63  		break;
     64  	case 'k': /* old title set compatibility */
     65 -		xsettitle(strescseq.args[0]);
     66 +		xsettitle(strescseq.args[0], 0);
     67  		return;
     68  	case 'P': /* DCS -- Device Control String */
     69  	case '_': /* APC -- Application Program Command */
     70 @@ -2264,6 +2291,7 @@ eschandle(uchar ascii)
     71  		break;
     72  	case 'c': /* RIS -- Reset to initial state */
     73  		treset();
     74 +		xfreetitlestack();
     75  		resettitle();
     76  		xloadcols();
     77  		break;
     78 @@ -2546,7 +2574,7 @@ tresize(int col, int row)
     79  void
     80  resettitle(void)
     81  {
     82 -	xsettitle(NULL);
     83 +	xsettitle(NULL, 0);
     84  }
     85  
     86  void
     87 diff --git a/st.info b/st.info
     88 index 8201ad6..aeef606 100644
     89 --- a/st.info
     90 +++ b/st.info
     91 @@ -161,7 +161,7 @@ st-mono| simpleterm monocolor,
     92  	rin=\E[%p1%dT,
     93  	ritm=\E[23m,
     94  	rmacs=\E(B,
     95 -	rmcup=\E[?1049l,
     96 +	rmcup=\E[?1049l\E[23;0;0t,
     97  	rmir=\E[4l,
     98  	rmkx=\E[?1l\E>,
     99  	rmso=\E[27m,
    100 @@ -172,7 +172,7 @@ st-mono| simpleterm monocolor,
    101  	sitm=\E[3m,
    102  	sgr0=\E[0m,
    103  	smacs=\E(0,
    104 -	smcup=\E[?1049h,
    105 +	smcup=\E[?1049h\E[22;0;0t,
    106  	smir=\E[4h,
    107  	smkx=\E[?1h\E=,
    108  	smso=\E[7m,
    109 diff --git a/win.h b/win.h
    110 index a6ef1b9..e24337e 100644
    111 --- a/win.h
    112 +++ b/win.h
    113 @@ -30,7 +30,9 @@ void xdrawline(Line, int, int, int);
    114  void xfinishdraw(void);
    115  void xloadcols(void);
    116  int xsetcolorname(int, const char *);
    117 -void xsettitle(char *);
    118 +void xfreetitlestack(void);
    119 +void xsettitle(char *, int);
    120 +void xpushtitle(void);
    121  int xsetcursor(int);
    122  void xsetmode(int, unsigned int);
    123  void xsetpointermotion(int);
    124 diff --git a/x.c b/x.c
    125 index 210f184..b4bebff 100644
    126 --- a/x.c
    127 +++ b/x.c
    128 @@ -63,6 +63,9 @@ static void ttysend(const Arg *);
    129  /* config.h for applying patches and the configuration. */
    130  #include "config.h"
    131  
    132 +/* size of title stack */
    133 +#define TITLESTACKSIZE 8
    134 +
    135  /* XEMBED messages */
    136  #define XEMBED_FOCUS_IN  4
    137  #define XEMBED_FOCUS_OUT 5
    138 @@ -220,6 +223,8 @@ static DC dc;
    139  static XWindow xw;
    140  static XSelection xsel;
    141  static TermWindow win;
    142 +static int tstki; /* title stack index */
    143 +static char *titlestack[TITLESTACKSIZE]; /* title stack */
    144  
    145  /* Font Ring Cache */
    146  enum {
    147 @@ -1580,18 +1585,47 @@ xsetenv(void)
    148  }
    149  
    150  void
    151 -xsettitle(char *p)
    152 +xfreetitlestack(void)
    153  {
    154 -	XTextProperty prop;
    155 -	DEFAULT(p, opt_title);
    156 +	for (int i = 0; i < LEN(titlestack); i++) {
    157 +		free(titlestack[i]);
    158 +		titlestack[i] = NULL;
    159 +	}
    160 +}
    161  
    162 -	Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
    163 -			&prop);
    164 +void
    165 +xsettitle(char *p, int pop)
    166 +{
    167 + 	XTextProperty prop;
    168 + 
    169 +	free(titlestack[tstki]);
    170 +	if (pop) {
    171 +		titlestack[tstki] = NULL;
    172 +		tstki = (tstki - 1 + TITLESTACKSIZE) % TITLESTACKSIZE;
    173 +		p = titlestack[tstki] ? titlestack[tstki] : opt_title;
    174 +	} else if (p) {
    175 +		titlestack[tstki] = xstrdup(p);
    176 +	} else {
    177 +		titlestack[tstki] = NULL;
    178 +		p = opt_title;
    179 +	}
    180 + 
    181 + 	Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, &prop);
    182  	XSetWMName(xw.dpy, xw.win, &prop);
    183  	XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
    184  	XFree(prop.value);
    185  }
    186  
    187 +void
    188 +xpushtitle(void)
    189 +{
    190 +	int tstkin = (tstki + 1) % TITLESTACKSIZE;
    191 +
    192 +	free(titlestack[tstkin]);
    193 +	titlestack[tstkin] = titlestack[tstki] ? xstrdup(titlestack[tstki]) : NULL;
    194 +	tstki = tstkin;
    195 +}
    196 +
    197  int
    198  xstartdraw(void)
    199  {
    200 -- 
    201 2.32.0
    202