From b24ce51172556e3c3ad67fc71571514f9503ff1c Mon Sep 17 00:00:00 2001 From: mrdotx Date: Tue, 27 Jul 2021 10:10:28 +0200 Subject: [PATCH] center added --- config.def.h | 7 ++++--- pinentry-dmenu.1 | 6 +++++- pinentry-dmenu.c | 29 +++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/config.def.h b/config.def.h index e2fd90a..8b9c80f 100644 --- a/config.def.h +++ b/config.def.h @@ -2,10 +2,11 @@ /* Default settings; can be overriden by command line. */ static int mon = -1; -static int bottom = 0; -static int embedded = 0; -static int minpwlen = 32; +static unsigned int center = 0; +static unsigned int bottom = 0; +static unsigned int embedded = 0; +static unsigned int minpwlen = 32; static unsigned int lineheight = 22; static unsigned int borderwidth = 2; diff --git a/pinentry-dmenu.1 b/pinentry-dmenu.1 index eecac23..7d12c07 100644 --- a/pinentry-dmenu.1 +++ b/pinentry-dmenu.1 @@ -28,6 +28,9 @@ You can change the path to the config file with the environment variable .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 "bottom =" " false" pinentry-dmenu appears at the bottom of the screen. .TP @@ -192,12 +195,13 @@ Paste from primary X selection .\} .nf monitor = -1; +center = false; bottom = false; embedded = false; line_height = 22; border_width = 2; font = "DejaVuSansMono Nerd Font:pixelsize=16:antialias=true:autohint=true"; -min_passwword_length = 32; +min_password_length = 32; asterisk= "*"; prompt = ""; prompt_fg = "#cccccc"; diff --git a/pinentry-dmenu.c b/pinentry-dmenu.c index 5ce6a68..58f7122 100644 --- a/pinentry-dmenu.c +++ b/pinentry-dmenu.c @@ -330,9 +330,16 @@ setup(void) { } } - x = info[i].x_org; - y = info[i].y_org + (bottom ? info[i].height - mh : 0); - mw = info[i].width; + if (center) { + mw = info[i].width; + x = info[i].x_org + ((info[i].width - mw) / 2); + y = info[i].y_org + ((info[i].height - mh) / 2); + } else { + x = info[i].x_org; + y = info[i].y_org + (bottom ? info[i].height - mh : 0); + mw = info[i].width; + } + XFree(info); } else #endif @@ -340,9 +347,16 @@ setup(void) { if (!XGetWindowAttributes(dpy, parentwin, &wa)) { die("could not get embedding window attributes: 0x%lx", parentwin); } - x = 0; - y = bottom ? wa.height - mh : 0; - mw = wa.width; + + if (center) { + mw = wa.width; + x = (wa.width - mw) / 2; + y = (wa.height - mh) / 2; + } else { + x = 0; + y = bottom ? wa.height - mh : 0; + mw = wa.width; + } } pdescw = (pinentry_info->description) ? TEXTW(pinentry_info->description) : 0; @@ -741,6 +755,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_bool(&cfg, "bottom", &bval)) { bottom = bval; }