add check for debug flag in printdbg() function itself

This commit is contained in:
Hiltjo Posthuma 2021-03-28 14:56:05 +02:00
parent 7980cb5f51
commit 4b5a61b275
1 changed files with 25 additions and 40 deletions

31
svkbd.c
View File

@ -165,7 +165,6 @@ motionnotify(XEvent *e)
for (i = 0; i < numkeys; i++) { for (i = 0; i < numkeys; i++) {
if (!IsModifierKey(keys[i].keysym) && keys[i].pressed == True && lostfocus != gainedfocus) { if (!IsModifierKey(keys[i].keysym) && keys[i].pressed == True && lostfocus != gainedfocus) {
if (debug)
printdbg("Pressed key lost focus: %ld\n", keys[i].keysym); printdbg("Pressed key lost focus: %ld\n", keys[i].keysym);
lostfocus = i; lostfocus = i;
ispressingkeysym = 0; ispressingkeysym = 0;
@ -175,7 +174,6 @@ motionnotify(XEvent *e)
} }
if ((lostfocus != -1) && (gainedfocus != -1) && (lostfocus != gainedfocus)) { if ((lostfocus != -1) && (gainedfocus != -1) && (lostfocus != gainedfocus)) {
if (debug)
printdbg("Clicking new key that gained focus\n"); printdbg("Clicking new key that gained focus\n");
press(&keys[gainedfocus], 0); press(&keys[gainedfocus], 0);
keys[gainedfocus].pressed = True; keys[gainedfocus].pressed = True;
@ -433,7 +431,6 @@ press(Key *k, KeySym buttonmod)
k->pressed = !k->pressed; k->pressed = !k->pressed;
if (debug)
printdbg("Begin click: %ld\n", k->keysym); printdbg("Begin click: %ld\n", k->keysym);
pressbegin.tv_sec = 0; pressbegin.tv_sec = 0;
pressbegin.tv_usec = 0; pressbegin.tv_usec = 0;
@ -446,7 +443,6 @@ press(Key *k, KeySym buttonmod)
/*record the begin of the press, don't simulate the actual keypress yet */ /*record the begin of the press, don't simulate the actual keypress yet */
record_press_begin(k->keysym); record_press_begin(k->keysym);
} else { } else {
if (debug)
printdbg("Simulating press: %ld (mod %ld)\n", k->keysym, buttonmod); printdbg("Simulating press: %ld (mod %ld)\n", k->keysym, buttonmod);
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)) {
@ -493,7 +489,6 @@ printkey(Key *k, KeySym mod)
} }
} }
} }
if (debug)
printdbg("Printing key %ld (shift=%d)\n", k->keysym, shift); printdbg("Printing key %ld (shift=%d)\n", k->keysym, shift);
if (k->keysym == XK_Cancel) if (k->keysym == XK_Cancel)
return; return;
@ -514,7 +509,6 @@ printkey(Key *k, KeySym mod)
Status return_status; Status return_status;
int l = Xutf8LookupString(xic, &event, buffer, 32, &ignore, &return_status); int l = Xutf8LookupString(xic, &event, buffer, 32, &ignore, &return_status);
buffer[l] = '\0'; buffer[l] = '\0';
if (debug)
printdbg("Print buffer: [%s] (length=%d)\n", &buffer, l); printdbg("Print buffer: [%s] (length=%d)\n", &buffer, l);
printf("%s", buffer); printf("%s", buffer);
@ -579,7 +573,6 @@ unpress(Key *k, KeySym buttonmod)
} }
if ((pressbegin.tv_sec || pressbegin.tv_usec) && (enableoverlays || pressonrelease) && k && k->keysym == ispressingkeysym) { if ((pressbegin.tv_sec || pressbegin.tv_usec) && (enableoverlays || pressonrelease) && k && k->keysym == ispressingkeysym) {
if (debug)
printdbg("Delayed simulation of press after release: %ld\n", k->keysym); printdbg("Delayed simulation of press after release: %ld\n", k->keysym);
/* simulate the press event, as we postponed it earlier in press() */ /* simulate the press event, as we postponed it earlier in press() */
for (i = 0; i < numkeys; i++) { for (i = 0; i < numkeys; i++) {
@ -595,14 +588,10 @@ unpress(Key *k, KeySym buttonmod)
pressbegin.tv_usec = 0; pressbegin.tv_usec = 0;
} }
if (debug) { if (k)
if (k) {
printdbg("Simulation of release: %ld\n", k->keysym); printdbg("Simulation of release: %ld\n", k->keysym);
} else { else
printdbg("Simulation of release (all keys)\n"); printdbg("Simulation of release (all keys)\n");
}
}
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)) {
@ -670,19 +659,17 @@ run(void)
/* time-out expired without anything interesting happening, check for long-presses */ /* time-out expired without anything interesting happening, check for long-presses */
if (ispressing && ispressingkeysym) { if (ispressing && ispressingkeysym) {
duration = get_press_duration(); duration = get_press_duration();
if (debug == 2) if (debug >= 2)
printdbg("%f\n", duration); printdbg("%f\n", duration);
overlayidx = hasoverlay(ispressingkeysym); overlayidx = hasoverlay(ispressingkeysym);
duration = get_press_duration(); duration = get_press_duration();
if ((overlayidx != -1) && (duration >= overlay_delay)) { if ((overlayidx != -1) && (duration >= overlay_delay)) {
if (debug)
printdbg("press duration %f, activating overlay\n", duration); printdbg("press duration %f, activating overlay\n", duration);
showoverlay(overlayidx); showoverlay(overlayidx);
pressbegin.tv_sec = 0; pressbegin.tv_sec = 0;
pressbegin.tv_usec = 0; pressbegin.tv_usec = 0;
ispressingkeysym = 0; ispressingkeysym = 0;
} else if ((overlayidx == -1) && (duration >= repeat_delay)) { } else if ((overlayidx == -1) && (duration >= repeat_delay)) {
if (debug)
printdbg("press duration %f, activating repeat\n", duration); printdbg("press duration %f, activating repeat\n", duration);
simulate_keyrelease(ispressingkeysym); simulate_keyrelease(ispressingkeysym);
simulate_keypress(ispressingkeysym); simulate_keypress(ispressingkeysym);
@ -698,7 +685,6 @@ run(void)
since then X doesn't know the keyup is never coming.. (since since then X doesn't know the keyup is never coming.. (since
process will be dead before finger lifts - in that case we process will be dead before finger lifts - in that case we
just trigger out fake up presses for all keys */ just trigger out fake up presses for all keys */
if (debug)
printdbg("signal received, releasing all keys"); printdbg("signal received, releasing all keys");
for (i = 0; i < numkeys; i++) { for (i = 0; i < numkeys; i++) {
XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, keys[i].keysym), False, 0); XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, keys[i].keysym), False, 0);
@ -990,7 +976,6 @@ cyclelayer(void)
currentlayer++; currentlayer++;
if (currentlayer >= numlayers) if (currentlayer >= numlayers)
currentlayer = 0; currentlayer = 0;
if (debug)
printdbg("Cycling to layer %d\n", currentlayer); printdbg("Cycling to layer %d\n", currentlayer);
setlayer(); setlayer();
updatekeys(); updatekeys();
@ -1005,7 +990,6 @@ togglelayer(void)
} else if (numlayers > 1) { } else if (numlayers > 1) {
currentlayer = 1; currentlayer = 1;
} }
if (debug)
printdbg("Toggling layer %d\n", currentlayer); printdbg("Toggling layer %d\n", currentlayer);
setlayer(); setlayer();
updatekeys(); updatekeys();
@ -1015,9 +999,9 @@ togglelayer(void)
void void
showoverlay(int idx) showoverlay(int idx)
{ {
if (debug) int i, j;
printdbg("Showing overlay %d\n", idx); printdbg("Showing overlay %d\n", idx);
int i,j;
/* unpress existing key (visually only) */ /* unpress existing key (visually only) */
for (i = 0; i < numkeys; i++) { for (i = 0; i < numkeys; i++) {
@ -1053,7 +1037,6 @@ showoverlay(int idx)
void void
hideoverlay(void) hideoverlay(void)
{ {
if (debug)
printdbg("Hiding overlay, overlay was #%d\n", currentoverlay); printdbg("Hiding overlay, overlay was #%d\n", currentoverlay);
currentoverlay = -1; currentoverlay = -1;
overlaykeysym = 0; overlaykeysym = 0;
@ -1066,7 +1049,6 @@ sigterm(int signo)
{ {
running = False; running = False;
sigtermd = True; sigtermd = True;
if (debug)
printdbg("SIGTERM received\n"); printdbg("SIGTERM received\n");
} }
@ -1118,6 +1100,9 @@ init_layers(char *layer_names_list, const char *initial_layer_name)
void void
printdbg(const char *fmt, ...) printdbg(const char *fmt, ...)
{ {
if (!debug)
return;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);