diff --git a/README b/README index 9034038..b324940 100644 --- a/README +++ b/README @@ -33,9 +33,7 @@ To use pinentry-dmenu add in `~/.gnupg/gpg-agent.conf`: The config is located in `~/.gnupg/pinentry-dmenu.conf`. monitor = -1; -center = false; center_width = 1024; -bottom = false; embedded = false; line_height = 22; border_width = 2; @@ -48,6 +46,7 @@ select_fg_alpha = 255; select_bg_alpha = 255; desc_fg_alpha = 255; desc_bg_alpha = 230; +position = "center"; font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true"; prompt = ""; asterisk = "*"; diff --git a/config.def.h b/config.def.h index e92c84d..01fefc8 100644 --- a/config.def.h +++ b/config.def.h @@ -2,9 +2,7 @@ /* Default settings; can be overriden by pinentry-dmenu.conf */ static unsigned int mon = -1; -static unsigned int center = 0; static unsigned int centerwidth = 1024; -static unsigned int bottom = 0; static unsigned int embedded = 0; static unsigned int lineheight = 22; static unsigned int borderwidth = 2; @@ -18,6 +16,7 @@ static unsigned int alphas[SchemeLast][2] = { [SchemeDesc] = { 255, 230 }, }; +static const char *position = "center"; static const char *fonts[] = { "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true" }; diff --git a/pinentry-dmenu.1 b/pinentry-dmenu.1 index fdb5b4b..44ac3fb 100644 --- a/pinentry-dmenu.1 +++ b/pinentry-dmenu.1 @@ -25,31 +25,25 @@ You can change the path to the config file with the environment variable .SH OPTIONS .TP -.BI "monitor =" " -1" +.BI "monitor = " "-1" pinentry-dmenu is displayed on the monitor number supplied. Monitor numbers are starting from 0. .TP -.BI "center =" " false" -pinentry-dmenu appears in the center of the screen. -.TP -.BI "center_width =" " 1024" +.BI "center_width = " "1024" Defines the width for the 'center' menu. .TP -.BI "bottom =" " false" -pinentry-dmenu appears at the bottom of the screen. -.TP -.BI "embedded =" " false" +.BI "embedded = " "false" Embed into window. .TP -.BI "line_height =" " 22" +.BI "line_height = " "22" Defines menu line of at least 'line_height' pixels tall. .TP -.BI "border_width =" " 2" +.BI "border_width = " "2" Defines the border width for the menu. .TP -.BI "min_password_length =" " 32" +.BI "min_password_length = " "32" The minimal space of the password field. This value has affect to the description field after the password field. .TP -.BI "prompt_fg_alpha =" " 255" +.BI "prompt_fg_alpha = " "255" Defines the prompt foreground alpha value. Values between .IR 0 @@ -57,61 +51,69 @@ Values between .IR 255 (opaque) are supported. .TP -.BI "prompt_bg_alpha =" " 255" +.BI "prompt_bg_alpha = " "255" Defines the prompt background alpha value. .TP -.BI "normal_fg_alpha =" " 255" +.BI "normal_fg_alpha = " "255" Defines the normal foreground alpha value. .TP -.BI "normal_bg_alpha =" " 230" +.BI "normal_bg_alpha = " "230" Defines the normal background alpha value. .TP -.BI "select_fg_alpha =" " 255" +.BI "select_fg_alpha = " "255" Defines the selected foreground alpha value. .TP -.BI "select_bg_alpha =" " 255" +.BI "select_bg_alpha = " "255" Defines the selected background alpha value. .TP -.BI "desc_fg_alpha =" " 255" +.BI "desc_fg_alpha = " "255" Defines the description foreground alpha value. .TP -.BI "desc_bg_alpha =" " 230" +.BI "desc_bg_alpha = " "230" Defines the description background alpha value. .TP -.BI "font =" " DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true" +.BI "position = " """center""" +Defines the osition of the menu. +.IR bottom , +.I center +and +.I top +are supported. +.TP +.BI "font = " """DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true""" Defines the font or font set used. .TP -.BI "prompt =" " """" +.BI "prompt = " """""" Defines the prompt to be displayed to the left of the input field. .TP -.BI "asterisk =" " *" +.BI "asterisk = " """*""" Defines the symbol which is showed for each typed character. .TP -.BI "prompt_fg =" " #cccccc" +.BI "prompt_fg = " """#cccccc""" Defines the prompt foreground color. .IR #RGB , .I #RRGGBB and X color names are supported. .TP -.BI "prompt_bg =" " #4185d7" +.BI "prompt_bg = " """#4185d7""" Defines the prompt background color. .TP -.BI "normal_fg =" " #cccccc" +.BI "normal_fg = " """#cccccc""" Defines the normal foreground color. .TP -.BI "normal_bg =" " #000000" +.BI "normal_bg = " """#000000""" Defines the normal background color. .TP -.BI "select_fg =" " #ffffff" +.BI "select_fg = " """#ffffff""" Defines the selected foreground color. .TP -.BI "select_bg =" " #4185d7" +.BI "select_bg = " """#4185d7""" Defines the selected background color. .TP -.BI "desc_fg =" " #cccccc" +.BI "desc_fg = " """#cccccc""" Defines the description foreground color. .TP -.BI "desc_bg =" " #000000" +.BI "desc_bg = " """#000000""" Defines the description background color. .SH USAGE @@ -227,9 +229,7 @@ Paste from primary X selection .\} .nf monitor = -1; -center = false; center_width = 1024; -bottom = false; embedded = false; line_height = 22; border_width = 2; @@ -242,6 +242,7 @@ select_fg_alpha = 255; select_bg_alpha = 255; desc_fg_alpha = 255; desc_bg_alpha = 230; +position = "center"; font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true"; prompt = ""; asterisk = "*"; diff --git a/pinentry-dmenu.c b/pinentry-dmenu.c index 2d630e2..815888e 100644 --- a/pinentry-dmenu.c +++ b/pinentry-dmenu.c @@ -48,6 +48,8 @@ static int lrpad; static size_t cursor; static int screen; +static int bottom = 0, center = 0; + static char* pin; static int pin_len; static char* pin_repeat; @@ -147,7 +149,7 @@ grabkeyboard(void) { * we may have to wait for another process to ungrab */ for (i = 0; i < 1000; i++) { if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, - GrabModeAsync, CurrentTime) == GrabSuccess) { + GrabModeAsync, CurrentTime) == GrabSuccess) { return; } usleep(1000); @@ -162,8 +164,8 @@ nextrune(int cursor, int inc) { /* Return location of next utf8 rune in the given direction (+1 or -1) */ for (n = cursor + inc; - n + inc >= 0 && (pin[n] & 0xc0) == 0x80; - n += inc); + n + inc >= 0 && (pin[n] & 0xc0) == 0x80; + n += inc); return n; } @@ -272,7 +274,7 @@ drawwin(void) { drw_setscheme(drw, scheme[SchemeDesc]); if (center) { - drw_text(drw, ppromptw, lineheight, centerwidth, + drw_text(drw, promptw + ppromptw, lineheight, centerwidth, bh + borderwidth, lrpad / 2, pinentry_info->description, 0); } else { @@ -338,7 +340,7 @@ setup(void) { /* Calculate menu geometry */ bh = drw->fonts->h + 2; - bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */ + bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */ mh = (center) ? bh * 2 : bh; #ifdef XINERAMA info = XineramaQueryScreens(dpy, &n); @@ -367,7 +369,7 @@ setup(void) { } /* No focused window is on screen, so use pointer location instead */ if (mon < 0 && !area - && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) { + && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) { for (i = 0; i < n; i++) { if (INTERSECT(x, y, 1, 1, info[i])) { break; @@ -413,8 +415,8 @@ setup(void) { swa.colormap = cmap; swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; win = XCreateWindow(dpy, parentwin, x, y, mw, mh, borderwidth, - depth, CopyFromParent, visual, - CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa); + depth, CopyFromParent, visual, + CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa); if (borderwidth) XSetWindowBorder(dpy, win, scheme[SchemeSelect][ColBg].pixel); XSetClassHint(dpy, win, &ch); @@ -422,7 +424,7 @@ setup(void) { /* Open input methods */ xim = XOpenIM(dpy, NULL, NULL, NULL); xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, win, XNFocusWindow, win, NULL); + XNClientWindow, win, XNFocusWindow, win, NULL); XMapRaised(dpy, win); if (embedded) { @@ -532,7 +534,7 @@ keypress_pin(XKeyEvent *ev, KeySym ksym, char* buf, int len) { break; case XK_v: XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, - utf8, utf8, win, CurrentTime); + utf8, utf8, win, CurrentTime); return 0; case XK_Return: case XK_KP_Enter: @@ -624,7 +626,7 @@ paste(void) { /* We have been given the current selection, now insert it into input */ XGetWindowProperty(dpy, win, utf8, 0, pin_len / 4, False, utf8, &da, &di, - &dl, &dl, (unsigned char **)&p); + &dl, &dl, (unsigned char **)&p); insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t) strlen(p)); XFree(p); drawwin(); @@ -753,7 +755,7 @@ cmdhandler(pinentry_t received_pinentry) { do { password(); } while (!pinentry_info->canceled && pinentry_info->repeat_passphrase - && !pinentry_info->repeat_okay); + && !pinentry_info->repeat_okay); } else { confirm(); } @@ -804,15 +806,9 @@ main(int argc, char *argv[]) { if (config_lookup_int(&cfg, "monitor", &val)) { mon = val; } - if (config_lookup_bool(&cfg, "center", &bval)) { - center = bval; - } if (config_lookup_int(&cfg, "center_width", &val)) { centerwidth = val; } - if (config_lookup_bool(&cfg, "bottom", &bval)) { - bottom = bval; - } if (config_lookup_bool(&cfg, "embedded", &bval)) { embedded = bval; } @@ -822,6 +818,33 @@ main(int argc, char *argv[]) { if (config_lookup_int(&cfg, "border_width", &val)) { borderwidth = val; } + if (config_lookup_int(&cfg, "prompt_fg_alpha", &val)) { + alphas[SchemePrompt][0] = val; + } + if (config_lookup_int(&cfg, "prompt_bg_alpha", &val)) { + alphas[SchemePrompt][1] = val; + } + if (config_lookup_int(&cfg, "normal_fg_alpha", &val)) { + alphas[SchemeNormal][0] = val; + } + if (config_lookup_int(&cfg, "normal_bg_alpha", &val)) { + alphas[SchemeNormal][1] = val; + } + if (config_lookup_int(&cfg, "select_fg_alpha", &val)) { + alphas[SchemeSelect][0] = val; + } + if (config_lookup_int(&cfg, "select_bg_alpha", &val)) { + alphas[SchemeSelect][1] = val; + } + if (config_lookup_int(&cfg, "desc_fg_alpha", &val)) { + alphas[SchemeDesc][0] = val; + } + if (config_lookup_int(&cfg, "desc_bg_alpha", &val)) { + alphas[SchemeDesc][1] = val; + } + if (config_lookup_string(&cfg, "position", &str)) { + position = str; + } if (config_lookup_string(&cfg, "font", &str)) { fonts[0] = str; } @@ -858,38 +881,23 @@ main(int argc, char *argv[]) { if (config_lookup_string(&cfg, "desc_bg", &str)) { colors[SchemeDesc][ColBg] = str; } - if (config_lookup_int(&cfg, "prompt_fg_alpha", &val)) { - alphas[SchemePrompt][0] = val; - } - if (config_lookup_int(&cfg, "prompt_bg_alpha", &val)) { - alphas[SchemePrompt][1] = val; - } - if (config_lookup_int(&cfg, "normal_fg_alpha", &val)) { - alphas[SchemeNormal][0] = val; - } - if (config_lookup_int(&cfg, "normal_bg_alpha", &val)) { - alphas[SchemeNormal][1] = val; - } - if (config_lookup_int(&cfg, "select_fg_alpha", &val)) { - alphas[SchemeSelect][0] = val; - } - if (config_lookup_int(&cfg, "select_bg_alpha", &val)) { - alphas[SchemeSelect][1] = val; - } - if (config_lookup_int(&cfg, "desc_fg_alpha", &val)) { - alphas[SchemeDesc][0] = val; - } - if (config_lookup_int(&cfg, "desc_bg_alpha", &val)) { - alphas[SchemeDesc][1] = val; - } } else if ((str = config_error_file(&cfg))) { fprintf(stderr, "%s:%d: %s\n", config_error_file(&cfg), - config_error_line(&cfg), config_error_text(&cfg)); + config_error_line(&cfg), config_error_text(&cfg)); return(EXIT_FAILURE); } else { printf("No config file found. Use defaults.\n"); } + if (0 == strcmp(position, "center")) { + center = 1; + bottom = 0; + } + if (0 == strcmp(position, "bottom")) { + center = 0; + bottom = 1; + } + pinentry_init("pinentry-dmenu"); pinentry_parse_opts(argc, argv);