Split keypress function in a WinConfirm and a WinPin branch

pull/4/head
Moritz Luedecke 7 years ago
parent 734f628b4a
commit 0910a906dc

@ -357,20 +357,19 @@ cleanup(void) {
} }
static int static int
keypress(XKeyEvent *ev) { keypress_confirm(XKeyEvent *ev, KeySym ksym) {
char buf[32]; if (ev->state & ControlMask) {
int len; switch(ksym) {
case XK_c:
KeySym ksym = NoSymbol; pinentry->canceled = 1;
Status status; sel = No;
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); return 1;
default:
if (status == XBufferOverflow) { return 1;
return 0; }
} }
if (winmode == WinConfirm) { switch(ksym) {
switch(ksym) {
case XK_KP_Enter: case XK_KP_Enter:
case XK_Return: case XK_Return:
if (sel != Nothing) { if (sel != Nothing) {
@ -385,12 +384,6 @@ keypress(XKeyEvent *ev) {
case XK_N: case XK_N:
sel = No; sel = No;
return 1; return 1;
case XK_c:
if (ev->state == ControlMask) {
pinentry->canceled = 1;
sel = No;
return 1;
}
case XK_Escape: case XK_Escape:
pinentry->canceled = 1; pinentry->canceled = 1;
sel = No; sel = No;
@ -402,57 +395,89 @@ keypress(XKeyEvent *ev) {
sel = Yes; sel = Yes;
break; break;
} }
} else {
return 0;
}
static int
keypress_pin(XKeyEvent *ev, KeySym ksym, char* buf, int len) {
if (ev->state & ControlMask) {
switch(ksym) { switch(ksym) {
case XK_Delete:
if (pin[cursor] == '\0') {
return 0;
}
cursor = nextrune(cursor, +1);
/* Fallthrough */
case XK_BackSpace:
if (cursor == 0) {
return 0;
}
insert(NULL, nextrune(cursor, -1) - cursor);
break;
case XK_c: case XK_c:
if (ev->state == ControlMask) {
pinentry->canceled = 1;
return 1;
}
case XK_Escape:
pinentry->canceled = 1; pinentry->canceled = 1;
return 1; return 1;
//Cleanup();
//exit(1);
break;
case XK_Left:
if (cursor > 0) {
cursor = nextrune(cursor, -1);
}
break;
case XK_Right:
if (pin[cursor] != '\0') {
cursor = nextrune(cursor, +1);
}
break;
case XK_Return:
case XK_KP_Enter:
return 1;
break;
default: default:
if (!iscntrl(*buf)) { return 1;
insert(buf, len);
}
} }
} }
drawwin(); switch(ksym) {
case XK_Delete:
if (pin[cursor] == '\0') {
return 0;
}
cursor = nextrune(cursor, +1);
/* Fallthrough */
case XK_BackSpace:
if (cursor == 0) {
return 0;
}
insert(NULL, nextrune(cursor, -1) - cursor);
break;
case XK_Escape:
pinentry->canceled = 1;
return 1;
//Cleanup();
//exit(1);
break;
case XK_Left:
if (cursor > 0) {
cursor = nextrune(cursor, -1);
}
break;
case XK_Right:
if (pin[cursor] != '\0') {
cursor = nextrune(cursor, +1);
}
break;
case XK_Return:
case XK_KP_Enter:
return 1;
break;
default:
if (!iscntrl(*buf)) {
insert(buf, len);
}
}
return 0; return 0;
} }
static int
keypress(XKeyEvent *ev) {
char buf[32];
int len;
int ret = 1;
KeySym ksym = NoSymbol;
Status status;
len = XmbLookupString(xic, ev, buf, sizeof(buf), &ksym, &status);
if (status != XBufferOverflow) {
if (winmode == WinConfirm) {
ret = keypress_confirm(ev, ksym);
} else {
ret = keypress_pin(ev, ksym, buf, len);
}
if (ret == 0) {
drawwin();
}
}
return ret;
}
static void static void
paste(void) { paste(void) {
char *p, *q; char *p, *q;

Loading…
Cancel
Save