From 7b2ee699f5e5759ac034765d82cbe9ebab65f30a Mon Sep 17 00:00:00 2001 From: Steve Ward Date: Fri, 15 May 2020 22:50:00 -0400 Subject: [PATCH] Enable blinking cursor Adapted from this patch https://lists.suckless.org/hackers/1708/15376.html Idea to inhibit blinking cursor during drawing inspired by this patch https://lists.suckless.org/hackers/2005/17339.html Rename cursorshape to cursorstyle --- config.def.h | 15 ++++++++++----- x.c | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/config.def.h b/config.def.h index fdbacfd..f404201 100644 --- a/config.def.h +++ b/config.def.h @@ -129,13 +129,18 @@ static unsigned int defaultcs = 256; static unsigned int defaultrcs = 257; /* - * Default shape of cursor - * 2: Block ("█") - * 4: Underline ("_") - * 6: Bar ("|") + * 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 + * Default style of cursor + * 0: blinking block + * 1: blinking block (default) + * 2: steady block ("█") + * 3: blinking underline + * 4: steady underline ("_") + * 5: blinking bar + * 6: steady bar ("|") * 7: Snowman ("☃") */ -static unsigned int cursorshape = 2; +static unsigned int cursorstyle = 1; /* * Default columns and rows numbers diff --git a/x.c b/x.c index 1dc44d6..bf280fe 100644 --- a/x.c +++ b/x.c @@ -1528,13 +1528,20 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) switch (win.cursor) { case 7: /* st extension: snowman (U+2603) */ g.u = 0x2603; - /* FALLTHROUGH */ + xdrawglyph(g, cx, cy); + break; case 0: /* Blinking Block */ case 1: /* Blinking Block (Default) */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ case 2: /* Steady Block */ xdrawglyph(g, cx, cy); break; case 3: /* Blinking Underline */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ case 4: /* Steady Underline */ XftDrawRect(xw.draw, &drawcol, borderpx + cx * win.cw, @@ -1543,6 +1550,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) win.cw, cursorthickness); break; case 5: /* Blinking bar */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ case 6: /* Steady bar */ XftDrawRect(xw.draw, &drawcol, borderpx + cx * win.cw, @@ -1871,6 +1881,7 @@ run(void) int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing; struct timespec seltv, *tv, now, lastblink, trigger; double timeout; + int blinkcursor; /* Waiting for window mapping */ do { @@ -1937,6 +1948,10 @@ run(void) if (FD_ISSET(ttyfd, &rfd) || xev) { if (!drawing) { trigger = now; + if (IS_SET(MODE_BLINK)) { + win.mode ^= MODE_BLINK; + } + lastblink = now; drawing = 1; } timeout = (maxlatency - TIMEDIFF(now, trigger)) \ @@ -1947,7 +1962,9 @@ run(void) /* idle detected or maxlatency exhausted -> draw */ timeout = -1; - if (blinktimeout && tattrset(ATTR_BLINK)) { + blinkcursor = win.cursor == 0 || win.cursor == 1 || + win.cursor == 3 || win.cursor == 5; + if (blinktimeout && (blinkcursor || tattrset(ATTR_BLINK))) { timeout = blinktimeout - TIMEDIFF(now, lastblink); if (timeout <= 0) { if (-timeout > blinktimeout) /* start visible */ @@ -1983,7 +2000,7 @@ main(int argc, char *argv[]) { xw.l = xw.t = 0; xw.isfixed = False; - win.cursor = cursorshape; + win.cursor = cursorstyle; ARGBEGIN { case 'a': -- 2.20.1