aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRatakor <ratakor@disroot.org>2023-04-15 00:46:19 +0200
committerRatakor <ratakor@disroot.org>2023-04-15 00:46:19 +0200
commit32003d176c433411fe4ad04a8bc4dbab5447112c (patch)
tree3c1baad50ef25236456b870222376440febc90a0
parent51c595a1e11cee49b192c8b170d7c5b094d77298 (diff)
remove config add xresource
-rw-r--r--README.md3
-rw-r--r--config.def.h47
-rw-r--r--config.mk8
-rw-r--r--drw.c2
-rw-r--r--drw.h2
-rw-r--r--pinentry-dmenu.c1480
6 files changed, 766 insertions, 776 deletions
diff --git a/README.md b/README.md
index 96dbcdd..c40749a 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
# pinentry-dmenu
+MAN PAGE IS NOT UP TO DATE: THERE IS NO CONFIGURATION FILE ANYMORE AND THERE IS
+XRESOURCE SUPPORT NOW
+
pinentry-dmenu is a pinentry program based on dmenu.
This program is a fork from https://gitgud.io/zavok/spine.git
diff --git a/config.def.h b/config.def.h
index 7f6d889..da63fea 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,30 +2,47 @@
/* Default settings; can be overriden by pinentry-dmenu.conf */
static unsigned int mon = -1;
-static unsigned int centerwidth = 1024;
+static unsigned int centerwidth = 700;
static unsigned int embedded = 0;
static unsigned int lineheight = 25;
static unsigned int borderwidth = 1;
static unsigned int minpwlen = 32;
static unsigned int alphas[SchemeLast][2] = {
- /* values between 0 (transparent) and 255 (opaque) */
- /* foreground, background */
- [SchemePrompt] = { 255, 255 },
- [SchemeNormal] = { 255, 230 },
- [SchemeSelect] = { 255, 255 },
- [SchemeDesc] = { 255, 255 },
+ /* values between 0 (transparent) and 255 (opaque) */
+ /* foreground, background */
+ [SchemePrompt] = { 255, 0xe0 },
+ [SchemeNormal] = { 255, 0xe0 },
+ [SchemeSelect] = { 255, 0xe0 },
+ [SchemeDesc] = { 255, 0xe0 }
};
static const char *position = "center";
+static char font[] = "monospace:size=12";
static const char *fonts[] = {
- "DejaVuSansMono Nerd Font Mono:pixelsize=16"
+ font,
+ "monospace:size=12"
};
-static const char *prompt = NULL;
+static const char *prompt = NULL;
static const char *asterisk = "*";
-static const char *colors[SchemeLast][2] = {
- /* foreground, background */
- [SchemePrompt] = { "#cccccc", "#4185d7" },
- [SchemeNormal] = { "#cccccc", "#000000" },
- [SchemeSelect] = { "#ffffff", "#4185d7" },
- [SchemeDesc] = { "#cccccc", "#4185d7" },
+static char normfgcolor[] = "#f8f8f2";
+static char normbgcolor[] = "#282a36";
+static char selfgcolor[] = "#f8f8f2";
+static char selbgcolor[] = "#6272a4";
+static char *colors[SchemeLast][2] = {
+ /* foreground, background */
+ [SchemePrompt] = { normfgcolor, normbgcolor },
+ [SchemeNormal] = { normfgcolor, normbgcolor },
+ [SchemeSelect] = { selfgcolor, selbgcolor },
+ [SchemeDesc] = { normfgcolor, normbgcolor }
+};
+
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "font", STRING, &font },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "normbgcolor", STRING, &normbgcolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "selbgcolor", STRING, &selbgcolor }
};
diff --git a/config.mk b/config.mk
index f82c333..43da862 100644
--- a/config.mk
+++ b/config.mk
@@ -1,7 +1,7 @@
# Pinentry settings
DATE = $$(date +'%B %Y')
VERSION = 0.1.5
-BUGREPORT = https:\/\/github.com\/mrdotx\/pinentry-dmenu
+BUGREPORT = https:\/\/github.com\/ratakor\/pinentry-dmenu
# Paths
PREFIX = /usr/local
@@ -26,9 +26,9 @@ INCS = -I${X11INC} -I${FREETYPEINC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender
# Flags
-CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} -DPACKAGE_VERSION=\"${VERSION}\" -DPACKAGE_BUGREPORT=\"${BUGREPORT}\"
-CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
-LDFLAGS = -s ${LIBS}
+CPPFLAGS += -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} -DPACKAGE_VERSION=\"${VERSION}\" -DPACKAGE_BUGREPORT=\"${BUGREPORT}\"
+CFLAGS += -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
+LDFLAGS += -s ${LIBS}
# Compiler and linker
CC = cc
diff --git a/drw.c b/drw.c
index a930d1e..d3dd4ab 100644
--- a/drw.c
+++ b/drw.c
@@ -198,7 +198,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
/* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */
Clr *
-drw_scm_create(Drw *drw, const char *clrnames[], unsigned int alphas[], size_t clrcount)
+drw_scm_create(Drw *drw, char *clrnames[], unsigned int alphas[], size_t clrcount)
{
size_t i;
Clr *ret;
diff --git a/drw.h b/drw.h
index 0c86110..1e9e143 100644
--- a/drw.h
+++ b/drw.h
@@ -42,7 +42,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
/* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
-Clr *drw_scm_create(Drw *drw, const char *clrnames[], unsigned int alphas[], size_t clrcount);
+Clr *drw_scm_create(Drw *drw, char *clrnames[], unsigned int alphas[], size_t clrcount);
/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);
diff --git a/pinentry-dmenu.c b/pinentry-dmenu.c
index e08c823..f558eda 100644
--- a/pinentry-dmenu.c
+++ b/pinentry-dmenu.c
@@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <ctype.h>
-#include <libconfig.h>
#include <locale.h>
#include <signal.h>
#include <stdio.h>
@@ -15,6 +14,7 @@
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
@@ -27,10 +27,9 @@
#include "pinentry/memory.h"
#define CONFIG_DIR "/.gnupg"
-#define CONFIG_FILE "/pinentry-dmenu.conf"
#define INTERSECT(x, y, w, h, r) \
- (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
- && MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
+ (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
+ && MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define LENGTH(X) (sizeof(X) / sizeof(X[0]))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define MINDESCLEN 8
@@ -49,7 +48,7 @@ static size_t cursor;
static int screen;
static int bottom = 0,
- center = 0;
+ center = 0;
static char* pin;
static int pin_len;
@@ -65,6 +64,21 @@ static XIC xic;
static Drw *drw;
static Clr *scheme[SchemeLast];
+/* Xresources preferences */
+enum resource_type {
+ STRING = 0,
+ INTEGER = 1,
+ FLOAT = 2
+};
+typedef struct {
+ char *name;
+ enum resource_type type;
+ void *dst;
+} ResourcePref;
+
+static void load_xresources(void);
+static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
+
static int useargb = 0;
static Visual *visual;
static int depth;
@@ -78,850 +92,806 @@ pinentry_t pinentry_info;
static void
xinitvisual(void) {
- XVisualInfo *infos;
- XRenderPictFormat *fmt;
- int nitems;
- int i;
-
- XVisualInfo tpl = {
- .screen = screen,
- .depth = 32,
- .class = TrueColor
- };
- long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
-
- infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
- visual = NULL;
- for(i = 0; i < nitems; i ++) {
- fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
- if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
- visual = infos[i].visual;
- depth = infos[i].depth;
- cmap = XCreateColormap(dpy, root, visual, AllocNone);
- useargb = 1;
- break;
- }
- }
-
- XFree(infos);
-
- if (! visual) {
- visual = DefaultVisual(dpy, screen);
- depth = DefaultDepth(dpy, screen);
- cmap = DefaultColormap(dpy, screen);
- }
+ XVisualInfo *infos;
+ XRenderPictFormat *fmt;
+ int nitems;
+ int i;
+
+ XVisualInfo tpl = {
+ .screen = screen,
+ .depth = 32,
+ .class = TrueColor
+ };
+ long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
+
+ infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
+ visual = NULL;
+ for(i = 0; i < nitems; i ++) {
+ fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
+ visual = infos[i].visual;
+ depth = infos[i].depth;
+ cmap = XCreateColormap(dpy, root, visual, AllocNone);
+ useargb = 1;
+ break;
+ }
+ }
+
+ XFree(infos);
+
+ if (! visual) {
+ visual = DefaultVisual(dpy, screen);
+ depth = DefaultDepth(dpy, screen);
+ cmap = DefaultColormap(dpy, screen);
+ }
}
static int
drawitem(const char* text, Bool sel, int x, int y, int w) {
- unsigned int i = (sel) ? SchemeSelect : SchemeNormal;
+ unsigned int i = (sel) ? SchemeSelect : SchemeNormal;
- drw_setscheme(drw, scheme[i]);
+ drw_setscheme(drw, scheme[i]);
- return drw_text(drw, x, y, w, bh, lrpad / 2, text, 0);
+ return drw_text(drw, x, y, w, bh, lrpad / 2, text, 0);
}
static void
grabfocus(void) {
- Window focuswin;
- int i, revertwin;
-
- for (i = 0; i < 100; ++i) {
- XGetInputFocus(dpy, &focuswin, &revertwin);
- if (focuswin == win) {
- return;
- }
- XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
- usleep(1000);
- }
-
- die("cannot grab focus");
+ Window focuswin;
+ int i, revertwin;
+
+ for (i = 0; i < 100; ++i) {
+ XGetInputFocus(dpy, &focuswin, &revertwin);
+ if (focuswin == win) {
+ return;
+ }
+ XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
+ usleep(1000);
+ }
+
+ die("cannot grab focus");
}
static void
grabkeyboard(void) {
- int i;
-
- if (embedded) {
- return;
- }
-
- /* Try to grab keyboard,
- * 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) {
- return;
- }
- usleep(1000);
- }
-
- die("cannot grab keyboard");
+ int i;
+
+ if (embedded) {
+ return;
+ }
+
+ /* Try to grab keyboard,
+ * 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) {
+ return;
+ }
+ usleep(1000);
+ }
+
+ die("cannot grab keyboard");
}
static size_t
nextrune(int cursor, int inc) {
- ssize_t n;
+ ssize_t n;
- /* 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);
+ /* 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);
- return n;
+ return n;
}
static void
setup_pin(char* pin_ptr, int len, int reset) {
- pin = pin_ptr;
- pin_len = len;
+ pin = pin_ptr;
+ pin_len = len;
- if (reset) {
- promptw = (prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
- cursor = 0;
+ if (reset) {
+ promptw = (prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
+ cursor = 0;
- if (pin) {
- pin[0] = '\0';
- }
- }
+ if (pin) {
+ pin[0] = '\0';
+ }
+ }
}
static void
insert(const char *str, ssize_t n) {
- size_t len = strlen(pin);
-
- // FIXME: Pinentry crashes when increasing the pin buffer the second time.
- // Other pinentry programs has a limited password field length.
- if (len + n > pin_len - 1) {
- if (repeat) {
- pin_repeat_len = 2 * pin_repeat_len;
- pin_repeat = secmem_realloc(pin_repeat, pin_repeat_len);
- setup_pin(pin_repeat, pin_repeat_len, 0);
- if (!pin_repeat) {
- pin_len = 0;
- }
- } else {
- if (!pinentry_setbufferlen(pinentry_info, 2 * pinentry_info->pin_len)) {
- pin_len = 0;
- } else {
- setup_pin(pinentry_info->pin, pinentry_info->pin_len, 0);
- }
- }
- if (pin_len == 0) {
- printf("Error: Couldn't allocate secure memory\n");
- return;
- }
- }
-
- /* Move existing text out of the way, insert new text, and update cursor */
- memmove(&pin[cursor + n], &pin[cursor], pin_len - cursor - MAX(n, 0));
-
- if (n > 0) {
- memcpy(&pin[cursor], str, n);
- }
-
- cursor += n;
- pin[len + n] = '\0';
+ size_t len = strlen(pin);
+
+ // FIXME: Pinentry crashes when increasing the pin buffer the second time.
+ // Other pinentry programs has a limited password field length.
+ if (len + n > pin_len - 1) {
+ if (repeat) {
+ pin_repeat_len = 2 * pin_repeat_len;
+ pin_repeat = secmem_realloc(pin_repeat, pin_repeat_len);
+ setup_pin(pin_repeat, pin_repeat_len, 0);
+ if (!pin_repeat) {
+ pin_len = 0;
+ }
+ } else {
+ if (!pinentry_setbufferlen(pinentry_info, 2 * pinentry_info->pin_len)) {
+ pin_len = 0;
+ } else {
+ setup_pin(pinentry_info->pin, pinentry_info->pin_len, 0);
+ }
+ }
+ if (pin_len == 0) {
+ printf("Error: Couldn't allocate secure memory\n");
+ return;
+ }
+ }
+
+ /* Move existing text out of the way, insert new text, and update cursor */
+ memmove(&pin[cursor + n], &pin[cursor], pin_len - cursor - MAX(n, 0));
+
+ if (n > 0) {
+ memcpy(&pin[cursor], str, n);
+ }
+
+ cursor += n;
+ pin[len + n] = '\0';
}
static void
clear_string(char *str)
{
- int i;
- char *dest = str;
-
- /* remove new lines */
- for (i = 0; i < strlen(str); i++) {
- if (str[i] == '\n') {
- str[i] = ' ';
- }
- }
-
- /* remove multiple spaces */
- while (*str != '\0') {
- while (*str == ' ' && *(str + 1) == ' ')
- str++;
-
- *dest++ = *str++;
- }
- *dest = '\0';
+ int i;
+ char *dest = str;
+
+ /* remove new lines */
+ for (i = 0; i < strlen(str); i++) {
+ if (str[i] == '\n') {
+ str[i] = ' ';
+ }
+ }
+
+ /* remove multiple spaces */
+ while (*str != '\0') {
+ while (*str == ' ' && *(str + 1) == ' ')
+ str++;
+
+ *dest++ = *str++;
+ }
+ *dest = '\0';
}
static void
drawwin(void) {
- unsigned int curpos;
- int x = 0, pb, pbw = 0, fh = drw->fonts->h, i;
- size_t asterlen = strlen(asterisk);
- size_t pdesclen;
- int leftinput;
- char* censort;
-
- char* pprompt = (repeat) ? pinentry_info->repeat_passphrase : pinentry_info->prompt;
- int ppromptw = (pprompt) ? TEXTW(pprompt) : 0;
-
- unsigned int censortl = (center) ? 0 : minpwlen * TEXTW(asterisk) / strlen(asterisk);
- unsigned int confirml = TEXTW(" YesNo ") + 3 * lrpad;
-
- drw_setscheme(drw, scheme[SchemeNormal]);
- drw_rect(drw, 0, 0, mw, mh, 1, 1);
-
- if (prompt) {
- drw_setscheme(drw, scheme[SchemePrompt]);
- x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
- }
-
- if (pprompt) {
- drw_setscheme(drw, scheme[SchemePrompt]);
- drw_text(drw, x, 0, ppromptw, bh, lrpad / 2, pprompt, 0);
- x += ppromptw;
- }
-
- if (pinentry_info->description) {
- clear_string(pinentry_info->description);
- pdesclen = strlen(pinentry_info->description);
- pb = mw - x;
-
- if (pb > 0) {
- pb -= (winmode == WinPin) ? censortl : confirml;
- pbw = MIN(MINDESCLEN * pdescw / pdesclen, pdescw);
-
- if (pb >= pbw) {
- pbw = MIN(MAX(pbw, pdescw), pb);
- pb = mw - pbw;
-
- drw_setscheme(drw, scheme[SchemeDesc]);
- if (center) {
- drw_text(drw, promptw + ppromptw, lineheight, centerwidth,
- bh, lrpad / 2,
- pinentry_info->description, 0);
- } else {
- drw_text(drw, pb, 0, pbw, bh, lrpad / 2,
- pinentry_info->description, 0);
- }
- } else {
- pbw = 0;
- }
- }
- }
-
- /* Draw input field */
- drw_setscheme(drw, scheme[SchemeNormal]);
-
- if (winmode == WinPin) {
- censort = ecalloc(1, asterlen * pin_len);
-
- for (i = 0; i < asterlen * strlen(pin); i += asterlen) {
- memcpy(&censort[i], asterisk, asterlen);
- }
-
- censort[i+1] = '\n';
- leftinput = (center) ? mw - x : mw - x - pbw;
- drw_text(drw, x, 0, leftinput, bh, lrpad / 2, censort, 0);
- drw_font_getexts(drw->fonts, censort, cursor * asterlen, &curpos, NULL);
-
- if ((curpos += lrpad / 2 - 1) < leftinput) {
- drw_setscheme(drw, scheme[SchemeNormal]);
- drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
- }
-
- free(censort);
- } else {
- x = drawitem("No", (sel == No), x, 0, TEXTW("No"));
- x = drawitem("Yes", (sel == Yes), x, 0, TEXTW("Yes"));
- }
-
- drw_map(drw, win, 0, 0, mw, mh);
+ unsigned int curpos;
+ int x = 0, pb, pbw = 0, fh = drw->fonts->h, i;
+ size_t asterlen = strlen(asterisk);
+ size_t pdesclen;
+ int leftinput;
+ char* censort;
+
+ char* pprompt = (repeat) ? pinentry_info->repeat_passphrase : pinentry_info->prompt;
+ int ppromptw = (pprompt) ? TEXTW(pprompt) : 0;
+
+ unsigned int censortl = (center) ? 0 : minpwlen * TEXTW(asterisk) / strlen(asterisk);
+ unsigned int confirml = TEXTW(" YesNo ") + 3 * lrpad;
+
+ drw_setscheme(drw, scheme[SchemeNormal]);
+ drw_rect(drw, 0, 0, mw, mh, 1, 1);
+
+ if (prompt) {
+ drw_setscheme(drw, scheme[SchemePrompt]);
+ x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
+ }
+
+ if (pprompt) {
+ drw_setscheme(drw, scheme[SchemePrompt]);
+ drw_text(drw, x, 0, ppromptw, bh, lrpad / 2, pprompt, 0);
+ x += ppromptw;
+ }
+
+ if (pinentry_info->description) {
+ clear_string(pinentry_info->description);
+ pdesclen = strlen(pinentry_info->description);
+ pb = mw - x;
+
+ if (pb > 0) {
+ pb -= (winmode == WinPin) ? censortl : confirml;
+ pbw = MIN(MINDESCLEN * pdescw / pdesclen, pdescw);
+
+ if (pb >= pbw) {
+ pbw = MIN(MAX(pbw, pdescw), pb);
+ pb = mw - pbw;
+
+ drw_setscheme(drw, scheme[SchemeDesc]);
+ if (center) {
+ drw_text(drw, promptw + ppromptw, lineheight, centerwidth,
+ bh, lrpad / 2,
+ pinentry_info->description, 0);
+ } else {
+ drw_text(drw, pb, 0, pbw, bh, lrpad / 2,
+ pinentry_info->description, 0);
+ }
+ } else {
+ pbw = 0;
+ }
+ }
+ }
+
+ /* Draw input field */
+ drw_setscheme(drw, scheme[SchemeNormal]);
+
+ if (winmode == WinPin) {
+ censort = ecalloc(1, asterlen * pin_len);
+
+ for (i = 0; i < asterlen * strlen(pin); i += asterlen) {
+ memcpy(&censort[i], asterisk, asterlen);
+ }
+
+ censort[i+1] = '\n';
+ leftinput = (center) ? mw - x : mw - x - pbw;
+ drw_text(drw, x, 0, leftinput, bh, lrpad / 2, censort, 0);
+ drw_font_getexts(drw->fonts, censort, cursor * asterlen, &curpos, NULL);
+
+ if ((curpos += lrpad / 2 - 1) < leftinput) {
+ drw_setscheme(drw, scheme[SchemeNormal]);
+ drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
+ }
+
+ free(censort);
+ } else {
+ x = drawitem("No", (sel == No), x, 0, TEXTW("No"));
+ x = drawitem("Yes", (sel == Yes), x, 0, TEXTW("Yes"));
+ }
+
+ drw_map(drw, win, 0, 0, mw, mh);
}
static void
setup(void) {
- int x, y, i = 0, j;
- unsigned int du;
- XSetWindowAttributes swa;
- XIM xim;
- Window w, dw, *dws;
- XWindowAttributes wa;
- XClassHint ch = {"pinentry-dmenu", "prinentry-dmenu"};
+ int x, y, i = 0, j;
+ unsigned int du;
+ XSetWindowAttributes swa;
+ XIM xim;
+ Window w, dw, *dws;
+ XWindowAttributes wa;
+ XClassHint ch = {"pinentry-dmenu", "prinentry-dmenu"};
#ifdef XINERAMA
- XineramaScreenInfo *info;
- Window pw;
- int a, di, n, area = 0;
+ XineramaScreenInfo *info;
+ Window pw;
+ int a, di, n, area = 0;
#endif
- /* Init appearance */
- for (j = 0; j < SchemeLast; j++)
- scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2);
+ /* Init appearance */
+ for (j = 0; j < SchemeLast; j++)
+ scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2);
- clip = XInternAtom(dpy, "CLIPBOARD", False);
- utf8 = XInternAtom(dpy, "UTF8_STRING", False);
+ clip = XInternAtom(dpy, "CLIPBOARD", False);
+ utf8 = XInternAtom(dpy, "UTF8_STRING", False);
- /* Calculate menu geometry */
- bh = MAX(drw->fonts->h + 2, lineheight); /* at least line height */
- mh = bh + (borderwidth * 2);
+ /* Calculate menu geometry */
+ bh = MAX(drw->fonts->h + 2, lineheight); /* at least line height */
+ mh = bh + (borderwidth * 2);
#ifdef XINERAMA
- info = XineramaQueryScreens(dpy, &n);
-
- if (parentwin == root && info) {
- XGetInputFocus(dpy, &w, &di);
- if (mon >= 0 && mon < n) {
- i = mon;
- } else if (w != root && w != PointerRoot && w != None) {
- /* Find top-level window containing current input focus */
- do {
- if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) {
- XFree(dws);
- }
- } while (w != root && w != pw);
- /* Find xinerama screen with which the window intersects most */
- if (XGetWindowAttributes(dpy, pw, &wa)) {
- for (j = 0; j < n; j++) {
- a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j]);
- if (a > area) {
- area = a;
- i = j;
- }
- }
- }
- }
- /* 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)) {
- for (i = 0; i < n; i++) {
- if (INTERSECT(x, y, 1, 1, info[i])) {
- break;
- }
- }
- }
-
- if (center) {
- mw = MIN(centerwidth, info[i].width) - (borderwidth * 2);
- mh = (mh * 2) - (borderwidth * 2);
- x = info[i].x_org + ((info[i].width - mw) / 2) - borderwidth;
- y = info[i].y_org + ((info[i].height - mh) / 2) - borderwidth;
- } else {
- x = info[i].x_org;
- y = info[i].y_org + (bottom ? info[i].height - mh : 0);
- mw = info[i].width - (borderwidth * 2);
- }
-
- XFree(info);
- } else
+ info = XineramaQueryScreens(dpy, &n);
+
+ if (parentwin == root && info) {
+ XGetInputFocus(dpy, &w, &di);
+ if (mon >= 0 && mon < n) {
+ i = mon;
+ } else if (w != root && w != PointerRoot && w != None) {
+ /* Find top-level window containing current input focus */
+ do {
+ if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) {
+ XFree(dws);
+ }
+ } while (w != root && w != pw);
+ /* Find xinerama screen with which the window intersects most */
+ if (XGetWindowAttributes(dpy, pw, &wa)) {
+ for (j = 0; j < n; j++) {
+ a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j]);
+ if (a > area) {
+ area = a;
+ i = j;
+ }
+ }
+ }
+ }
+ /* 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)) {
+ for (i = 0; i < n; i++) {
+ if (INTERSECT(x, y, 1, 1, info[i])) {
+ break;
+ }
+ }
+ }
+
+ if (center) {
+ mw = MIN(centerwidth, info[i].width) - (borderwidth * 2);
+ mh = (mh * 2) - (borderwidth * 2);
+ x = info[i].x_org + ((info[i].width - mw) / 2) - borderwidth;
+ y = info[i].y_org + ((info[i].height - mh) / 2) - borderwidth;
+ } else {
+ x = info[i].x_org;
+ y = info[i].y_org + (bottom ? info[i].height - mh : 0);
+ mw = info[i].width - (borderwidth * 2);
+ }
+
+ XFree(info);
+ } else
#endif
- {
- if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
- die("could not get embedding window attributes: 0x%lx", parentwin);
- }
-
- if (center) {
- mw = MIN(centerwidth, wa.width) - (borderwidth * 2);
- mh = (mh * 2) - (borderwidth * 2);
- x = ((wa.width - mw) / 2) - borderwidth;
- y = ((wa.height - mh) / 2) - borderwidth;
- } else {
- x = 0;
- y = bottom ? wa.height - mh : 0;
- mw = wa.width - (borderwidth * 2);
- }
- }
-
- pdescw = (pinentry_info->description) ? TEXTW(pinentry_info->description) : 0;
-
- /* Create menu window */
- swa.override_redirect = True;
- swa.background_pixel = 0;
- swa.border_pixel = 0;
- swa.colormap = cmap;
- swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
- win = XCreateWindow(dpy, parentwin, x, y, mw, mh - (borderwidth * 2),
- borderwidth, depth, CopyFromParent, visual,
- CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
- if (borderwidth)
- XSetWindowBorder(dpy, win, scheme[SchemeSelect][ColBg].pixel);
- XSetClassHint(dpy, win, &ch);
-
- /* Open input methods */
- xim = XOpenIM(dpy, NULL, NULL, NULL);
- xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
- XNClientWindow, win, XNFocusWindow, win, NULL);
- XMapRaised(dpy, win);
-
- if (embedded) {
- XSelectInput(dpy, parentwin, FocusChangeMask);
-
- if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
- for (i = 0; i < du && dws[i] != win; ++i) {
- XSelectInput(dpy, dws[i], FocusChangeMask);
- }
-
- XFree(dws);
- }
- grabfocus();
- }
-
- drw_resize(drw, mw, mh);
+ {
+ if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
+ die("could not get embedding window attributes: 0x%lx", parentwin);
+ }
+
+ if (center) {
+ mw = MIN(centerwidth, wa.width) - (borderwidth * 2);
+ mh = (mh * 2) - (borderwidth * 2);
+ x = ((wa.width - mw) / 2) - borderwidth;
+ y = ((wa.height - mh) / 2) - borderwidth;
+ } else {
+ x = 0;
+ y = bottom ? wa.height - mh : 0;
+ mw = wa.width - (borderwidth * 2);
+ }
+ }
+
+ pdescw = (pinentry_info->description) ? TEXTW(pinentry_info->description) : 0;
+
+ /* Create menu window */
+ swa.override_redirect = True;
+ swa.background_pixel = 0;
+ swa.border_pixel = 0;
+ swa.colormap = cmap;
+ swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
+ win = XCreateWindow(dpy, parentwin, x, y, mw, mh - (borderwidth * 2),
+ borderwidth, depth, CopyFromParent, visual,
+ CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
+ if (borderwidth)
+ XSetWindowBorder(dpy, win, scheme[SchemeSelect][ColBg].pixel);
+ XSetClassHint(dpy, win, &ch);
+
+ /* Open input methods */
+ xim = XOpenIM(dpy, NULL, NULL, NULL);
+ xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ XNClientWindow, win, XNFocusWindow, win, NULL);
+ XMapRaised(dpy, win);
+
+ if (embedded) {
+ XSelectInput(dpy, parentwin, FocusChangeMask);
+
+ if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
+ for (i = 0; i < du && dws[i] != win; ++i) {
+ XSelectInput(dpy, dws[i], FocusChangeMask);
+ }
+
+ XFree(dws);
+ }
+ grabfocus();
+ }
+
+ drw_resize(drw, mw, mh);
}
static void
cleanup(void) {
- size_t i;
-
- XUngrabKey(dpy, AnyKey, AnyModifier, root);
- for (i = 0; i < SchemeLast; i++)
- free(scheme[i]);
- drw_free(drw);
- XSync(dpy, False);
- XCloseDisplay(dpy);
+ size_t i;
+
+ XUngrabKey(dpy, AnyKey, AnyModifier, root);
+ for (i = 0; i < SchemeLast; i++)
+ free(scheme[i]);
+ drw_free(drw);
+ XSync(dpy, False);
+ XCloseDisplay(dpy);
}
static int
keypress_confirm(XKeyEvent *ev, KeySym ksym) {
- if (ev->state & ControlMask) {
- switch(ksym) {
- case XK_c:
- pinentry_info->canceled = 1;
- sel = No;
- return 1;
- default:
- return 1;
- }
- }
-
- switch(ksym) {
- case XK_KP_Enter:
- case XK_Return:
- if (sel != Nothing) {
- return 1;
- }
- break;
- case XK_y:
- case XK_Y:
- sel = Yes;
- return 1;
- case XK_n:
- case XK_N:
- sel = No;
- return 1;
- case XK_g:
- case XK_G:
- case XK_Escape:
- pinentry_info->canceled = 1;
- sel = No;
- return 1;
- case XK_h:
- case XK_j:
- case XK_Home:
- case XK_Left:
- case XK_Prior:
- case XK_Up:
- sel = No;
- break;
- case XK_k:
- case XK_l:
- case XK_Down:
- case XK_End:
- case XK_Next:
- case XK_Right:
- sel = Yes;
- break;
- }
-
- return 0;
+ if (ev->state & ControlMask) {
+ switch(ksym) {
+ case XK_c:
+ pinentry_info->canceled = 1;
+ sel = No;
+ return 1;
+ default:
+ return 1;
+ }
+ }
+
+ switch(ksym) {
+ case XK_KP_Enter:
+ case XK_Return:
+ if (sel != Nothing) {
+ return 1;
+ }
+ break;
+ case XK_y:
+ case XK_Y:
+ sel = Yes;
+ return 1;
+ case XK_n:
+ case XK_N:
+ sel = No;
+ return 1;
+ case XK_g:
+ case XK_G:
+ case XK_Escape:
+ pinentry_info->canceled = 1;
+ sel = No;
+ return 1;
+ case XK_h:
+ case XK_j:
+ case XK_Home:
+ case XK_Left:
+ case XK_Prior:
+ case XK_Up:
+ sel = No;
+ break;
+ case XK_k:
+ case XK_l:
+ case XK_Down:
+ case XK_End:
+ case XK_Next:
+ case XK_Right:
+ sel = Yes;
+ break;
+ }
+
+ return 0;
}
static int
keypress_pin(XKeyEvent *ev, KeySym ksym, char* buf, int len) {
- int old;
-
- if (ev->state & ControlMask) {
- switch(ksym) {
- case XK_a: ksym = XK_Home; break;
- case XK_b: ksym = XK_Left; break;
- case XK_c: ksym = XK_Escape; break;
- case XK_d: ksym = XK_Delete; break;
- case XK_e: ksym = XK_End; break;
- case XK_f: ksym = XK_Right; break;
- case XK_g: ksym = XK_Escape; break;
- case XK_h: ksym = XK_BackSpace; break;
- case XK_k:
- old = cursor;
- cursor = strlen(pin);
- insert(NULL, old - cursor);
- break;
- case XK_u:
- insert(NULL, -cursor);
- break;
- case XK_v:
- XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
- utf8, utf8, win, CurrentTime);
- return 0;
- case XK_Return:
- case XK_KP_Enter:
- break;
- case XK_bracketleft:
- pinentry_info->canceled = 1;
- return 1;
- default:
- return 1;
- }
- }
-
- switch(ksym) {
- case XK_Delete:
- if (pin[cursor] == '\0') {
- return 0;
- }
- cursor = nextrune(cursor, +1);
- /* Fallthrough */
- case XK_BackSpace:
- if (cursor == 0) {
- return 0;
- }
- insert(NULL, nextrune(cursor, -1) - cursor);
- break;
- case XK_Escape:
- pinentry_info->canceled = 1;
- return 1;
- case XK_Left:
- if (cursor > 0) {
- cursor = nextrune(cursor, -1);
- }
- break;
- case XK_Right:
- if (pin[cursor] != '\0') {
- cursor = nextrune(cursor, +1);
- }
- break;
- case XK_Home:
- cursor = 0;
- break;
- case XK_End:
- cursor = strlen(pin);
- break;
- case XK_Return:
- case XK_KP_Enter:
- return 1;
- break;
- default:
- if (!iscntrl(*buf)) {
- insert(buf, len);
- }
- }
-
- return 0;
+ int old;
+
+ if (ev->state & ControlMask) {
+ switch(ksym) {
+ case XK_a: ksym = XK_Home; break;
+ case XK_b: ksym = XK_Left; break;
+ case XK_c: ksym = XK_Escape; break;
+ case XK_d: ksym = XK_Delete; break;
+ case XK_e: ksym = XK_End; break;
+ case XK_f: ksym = XK_Right; break;
+ case XK_g: ksym = XK_Escape; break;
+ case XK_h: ksym = XK_BackSpace; break;
+ case XK_k:
+ old = cursor;
+ cursor = strlen(pin);
+ insert(NULL, old - cursor);
+ break;
+ case XK_u:
+ insert(NULL, -cursor);
+ break;
+ case XK_v:
+ XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
+ utf8, utf8, win, CurrentTime);
+ return 0;
+ case XK_Return:
+ case XK_KP_Enter:
+ break;
+ case XK_bracketleft:
+ pinentry_info->canceled = 1;
+ return 1;
+ default:
+ return 1;
+ }
+ }
+
+ switch(ksym) {
+ case XK_Delete:
+ if (pin[cursor] == '\0') {
+ return 0;
+ }
+ cursor = nextrune(cursor, +1);
+ /* Fallthrough */
+ case XK_BackSpace:
+ if (cursor == 0) {
+ return 0;
+ }
+ insert(NULL, nextrune(cursor, -1) - cursor);
+ break;
+ case XK_Escape:
+ pinentry_info->canceled = 1;
+ return 1;
+ case XK_Left:
+ if (cursor > 0) {
+ cursor = nextrune(cursor, -1);
+ }
+ break;
+ case XK_Right:
+ if (pin[cursor] != '\0') {
+ cursor = nextrune(cursor, +1);
+ }
+ break;
+ case XK_Home:
+ cursor = 0;
+ break;
+ case XK_End:
+ cursor = strlen(pin);
+ break;
+ case XK_Return:
+ case XK_KP_Enter:
+ return 1;
+ break;
+ default:
+ if (!iscntrl(*buf)) {
+ insert(buf, len);
+ }
+ }
+
+ return 0;
}
static int
keypress(XKeyEvent *ev) {
- char buf[32];
- int len;
- int ret = 1;
-
- KeySym ksym = NoSymbol;
- Status status;
- len = XmbLookupString(xic, ev, buf, sizeof(buf), &ksym, &status);
-
- if (status != XBufferOverflow) {
- if (winmode == WinConfirm) {
- ret = keypress_confirm(ev, ksym);
- } else {
- ret = keypress_pin(ev, ksym, buf, len);
- }
-
- if (ret == 0) {
- drawwin();
- }
- }
-
- return ret;
+ char buf[32];
+ int len;
+ int ret = 1;
+
+ KeySym ksym = NoSymbol;
+ Status status;
+ len = XmbLookupString(xic, ev, buf, sizeof(buf), &ksym, &status);
+
+ if (status != XBufferOverflow) {
+ if (winmode == WinConfirm) {
+ ret = keypress_confirm(ev, ksym);
+ } else {
+ ret = keypress_pin(ev, ksym, buf, len);
+ }
+
+ if (ret == 0) {
+ drawwin();
+ }
+ }
+
+ return ret;
}
static void
paste(void) {
- char *p, *q;
- int di;
- unsigned long dl;
- Atom da;
-
- /* 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);
- insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t) strlen(p));
- XFree(p);
- drawwin();
+ char *p, *q;
+ int di;
+ unsigned long dl;
+ Atom da;
+
+ /* 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);
+ insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t) strlen(p));
+ XFree(p);
+ drawwin();
+}
+
+void
+resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
+{
+ char *sdst = NULL;
+ int *idst = NULL;
+ float *fdst = NULL;
+ sdst = dst;
+ idst = dst;
+ fdst = dst;
+ char fullname[256];
+ char *type;
+ XrmValue ret;
+ snprintf(fullname, sizeof(fullname), "%s.%s", "dmenu", name);
+ fullname[sizeof(fullname) - 1] = '\0';
+ XrmGetResource(db, fullname, "*", &type, &ret);
+ if (!(ret.addr == NULL || strncmp("String", type, 64)))
+ {
+ switch (rtype) {
+ case STRING:
+ strcpy(sdst, ret.addr);
+ break;
+ case INTEGER:
+ *idst = strtoul(ret.addr, NULL, 10);
+ break;
+ case FLOAT:
+ *fdst = strtof(ret.addr, NULL);
+ break;
+ }
+ }
+}
+
+void
+load_xresources(void)
+{
+ Display *display;
+ char *resm;
+ XrmDatabase db;
+ ResourcePref *p;
+ display = XOpenDisplay(NULL);
+ resm = XResourceManagerString(display);
+ if (!resm)
+ return;
+ db = XrmGetStringDatabase(resm);
+ for (p = resources; p < resources + LENGTH(resources); p++)
+ resource_load(db, p->name, p->type, p->dst);
+ XCloseDisplay(display);
}
void
run(void) {
- XEvent ev;
-
- drawwin();
-
- while (!XNextEvent(dpy, &ev)) {
- if (XFilterEvent(&ev, win)) {
- continue;
- }
- switch(ev.type) {
- case Expose:
- if (ev.xexpose.count == 0) {
- drw_map(drw, win, 0, 0, mw, mh);
- }
- break;
- case KeyPress:
- if (keypress(&ev.xkey)) {
- return;
- }
- break;
- case SelectionNotify:
- if (ev.xselection.property == utf8) {
- paste();
- }
- break;
- case VisibilityNotify:
- if (ev.xvisibility.state != VisibilityUnobscured) {
- XRaiseWindow(dpy, win);
- }
- break;
- }
- }
+ XEvent ev;
+
+ drawwin();
+
+ while (!XNextEvent(dpy, &ev)) {
+ if (XFilterEvent(&ev, win)) {
+ continue;
+ }
+ switch(ev.type) {
+ case Expose:
+ if (ev.xexpose.count == 0) {
+ drw_map(drw, win, 0, 0, mw, mh);
+ }
+ break;
+ case KeyPress:
+ if (keypress(&ev.xkey)) {
+ return;
+ }
+ break;
+ case SelectionNotify:
+ if (ev.xselection.property == utf8) {
+ paste();
+ }
+ break;
+ case VisibilityNotify:
+ if (ev.xvisibility.state != VisibilityUnobscured) {
+ XRaiseWindow(dpy, win);
+ }
+ break;
+ }
+ }
}
static void
catchsig(int sig) {
- if (sig == SIGALRM) {
- timed_out = 1;
- }
+ if (sig == SIGALRM) {
+ timed_out = 1;
+ }
}
static void
password(void) {
- winmode = WinPin;
- repeat = 0;
- setup_pin(pinentry_info->pin, pinentry_info->pin_len, 1);
- run();
-
- if (!pinentry_info->canceled && pinentry_info->repeat_passphrase) {
- repeat = 1;
- pin_repeat_len = pinentry_info->pin_len;
- pin_repeat = secmem_malloc(pinentry_info->pin_len);
- setup_pin(pin_repeat, pin_repeat_len, 1);
- run();
-
- pinentry_info->repeat_okay = (strcmp(pinentry_info->pin, pin_repeat) == 0)? 1 : 0;
- secmem_free(pin_repeat);
-
- if (!pinentry_info->repeat_okay) {
- pinentry_info->result = -1;
- return;
- }
- }
-
- if (pinentry_info->canceled) {
- pinentry_info->result = -1;
- return;
- }
-
- pinentry_info->result = strlen(pinentry_info->pin);
+ winmode = WinPin;
+ repeat = 0;
+ setup_pin(pinentry_info->pin, pinentry_info->pin_len, 1);
+ run();
+
+ if (!pinentry_info->canceled && pinentry_info->repeat_passphrase) {
+ repeat = 1;
+ pin_repeat_len = pinentry_info->pin_len;
+ pin_repeat = secmem_malloc(pinentry_info->pin_len);
+ setup_pin(pin_repeat, pin_repeat_len, 1);
+ run();
+
+ pinentry_info->repeat_okay = (strcmp(pinentry_info->pin, pin_repeat) == 0)? 1 : 0;
+ secmem_free(pin_repeat);
+
+ if (!pinentry_info->repeat_okay) {
+ pinentry_info->result = -1;
+ return;
+ }
+ }
+
+ if (pinentry_info->canceled) {
+ pinentry_info->result = -1;
+ return;
+ }
+
+ pinentry_info->result = strlen(pinentry_info->pin);
}
static void
confirm(void) {
- winmode = WinConfirm;
- sel = Nothing;
- run();
- pinentry_info->result = sel != No;
+ winmode = WinConfirm;
+ sel = Nothing;
+ run();
+ pinentry_info->result = sel != No;
}
static int
cmdhandler(pinentry_t received_pinentry) {
- struct sigaction sa;
- XWindowAttributes wa;
-
- pinentry_info = received_pinentry;
-
- if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) {
- fputs("warning: no locale support\n", stderr);
- }
- if (!(dpy = XOpenDisplay(pinentry_info->display))) {
- die("cannot open display");
- }
- screen = DefaultScreen(dpy);
- root = RootWindow(dpy, screen);
- embedded = (pinentry_info->parent_wid) ? embedded : 0;
- parentwin = (embedded) ? pinentry_info->parent_wid : root;
- if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
- die("could not get embedding window attributes: 0x%lx", parentwin);
- }
- xinitvisual();
- drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
- if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) {
- die("no fonts could be loaded.");
- }
- lrpad = drw->fonts->h;
- drw_setscheme(drw, scheme[SchemePrompt]);
-
- if (pinentry_info->timeout) {
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = catchsig;
- sigaction(SIGALRM, &sa, NULL);
- alarm(pinentry_info->timeout);
- }
-
- grabkeyboard();
- setup();
-
- if (pinentry_info->pin) {
- do {
- password();
- } while (!pinentry_info->canceled && pinentry_info->repeat_passphrase
- && !pinentry_info->repeat_okay);
- } else {
- confirm();
- }
-
- cleanup();
-
- return pinentry_info->result;
+ struct sigaction sa;
+ XWindowAttributes wa;
+
+ pinentry_info = received_pinentry;
+
+ if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) {
+ fputs("warning: no locale support\n", stderr);
+ }
+ if (!(dpy = XOpenDisplay(pinentry_info->display))) {
+ die("cannot open display");
+ }
+ screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
+ embedded = (pinentry_info->parent_wid) ? embedded : 0;
+ parentwin = (embedded) ? pinentry_info->parent_wid : root;
+ if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
+ die("could not get embedding window attributes: 0x%lx", parentwin);
+ }
+ xinitvisual();
+ drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
+ if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
+ die("no fonts could be loaded.");
+ lrpad = drw->fonts->h;
+ drw_setscheme(drw, scheme[SchemePrompt]);
+
+ if (pinentry_info->timeout) {
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = catchsig;
+ sigaction(SIGALRM, &sa, NULL);
+ alarm(pinentry_info->timeout);
+ }
+
+ grabkeyboard();
+ setup();
+
+ if (pinentry_info->pin) {
+ do {
+ password();
+ } while (!pinentry_info->canceled && pinentry_info->repeat_passphrase
+ && !pinentry_info->repeat_okay);
+ } else {
+ confirm();
+ }
+
+ cleanup();
+
+ return pinentry_info->result;
}
pinentry_cmd_handler_t pinentry_cmd_handler = cmdhandler;
int
main(int argc, char *argv[]) {
- Bool bval;
- int i, val;
- const char *str;
- struct passwd *pw;
- char path[PATH_MAX];
- char *sudo_uid = getenv("SUDO_UID");
- char *home = getenv("HOME");
- char *gnupghome = getenv("GNUPGHOME");
- config_t cfg;
-
- if (gnupghome) {
- i = strlen(gnupghome);
- strcpy(path, gnupghome);
- } else {
- /* Get the home dir even if the user used sudo or logged in as root */
- if (sudo_uid) {
- i = atoi(sudo_uid);
- pw = getpwuid(i);
- home = pw->pw_dir;
- }
-
- i = strlen(home);
- strcpy(path, home);
- strcpy(&path[i], CONFIG_DIR);
- i += strlen(CONFIG_DIR);
- }
-
- strcpy(&path[i], CONFIG_FILE);
- endpwent();
-
- config_init(&cfg);
-
- /* Read the file. If there is an error, report it and exit. */
- if (config_read_file(&cfg, path)) {
- if (config_lookup_int(&cfg, "monitor", &val)) {
- mon = val;
- }
- if (config_lookup_int(&cfg, "center_width", &val)) {
- centerwidth = val;
- }
- if (config_lookup_bool(&cfg, "embedded", &bval)) {
- embedded = bval;
- }
- if (config_lookup_int(&cfg, "line_height", &val)) {
- lineheight = val;
- }
- 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;
- }
- if (config_lookup_int(&cfg, "min_password_length", &val)) {
- minpwlen = val;
- }
- if (config_lookup_string(&cfg, "asterisk", &str)) {
- asterisk = str;
- }
- if (config_lookup_string(&cfg, "prompt", &str)) {
- prompt = str;
- }
- if (config_lookup_string(&cfg, "prompt_fg", &str)) {
- colors[SchemePrompt][ColFg] = str;
- }
- if (config_lookup_string(&cfg, "prompt_bg", &str)) {
- colors[SchemePrompt][ColBg] = str;
- }
- if (config_lookup_string(&cfg, "normal_fg", &str)) {
- colors[SchemeNormal][ColFg] = str;
- }
- if (config_lookup_string(&cfg, "normal_bg", &str)) {
- colors[SchemeNormal][ColBg] = str;
- }
- if (config_lookup_string(&cfg, "select_fg", &str)) {
- colors[SchemeSelect][ColFg] = str;
- }
- if (config_lookup_string(&cfg, "select_bg", &str)) {
- colors[SchemeSelect][ColBg] = str;
- }
- if (config_lookup_string(&cfg, "desc_fg", &str)) {
- colors[SchemeDesc][ColFg] = str;
- }
- if (config_lookup_string(&cfg, "desc_bg", &str)) {
- colors[SchemeDesc][ColBg] = str;
- }
- } 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));
- return(EXIT_FAILURE);
- }
-
- 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);
-
- if (pinentry_loop()) {
- return 1;
- }
-
- config_destroy(&cfg);
-
- return 0;
+ int i;
+ struct passwd *pw;
+ char path[PATH_MAX];
+ char *sudo_uid = getenv("SUDO_UID");
+ char *home = getenv("HOME");
+ char *gnupghome = getenv("GNUPGHOME");
+
+ XrmInitialize();
+ load_xresources();
+
+ if (gnupghome) {
+ i = strlen(gnupghome);
+ strcpy(path, gnupghome);
+ } else {
+ /* Get the home dir even if the user used sudo or logged in as root */
+ if (sudo_uid) {
+ i = atoi(sudo_uid);
+ pw = getpwuid(i);
+ home = pw->pw_dir;
+ }
+
+ i = strlen(home);
+ strcpy(path, home);
+ strcpy(&path[i], CONFIG_DIR);
+ i += strlen(CONFIG_DIR);
+ }
+
+ /* endpwent(); */
+
+ 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);
+
+ if (pinentry_loop()) {
+ return 1;
+ }
+
+ return 0;
}