sites

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

st-blinking_cursor-20200515-045a0fa.diff (3543B)


      1 From 7b2ee699f5e5759ac034765d82cbe9ebab65f30a Mon Sep 17 00:00:00 2001
      2 From: Steve Ward <planet36@gmail.com>
      3 Date: Fri, 15 May 2020 22:50:00 -0400
      4 Subject: [PATCH] Enable blinking cursor
      5 
      6 Adapted from this patch
      7 https://lists.suckless.org/hackers/1708/15376.html
      8 
      9 Idea to inhibit blinking cursor during drawing inspired by this patch
     10 https://lists.suckless.org/hackers/2005/17339.html
     11 
     12 Rename cursorshape to cursorstyle
     13 ---
     14  config.def.h | 15 ++++++++++-----
     15  x.c          | 23 ++++++++++++++++++++---
     16  2 files changed, 30 insertions(+), 8 deletions(-)
     17 
     18 diff --git a/config.def.h b/config.def.h
     19 index fdbacfd..f404201 100644
     20 --- a/config.def.h
     21 +++ b/config.def.h
     22 @@ -129,13 +129,18 @@ static unsigned int defaultcs = 256;
     23  static unsigned int defaultrcs = 257;
     24  
     25  /*
     26 - * Default shape of cursor
     27 - * 2: Block ("█")
     28 - * 4: Underline ("_")
     29 - * 6: Bar ("|")
     30 + * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81
     31 + * Default style of cursor
     32 + * 0: blinking block
     33 + * 1: blinking block (default)
     34 + * 2: steady block ("█")
     35 + * 3: blinking underline
     36 + * 4: steady underline ("_")
     37 + * 5: blinking bar
     38 + * 6: steady bar ("|")
     39   * 7: Snowman ("☃")
     40   */
     41 -static unsigned int cursorshape = 2;
     42 +static unsigned int cursorstyle = 1;
     43  
     44  /*
     45   * Default columns and rows numbers
     46 diff --git a/x.c b/x.c
     47 index 1dc44d6..bf280fe 100644
     48 --- a/x.c
     49 +++ b/x.c
     50 @@ -1528,13 +1528,20 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     51  		switch (win.cursor) {
     52  		case 7: /* st extension: snowman (U+2603) */
     53  			g.u = 0x2603;
     54 -			/* FALLTHROUGH */
     55 +			xdrawglyph(g, cx, cy);
     56 +			break;
     57  		case 0: /* Blinking Block */
     58  		case 1: /* Blinking Block (Default) */
     59 +			if (IS_SET(MODE_BLINK))
     60 +				break;
     61 +			/* FALLTHROUGH */
     62  		case 2: /* Steady Block */
     63  			xdrawglyph(g, cx, cy);
     64  			break;
     65  		case 3: /* Blinking Underline */
     66 +			if (IS_SET(MODE_BLINK))
     67 +				break;
     68 +			/* FALLTHROUGH */
     69  		case 4: /* Steady Underline */
     70  			XftDrawRect(xw.draw, &drawcol,
     71  					borderpx + cx * win.cw,
     72 @@ -1543,6 +1550,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     73  					win.cw, cursorthickness);
     74  			break;
     75  		case 5: /* Blinking bar */
     76 +			if (IS_SET(MODE_BLINK))
     77 +				break;
     78 +			/* FALLTHROUGH */
     79  		case 6: /* Steady bar */
     80  			XftDrawRect(xw.draw, &drawcol,
     81  					borderpx + cx * win.cw,
     82 @@ -1871,6 +1881,7 @@ run(void)
     83  	int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
     84  	struct timespec seltv, *tv, now, lastblink, trigger;
     85  	double timeout;
     86 +	int blinkcursor;
     87  
     88  	/* Waiting for window mapping */
     89  	do {
     90 @@ -1937,6 +1948,10 @@ run(void)
     91  		if (FD_ISSET(ttyfd, &rfd) || xev) {
     92  			if (!drawing) {
     93  				trigger = now;
     94 +				if (IS_SET(MODE_BLINK)) {
     95 +					win.mode ^= MODE_BLINK;
     96 +				}
     97 +				lastblink = now;
     98  				drawing = 1;
     99  			}
    100  			timeout = (maxlatency - TIMEDIFF(now, trigger)) \
    101 @@ -1947,7 +1962,9 @@ run(void)
    102  
    103  		/* idle detected or maxlatency exhausted -> draw */
    104  		timeout = -1;
    105 -		if (blinktimeout && tattrset(ATTR_BLINK)) {
    106 +		blinkcursor = win.cursor == 0 || win.cursor == 1 ||
    107 +		              win.cursor == 3 || win.cursor == 5;
    108 +		if (blinktimeout && (blinkcursor || tattrset(ATTR_BLINK))) {
    109  			timeout = blinktimeout - TIMEDIFF(now, lastblink);
    110  			if (timeout <= 0) {
    111  				if (-timeout > blinktimeout) /* start visible */
    112 @@ -1983,7 +2000,7 @@ main(int argc, char *argv[])
    113  {
    114  	xw.l = xw.t = 0;
    115  	xw.isfixed = False;
    116 -	win.cursor = cursorshape;
    117 +	win.cursor = cursorstyle;
    118  
    119  	ARGBEGIN {
    120  	case 'a':
    121 -- 
    122 2.20.1
    123