Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.1 KiB

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