sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit e946e2a4b00aa1132dd01886abb0dd1eb4729623
parent 7c8331357d86974fa708e82131d1eb4ba35fcda9
Author: Avi Halachmi (:avih) <avihpit@yahoo.com>
Date:   Wed, 13 May 2020 00:44:39 +0300

[st][patch][visualbell2] rebased to newest st, reduce page text

Diffstat:
Mst.suckless.org/patches/visualbell2/index.md | 38++++++++++++++++----------------------
Ast.suckless.org/patches/visualbell2/st-visualbell2-basic-2020-05-13-045a0fa.diff | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ast.suckless.org/patches/visualbell2/st-visualbell2-enhanced-2020-05-13-045a0fa.diff | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 214 insertions(+), 22 deletions(-)

diff --git a/st.suckless.org/patches/visualbell2/index.md b/st.suckless.org/patches/visualbell2/index.md @@ -4,37 +4,31 @@ Description ----------- Briefly renders a configurable visual indication on terminal bell event. -Notes ------ -* There are two variants available for download: basic and enhanced. -* The enhanced version file already includes the basic version in it, and - supports the basic options too. -* Both variants can be applied with either `git am <patch-file>` or ` patch -p1 - < <patch-file>`. -* Visual bell is disabled by default, and can be enabled/configured via - `config.h`. If you already have this file, you'll need to add the visual-bell - values by copying them from `config.def.h` - which also includes their docs. +Two variants are available: ### The basic variant supports: -* Invert the whole screen (default). -* Invert only the outer (border) cells for a less jarring effect. -* Configuring the flash duration (default: 100ms). - -### The enhanced variant: -This version experiments with a more graphical indication, by adding support -for rendering a filled circle (needs to be chosen at `config.h`), which can be -configured for: +* Invert the whole screen, or the border cells, or (only in 2020-05-13) the + bottom-right corner or any custom group of cells. +* Configurable duration (default: 150ms). +### The enhanced variant supports in addition: +Rendeding a configurable circle: * Position: any corner/edge, center of the screen, or anything in between. * Size: relative to the window width or to the cell width. -* Colors: base and outline. +* Colors: inner and outline. -The enhanced variant allows, for instance, to render what looks like a LED -indicator at a tmux status bar, with correct cell height, and can be positioned -at the side/middle of a top/bottom bar, etc. +Notes +----- +* All files are git patches and can be applied with either `git am` or `patch`. +* Configuration is done at `config.h`. Download -------- +After st 0.8.3 (the enhanced patch needs the basic patch applied first): +* [st-visualbell2-basic-2020-05-13-045a0fa.diff](st-visualbell2-basic-2020-05-13-045a0fa.diff) +* [st-visualbell2-enhanced-2020-05-13-045a0fa.diff](st-visualbell2-enhanced-2020-05-13-045a0fa.diff) + +st 0.8.3 or earlier (the enhanced patch also includes basic in the same file): * [st-visualbell2-basic-2018-10-16-30ec9a3.diff](st-visualbell2-basic-2018-10-16-30ec9a3.diff) * [st-visualbell2-enhanced-2018-10-16-30ec9a3.diff](st-visualbell2-enhanced-2018-10-16-30ec9a3.diff) diff --git a/st.suckless.org/patches/visualbell2/st-visualbell2-basic-2020-05-13-045a0fa.diff b/st.suckless.org/patches/visualbell2/st-visualbell2-basic-2020-05-13-045a0fa.diff @@ -0,0 +1,105 @@ +From 18fc7793b0bb2f9a93d39fe69a72d40122e151eb Mon Sep 17 00:00:00 2001 +From: "Avi Halachmi (:avih)" <avihpit@yahoo.com> +Date: Mon, 15 Oct 2018 01:06:01 +0300 +Subject: [PATCH] add visual bell with few rendering modes + +- Inverse the whole terminal - "standard" visual-bell, a bit jarring. +- Inverse outer (border) cells - much less jarring, yet plenty visible. +- Inverse the bottom-right corner only. +- Inverse cells according to custom logic. +--- + config.def.h | 8 ++++++++ + x.c | 35 +++++++++++++++++++++++++++++++++++ + 2 files changed, 43 insertions(+) + +diff --git a/config.def.h b/config.def.h +index fdbacfd..fe07204 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -69,6 +69,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 1dc44d6..44d5a8d 100644 +--- a/x.c ++++ b/x.c +@@ -1592,6 +1592,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) + { +@@ -1613,6 +1634,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; +@@ -1714,6 +1737,8 @@ xbell(void) + xseturgency(1); + if (bellvolume) + XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL); ++ if (vbelltimeout) ++ vbellbegin(); + } + + void +@@ -1959,6 +1984,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; + +base-commit: 045a0fab4f80b57f4a982ae6bc5f33fe21d66111 +-- +2.17.1 + diff --git a/st.suckless.org/patches/visualbell2/st-visualbell2-enhanced-2020-05-13-045a0fa.diff b/st.suckless.org/patches/visualbell2/st-visualbell2-enhanced-2020-05-13-045a0fa.diff @@ -0,0 +1,93 @@ +From d6a060dfeeef28548e6c6b1fcb92c73c4884cd6c Mon Sep 17 00:00:00 2001 +From: "Avi Halachmi (:avih)" <avihpit@yahoo.com> +Date: Tue, 12 May 2020 11:40:19 +0300 +Subject: [PATCH] visual bell: add circle rendering mode + +This commit experiments with alternative rendering of visual bell, +and as such it's extensively/excessively configurable. + +It renders an overlay of a circle with configurable colors (base, +outline), position and size. Defaults to the center of the window. + +Size can be relative to window or chars width, and allows for instance +to place it at the middle/side of a top/bottom tmux status-bar with +exact char height to make it look like a flashing LED at the bar, etc. +--- + config.def.h | 11 +++++++++++ + x.c | 21 ++++++++++++++++++++- + 2 files changed, 31 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index fe07204..927dfea 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -77,6 +77,17 @@ static int vbelltimeout = 150; + // #define VBCELL 1 /* all cells - whole screen */ + // #define VBCELL y==bottom && x>right-2 /* bottom-right */ + ++static int vbellmode = 1; ++/* vbellmode: 0: invert cells. 1: draw a circle with these parameters: ++ * - base and outline colors (colorname index - see below) ++ * - radius: relative to window width, or if negative: relative to cell-width ++ * - position: relative to window width/height (0 and 1 are at the edges) */ ++static int vbellcolor = 3; ++static int vbellcolor_outline = 1; ++static float vbellradius = 0.03; ++static float vbellx = 0.5; ++static float vbelly = 0.5; ++ + /* default TERM value */ + char *termname = "st-256color"; + +diff --git a/x.c b/x.c +index 44d5a8d..189aa1c 100644 +--- a/x.c ++++ b/x.c +@@ -1600,7 +1600,7 @@ 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 */ ++ return vbellmode == 0 && (VBCELL); /* logic defined at config.h */ + } + + static void +@@ -1613,6 +1613,22 @@ vbellbegin() { + XFlush(xw.dpy); + } + ++static void ++xfillcircle(int x, int y, int r, uint color_ix) ++{ ++ XSetForeground(xw.dpy, dc.gc, dc.col[color_ix].pixel); ++ XFillArc(xw.dpy, xw.buf, dc.gc, x - r, y - r, r * 2, r * 2, 0, 360*64); ++} ++ ++static void ++xdrawvbell() { ++ int r = round(vbellradius * (vbellradius > 0 ? win.w : -win.cw)); ++ int x = borderpx + r + vbellx * (win.tw - 2 * r); ++ int y = borderpx + r + vbelly * (win.th - 2 * r); ++ xfillcircle(x, y, r, vbellcolor_outline); ++ xfillcircle(x, y, r / 1.2, vbellcolor); /* 1.2 - an artistic choice */ ++} ++ + int + xstartdraw(void) + { +@@ -1655,6 +1671,9 @@ xdrawline(Line line, int x1, int y1, int x2) + void + xfinishdraw(void) + { ++ if (vbellset && vbellmode == 1) ++ xdrawvbell(); ++ + XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, + win.h, 0, 0); + XSetForeground(xw.dpy, dc.gc, + +base-commit: 045a0fab4f80b57f4a982ae6bc5f33fe21d66111 +prerequisite-patch-id: d5f30ab22e0caa901341e31c40606787c3921821 +-- +2.17.1 +