st-blinking_cursor-20211116-2f6e597.diff 4.2 KB

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