st

Mahdi's build of st
git clone git://mahdi.pw/st.git
Log | Files | Refs | README | LICENSE

st-blinking_cursor-20211116-2f6e597.diff (4259B)


      1 From a3cdd0753bf578cd4e6db7c6507481f3b5c38aea Mon Sep 17 00:00:00 2001
      2 From: Steve Ward <[email protected]>
      3 Date: Tue, 16 Nov 2021 14:15:06 -0500
      4 Subject: [PATCH] Allow blinking cursor
      5 
      6 ---
      7  config.def.h | 19 +++++++++++++------
      8  x.c          | 47 +++++++++++++++++++++++++++++++++++------------
      9  2 files changed, 48 insertions(+), 18 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 6f05dce..1a5fed0 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -133,13 +133,20 @@ static unsigned int defaultcs = 256;
     16  static unsigned int defaultrcs = 257;
     17  
     18  /*
     19 - * Default shape of cursor
     20 - * 2: Block ("█")
     21 - * 4: Underline ("_")
     22 - * 6: Bar ("|")
     23 - * 7: Snowman ("☃")
     24 + * 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
     25 + * Default style of cursor
     26 + * 0: blinking block
     27 + * 1: blinking block (default)
     28 + * 2: steady block ("█")
     29 + * 3: blinking underline
     30 + * 4: steady underline ("_")
     31 + * 5: blinking bar
     32 + * 6: steady bar ("|")
     33 + * 7: blinking st cursor
     34 + * 8: steady st cursor
     35   */
     36 -static unsigned int cursorshape = 2;
     37 +static unsigned int cursorstyle = 1;
     38 +static Rune stcursor = 0x2603; /* snowman ("☃") */
     39  
     40  /*
     41   * Default columns and rows numbers
     42 diff --git a/x.c b/x.c
     43 index 89786b8..7d2447d 100644
     44 --- a/x.c
     45 +++ b/x.c
     46 @@ -253,6 +253,7 @@ static char *opt_name  = NULL;
     47  static char *opt_title = NULL;
     48  
     49  static int oldbutton = 3; /* button event on startup: 3 = release */
     50 +static int cursorblinks = 0;
     51  
     52  void
     53  clipcopy(const Arg *dummy)
     54 @@ -1529,29 +1530,44 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     55  	/* draw the new one */
     56  	if (IS_SET(MODE_FOCUSED)) {
     57  		switch (win.cursor) {
     58 -		case 7: /* st extension */
     59 -			g.u = 0x2603; /* snowman (U+2603) */
     60 +		default:
     61 +		case 0: /* blinking block */
     62 +		case 1: /* blinking block (default) */
     63 +			if (IS_SET(MODE_BLINK))
     64 +				break;
     65  			/* FALLTHROUGH */
     66 -		case 0: /* Blinking Block */
     67 -		case 1: /* Blinking Block (Default) */
     68 -		case 2: /* Steady Block */
     69 +		case 2: /* steady block */
     70  			xdrawglyph(g, cx, cy);
     71  			break;
     72 -		case 3: /* Blinking Underline */
     73 -		case 4: /* Steady Underline */
     74 +		case 3: /* blinking underline */
     75 +			if (IS_SET(MODE_BLINK))
     76 +				break;
     77 +			/* FALLTHROUGH */
     78 +		case 4: /* steady underline */
     79  			XftDrawRect(xw.draw, &drawcol,
     80  					borderpx + cx * win.cw,
     81  					borderpx + (cy + 1) * win.ch - \
     82  						cursorthickness,
     83  					win.cw, cursorthickness);
     84  			break;
     85 -		case 5: /* Blinking bar */
     86 -		case 6: /* Steady bar */
     87 +		case 5: /* blinking bar */
     88 +			if (IS_SET(MODE_BLINK))
     89 +				break;
     90 +			/* FALLTHROUGH */
     91 +		case 6: /* steady bar */
     92  			XftDrawRect(xw.draw, &drawcol,
     93  					borderpx + cx * win.cw,
     94  					borderpx + cy * win.ch,
     95  					cursorthickness, win.ch);
     96  			break;
     97 +		case 7: /* blinking st cursor */
     98 +			if (IS_SET(MODE_BLINK))
     99 +				break;
    100 +			/* FALLTHROUGH */
    101 +		case 8: /* steady st cursor */
    102 +			g.u = stcursor;
    103 +			xdrawglyph(g, cx, cy);
    104 +			break;
    105  		}
    106  	} else {
    107  		XftDrawRect(xw.draw, &drawcol,
    108 @@ -1708,9 +1724,12 @@ xsetmode(int set, unsigned int flags)
    109  int
    110  xsetcursor(int cursor)
    111  {
    112 -	if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
    113 +	if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */
    114  		return 1;
    115  	win.cursor = cursor;
    116 +	cursorblinks = win.cursor == 0 || win.cursor == 1 ||
    117 +	               win.cursor == 3 || win.cursor == 5 ||
    118 +	               win.cursor == 7;
    119  	return 0;
    120  }
    121  
    122 @@ -1954,6 +1973,10 @@ run(void)
    123  		if (FD_ISSET(ttyfd, &rfd) || xev) {
    124  			if (!drawing) {
    125  				trigger = now;
    126 +				if (IS_SET(MODE_BLINK)) {
    127 +					win.mode ^= MODE_BLINK;
    128 +				}
    129 +				lastblink = now;
    130  				drawing = 1;
    131  			}
    132  			timeout = (maxlatency - TIMEDIFF(now, trigger)) \
    133 @@ -1964,7 +1987,7 @@ run(void)
    134  
    135  		/* idle detected or maxlatency exhausted -> draw */
    136  		timeout = -1;
    137 -		if (blinktimeout && tattrset(ATTR_BLINK)) {
    138 +		if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) {
    139  			timeout = blinktimeout - TIMEDIFF(now, lastblink);
    140  			if (timeout <= 0) {
    141  				if (-timeout > blinktimeout) /* start visible */
    142 @@ -2000,7 +2023,7 @@ main(int argc, char *argv[])
    143  {
    144  	xw.l = xw.t = 0;
    145  	xw.isfixed = False;
    146 -	xsetcursor(cursorshape);
    147 +	xsetcursor(cursorstyle);
    148  
    149  	ARGBEGIN {
    150  	case 'a':
    151 -- 
    152 2.34.0
    153