confirm mode confirmed

pull/4/head
zavok 9 years ago
parent 377dc49065
commit 2df401ad8c

@ -0,0 +1 @@
* Xorg error when trying to intiate promptwin second time in one session

@ -1,3 +1,4 @@
* replace pinentry's code with our own talker to gpg-agent * replace pinentry's code with our own talker to gpg-agent
* look over code and see what I broke while copypasting code from dmenu * look over code and see what I broke while copypasting code from dmenu
* get licenses in order * get licenses in order
* fallback TTY mode

@ -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,11 +128,14 @@ 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,6 +198,25 @@ 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;
if (winmode == WinConfirm){
switch(ksym){
case XK_KP_Enter:
case XK_Return:
case XK_y:
confirmed = 1;
return 1;
break;
case XK_n:
confirmed = 0;
return 1;
break;
case XK_Escape:
pinentry->canceled = 1;
confirmed = 0;
return 1;
break;
}
} else {
switch(ksym){ switch(ksym){
default: default:
if (!iscntrl(*buf)) if (!iscntrl(*buf))
@ -206,8 +233,10 @@ keypress(XKeyEvent *ev) {
insert(NULL, nextrune(cursor, -1) - cursor); insert(NULL, nextrune(cursor, -1) - cursor);
break; break;
case XK_Escape: case XK_Escape:
cleanup(); pinentry->canceled = 1;
exit(1); return 1;
/*cleanup();
exit(1);*/
break; break;
case XK_Left: case XK_Left:
if(cursor > 0) { if(cursor > 0) {
@ -224,6 +253,7 @@ keypress(XKeyEvent *ev) {
return 1; return 1;
break; break;
} }
}
drawwin(); drawwin();
return 0; return 0;
} }
@ -299,7 +329,9 @@ catchsig(int sig)
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

Loading…
Cancel
Save