st-blinking_cursor-20200511-914fb82.diff (3088B)
1 From f570c5ba723be9391cdf03878a6f8c5d71a97a56 Mon Sep 17 00:00:00 2001 2 From: Steve Ward <planet36@gmail.com> 3 Date: Mon, 11 May 2020 22:44:25 -0400 4 Subject: [PATCH] Enable blinking cursor 5 6 Adapted from this patch 7 https://lists.suckless.org/hackers/1708/15376.html 8 --- 9 config.def.h | 15 ++++++++++----- 10 x.c | 18 +++++++++++++++--- 11 2 files changed, 25 insertions(+), 8 deletions(-) 12 13 diff --git a/config.def.h b/config.def.h 14 index fdbacfd..f404201 100644 15 --- a/config.def.h 16 +++ b/config.def.h 17 @@ -129,13 +129,18 @@ static unsigned int defaultcs = 256; 18 static unsigned int defaultrcs = 257; 19 20 /* 21 - * Default shape of cursor 22 - * 2: Block ("█") 23 - * 4: Underline ("_") 24 - * 6: Bar ("|") 25 + * 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 26 + * Default style of cursor 27 + * 0: blinking block 28 + * 1: blinking block (default) 29 + * 2: steady block ("█") 30 + * 3: blinking underline 31 + * 4: steady underline ("_") 32 + * 5: blinking bar 33 + * 6: steady bar ("|") 34 * 7: Snowman ("☃") 35 */ 36 -static unsigned int cursorshape = 2; 37 +static unsigned int cursorstyle = 1; 38 39 /* 40 * Default columns and rows numbers 41 diff --git a/x.c b/x.c 42 index 1dc44d6..b6aa7b4 100644 43 --- a/x.c 44 +++ b/x.c 45 @@ -1528,13 +1528,20 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) 46 switch (win.cursor) { 47 case 7: /* st extension: snowman (U+2603) */ 48 g.u = 0x2603; 49 - /* FALLTHROUGH */ 50 + xdrawglyph(g, cx, cy); 51 + break; 52 case 0: /* Blinking Block */ 53 case 1: /* Blinking Block (Default) */ 54 + if (IS_SET(MODE_BLINK)) 55 + break; 56 + /* FALLTHROUGH */ 57 case 2: /* Steady Block */ 58 xdrawglyph(g, cx, cy); 59 break; 60 case 3: /* Blinking Underline */ 61 + if (IS_SET(MODE_BLINK)) 62 + break; 63 + /* FALLTHROUGH */ 64 case 4: /* Steady Underline */ 65 XftDrawRect(xw.draw, &drawcol, 66 borderpx + cx * win.cw, 67 @@ -1543,6 +1550,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) 68 win.cw, cursorthickness); 69 break; 70 case 5: /* Blinking bar */ 71 + if (IS_SET(MODE_BLINK)) 72 + break; 73 + /* FALLTHROUGH */ 74 case 6: /* Steady bar */ 75 XftDrawRect(xw.draw, &drawcol, 76 borderpx + cx * win.cw, 77 @@ -1871,6 +1881,8 @@ run(void) 78 int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing; 79 struct timespec seltv, *tv, now, lastblink, trigger; 80 double timeout; 81 + int blinkcursor = win.cursor == 0 || win.cursor == 1 || 82 + win.cursor == 3 || win.cursor == 5; 83 84 /* Waiting for window mapping */ 85 do { 86 @@ -1947,7 +1959,7 @@ run(void) 87 88 /* idle detected or maxlatency exhausted -> draw */ 89 timeout = -1; 90 - if (blinktimeout && tattrset(ATTR_BLINK)) { 91 + if (blinktimeout && (blinkcursor || tattrset(ATTR_BLINK))) { 92 timeout = blinktimeout - TIMEDIFF(now, lastblink); 93 if (timeout <= 0) { 94 if (-timeout > blinktimeout) /* start visible */ 95 @@ -1983,7 +1995,7 @@ main(int argc, char *argv[]) 96 { 97 xw.l = xw.t = 0; 98 xw.isfixed = False; 99 - win.cursor = cursorshape; 100 + win.cursor = cursorstyle; 101 102 ARGBEGIN { 103 case 'a': 104 -- 105 2.20.1 106