mirror of
git://git.suckless.org/svkbd
synced 2025-02-17 19:16:59 +00:00
Simpler implementation for keeping track overlay keys (solution by stacy)
This commit is contained in:
parent
174c86d8fa
commit
c2251315e5
27
svkbd.c
27
svkbd.c
@ -47,6 +47,7 @@ typedef struct {
|
|||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
Bool pressed;
|
Bool pressed;
|
||||||
Bool highlighted;
|
Bool highlighted;
|
||||||
|
Bool isoverlay;
|
||||||
} Key;
|
} Key;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -64,7 +65,7 @@ static void configurenotify(XEvent *e);
|
|||||||
static void countrows();
|
static void countrows();
|
||||||
static int countkeys(Key *layer);
|
static int countkeys(Key *layer);
|
||||||
static void drawkeyboard(void);
|
static void drawkeyboard(void);
|
||||||
static void drawkey(Key *k, int idx);
|
static void drawkey(Key *k);
|
||||||
static void expose(XEvent *e);
|
static void expose(XEvent *e);
|
||||||
static Key *findkey(int x, int y);
|
static Key *findkey(int x, int y);
|
||||||
static void leavenotify(XEvent *e);
|
static void leavenotify(XEvent *e);
|
||||||
@ -104,7 +105,6 @@ static struct timeval pressbegin;
|
|||||||
static int currentlayer = 0;
|
static int currentlayer = 0;
|
||||||
static int enableoverlays = 1;
|
static int enableoverlays = 1;
|
||||||
static int currentoverlay = -1; /* -1 = no overlay */
|
static int currentoverlay = -1; /* -1 = no overlay */
|
||||||
static int overlaykeycount = 0; /* number of keys in the current overlay */
|
|
||||||
static int pressonrelease = 1;
|
static int pressonrelease = 1;
|
||||||
static KeySym overlaykeysym = 0; /* keysym for which the overlay is presented */
|
static KeySym overlaykeysym = 0; /* keysym for which the overlay is presented */
|
||||||
static int releaseprotect = 0; /* set to 1 after overlay is shown, protecting against immediate release */
|
static int releaseprotect = 0; /* set to 1 after overlay is shown, protecting against immediate release */
|
||||||
@ -152,7 +152,7 @@ motionnotify(XEvent *e)
|
|||||||
} else {
|
} else {
|
||||||
keys[i].highlighted = True;
|
keys[i].highlighted = True;
|
||||||
}
|
}
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -162,11 +162,11 @@ motionnotify(XEvent *e)
|
|||||||
lostfocus = i;
|
lostfocus = i;
|
||||||
ispressingkeysym = 0;
|
ispressingkeysym = 0;
|
||||||
unpress(&keys[i], 0);
|
unpress(&keys[i], 0);
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
if (keys[i].highlighted == True) {
|
if (keys[i].highlighted == True) {
|
||||||
keys[i].highlighted = False;
|
keys[i].highlighted = False;
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,12 +297,12 @@ drawkeyboard(void)
|
|||||||
|
|
||||||
for (i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if (keys[i].keysym != 0)
|
if (keys[i].keysym != 0)
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawkey(Key *k, int idx)
|
drawkey(Key *k)
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
int x2, y2, w2, h2;
|
int x2, y2, w2, h2;
|
||||||
@ -314,7 +314,7 @@ drawkey(Key *k, int idx)
|
|||||||
use_scheme = SchemePress;
|
use_scheme = SchemePress;
|
||||||
else if (k->highlighted)
|
else if (k->highlighted)
|
||||||
use_scheme = SchemeHighlight;
|
use_scheme = SchemeHighlight;
|
||||||
else if (idx < overlaykeycount)
|
else if (k->isoverlay)
|
||||||
use_scheme = SchemeOverlay;
|
use_scheme = SchemeOverlay;
|
||||||
else if ((k->keysym == XK_Return) ||
|
else if ((k->keysym == XK_Return) ||
|
||||||
((k->keysym >= XK_a) && (k->keysym <= XK_z)) ||
|
((k->keysym >= XK_a) && (k->keysym <= XK_z)) ||
|
||||||
@ -461,7 +461,7 @@ press(Key *k, KeySym mod)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawkey(k, 0);
|
drawkey(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -595,7 +595,7 @@ unpress(Key *k, KeySym mod)
|
|||||||
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
||||||
simulate_keyrelease(keys[i].keysym);
|
simulate_keyrelease(keys[i].keysym);
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -609,7 +609,7 @@ unpress(Key *k, KeySym mod)
|
|||||||
if (keys[i].pressed) {
|
if (keys[i].pressed) {
|
||||||
simulate_keyrelease(keys[i].keysym);
|
simulate_keyrelease(keys[i].keysym);
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -913,14 +913,13 @@ showoverlay(int idx)
|
|||||||
for (i = 0; i < numkeys; i++) {
|
for (i = 0; i < numkeys; i++) {
|
||||||
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
if (keys[i].pressed && !IsModifierKey(keys[i].keysym)) {
|
||||||
keys[i].pressed = 0;
|
keys[i].pressed = 0;
|
||||||
drawkey(&keys[i], i);
|
drawkey(&keys[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = idx, j=0; i < OVERLAYS; i++, j++) {
|
for (i = idx, j=0; i < OVERLAYS; i++, j++) {
|
||||||
if (overlay[i].keysym == XK_Cancel) {
|
if (overlay[i].keysym == XK_Cancel) {
|
||||||
overlaykeycount = j;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while (keys[j].keysym == 0)
|
while (keys[j].keysym == 0)
|
||||||
@ -931,6 +930,7 @@ showoverlay(int idx)
|
|||||||
keys[j].label2 = overlay[i].label2;
|
keys[j].label2 = overlay[i].label2;
|
||||||
keys[j].keysym = overlay[i].keysym;
|
keys[j].keysym = overlay[i].keysym;
|
||||||
keys[j].modifier = overlay[i].modifier;
|
keys[j].modifier = overlay[i].modifier;
|
||||||
|
keys[j].isoverlay = True;
|
||||||
}
|
}
|
||||||
currentoverlay = idx;
|
currentoverlay = idx;
|
||||||
overlaykeysym = ispressingkeysym;
|
overlaykeysym = ispressingkeysym;
|
||||||
@ -945,7 +945,6 @@ hideoverlay(void)
|
|||||||
{
|
{
|
||||||
if (debug) printdbg("Hiding overlay, overlay was #%d\n", currentoverlay);
|
if (debug) printdbg("Hiding overlay, overlay was #%d\n", currentoverlay);
|
||||||
currentoverlay = -1;
|
currentoverlay = -1;
|
||||||
overlaykeycount = 0;
|
|
||||||
overlaykeysym = 0;
|
overlaykeysym = 0;
|
||||||
currentlayer--;
|
currentlayer--;
|
||||||
cyclelayer();
|
cyclelayer();
|
||||||
|
Loading…
Reference in New Issue
Block a user