diff --git a/README.md b/README.md index 13a3727..5321549 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the ### Changelog: +2021-05-08 - Added blinking cursor patch + 2021-05-07 - Added xresources reload patch 2021-04-21 - Added (temporary?) hack for Variable Fonts (VT) support @@ -70,6 +72,9 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the - [anysize_nobar](https://github.com/connor-brooks/st-anysize-nobar) - a patch that aims to prevent black bars being drawn on the edges of st terminals using the anysize patch + - [blinking-cursor](https://st.suckless.org/patches/blinking_cursor/) + - allows the use of a blinking cursor + - [bold-is-not-bright](https://st.suckless.org/patches/bold-is-not-bright/) - by default bold text is rendered with a bold font in the bright variant of the current color - this patch makes bold text rendered simply as bold, leaving the color unaffected diff --git a/config.def.h b/config.def.h index e556761..41b2560 100644 --- a/config.def.h +++ b/config.def.h @@ -175,6 +175,23 @@ unsigned int defaultbg = 258; unsigned int defaultcs = 256; unsigned int defaultrcs = 257; +#if BLINKING_CURSOR_PATCH +/* + * 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: Blinking st cursor + * 8: Steady st cursor + */ +static unsigned int cursorstyle = 1; +static Rune stcursor = 0x2603; /* snowman (U+2603) */ +#else /* * Default shape of cursor * 2: Block ("█") @@ -183,6 +200,7 @@ unsigned int defaultrcs = 257; * 7: Snowman ("☃") */ static unsigned int cursorshape = 2; +#endif // BLINKING_CURSOR_PATCH /* * Default columns and rows numbers diff --git a/patches.def.h b/patches.def.h index 6d1e95a..aa2433e 100644 --- a/patches.def.h +++ b/patches.def.h @@ -35,6 +35,14 @@ */ #define ANYSIZE_NOBAR_PATCH 0 +/* This patch allows the use of a blinking cursor. + * Only cursor styles 0, 1, 3, 5, and 7 blink. Set cursorstyle accordingly. + * Cursor styles are defined here: + * 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 + * https://st.suckless.org/patches/blinking_cursor/ + */ +#define BLINKING_CURSOR_PATCH 0 + /* By default bold text is rendered with a bold font in the bright variant of the current color. * This patch makes bold text rendered simply as bold, leaving the color unaffected. * https://st.suckless.org/patches/bold-is-not-bright/ diff --git a/x.c b/x.c index 9fd4a88..e61a1fa 100644 --- a/x.c +++ b/x.c @@ -186,6 +186,9 @@ static char *opt_dir = NULL; #endif // WORKINGDIR_PATCH static int oldbutton = 3; /* button event on startup: 3 = release */ +#if BLINKING_CURSOR_PATCH +static int cursorblinks = 0; +#endif // BLINKING_CURSOR_PATCH #if VISUALBELL_1_PATCH static int bellon = 0; /* visual bell status */ #endif // VISUALBELL_1_PATCH @@ -1826,16 +1829,28 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) /* draw the new one */ if (IS_SET(MODE_FOCUSED)) { switch (win.cursor) { + #if !BLINKING_CURSOR_PATCH case 7: /* st extension */ g.u = 0x2603; /* snowman (U+2603) */ /* FALLTHROUGH */ - case 0: /* Blinking Block */ - case 1: /* Blinking Block (Default) */ - case 2: /* Steady Block */ + #endif // BLINKING_CURSOR_PATCH + case 0: /* Blinking block */ + case 1: /* Blinking block (default) */ + #if BLINKING_CURSOR_PATCH + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ + #endif // BLINKING_CURSOR_PATCH + case 2: /* Steady block */ xdrawglyph(g, cx, cy); break; - case 3: /* Blinking Underline */ - case 4: /* Steady Underline */ + case 3: /* Blinking underline */ + #if BLINKING_CURSOR_PATCH + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ + #endif // BLINKING_CURSOR_PATCH + case 4: /* Steady underline */ #if ANYSIZE_PATCH XftDrawRect(xw.draw, &drawcol, win.hborderpx + cx * win.cw, @@ -1851,6 +1866,11 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) #endif // ANYSIZE_PATCH break; case 5: /* Blinking bar */ + #if BLINKING_CURSOR_PATCH + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ + #endif // BLINKING_CURSOR_PATCH case 6: /* Steady bar */ XftDrawRect(xw.draw, &drawcol, #if ANYSIZE_PATCH @@ -1862,6 +1882,16 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) #endif // ANYSIZE_PATCH cursorthickness, win.ch); break; + #if BLINKING_CURSOR_PATCH + case 7: /* Blinking st cursor */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ + case 8: /* Steady st cursor */ + g.u = stcursor; + xdrawglyph(g, cx, cy); + break; + #endif // BLINKING_CURSOR_PATCH } } else { XftDrawRect(xw.draw, &drawcol, @@ -2150,9 +2180,18 @@ xsetmode(int set, unsigned int flags) int xsetcursor(int cursor) { + #if BLINKING_CURSOR_PATCH + if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */ + #else if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */ + #endif // BLINKING_CURSOR_PATCH return 1; win.cursor = cursor; + #if BLINKING_CURSOR_PATCH + cursorblinks = win.cursor == 0 || win.cursor == 1 || + win.cursor == 3 || win.cursor == 5 || + win.cursor == 7; + #endif // BLINKING_CURSOR_PATCH return 0; } @@ -2439,6 +2478,12 @@ run(void) if (FD_ISSET(ttyfd, &rfd) || xev) { if (!drawing) { trigger = now; + #if BLINKING_CURSOR_PATCH + if (IS_SET(MODE_BLINK)) { + win.mode ^= MODE_BLINK; + } + lastblink = now; + #endif // BLINKING_CURSOR_PATCH drawing = 1; } timeout = (maxlatency - TIMEDIFF(now, trigger)) \ @@ -2449,7 +2494,12 @@ run(void) /* idle detected or maxlatency exhausted -> draw */ timeout = -1; - if (blinktimeout && tattrset(ATTR_BLINK)) { + #if BLINKING_CURSOR_PATCH + if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) + #else + if (blinktimeout && tattrset(ATTR_BLINK)) + #endif // BLINKING_CURSOR_PATCH + { timeout = blinktimeout - TIMEDIFF(now, lastblink); if (timeout <= 0) { if (-timeout > blinktimeout) /* start visible */ @@ -2511,7 +2561,11 @@ main(int argc, char *argv[]) { xw.l = xw.t = 0; xw.isfixed = False; + #if BLINKING_CURSOR_PATCH + xsetcursor(cursorstyle); + #else xsetcursor(cursorshape); + #endif // BLINKING_CURSOR_PATCH ARGBEGIN { case 'a':