[hackers] [PATCH 4/5] increase spacing, set scheme for window, make window render faster by removing unnecessary map requests to X

From: Maarten van Gompel <proycon_AT_anaproy.nl>
Date: Sun, 13 Jun 2021 22:28:00 +0200

---
 config.def.h |  5 +++--
 svkbd.c      | 35 ++++++++++++++++++++---------------
 2 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/config.def.h b/config.def.h
index 21e9f49..cb9d134 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -4,8 +4,8 @@ static double overlay_delay = 1.0; //in seconds
 static double repeat_delay = 0.75; //in seconds, will not work on keys with overlays
 static int scan_rate = 50; //scan rate in microseconds, affects key repetition rate
 static int heightfactor = 14; //one row of keys takes up 1/x of the screen height
-static int xspacing = 3;
-static int yspacing = 3;
+static int xspacing = 5;
+static int yspacing = 5;
 static const char *defaultfonts[] = {
 	"DejaVu Sans:bold:size=22"
 };
_AT_@ -21,5 +21,6 @@ static const char *defaultcolors[SchemeLast][2] = {
 	[SchemeHighlightShift] = { "#008ac0", "#005577" },
 	[SchemeOverlay] = { "#ffffff", "#2b3313" },
 	[SchemeOverlayShift] = { "#008ac0", "#2b3313" },
+	[SchemeWindow] = { "#bbbbbb", "#132a33" },
 };
 
diff --git a/svkbd.c b/svkbd.c
index 9d85b52..009fff1 100644
--- a/svkbd.c
+++ b/svkbd.c
_AT_@ -38,7 +38,7 @@
 enum {
 	SchemeNorm, SchemeNormABC, SchemeNormABCShift, SchemeNormShift, SchemePress,
 	SchemePressShift, SchemeHighlight, SchemeHighlightShift, SchemeOverlay,
-	SchemeOverlayShift, SchemeLast
+	SchemeOverlayShift, SchemeWindow, SchemeLast
 };
 enum { NetWMWindowType, NetLast };
 
_AT_@ -70,7 +70,7 @@ static void configurenotify(XEvent *e);
 static void countrows();
 static int countkeys(Key *layer);
 static void drawkeyboard(void);
-static void drawkey(Key *k);
+static void drawkey(Key *k, Bool map);
 static void expose(XEvent *e);
 static Key *findkey(int x, int y);
 static void leavenotify(XEvent *e);
_AT_@ -121,7 +121,7 @@ static int debug = 0;
 static int numlayers = 0;
 static int numkeys = 0;
 
-static char *colors[10][2]; /* 10 schemes, 2 colors each */
+static char *colors[11][2]; /* 11 schemes, 2 colors each */
 static char *fonts[] = { 0 };
 
 static KeySym ispressingkeysym;
_AT_@ -158,12 +158,12 @@ motionnotify(XEvent *e)
 				} else {
 					keys[i].highlighted = True;
 				}
-				drawkey(&keys[i]);
+				drawkey(&keys[i], True);
 			}
 			continue;
 		} else if (keys[i].highlighted == True) {
 			keys[i].highlighted = False;
-			drawkey(&keys[i]);
+			drawkey(&keys[i], True);
 		}
 	}
 
_AT_@ -173,7 +173,7 @@ motionnotify(XEvent *e)
 			lostfocus = i;
 			ispressingkeysym = 0;
 			keys[i].pressed = 0;
-			drawkey(&keys[i]);
+			drawkey(&keys[i], True);
 		}
 	}
 
_AT_@ -309,18 +309,17 @@ drawkeyboard(void)
 	int i;
 	int row = 0;
 
-	drw_setscheme(drw, scheme[SchemeNorm]);
+	drw_setscheme(drw, scheme[SchemeWindow]);
 	drw_rect(drw, 0, 0, ww, wh, 1, 1);
-	drw_map(drw, win, 0, 0, ww, wh);
 	for (i = 0; i < numkeys; i++) {
 		if (keys[i].keysym != 0)
-			drawkey(&keys[i]);
+			drawkey(&keys[i], False);
 	}
 	drw_map(drw, win, 0, 0, ww, wh);
 }
 
 void
-drawkey(Key *k)
+drawkey(Key *k, Bool map)
 {
 	int x, y, w, h;
 	const char *l;
_AT_@ -377,7 +376,8 @@ drawkey(Key *k)
 		w = TEXTW(l);
 		drw_text(drw, x, y, w, h, 0, l, 0);
 	}
-	drw_map(drw, win, k->x, k->y, k->w, k->h);
+	if (map)
+		drw_map(drw, win, k->x, k->y, k->w, k->h);
 }
 
 void
_AT_@ -475,7 +475,7 @@ press(Key *k, KeySym buttonmod)
 			}
 		}
 	}
-	drawkey(k);
+	drawkey(k, True);
 }
 
 int
_AT_@ -625,7 +625,7 @@ unpress(Key *k, KeySym buttonmod)
 			if (printoutput)
 				printkey(&keys[i], buttonmod);
 			keys[i].pressed = 0;
-			drawkey(&keys[i]);
+			drawkey(&keys[i], True);
 		}
 	}
 
_AT_@ -639,7 +639,7 @@ unpress(Key *k, KeySym buttonmod)
 				if (!(keys[i].keysym == buttonmod && neutralizebuttonmod))
 					simulate_keyrelease(keys[i].keysym);
 				keys[i].pressed = 0;
-				drawkey(&keys[i]);
+				drawkey(&keys[i], True);
 			}
 		}
 	}
_AT_@ -786,6 +786,11 @@ readxresources(void)
 		if (XrmGetResource(xdb, "svkbd.overlayshiftforeground", "*", &type, &xval) && !colors[SchemeOverlayShift][ColFg])
 			colors[SchemeOverlayShift][ColFg] = estrdup(xval.addr);
 
+		if (XrmGetResource(xdb, "svkbd.windowbackground", "*", &type, &xval) && !colors[SchemeWindow][ColBg])
+			colors[SchemeWindow][ColBg] = estrdup(xval.addr);
+		if (XrmGetResource(xdb, "svkbd.windowforeground", "*", &type, &xval) && !colors[SchemeWindow][ColFg])
+			colors[SchemeWindow][ColFg] = estrdup(xval.addr);
+
 		XrmDestroyDatabase(xdb);
 	}
 }
_AT_@ -1037,7 +1042,7 @@ showoverlay(int idx)
 	for (i = 0; i < numkeys; i++) {
 		if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
 			keys[i].pressed = 0;
-			drawkey(&keys[i]);
+			drawkey(&keys[i], True);
 			break;
 		}
 	}
-- 
2.32.0
Received on Sun Jun 13 2021 - 22:28:00 CEST

This archive was generated by hypermail 2.3.0 : Sun Jun 13 2021 - 23:12:31 CEST