indentation changed from tabs to spaces

This commit is contained in:
mrdotx 2021-07-31 10:53:44 +02:00
parent 431d99aab6
commit 69d369f6a2
No known key found for this signature in database
GPG Key ID: 433F70E636E6EB87
7 changed files with 988 additions and 988 deletions

4
README
View File

@ -18,7 +18,7 @@ the /usr/local namespace by default).
Afterwards enter the following command to build and install dmenu Afterwards enter the following command to build and install dmenu
(if necessary as root): (if necessary as root):
make clean install make clean install
Running pinentry-dmenu Running pinentry-dmenu
---------------------- ----------------------
@ -28,7 +28,7 @@ Config
------ ------
To use pinentry-dmenu add in `~/.gnupg/gpg-agent.conf`: To use pinentry-dmenu add in `~/.gnupg/gpg-agent.conf`:
pinentry-program <absolut path to pinentry-dmenu> pinentry-program <absolut path to pinentry-dmenu>
The config is located in `~/.gnupg/pinentry-dmenu.conf`. The config is located in `~/.gnupg/pinentry-dmenu.conf`.

View File

@ -8,24 +8,24 @@ static unsigned int lineheight = 22;
static unsigned int borderwidth = 2; static unsigned int borderwidth = 2;
static unsigned int minpwlen = 32; static unsigned int minpwlen = 32;
static unsigned int alphas[SchemeLast][2] = { static unsigned int alphas[SchemeLast][2] = {
/* values between 0 (transparent) and 255 (opaque) */ /* values between 0 (transparent) and 255 (opaque) */
/* foreground, background */ /* foreground, background */
[SchemePrompt] = { 255, 255 }, [SchemePrompt] = { 255, 255 },
[SchemeNormal] = { 255, 230 }, [SchemeNormal] = { 255, 230 },
[SchemeSelect] = { 255, 255 }, [SchemeSelect] = { 255, 255 },
[SchemeDesc] = { 255, 230 }, [SchemeDesc] = { 255, 230 },
}; };
static const char *position = "center"; 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"
}; };
static const char *prompt = NULL; static const char *prompt = NULL;
static const char *asterisk = "*"; static const char *asterisk = "*";
static const char *colors[SchemeLast][2] = { static const char *colors[SchemeLast][2] = {
/* foreground, background */ /* foreground, background */
[SchemePrompt] = { "#cccccc", "#4185d7" }, [SchemePrompt] = { "#cccccc", "#4185d7" },
[SchemeNormal] = { "#cccccc", "#000000" }, [SchemeNormal] = { "#cccccc", "#000000" },
[SchemeSelect] = { "#ffffff", "#4185d7" }, [SchemeSelect] = { "#ffffff", "#4185d7" },
[SchemeDesc] = { "#cccccc", "#000000" }, [SchemeDesc] = { "#cccccc", "#000000" },
}; };

520
drw.c
View File

@ -19,86 +19,86 @@ static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF
static long static long
utf8decodebyte(const char c, size_t *i) utf8decodebyte(const char c, size_t *i)
{ {
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
return (unsigned char)c & ~utfmask[*i]; return (unsigned char)c & ~utfmask[*i];
return 0; return 0;
} }
static size_t static size_t
utf8validate(long *u, size_t i) utf8validate(long *u, size_t i)
{ {
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
*u = UTF_INVALID; *u = UTF_INVALID;
for (i = 1; *u > utfmax[i]; ++i) for (i = 1; *u > utfmax[i]; ++i)
; ;
return i; return i;
} }
static size_t static size_t
utf8decode(const char *c, long *u, size_t clen) utf8decode(const char *c, long *u, size_t clen)
{ {
size_t i, j, len, type; size_t i, j, len, type;
long udecoded; long udecoded;
*u = UTF_INVALID; *u = UTF_INVALID;
if (!clen) if (!clen)
return 0; return 0;
udecoded = utf8decodebyte(c[0], &len); udecoded = utf8decodebyte(c[0], &len);
if (!BETWEEN(len, 1, UTF_SIZ)) if (!BETWEEN(len, 1, UTF_SIZ))
return 1; return 1;
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
if (type) if (type)
return j; return j;
} }
if (j < len) if (j < len)
return 0; return 0;
*u = udecoded; *u = udecoded;
utf8validate(u, len); utf8validate(u, len);
return len; return len;
} }
Drw * Drw *
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap) drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
{ {
Drw *drw = ecalloc(1, sizeof(Drw)); Drw *drw = ecalloc(1, sizeof(Drw));
drw->dpy = dpy; drw->dpy = dpy;
drw->screen = screen; drw->screen = screen;
drw->root = root; drw->root = root;
drw->w = w; drw->w = w;
drw->h = h; drw->h = h;
drw->visual = visual; drw->visual = visual;
drw->depth = depth; drw->depth = depth;
drw->cmap = cmap; drw->cmap = cmap;
drw->drawable = XCreatePixmap(dpy, root, w, h, depth); drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL); drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw; return drw;
} }
void void
drw_resize(Drw *drw, unsigned int w, unsigned int h) drw_resize(Drw *drw, unsigned int w, unsigned int h)
{ {
if (!drw) if (!drw)
return; return;
drw->w = w; drw->w = w;
drw->h = h; drw->h = h;
if (drw->drawable) if (drw->drawable)
XFreePixmap(drw->dpy, drw->drawable); XFreePixmap(drw->dpy, drw->drawable);
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth); drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
} }
void void
drw_free(Drw *drw) drw_free(Drw *drw)
{ {
XFreePixmap(drw->dpy, drw->drawable); XFreePixmap(drw->dpy, drw->drawable);
XFreeGC(drw->dpy, drw->gc); XFreeGC(drw->dpy, drw->gc);
free(drw); free(drw);
} }
/* This function is an implementation detail. Library users should use /* This function is an implementation detail. Library users should use
@ -107,92 +107,92 @@ drw_free(Drw *drw)
static Fnt * static Fnt *
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
{ {
Fnt *font; Fnt *font;
XftFont *xfont = NULL; XftFont *xfont = NULL;
FcPattern *pattern = NULL; FcPattern *pattern = NULL;
if (fontname) { if (fontname) {
/* Using the pattern found at font->xfont->pattern does not yield the /* Using the pattern found at font->xfont->pattern does not yield the
* same substitution results as using the pattern returned by * same substitution results as using the pattern returned by
* FcNameParse; using the latter results in the desired fallback * FcNameParse; using the latter results in the desired fallback
* behaviour whereas the former just results in missing-character * behaviour whereas the former just results in missing-character
* rectangles being drawn, at least with some fonts. */ * rectangles being drawn, at least with some fonts. */
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
return NULL; return NULL;
} }
if (!(pattern = FcNameParse((FcChar8 *) fontname))) { if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
XftFontClose(drw->dpy, xfont); XftFontClose(drw->dpy, xfont);
return NULL; return NULL;
} }
} else if (fontpattern) { } else if (fontpattern) {
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
fprintf(stderr, "error, cannot load font from pattern.\n"); fprintf(stderr, "error, cannot load font from pattern.\n");
return NULL; return NULL;
} }
} else { } else {
die("no font specified."); die("no font specified.");
} }
font = ecalloc(1, sizeof(Fnt)); font = ecalloc(1, sizeof(Fnt));
font->xfont = xfont; font->xfont = xfont;
font->pattern = pattern; font->pattern = pattern;
font->h = xfont->ascent + xfont->descent; font->h = xfont->ascent + xfont->descent;
font->dpy = drw->dpy; font->dpy = drw->dpy;
return font; return font;
} }
static void static void
xfont_free(Fnt *font) xfont_free(Fnt *font)
{ {
if (!font) if (!font)
return; return;
if (font->pattern) if (font->pattern)
FcPatternDestroy(font->pattern); FcPatternDestroy(font->pattern);
XftFontClose(font->dpy, font->xfont); XftFontClose(font->dpy, font->xfont);
free(font); free(font);
} }
Fnt* Fnt*
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
{ {
Fnt *cur, *ret = NULL; Fnt *cur, *ret = NULL;
size_t i; size_t i;
if (!drw || !fonts) if (!drw || !fonts)
return NULL; return NULL;
for (i = 1; i <= fontcount; i++) { for (i = 1; i <= fontcount; i++) {
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
cur->next = ret; cur->next = ret;
ret = cur; ret = cur;
} }
} }
return (drw->fonts = ret); return (drw->fonts = ret);
} }
void void
drw_fontset_free(Fnt *font) drw_fontset_free(Fnt *font)
{ {
if (font) { if (font) {
drw_fontset_free(font->next); drw_fontset_free(font->next);
xfont_free(font); xfont_free(font);
} }
} }
void void
drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha) drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
{ {
if (!drw || !dest || !clrname) if (!drw || !dest || !clrname)
return; return;
if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap, if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
clrname, dest)) clrname, dest))
die("error, cannot allocate color '%s'", clrname); die("error, cannot allocate color '%s'", clrname);
dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
} }
/* Wrapper to create color schemes. The caller has to call free(3) on the /* Wrapper to create color schemes. The caller has to call free(3) on the
@ -200,224 +200,224 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
Clr * Clr *
drw_scm_create(Drw *drw, const char *clrnames[], unsigned int alphas[], size_t clrcount) drw_scm_create(Drw *drw, const char *clrnames[], unsigned int alphas[], size_t clrcount)
{ {
size_t i; size_t i;
Clr *ret; Clr *ret;
/* need at least two colors for a scheme */ /* need at least two colors for a scheme */
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor))))
return NULL; return NULL;
for (i = 0; i < clrcount; i++) for (i = 0; i < clrcount; i++)
drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]); drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]);
return ret; return ret;
} }
void void
drw_setfontset(Drw *drw, Fnt *set) drw_setfontset(Drw *drw, Fnt *set)
{ {
if (drw) if (drw)
drw->fonts = set; drw->fonts = set;
} }
void void
drw_setscheme(Drw *drw, Clr *scm) drw_setscheme(Drw *drw, Clr *scm)
{ {
if (drw) if (drw)
drw->scheme = scm; drw->scheme = scm;
} }
void void
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
{ {
if (!drw || !drw->scheme) if (!drw || !drw->scheme)
return; return;
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
if (filled) if (filled)
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
else else
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
} }
int int
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
{ {
char buf[1024]; char buf[1024];
int ty; int ty;
unsigned int ew; unsigned int ew;
XftDraw *d = NULL; XftDraw *d = NULL;
Fnt *usedfont, *curfont, *nextfont; Fnt *usedfont, *curfont, *nextfont;
size_t i, len; size_t i, len;
int utf8strlen, utf8charlen, render = x || y || w || h; int utf8strlen, utf8charlen, render = x || y || w || h;
long utf8codepoint = 0; long utf8codepoint = 0;
const char *utf8str; const char *utf8str;
FcCharSet *fccharset; FcCharSet *fccharset;
FcPattern *fcpattern; FcPattern *fcpattern;
FcPattern *match; FcPattern *match;
XftResult result; XftResult result;
int charexists = 0; int charexists = 0;
if (!drw || (render && !drw->scheme) || !text || !drw->fonts) if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
return 0; return 0;
if (!render) { if (!render) {
w = ~w; w = ~w;
} else { } else {
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap); d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
x += lpad; x += lpad;
w -= lpad; w -= lpad;
} }
usedfont = drw->fonts; usedfont = drw->fonts;
while (1) { while (1) {
utf8strlen = 0; utf8strlen = 0;
utf8str = text; utf8str = text;
nextfont = NULL; nextfont = NULL;
while (*text) { while (*text) {
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
for (curfont = drw->fonts; curfont; curfont = curfont->next) { for (curfont = drw->fonts; curfont; curfont = curfont->next) {
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
if (charexists) { if (charexists) {
if (curfont == usedfont) { if (curfont == usedfont) {
utf8strlen += utf8charlen; utf8strlen += utf8charlen;
text += utf8charlen; text += utf8charlen;
} else { } else {
nextfont = curfont; nextfont = curfont;
} }
break; break;
} }
} }
if (!charexists || nextfont) if (!charexists || nextfont)
break; break;
else else
charexists = 0; charexists = 0;
} }
if (utf8strlen) { if (utf8strlen) {
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
/* shorten text if necessary */ /* shorten text if necessary */
for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
drw_font_getexts(usedfont, utf8str, len, &ew, NULL); drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
if (len) { if (len) {
memcpy(buf, utf8str, len); memcpy(buf, utf8str, len);
buf[len] = '\0'; buf[len] = '\0';
if (len < utf8strlen) if (len < utf8strlen)
for (i = len; i && i > len - 3; buf[--i] = '.') for (i = len; i && i > len - 3; buf[--i] = '.')
; /* NOP */ ; /* NOP */
if (render) { if (render) {
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
usedfont->xfont, x, ty, (XftChar8 *)buf, len); usedfont->xfont, x, ty, (XftChar8 *)buf, len);
} }
x += ew; x += ew;
w -= ew; w -= ew;
} }
} }
if (!*text) { if (!*text) {
break; break;
} else if (nextfont) { } else if (nextfont) {
charexists = 0; charexists = 0;
usedfont = nextfont; usedfont = nextfont;
} else { } else {
/* Regardless of whether or not a fallback font is found, the /* Regardless of whether or not a fallback font is found, the
* character must be drawn. */ * character must be drawn. */
charexists = 1; charexists = 1;
fccharset = FcCharSetCreate(); fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, utf8codepoint); FcCharSetAddChar(fccharset, utf8codepoint);
if (!drw->fonts->pattern) { if (!drw->fonts->pattern) {
/* Refer to the comment in xfont_create for more information. */ /* Refer to the comment in xfont_create for more information. */
die("the first font in the cache must be loaded from a font string."); die("the first font in the cache must be loaded from a font string.");
} }
fcpattern = FcPatternDuplicate(drw->fonts->pattern); fcpattern = FcPatternDuplicate(drw->fonts->pattern);
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
FcDefaultSubstitute(fcpattern); FcDefaultSubstitute(fcpattern);
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
FcCharSetDestroy(fccharset); FcCharSetDestroy(fccharset);
FcPatternDestroy(fcpattern); FcPatternDestroy(fcpattern);
if (match) { if (match) {
usedfont = xfont_create(drw, NULL, match); usedfont = xfont_create(drw, NULL, match);
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
for (curfont = drw->fonts; curfont->next; curfont = curfont->next) for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
; /* NOP */ ; /* NOP */
curfont->next = usedfont; curfont->next = usedfont;
} else { } else {
xfont_free(usedfont); xfont_free(usedfont);
usedfont = drw->fonts; usedfont = drw->fonts;
} }
} }
} }
} }
if (d) if (d)
XftDrawDestroy(d); XftDrawDestroy(d);
return x + (render ? w : 0); return x + (render ? w : 0);
} }
void void
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
{ {
if (!drw) if (!drw)
return; return;
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
XSync(drw->dpy, False); XSync(drw->dpy, False);
} }
unsigned int unsigned int
drw_fontset_getwidth(Drw *drw, const char *text) drw_fontset_getwidth(Drw *drw, const char *text)
{ {
if (!drw || !drw->fonts || !text) if (!drw || !drw->fonts || !text)
return 0; return 0;
return drw_text(drw, 0, 0, 0, 0, 0, text, 0); return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
} }
void void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
{ {
XGlyphInfo ext; XGlyphInfo ext;
if (!font || !text) if (!font || !text)
return; return;
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
if (w) if (w)
*w = ext.xOff; *w = ext.xOff;
if (h) if (h)
*h = font->h; *h = font->h;
} }
Cur * Cur *
drw_cur_create(Drw *drw, int shape) drw_cur_create(Drw *drw, int shape)
{ {
Cur *cur; Cur *cur;
if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL; return NULL;
cur->cursor = XCreateFontCursor(drw->dpy, shape); cur->cursor = XCreateFontCursor(drw->dpy, shape);
return cur; return cur;
} }
void void
drw_cur_free(Drw *drw, Cur *cursor) drw_cur_free(Drw *drw, Cur *cursor)
{ {
if (!cursor) if (!cursor)
return; return;
XFreeCursor(drw->dpy, cursor->cursor); XFreeCursor(drw->dpy, cursor->cursor);
free(cursor); free(cursor);
} }

34
drw.h
View File

@ -1,32 +1,32 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
typedef struct { typedef struct {
Cursor cursor; Cursor cursor;
} Cur; } Cur;
typedef struct Fnt { typedef struct Fnt {
Display *dpy; Display *dpy;
unsigned int h; unsigned int h;
XftFont *xfont; XftFont *xfont;
FcPattern *pattern; FcPattern *pattern;
struct Fnt *next; struct Fnt *next;
} Fnt; } Fnt;
enum { ColFg, ColBg }; /* Clr scheme index */ enum { ColFg, ColBg }; /* Clr scheme index */
typedef XftColor Clr; typedef XftColor Clr;
typedef struct { typedef struct {
unsigned int w, h; unsigned int w, h;
Display *dpy; Display *dpy;
int screen; int screen;
Window root; Window root;
Visual *visual; Visual *visual;
unsigned int depth; unsigned int depth;
Colormap cmap; Colormap cmap;
Drawable drawable; Drawable drawable;
GC gc; GC gc;
Clr *scheme; Clr *scheme;
Fnt *fonts; Fnt *fonts;
} Drw; } Drw;
/* Drawable abstraction */ /* Drawable abstraction */

File diff suppressed because it is too large Load Diff

32
test.sh
View File

@ -17,20 +17,20 @@ SETREPEAT repeat
GETPIN" GETPIN"
case $1 in case $1 in
1) 1)
printf "%s\nBYE" "$prompt" \ printf "%s\nBYE" "$prompt" \
| ./pinentry-dmenu | ./pinentry-dmenu
;; ;;
2) 2)
printf "%s\nBYE" "$confirm" \ printf "%s\nBYE" "$confirm" \
| ./pinentry-dmenu | ./pinentry-dmenu
;; ;;
3) 3)
printf "%s\nBYE" "$repeat" \ printf "%s\nBYE" "$repeat" \
| ./pinentry-dmenu | ./pinentry-dmenu
;; ;;
*) *)
printf "%s\n%s\n%s\nBYE" "$prompt" "$confirm" "$repeat" \ printf "%s\n%s\n%s\nBYE" "$prompt" "$confirm" "$repeat" \
| ./pinentry-dmenu | ./pinentry-dmenu
;; ;;
esac esac

30
util.c
View File

@ -9,27 +9,27 @@
void * void *
ecalloc(size_t nmemb, size_t size) ecalloc(size_t nmemb, size_t size)
{ {
void *p; void *p;
if (!(p = calloc(nmemb, size))) if (!(p = calloc(nmemb, size)))
die("calloc:"); die("calloc:");
return p; return p;
} }
void void
die(const char *fmt, ...) { die(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
va_end(ap); va_end(ap);
if (fmt[0] && fmt[strlen(fmt)-1] == ':') { if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr); fputc(' ', stderr);
perror(NULL); perror(NULL);
} else { } else {
fputc('\n', stderr); fputc('\n', stderr);
} }
exit(1); exit(1);
} }