st-visualbell2-enhanced-2020-05-13-045a0fa.diff (2963B)
1 From d6a060dfeeef28548e6c6b1fcb92c73c4884cd6c Mon Sep 17 00:00:00 2001 2 From: "Avi Halachmi (:avih)" <avihpit@yahoo.com> 3 Date: Tue, 12 May 2020 11:40:19 +0300 4 Subject: [PATCH] visual bell: add circle rendering mode 5 6 This commit experiments with alternative rendering of visual bell, 7 and as such it's extensively/excessively configurable. 8 9 It renders an overlay of a circle with configurable colors (base, 10 outline), position and size. Defaults to the center of the window. 11 12 Size can be relative to window or chars width, and allows for instance 13 to place it at the middle/side of a top/bottom tmux status-bar with 14 exact char height to make it look like a flashing LED at the bar, etc. 15 --- 16 config.def.h | 11 +++++++++++ 17 x.c | 21 ++++++++++++++++++++- 18 2 files changed, 31 insertions(+), 1 deletion(-) 19 20 diff --git a/config.def.h b/config.def.h 21 index fe07204..927dfea 100644 22 --- a/config.def.h 23 +++ b/config.def.h 24 @@ -77,6 +77,17 @@ static int vbelltimeout = 150; 25 // #define VBCELL 1 /* all cells - whole screen */ 26 // #define VBCELL y==bottom && x>right-2 /* bottom-right */ 27 28 +static int vbellmode = 1; 29 +/* vbellmode: 0: invert cells. 1: draw a circle with these parameters: 30 + * - base and outline colors (colorname index - see below) 31 + * - radius: relative to window width, or if negative: relative to cell-width 32 + * - position: relative to window width/height (0 and 1 are at the edges) */ 33 +static int vbellcolor = 3; 34 +static int vbellcolor_outline = 1; 35 +static float vbellradius = 0.03; 36 +static float vbellx = 0.5; 37 +static float vbelly = 0.5; 38 + 39 /* default TERM value */ 40 char *termname = "st-256color"; 41 42 diff --git a/x.c b/x.c 43 index 44d5a8d..189aa1c 100644 44 --- a/x.c 45 +++ b/x.c 46 @@ -1600,7 +1600,7 @@ 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 + return vbellmode == 0 && (VBCELL); /* logic defined at config.h */ 52 } 53 54 static void 55 @@ -1613,6 +1613,22 @@ vbellbegin() { 56 XFlush(xw.dpy); 57 } 58 59 +static void 60 +xfillcircle(int x, int y, int r, uint color_ix) 61 +{ 62 + XSetForeground(xw.dpy, dc.gc, dc.col[color_ix].pixel); 63 + XFillArc(xw.dpy, xw.buf, dc.gc, x - r, y - r, r * 2, r * 2, 0, 360*64); 64 +} 65 + 66 +static void 67 +xdrawvbell() { 68 + int r = round(vbellradius * (vbellradius > 0 ? win.w : -win.cw)); 69 + int x = borderpx + r + vbellx * (win.tw - 2 * r); 70 + int y = borderpx + r + vbelly * (win.th - 2 * r); 71 + xfillcircle(x, y, r, vbellcolor_outline); 72 + xfillcircle(x, y, r / 1.2, vbellcolor); /* 1.2 - an artistic choice */ 73 +} 74 + 75 int 76 xstartdraw(void) 77 { 78 @@ -1655,6 +1671,9 @@ xdrawline(Line line, int x1, int y1, int x2) 79 void 80 xfinishdraw(void) 81 { 82 + if (vbellset && vbellmode == 1) 83 + xdrawvbell(); 84 + 85 XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, 86 win.h, 0, 0); 87 XSetForeground(xw.dpy, dc.gc, 88 89 base-commit: 045a0fab4f80b57f4a982ae6bc5f33fe21d66111 90 prerequisite-patch-id: d5f30ab22e0caa901341e31c40606787c3921821 91 -- 92 2.17.1 93