configuration optimized for menu position and some minor fixes

This commit is contained in:
mrdotx 2021-07-30 20:24:59 +02:00
parent 4e5c00ea38
commit 431d99aab6
No known key found for this signature in database
GPG Key ID: 433F70E636E6EB87
4 changed files with 87 additions and 80 deletions

3
README
View File

@ -33,9 +33,7 @@ To use pinentry-dmenu add in `~/.gnupg/gpg-agent.conf`:
The config is located in `~/.gnupg/pinentry-dmenu.conf`. The config is located in `~/.gnupg/pinentry-dmenu.conf`.
monitor = -1; monitor = -1;
center = false;
center_width = 1024; center_width = 1024;
bottom = false;
embedded = false; embedded = false;
line_height = 22; line_height = 22;
border_width = 2; border_width = 2;
@ -48,6 +46,7 @@ select_fg_alpha = 255;
select_bg_alpha = 255; select_bg_alpha = 255;
desc_fg_alpha = 255; desc_fg_alpha = 255;
desc_bg_alpha = 230; desc_bg_alpha = 230;
position = "center";
font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true"; font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true";
prompt = ""; prompt = "";
asterisk = "*"; asterisk = "*";

View File

@ -2,9 +2,7 @@
/* Default settings; can be overriden by pinentry-dmenu.conf */ /* Default settings; can be overriden by pinentry-dmenu.conf */
static unsigned int mon = -1; static unsigned int mon = -1;
static unsigned int center = 0;
static unsigned int centerwidth = 1024; static unsigned int centerwidth = 1024;
static unsigned int bottom = 0;
static unsigned int embedded = 0; static unsigned int embedded = 0;
static unsigned int lineheight = 22; static unsigned int lineheight = 22;
static unsigned int borderwidth = 2; static unsigned int borderwidth = 2;
@ -18,6 +16,7 @@ static unsigned int alphas[SchemeLast][2] = {
[SchemeDesc] = { 255, 230 }, [SchemeDesc] = { 255, 230 },
}; };
static const char *position = "center";
static const char *fonts[] = { static const char *fonts[] = {
"DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true" "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true"
}; };

View File

@ -25,31 +25,25 @@ You can change the path to the config file with the environment variable
.SH OPTIONS .SH OPTIONS
.TP .TP
.BI "monitor =" " -1" .BI "monitor = " "-1"
pinentry-dmenu is displayed on the monitor number supplied. Monitor numbers are starting from 0. pinentry-dmenu is displayed on the monitor number supplied. Monitor numbers are starting from 0.
.TP .TP
.BI "center =" " false" .BI "center_width = " "1024"
pinentry-dmenu appears in the center of the screen.
.TP
.BI "center_width =" " 1024"
Defines the width for the 'center' menu. Defines the width for the 'center' menu.
.TP .TP
.BI "bottom =" " false" .BI "embedded = " "false"
pinentry-dmenu appears at the bottom of the screen.
.TP
.BI "embedded =" " false"
Embed into window. Embed into window.
.TP .TP
.BI "line_height =" " 22" .BI "line_height = " "22"
Defines menu line of at least 'line_height' pixels tall. Defines menu line of at least 'line_height' pixels tall.
.TP .TP
.BI "border_width =" " 2" .BI "border_width = " "2"
Defines the border width for the menu. Defines the border width for the menu.
.TP .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. The minimal space of the password field. This value has affect to the description field after the password field.
.TP .TP
.BI "prompt_fg_alpha =" " 255" .BI "prompt_fg_alpha = " "255"
Defines the prompt foreground alpha value. Defines the prompt foreground alpha value.
Values between Values between
.IR 0 .IR 0
@ -57,61 +51,69 @@ Values between
.IR 255 .IR 255
(opaque) are supported. (opaque) are supported.
.TP .TP
.BI "prompt_bg_alpha =" " 255" .BI "prompt_bg_alpha = " "255"
Defines the prompt background alpha value. Defines the prompt background alpha value.
.TP .TP
.BI "normal_fg_alpha =" " 255" .BI "normal_fg_alpha = " "255"
Defines the normal foreground alpha value. Defines the normal foreground alpha value.
.TP .TP
.BI "normal_bg_alpha =" " 230" .BI "normal_bg_alpha = " "230"
Defines the normal background alpha value. Defines the normal background alpha value.
.TP .TP
.BI "select_fg_alpha =" " 255" .BI "select_fg_alpha = " "255"
Defines the selected foreground alpha value. Defines the selected foreground alpha value.
.TP .TP
.BI "select_bg_alpha =" " 255" .BI "select_bg_alpha = " "255"
Defines the selected background alpha value. Defines the selected background alpha value.
.TP .TP
.BI "desc_fg_alpha =" " 255" .BI "desc_fg_alpha = " "255"
Defines the description foreground alpha value. Defines the description foreground alpha value.
.TP .TP
.BI "desc_bg_alpha =" " 230" .BI "desc_bg_alpha = " "230"
Defines the description background alpha value. Defines the description background alpha value.
.TP .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. Defines the font or font set used.
.TP .TP
.BI "prompt =" " """" .BI "prompt = " """"""
Defines the prompt to be displayed to the left of the input field. Defines the prompt to be displayed to the left of the input field.
.TP .TP
.BI "asterisk =" " *" .BI "asterisk = " """*"""
Defines the symbol which is showed for each typed character. Defines the symbol which is showed for each typed character.
.TP .TP
.BI "prompt_fg =" " #cccccc" .BI "prompt_fg = " """#cccccc"""
Defines the prompt foreground color. Defines the prompt foreground color.
.IR #RGB , .IR #RGB ,
.I #RRGGBB .I #RRGGBB
and X color names are supported. and X color names are supported.
.TP .TP
.BI "prompt_bg =" " #4185d7" .BI "prompt_bg = " """#4185d7"""
Defines the prompt background color. Defines the prompt background color.
.TP .TP
.BI "normal_fg =" " #cccccc" .BI "normal_fg = " """#cccccc"""
Defines the normal foreground color. Defines the normal foreground color.
.TP .TP
.BI "normal_bg =" " #000000" .BI "normal_bg = " """#000000"""
Defines the normal background color. Defines the normal background color.
.TP .TP
.BI "select_fg =" " #ffffff" .BI "select_fg = " """#ffffff"""
Defines the selected foreground color. Defines the selected foreground color.
.TP .TP
.BI "select_bg =" " #4185d7" .BI "select_bg = " """#4185d7"""
Defines the selected background color. Defines the selected background color.
.TP .TP
.BI "desc_fg =" " #cccccc" .BI "desc_fg = " """#cccccc"""
Defines the description foreground color. Defines the description foreground color.
.TP .TP
.BI "desc_bg =" " #000000" .BI "desc_bg = " """#000000"""
Defines the description background color. Defines the description background color.
.SH USAGE .SH USAGE
@ -227,9 +229,7 @@ Paste from primary X selection
.\} .\}
.nf .nf
monitor = -1; monitor = -1;
center = false;
center_width = 1024; center_width = 1024;
bottom = false;
embedded = false; embedded = false;
line_height = 22; line_height = 22;
border_width = 2; border_width = 2;
@ -242,6 +242,7 @@ select_fg_alpha = 255;
select_bg_alpha = 255; select_bg_alpha = 255;
desc_fg_alpha = 255; desc_fg_alpha = 255;
desc_bg_alpha = 230; desc_bg_alpha = 230;
position = "center";
font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true"; font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true";
prompt = ""; prompt = "";
asterisk = "*"; asterisk = "*";

View File

@ -48,6 +48,8 @@ static int lrpad;
static size_t cursor; static size_t cursor;
static int screen; static int screen;
static int bottom = 0, center = 0;
static char* pin; static char* pin;
static int pin_len; static int pin_len;
static char* pin_repeat; static char* pin_repeat;
@ -147,7 +149,7 @@ grabkeyboard(void) {
* we may have to wait for another process to ungrab */ * we may have to wait for another process to ungrab */
for (i = 0; i < 1000; i++) { for (i = 0; i < 1000; i++) {
if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync,
GrabModeAsync, CurrentTime) == GrabSuccess) { GrabModeAsync, CurrentTime) == GrabSuccess) {
return; return;
} }
usleep(1000); usleep(1000);
@ -162,8 +164,8 @@ nextrune(int cursor, int inc) {
/* Return location of next utf8 rune in the given direction (+1 or -1) */ /* Return location of next utf8 rune in the given direction (+1 or -1) */
for (n = cursor + inc; for (n = cursor + inc;
n + inc >= 0 && (pin[n] & 0xc0) == 0x80; n + inc >= 0 && (pin[n] & 0xc0) == 0x80;
n += inc); n += inc);
return n; return n;
} }
@ -272,7 +274,7 @@ drawwin(void) {
drw_setscheme(drw, scheme[SchemeDesc]); drw_setscheme(drw, scheme[SchemeDesc]);
if (center) { if (center) {
drw_text(drw, ppromptw, lineheight, centerwidth, drw_text(drw, promptw + ppromptw, lineheight, centerwidth,
bh + borderwidth, lrpad / 2, bh + borderwidth, lrpad / 2,
pinentry_info->description, 0); pinentry_info->description, 0);
} else { } else {
@ -338,7 +340,7 @@ setup(void) {
/* Calculate menu geometry */ /* Calculate menu geometry */
bh = drw->fonts->h + 2; 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; mh = (center) ? bh * 2 : bh;
#ifdef XINERAMA #ifdef XINERAMA
info = XineramaQueryScreens(dpy, &n); info = XineramaQueryScreens(dpy, &n);
@ -367,7 +369,7 @@ setup(void) {
} }
/* No focused window is on screen, so use pointer location instead */ /* No focused window is on screen, so use pointer location instead */
if (mon < 0 && !area 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++) { for (i = 0; i < n; i++) {
if (INTERSECT(x, y, 1, 1, info[i])) { if (INTERSECT(x, y, 1, 1, info[i])) {
break; break;
@ -413,8 +415,8 @@ setup(void) {
swa.colormap = cmap; swa.colormap = cmap;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, borderwidth, win = XCreateWindow(dpy, parentwin, x, y, mw, mh, borderwidth,
depth, CopyFromParent, visual, depth, CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa); CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
if (borderwidth) if (borderwidth)
XSetWindowBorder(dpy, win, scheme[SchemeSelect][ColBg].pixel); XSetWindowBorder(dpy, win, scheme[SchemeSelect][ColBg].pixel);
XSetClassHint(dpy, win, &ch); XSetClassHint(dpy, win, &ch);
@ -422,7 +424,7 @@ setup(void) {
/* Open input methods */ /* Open input methods */
xim = XOpenIM(dpy, NULL, NULL, NULL); xim = XOpenIM(dpy, NULL, NULL, NULL);
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, win, XNFocusWindow, win, NULL); XNClientWindow, win, XNFocusWindow, win, NULL);
XMapRaised(dpy, win); XMapRaised(dpy, win);
if (embedded) { if (embedded) {
@ -532,7 +534,7 @@ keypress_pin(XKeyEvent *ev, KeySym ksym, char* buf, int len) {
break; break;
case XK_v: case XK_v:
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime); utf8, utf8, win, CurrentTime);
return 0; return 0;
case XK_Return: case XK_Return:
case XK_KP_Enter: case XK_KP_Enter:
@ -624,7 +626,7 @@ paste(void) {
/* We have been given the current selection, now insert it into input */ /* We have been given the current selection, now insert it into input */
XGetWindowProperty(dpy, win, utf8, 0, pin_len / 4, False, utf8, &da, &di, 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)); insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t) strlen(p));
XFree(p); XFree(p);
drawwin(); drawwin();
@ -753,7 +755,7 @@ cmdhandler(pinentry_t received_pinentry) {
do { do {
password(); password();
} while (!pinentry_info->canceled && pinentry_info->repeat_passphrase } while (!pinentry_info->canceled && pinentry_info->repeat_passphrase
&& !pinentry_info->repeat_okay); && !pinentry_info->repeat_okay);
} else { } else {
confirm(); confirm();
} }
@ -804,15 +806,9 @@ main(int argc, char *argv[]) {
if (config_lookup_int(&cfg, "monitor", &val)) { if (config_lookup_int(&cfg, "monitor", &val)) {
mon = val; mon = val;
} }
if (config_lookup_bool(&cfg, "center", &bval)) {
center = bval;
}
if (config_lookup_int(&cfg, "center_width", &val)) { if (config_lookup_int(&cfg, "center_width", &val)) {
centerwidth = val; centerwidth = val;
} }
if (config_lookup_bool(&cfg, "bottom", &bval)) {
bottom = bval;
}
if (config_lookup_bool(&cfg, "embedded", &bval)) { if (config_lookup_bool(&cfg, "embedded", &bval)) {
embedded = bval; embedded = bval;
} }
@ -822,6 +818,33 @@ main(int argc, char *argv[]) {
if (config_lookup_int(&cfg, "border_width", &val)) { if (config_lookup_int(&cfg, "border_width", &val)) {
borderwidth = 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)) { if (config_lookup_string(&cfg, "font", &str)) {
fonts[0] = str; fonts[0] = str;
} }
@ -858,38 +881,23 @@ main(int argc, char *argv[]) {
if (config_lookup_string(&cfg, "desc_bg", &str)) { if (config_lookup_string(&cfg, "desc_bg", &str)) {
colors[SchemeDesc][ColBg] = 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))) { } else if ((str = config_error_file(&cfg))) {
fprintf(stderr, "%s:%d: %s\n", 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); return(EXIT_FAILURE);
} else { } else {
printf("No config file found. Use defaults.\n"); 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_init("pinentry-dmenu");
pinentry_parse_opts(argc, argv); pinentry_parse_opts(argc, argv);