Simpler implementation for keeping track overlay keys (solution by stacy) - svk… | |
git clone git://git.suckless.org/svkbd | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit c2251315e5e3916293313a71ce0cd92f79c7b220 | |
parent 174c86d8fa3be12802af5127aee0381b5aa3f83e | |
Author: Maarten van Gompel <[email protected]> | |
Date: Sun, 7 Mar 2021 00:14:50 +0100 | |
Simpler implementation for keeping track overlay keys (solution by stacy) | |
Diffstat: | |
M svkbd.c | 27 +++++++++++++-------------- | |
1 file changed, 13 insertions(+), 14 deletions(-) | |
--- | |
diff --git a/svkbd.c b/svkbd.c | |
@@ -47,6 +47,7 @@ typedef struct { | |
int x, y, w, h; | |
Bool pressed; | |
Bool highlighted; | |
+ Bool isoverlay; | |
} Key; | |
typedef struct { | |
@@ -64,7 +65,7 @@ static void configurenotify(XEvent *e); | |
static void countrows(); | |
static int countkeys(Key *layer); | |
static void drawkeyboard(void); | |
-static void drawkey(Key *k, int idx); | |
+static void drawkey(Key *k); | |
static void expose(XEvent *e); | |
static Key *findkey(int x, int y); | |
static void leavenotify(XEvent *e); | |
@@ -104,7 +105,6 @@ static struct timeval pressbegin; | |
static int currentlayer = 0; | |
static int enableoverlays = 1; | |
static int currentoverlay = -1; /* -1 = no overlay */ | |
-static int overlaykeycount = 0; /* number of keys in the current overlay */ | |
static int pressonrelease = 1; | |
static KeySym overlaykeysym = 0; /* keysym for which the overlay is presented … | |
static int releaseprotect = 0; /* set to 1 after overlay is shown, protecting … | |
@@ -152,7 +152,7 @@ motionnotify(XEvent *e) | |
} else { | |
keys[i].highlighted = True; | |
} | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
} | |
continue; | |
} | |
@@ -162,11 +162,11 @@ motionnotify(XEvent *e) | |
lostfocus = i; | |
ispressingkeysym = 0; | |
unpress(&keys[i], 0); | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
} | |
if (keys[i].highlighted == True) { | |
keys[i].highlighted = False; | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
} | |
} | |
@@ -297,12 +297,12 @@ drawkeyboard(void) | |
for (i = 0; i < numkeys; i++) { | |
if (keys[i].keysym != 0) | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
} | |
} | |
void | |
-drawkey(Key *k, int idx) | |
+drawkey(Key *k) | |
{ | |
int x, y, w, h; | |
int x2, y2, w2, h2; | |
@@ -314,7 +314,7 @@ drawkey(Key *k, int idx) | |
use_scheme = SchemePress; | |
else if (k->highlighted) | |
use_scheme = SchemeHighlight; | |
- else if (idx < overlaykeycount) | |
+ else if (k->isoverlay) | |
use_scheme = SchemeOverlay; | |
else if ((k->keysym == XK_Return) || | |
((k->keysym >= XK_a) && (k->keysym <= XK_z)) || | |
@@ -461,7 +461,7 @@ press(Key *k, KeySym mod) | |
} | |
} | |
} | |
- drawkey(k, 0); | |
+ drawkey(k); | |
} | |
int | |
@@ -595,7 +595,7 @@ unpress(Key *k, KeySym mod) | |
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) { | |
simulate_keyrelease(keys[i].keysym); | |
keys[i].pressed = 0; | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
break; | |
} | |
} | |
@@ -609,7 +609,7 @@ unpress(Key *k, KeySym mod) | |
if (keys[i].pressed) { | |
simulate_keyrelease(keys[i].keysym); | |
keys[i].pressed = 0; | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
} | |
} | |
} | |
@@ -913,14 +913,13 @@ showoverlay(int idx) | |
for (i = 0; i < numkeys; i++) { | |
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) { | |
keys[i].pressed = 0; | |
- drawkey(&keys[i], i); | |
+ drawkey(&keys[i]); | |
break; | |
} | |
} | |
for (i = idx, j=0; i < OVERLAYS; i++, j++) { | |
if (overlay[i].keysym == XK_Cancel) { | |
- overlaykeycount = j; | |
break; | |
} | |
while (keys[j].keysym == 0) | |
@@ -931,6 +930,7 @@ showoverlay(int idx) | |
keys[j].label2 = overlay[i].label2; | |
keys[j].keysym = overlay[i].keysym; | |
keys[j].modifier = overlay[i].modifier; | |
+ keys[j].isoverlay = True; | |
} | |
currentoverlay = idx; | |
overlaykeysym = ispressingkeysym; | |
@@ -945,7 +945,6 @@ hideoverlay(void) | |
{ | |
if (debug) printdbg("Hiding overlay, overlay was #%d\n", currentoverla… | |
currentoverlay = -1; | |
- overlaykeycount = 0; | |
overlaykeysym = 0; | |
currentlayer--; | |
cyclelayer(); |