commit a4d8ea1853f5634db8f5db7813453f4b40c74261
parent ae97f681fca0b39b27f6148925ce055be438467d
Author: bakkeby <bakkeby@gmail.com>
Date: Mon, 20 Apr 2020 12:14:49 +0200
Added the force redraw on keypress patch
Diffstat:
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -1,4 +1,4 @@
-Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this st 0.8.2 (51e19ea11dd42eefed1ca136ee3f6be975f618b1, 2020-02-18) project has a different take on st patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.
+Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this st 0.8.2 (c279f5, 2020-04-19) project has a different take on st patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.
For example to include the `alpha` patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/st-flexipatch/blob/master/patches.def.h):
```c
@@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog:
+2020-04-20 - Added the force redraw on pselect after key is pressed patch
+
2020-03-29 - Added invert and workingdir patches
2020-03-24 - Upgraded to latest (master) of st (commit 51e19ea11dd42eefed1ca136ee3f6be975f618b1 at the time of writing). Custom changes to make the altscreen mouse scollback patch working.
@@ -68,6 +70,9 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- [font2](https://st.suckless.org/patches/font2/)
- allows you to add a spare font besides the default
+ - [force-redraw-after-keypress](https://lists.suckless.org/hackers/2004/17221.html)
+ - this patch forces the terminal to check for new data on the tty on keypress with the aim of reducing input latency
+
- [hidecursor](https://st.suckless.org/patches/hidecursor/)
- hides the X cursor whenever a key is pressed and show it back when the mouse is moved in the terminal window
diff --git a/patches.def.h b/patches.def.h
@@ -82,6 +82,15 @@
*/
#define FONT2_PATCH 0
+/* This patch creates a global flag which is set when a keypress is sent
+ * from X which forces the terminal to check for new data on the tty fd on
+ * every return from pselect(). When new data read from the tty results in
+ * a line being redrawn, the flag is reset. This results in a less input lag
+ * when typing on the terminal.
+ * https://lists.suckless.org/hackers/2004/17221.html
+ */
+#define FORCE_REDRAW_AFTER_KEYPRESS 0
+
/* Hide the X cursor whenever a key is pressed and show it back when the mouse is moved in
* the terminal window.
* https://st.suckless.org/patches/hidecursor/
diff --git a/x.c b/x.c
@@ -251,6 +251,9 @@ static DC dc;
static XWindow xw;
static XSelection xsel;
static TermWindow win;
+#if FORCE_REDRAW_AFTER_KEYPRESS
+static int pendingkpress = 0;
+#endif // FORCE_REDRAW_AFTER_KEYPRESS
/* Font Ring Cache */
enum {
@@ -936,6 +939,12 @@ xclear(int x1, int y1, int x2, int y2)
}
void
+xclearwin(void)
+{
+ xclear(0, 0, win.w, win.h);
+}
+
+void
xhints(void)
{
#if XRESOURCES_PATCH
@@ -1937,6 +1946,10 @@ xdrawline(Line line, int x1, int y1, int x2)
Glyph base, new;
XftGlyphFontSpec *specs = xw.specbuf;
+ #if FORCE_REDRAW_AFTER_KEYPRESS
+ pendingkpress = 0;
+ #endif // FORCE_REDRAW_AFTER_KEYPRESS
+
numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
i = ox = 0;
for (x = x1; x < x2 && i < numspecs; x++) {
@@ -2168,6 +2181,10 @@ kpress(XEvent *ev)
Status status;
Shortcut *bp;
+ #if FORCE_REDRAW_AFTER_KEYPRESS
+ pendingkpress = 1;
+ #endif // FORCE_REDRAW_AFTER_KEYPRESS
+
#if HIDECURSOR_PATCH
if (xw.pointerisvisible) {
XDefineCursor(xw.dpy, xw.win, xw.bpointer);
@@ -2330,6 +2347,10 @@ run(void)
tv = &drawtimeout;
dodraw = 0;
+ #if FORCE_REDRAW_AFTER_KEYPRESS
+ if (pendingkpress)
+ dodraw = 1;
+ #endif // FORCE_REDRAW_AFTER_KEYPRESS
#if VISUALBELL_2_PATCH || VISUALBELL_3_PATCH
to_ms = -1; /* timeout in ms, indefinite if negative */
if (blinkset) {