|
|
@ -31,6 +31,8 @@ const char *str_ERRNOTIMP = "ERR4100 not implemented yet\n";
|
|
|
|
|
|
|
|
|
|
|
|
/* enums */
|
|
|
|
/* enums */
|
|
|
|
enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
|
|
|
|
enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
|
|
|
|
|
|
|
|
enum {WinPin, WinConfirm}; /* window modes */
|
|
|
|
|
|
|
|
enum {Ok, NotOk, Cancel}; /* return status */
|
|
|
|
|
|
|
|
|
|
|
|
static char text[2048] = "";
|
|
|
|
static char text[2048] = "";
|
|
|
|
static int bh, mw, mh;
|
|
|
|
static int bh, mw, mh;
|
|
|
@ -50,6 +52,9 @@ static int sw, sh;
|
|
|
|
|
|
|
|
|
|
|
|
static int timed_out;
|
|
|
|
static int timed_out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int confirmed;
|
|
|
|
|
|
|
|
static int winmode;
|
|
|
|
|
|
|
|
|
|
|
|
pinentry_t pinentry;
|
|
|
|
pinentry_t pinentry;
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "config.h"
|
|
|
@ -123,10 +128,13 @@ drawwin(void){
|
|
|
|
seccursor = n;
|
|
|
|
seccursor = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (winmode==WinPin) {
|
|
|
|
drw_text(drw, x, y, mw, bh, sectext, 0);
|
|
|
|
drw_text(drw, x, y, mw, bh, sectext, 0);
|
|
|
|
if((curpos = TEXTNW(sectext, seccursor) + bh/2 - 2) < w) {
|
|
|
|
if((curpos = TEXTNW(sectext, seccursor) + bh/2 - 2) < w) {
|
|
|
|
drw_rect(drw, x + curpos + 2, y + 2, 1 , bh-4 , True, 1, 0);
|
|
|
|
drw_rect(drw, x + curpos + 2, y + 2, 1 , bh-4 , True, 1, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
drw_text(drw, x, y, mw, bh, "(y/n)", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drw_map(drw, win, 0, 0, mw, mh);
|
|
|
|
drw_map(drw, win, 0, 0, mw, mh);
|
|
|
@ -190,39 +198,61 @@ keypress(XKeyEvent *ev) {
|
|
|
|
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
|
|
|
|
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
|
|
|
|
if (status == XBufferOverflow)
|
|
|
|
if (status == XBufferOverflow)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
switch(ksym){
|
|
|
|
if (winmode == WinConfirm){
|
|
|
|
default:
|
|
|
|
switch(ksym){
|
|
|
|
if (!iscntrl(*buf))
|
|
|
|
case XK_KP_Enter:
|
|
|
|
insert(buf, len);
|
|
|
|
case XK_Return:
|
|
|
|
break;
|
|
|
|
case XK_y:
|
|
|
|
case XK_Delete:
|
|
|
|
confirmed = 1;
|
|
|
|
if(text[cursor] == '\0')
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
cursor = nextrune(cursor, +1);
|
|
|
|
case XK_n:
|
|
|
|
/* fallthrough */
|
|
|
|
confirmed = 0;
|
|
|
|
case XK_BackSpace:
|
|
|
|
return 1;
|
|
|
|
if(cursor == 0)
|
|
|
|
break;
|
|
|
|
return 0;
|
|
|
|
case XK_Escape:
|
|
|
|
insert(NULL, nextrune(cursor, -1) - cursor);
|
|
|
|
pinentry->canceled = 1;
|
|
|
|
break;
|
|
|
|
confirmed = 0;
|
|
|
|
case XK_Escape:
|
|
|
|
return 1;
|
|
|
|
cleanup();
|
|
|
|
break;
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_Left:
|
|
|
|
|
|
|
|
if(cursor > 0) {
|
|
|
|
|
|
|
|
cursor = nextrune(cursor, -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
case XK_Right:
|
|
|
|
switch(ksym){
|
|
|
|
if(text[cursor]!='\0') {
|
|
|
|
default:
|
|
|
|
|
|
|
|
if (!iscntrl(*buf))
|
|
|
|
|
|
|
|
insert(buf, len);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_Delete:
|
|
|
|
|
|
|
|
if(text[cursor] == '\0')
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
cursor = nextrune(cursor, +1);
|
|
|
|
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(text[cursor]!='\0') {
|
|
|
|
|
|
|
|
cursor = nextrune(cursor, +1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_Return:
|
|
|
|
|
|
|
|
case XK_KP_Enter:
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_Return:
|
|
|
|
|
|
|
|
case XK_KP_Enter:
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawwin();
|
|
|
|
drawwin();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -293,13 +323,15 @@ promptwin(void) {
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
catchsig(int sig)
|
|
|
|
catchsig(int sig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (sig == SIGALRM)
|
|
|
|
if (sig == SIGALRM)
|
|
|
|
timed_out = 1;
|
|
|
|
timed_out = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
static int
|
|
|
|
password (void) {
|
|
|
|
password (void) {
|
|
|
|
|
|
|
|
winmode = WinPin;
|
|
|
|
promptwin();
|
|
|
|
promptwin();
|
|
|
|
|
|
|
|
if (pinentry->canceled) return -1;
|
|
|
|
char *buf = secmem_malloc(strlen(text));
|
|
|
|
char *buf = secmem_malloc(strlen(text));
|
|
|
|
strcpy(buf, text);
|
|
|
|
strcpy(buf, text);
|
|
|
|
pinentry_setbuffer_use (pinentry, buf, 0);
|
|
|
|
pinentry_setbuffer_use (pinentry, buf, 0);
|
|
|
@ -308,7 +340,10 @@ password (void) {
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
static int
|
|
|
|
confirm(void) {
|
|
|
|
confirm(void) {
|
|
|
|
return 1;
|
|
|
|
winmode = WinConfirm;
|
|
|
|
|
|
|
|
confirmed = 0;
|
|
|
|
|
|
|
|
promptwin();
|
|
|
|
|
|
|
|
return confirmed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|