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 --- x.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'x.c') 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