st-visualbell2-basic-2020-05-13-045a0fa.diff (2652B)
1 From 18fc7793b0bb2f9a93d39fe69a72d40122e151eb Mon Sep 17 00:00:00 2001 2 From: "Avi Halachmi (:avih)" <avihpit@yahoo.com> 3 Date: Mon, 15 Oct 2018 01:06:01 +0300 4 Subject: [PATCH] add visual bell with few rendering modes 5 6 - Inverse the whole terminal - "standard" visual-bell, a bit jarring. 7 - Inverse outer (border) cells - much less jarring, yet plenty visible. 8 - Inverse the bottom-right corner only. 9 - Inverse cells according to custom logic. 10 --- 11 config.def.h | 8 ++++++++ 12 x.c | 35 +++++++++++++++++++++++++++++++++++ 13 2 files changed, 43 insertions(+) 14 15 diff --git a/config.def.h b/config.def.h 16 index fdbacfd..fe07204 100644 17 --- a/config.def.h 18 +++ b/config.def.h 19 @@ -69,6 +69,14 @@ static unsigned int cursorthickness = 2; 20 */ 21 static int bellvolume = 0; 22 23 +/* visual-bell timeout in ms (0 to disable visual-bell) */ 24 +static int vbelltimeout = 150; 25 + 26 +/* choose predefined visual-bell cells to inverse, or define your own logic */ 27 +#define VBCELL x==0 || x==right || y==0 || y==bottom /* border */ 28 +// #define VBCELL 1 /* all cells - whole screen */ 29 +// #define VBCELL y==bottom && x>right-2 /* bottom-right */ 30 + 31 /* default TERM value */ 32 char *termname = "st-256color"; 33 34 diff --git a/x.c b/x.c 35 index 1dc44d6..44d5a8d 100644 36 --- a/x.c 37 +++ b/x.c 38 @@ -1592,6 +1592,27 @@ xsettitle(char *p) 39 XFree(prop.value); 40 } 41 42 + 43 +static int vbellset = 0; /* 1 during visual bell, 0 otherwise */ 44 +static struct timespec lastvbell = {0}; 45 + 46 +static int 47 +isvbellcell(int x, int y) 48 +{ 49 + int right = win.tw / win.cw - 1, bottom = win.th / win.ch - 1; 50 + return VBCELL; /* logic condition defined at config.h */ 51 +} 52 + 53 +static void 54 +vbellbegin() { 55 + clock_gettime(CLOCK_MONOTONIC, &lastvbell); 56 + if (vbellset) 57 + return; 58 + vbellset = 1; 59 + redraw(); 60 + XFlush(xw.dpy); 61 +} 62 + 63 int 64 xstartdraw(void) 65 { 66 @@ -1613,6 +1634,8 @@ xdrawline(Line line, int x1, int y1, int x2) 67 continue; 68 if (selected(x, y1)) 69 new.mode ^= ATTR_REVERSE; 70 + if (vbellset && isvbellcell(x, y1)) 71 + new.mode ^= ATTR_REVERSE; 72 if (i > 0 && ATTRCMP(base, new)) { 73 xdrawglyphfontspecs(specs, base, i, ox, y1); 74 specs += i; 75 @@ -1714,6 +1737,8 @@ xbell(void) 76 xseturgency(1); 77 if (bellvolume) 78 XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL); 79 + if (vbelltimeout) 80 + vbellbegin(); 81 } 82 83 void 84 @@ -1959,6 +1984,16 @@ run(void) 85 } 86 } 87 88 + if (vbellset) { 89 + double remain = vbelltimeout - TIMEDIFF(now, lastvbell); 90 + if (remain <= 0) { 91 + vbellset = 0; 92 + redraw(); 93 + } else if (timeout < 0 || remain < timeout) { 94 + timeout = remain; 95 + } 96 + } 97 + 98 draw(); 99 XFlush(xw.dpy); 100 drawing = 0; 101 102 base-commit: 045a0fab4f80b57f4a982ae6bc5f33fe21d66111 103 -- 104 2.17.1 105