From 354bf243ff0b3e93e890f3ee34cb85ba95135e8d Mon Sep 17 00:00:00 2001 From: davidpkj Date: Wed, 15 Feb 2023 10:45:48 +0100 Subject: Patch: visualbell2-basic-2020-05-13 --- config.def.h | 8 ++++++++ x.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/config.def.h b/config.def.h index aa8dfd0..37b85d1 100644 --- a/config.def.h +++ b/config.def.h @@ -73,6 +73,14 @@ static unsigned int cursorthickness = 2; */ static int bellvolume = 0; +/* visual-bell timeout in ms (0 to disable visual-bell) */ +static int vbelltimeout = 150; + +/* choose predefined visual-bell cells to inverse, or define your own logic */ +#define VBCELL x==0 || x==right || y==0 || y==bottom /* border */ +// #define VBCELL 1 /* all cells - whole screen */ +// #define VBCELL y==bottom && x>right-2 /* bottom-right */ + /* default TERM value */ char *termname = "st-256color"; diff --git a/x.c b/x.c index ff4e284..39af5da 100644 --- a/x.c +++ b/x.c @@ -1704,6 +1704,27 @@ xsettitle(char *p) XFree(prop.value); } + +static int vbellset = 0; /* 1 during visual bell, 0 otherwise */ +static struct timespec lastvbell = {0}; + +static int +isvbellcell(int x, int y) +{ + int right = win.tw / win.cw - 1, bottom = win.th / win.ch - 1; + return VBCELL; /* logic condition defined at config.h */ +} + +static void +vbellbegin() { + clock_gettime(CLOCK_MONOTONIC, &lastvbell); + if (vbellset) + return; + vbellset = 1; + redraw(); + XFlush(xw.dpy); +} + int xstartdraw(void) { @@ -1725,6 +1746,8 @@ xdrawline(Line line, int x1, int y1, int x2) continue; if (selected(x, y1)) new.mode ^= ATTR_REVERSE; + if (vbellset && isvbellcell(x, y1)) + new.mode ^= ATTR_REVERSE; if (i > 0 && ATTRCMP(base, new)) { xdrawglyphfontspecs(specs, base, i, ox, y1); specs += i; @@ -1828,6 +1851,8 @@ xbell(void) xseturgency(1); if (bellvolume) XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL); + if (vbelltimeout) + vbellbegin(); } void @@ -2080,6 +2105,16 @@ run(void) } } + if (vbellset) { + double remain = vbelltimeout - TIMEDIFF(now, lastvbell); + if (remain <= 0) { + vbellset = 0; + redraw(); + } else if (timeout < 0 || remain < timeout) { + timeout = remain; + } + } + draw(); XFlush(xw.dpy); drawing = 0; -- cgit v1.2.3