sites

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

st-blinking_cursor-20200531-a2a7044.diff (4248B)


      1 From bff176133618854676bbdc74c0099f184d3da365 Mon Sep 17 00:00:00 2001
      2 From: Steve Ward <planet36@gmail.com>
      3 Date: Sun, 31 May 2020 22:48:25 -0400
      4 Subject: [PATCH] Allow blinking cursor
      5 
      6 ---
      7  config.def.h | 19 +++++++++++++------
      8  x.c          | 42 ++++++++++++++++++++++++++++++++----------
      9  2 files changed, 45 insertions(+), 16 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 6f05dce..3dbe915 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 (U+2603) */
     39  
     40  /*
     41   * Default columns and rows numbers
     42 diff --git a/x.c b/x.c
     43 index 210f184..bd80a5e 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 @@ -1526,16 +1527,19 @@ 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 +		case 0: /* Blinking block */
     61 +		case 1: /* Blinking block (default) */
     62 +			if (IS_SET(MODE_BLINK))
     63 +				break;
     64  			/* FALLTHROUGH */
     65 -		case 0: /* Blinking Block */
     66 -		case 1: /* Blinking Block (Default) */
     67 -		case 2: /* Steady Block */
     68 +		case 2: /* Steady block */
     69  			xdrawglyph(g, cx, cy);
     70  			break;
     71 -		case 3: /* Blinking Underline */
     72 -		case 4: /* Steady Underline */
     73 +		case 3: /* Blinking underline */
     74 +			if (IS_SET(MODE_BLINK))
     75 +				break;
     76 +			/* FALLTHROUGH */
     77 +		case 4: /* Steady underline */
     78  			XftDrawRect(xw.draw, &drawcol,
     79  					borderpx + cx * win.cw,
     80  					borderpx + (cy + 1) * win.ch - \
     81 @@ -1543,12 +1547,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     82  					win.cw, cursorthickness);
     83  			break;
     84  		case 5: /* Blinking bar */
     85 +			if (IS_SET(MODE_BLINK))
     86 +				break;
     87 +			/* FALLTHROUGH */
     88  		case 6: /* Steady bar */
     89  			XftDrawRect(xw.draw, &drawcol,
     90  					borderpx + cx * win.cw,
     91  					borderpx + cy * win.ch,
     92  					cursorthickness, win.ch);
     93  			break;
     94 +		case 7: /* Blinking st cursor */
     95 +			if (IS_SET(MODE_BLINK))
     96 +				break;
     97 +			/* FALLTHROUGH */
     98 +		case 8: /* Steady st cursor */
     99 +			g.u = stcursor;
    100 +			xdrawglyph(g, cx, cy);
    101 +			break;
    102  		}
    103  	} else {
    104  		XftDrawRect(xw.draw, &drawcol,
    105 @@ -1690,9 +1705,12 @@ xsetmode(int set, unsigned int flags)
    106  int
    107  xsetcursor(int cursor)
    108  {
    109 -	if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
    110 +	if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */
    111  		return 1;
    112  	win.cursor = cursor;
    113 +	cursorblinks = win.cursor == 0 || win.cursor == 1 ||
    114 +	               win.cursor == 3 || win.cursor == 5 ||
    115 +	               win.cursor == 7;
    116  	return 0;
    117  }
    118  
    119 @@ -1936,6 +1954,10 @@ run(void)
    120  		if (FD_ISSET(ttyfd, &rfd) || xev) {
    121  			if (!drawing) {
    122  				trigger = now;
    123 +				if (IS_SET(MODE_BLINK)) {
    124 +					win.mode ^= MODE_BLINK;
    125 +				}
    126 +				lastblink = now;
    127  				drawing = 1;
    128  			}
    129  			timeout = (maxlatency - TIMEDIFF(now, trigger)) \
    130 @@ -1946,7 +1968,7 @@ run(void)
    131  
    132  		/* idle detected or maxlatency exhausted -> draw */
    133  		timeout = -1;
    134 -		if (blinktimeout && tattrset(ATTR_BLINK)) {
    135 +		if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) {
    136  			timeout = blinktimeout - TIMEDIFF(now, lastblink);
    137  			if (timeout <= 0) {
    138  				if (-timeout > blinktimeout) /* start visible */
    139 @@ -1982,7 +2004,7 @@ main(int argc, char *argv[])
    140  {
    141  	xw.l = xw.t = 0;
    142  	xw.isfixed = False;
    143 -	xsetcursor(cursorshape);
    144 +	xsetcursor(cursorstyle);
    145  
    146  	ARGBEGIN {
    147  	case 'a':
    148 -- 
    149 2.20.1
    150