remov
This commit is contained in:
parent
4e9c014f44
commit
da695db237
38
dmenu.c
38
dmenu.c
|
@ -198,10 +198,9 @@ recalculatenumbers()
|
|||
static void
|
||||
drawmenu(void)
|
||||
{
|
||||
static int curpos, oldcurlen;
|
||||
unsigned int curpos;
|
||||
struct item *item;
|
||||
int x = 0, y = 0, w;
|
||||
int curlen, rcurlen;
|
||||
char *censort;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
@ -213,39 +212,20 @@ drawmenu(void)
|
|||
}
|
||||
/* draw input field */
|
||||
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
if (passwd) {
|
||||
censort = ecalloc(1, sizeof(text));
|
||||
memset(censort, '.', strlen(text));
|
||||
rcurlen = drw_fontset_getwidth(drw, censort + cursor);
|
||||
curlen = drw_fontset_getwidth(drw, censort) - rcurlen;
|
||||
curpos += curlen - oldcurlen;
|
||||
curpos = MIN(w-TEXTW(numbers), MAX(0, curpos));
|
||||
curpos = MAX(curpos, w -TEXTW(numbers)- rcurlen);
|
||||
curpos = MIN(curpos, curlen);
|
||||
oldcurlen = curlen;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text_align(drw, x, 0, curpos, bh, censort, cursor, AlignR);
|
||||
drw_text_align(drw, x + curpos, 0, w - curpos, bh, censort + cursor, strlen(censort) - cursor, AlignL);
|
||||
drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
|
||||
free(censort);
|
||||
} else {
|
||||
rcurlen = drw_fontset_getwidth(drw, text + cursor);
|
||||
curlen = drw_fontset_getwidth(drw, text) - rcurlen;
|
||||
curpos += curlen - oldcurlen;
|
||||
curpos = MIN(w-TEXTW(numbers), MAX(0, curpos));
|
||||
curpos = MAX(curpos, w -TEXTW(numbers)- rcurlen);
|
||||
curpos = MIN(curpos, curlen);
|
||||
oldcurlen = curlen;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text_align(drw, x, 0, curpos, bh, text, cursor, AlignR);
|
||||
drw_text_align(drw, x + curpos, 0, w - curpos, bh, text + cursor, strlen(text) - cursor, AlignL);
|
||||
drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0);
|
||||
free(censort);
|
||||
} else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
|
||||
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||
if ((curpos += lrpad / 2 - 1) < w) {
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
recalculatenumbers();
|
||||
if (lines > 0) {
|
||||
/* draw vertical list */
|
||||
|
|
20
dmenu.c.orig
20
dmenu.c.orig
|
@ -89,7 +89,7 @@ calcoffsets(void)
|
|||
if (lines > 0)
|
||||
n = lines * bh;
|
||||
else
|
||||
n = mw - (promptw + inputw + TEXTW(symbol_1) + TEXTW(symbol_2));
|
||||
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
|
||||
/* calculate which items will begin the next page and previous page */
|
||||
for (i = 0, next = curr; next; next = next->right)
|
||||
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
|
||||
|
@ -234,18 +234,18 @@ drawmenu(void)
|
|||
} else if (matches) {
|
||||
/* draw horizontal list */
|
||||
x += inputw;
|
||||
w = TEXTW(symbol_1);
|
||||
w = TEXTW("<");
|
||||
if (curr->left) {
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, symbol_1, 0);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0);
|
||||
}
|
||||
x += w;
|
||||
for (item = curr; item != next; item = item->right)
|
||||
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2) - TEXTW(numbers)));
|
||||
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
|
||||
if (next) {
|
||||
w = TEXTW(symbol_2);
|
||||
w = TEXTW(">");
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, symbol_2, 0);
|
||||
drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
|
||||
}
|
||||
}
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
@ -690,7 +690,7 @@ buttonpress(XEvent *e)
|
|||
* add that to the input width */
|
||||
if (ev->button == Button1 &&
|
||||
((lines <= 0 && ev->x >= 0 && ev->x <= x + w +
|
||||
((!prev || !curr->left) ? TEXTW(symbol_1) : 0)) ||
|
||||
((!prev || !curr->left) ? TEXTW("<") : 0)) ||
|
||||
(lines > 0 && ev->y >= y && ev->y <= y + h))) {
|
||||
insert(NULL, -cursor);
|
||||
drawmenu();
|
||||
|
@ -741,7 +741,7 @@ buttonpress(XEvent *e)
|
|||
} else if (matches) {
|
||||
/* left-click on left arrow */
|
||||
x += inputw;
|
||||
w = TEXTW(symbol_1);
|
||||
w = TEXTW("<");
|
||||
if (prev && curr->left) {
|
||||
if (ev->x >= x && ev->x <= x + w) {
|
||||
sel = curr = prev;
|
||||
|
@ -753,7 +753,7 @@ buttonpress(XEvent *e)
|
|||
/* horizontal list: (ctrl)left-click on item */
|
||||
for (item = curr; item != next; item = item->right) {
|
||||
x += w;
|
||||
w = MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2));
|
||||
w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
|
||||
if (ev->x >= x && ev->x <= x + w) {
|
||||
puts(item->text);
|
||||
if (!(ev->state & ControlMask))
|
||||
|
@ -767,7 +767,7 @@ buttonpress(XEvent *e)
|
|||
}
|
||||
}
|
||||
/* left-click on right arrow */
|
||||
w = TEXTW(symbol_2);
|
||||
w = TEXTW(">");
|
||||
x = mw - w;
|
||||
if (next && ev->x >= x && ev->x <= x + w) {
|
||||
sel = curr = next;
|
||||
|
|
54
dmenu.c.rej
54
dmenu.c.rej
|
@ -1,43 +1,17 @@
|
|||
--- dmenu.c
|
||||
+++ dmenu.c
|
||||
@@ -131,9 +131,10 @@ drawitem(struct item *item, int x, int y, int w)
|
||||
static void
|
||||
drawmenu(void)
|
||||
{
|
||||
- unsigned int curpos;
|
||||
+ static int curpos, oldcurlen;
|
||||
struct item *item;
|
||||
int x = 0, y = 0, w;
|
||||
int curlen, rcurlen;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||
@@ -144,14 +145,21 @@ drawmenu(void)
|
||||
@@ -165,11 +165,11 @@ drawmenu(void)
|
||||
}
|
||||
x += w;
|
||||
for (item = curr; item != next; item = item->right)
|
||||
- x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
|
||||
+ x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2)));
|
||||
if (next) {
|
||||
- w = TEXTW(">");
|
||||
+ w = TEXTW(symbol_2);
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
|
||||
+ drw_text(drw, mw - w, 0, w, bh, lrpad / 2, symbol_2, 0);
|
||||
}
|
||||
}
|
||||
/* draw input field */
|
||||
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||
- drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
+ w -= lrpad / 2;
|
||||
+ x += lrpad / 2;
|
||||
|
||||
- curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||
- if ((curpos += lrpad / 2 - 1) < w) {
|
||||
- drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
||||
- }
|
||||
+ rcurlen = drw_fontset_getwidth(drw, text + cursor);
|
||||
+ curlen = drw_fontset_getwidth(drw, text) - rcurlen;
|
||||
+ curpos += curlen - oldcurlen;
|
||||
+ curpos = MIN(w, MAX(0, curpos));
|
||||
+ curpos = MAX(curpos, w - rcurlen);
|
||||
+ curpos = MIN(curpos, curlen);
|
||||
+ oldcurlen = curlen;
|
||||
+
|
||||
+ drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
+ drw_text_align(drw, x, 0, curpos, bh, text, cursor, AlignR);
|
||||
+ drw_text_align(drw, x + curpos, 0, w - curpos, bh, text + cursor, strlen(text) - cursor, AlignL);
|
||||
+ drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
|
||||
|
||||
if (lines > 0) {
|
||||
/* draw vertical list */
|
||||
drw_map(drw, win, 0, 0, mw, mh);
|
||||
|
|
169
drw.c
169
drw.c
|
@ -366,175 +366,6 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
return x + (render ? w : 0);
|
||||
}
|
||||
|
||||
int
|
||||
utf8nextchar(const char *str, int len, int i, int inc)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = i + inc; n + inc >= 0 && n + inc <= len
|
||||
&& (str[n] & 0xc0) == 0x80; n += inc)
|
||||
;
|
||||
return n;
|
||||
}
|
||||
|
||||
int
|
||||
drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align)
|
||||
{
|
||||
int ty;
|
||||
unsigned int ew;
|
||||
XftDraw *d = NULL;
|
||||
Fnt *usedfont, *curfont, *nextfont;
|
||||
size_t len;
|
||||
int utf8strlen, utf8charlen, render = x || y || w || h;
|
||||
long utf8codepoint = 0;
|
||||
const char *utf8str;
|
||||
FcCharSet *fccharset;
|
||||
FcPattern *fcpattern;
|
||||
FcPattern *match;
|
||||
XftResult result;
|
||||
int charexists = 0;
|
||||
int i, n;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts || textlen <= 0
|
||||
|| (align != AlignL && align != AlignR))
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~w;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
}
|
||||
|
||||
usedfont = drw->fonts;
|
||||
i = align == AlignL ? 0 : textlen;
|
||||
x = align == AlignL ? x : x + w;
|
||||
while (1) {
|
||||
utf8strlen = 0;
|
||||
nextfont = NULL;
|
||||
/* if (align == AlignL) */
|
||||
utf8str = text + i;
|
||||
|
||||
while ((align == AlignL && i < textlen) || (align == AlignR && i > 0)) {
|
||||
if (align == AlignL) {
|
||||
utf8charlen = utf8decode(text + i, &utf8codepoint, MIN(textlen - i, UTF_SIZ));
|
||||
if (!utf8charlen) {
|
||||
textlen = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
n = utf8nextchar(text, textlen, i, -1);
|
||||
utf8charlen = utf8decode(text + n, &utf8codepoint, MIN(textlen - n, UTF_SIZ));
|
||||
if (!utf8charlen) {
|
||||
textlen -= i;
|
||||
text += i;
|
||||
i = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||
if (charexists) {
|
||||
if (curfont == usedfont) {
|
||||
utf8strlen += utf8charlen;
|
||||
i += align == AlignL ? utf8charlen : -utf8charlen;
|
||||
} else {
|
||||
nextfont = curfont;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!charexists || nextfont)
|
||||
break;
|
||||
else
|
||||
charexists = 0;
|
||||
}
|
||||
|
||||
if (align == AlignR)
|
||||
utf8str = text + i;
|
||||
|
||||
if (utf8strlen) {
|
||||
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
|
||||
/* shorten text if necessary */
|
||||
if (align == AlignL) {
|
||||
for (len = utf8strlen; len && ew > w; ) {
|
||||
len = utf8nextchar(utf8str, len, len, -1);
|
||||
drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||
}
|
||||
} else {
|
||||
for (len = utf8strlen; len && ew > w; ) {
|
||||
n = utf8nextchar(utf8str, len, 0, +1);
|
||||
utf8str += n;
|
||||
len -= n;
|
||||
drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (len) {
|
||||
if (render) {
|
||||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||
XftDrawStringUtf8(d, &drw->scheme[ColFg],
|
||||
usedfont->xfont, align == AlignL ? x : x - ew, ty, (XftChar8 *)utf8str, len);
|
||||
}
|
||||
x += align == AlignL ? ew : -ew;
|
||||
w -= ew;
|
||||
}
|
||||
if (len < utf8strlen)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((align == AlignR && i <= 0) || (align == AlignL && i >= textlen)) {
|
||||
break;
|
||||
} else if (nextfont) {
|
||||
charexists = 0;
|
||||
usedfont = nextfont;
|
||||
} else {
|
||||
/* Regardless of whether or not a fallback font is found, the
|
||||
* character must be drawn. */
|
||||
charexists = 1;
|
||||
|
||||
fccharset = FcCharSetCreate();
|
||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
|
||||
if (!drw->fonts->pattern) {
|
||||
/* Refer to the comment in xfont_create for more information. */
|
||||
die("the first font in the cache must be loaded from a font string.");
|
||||
}
|
||||
|
||||
fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
||||
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
||||
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
||||
|
||||
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
|
||||
FcDefaultSubstitute(fcpattern);
|
||||
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
|
||||
|
||||
FcCharSetDestroy(fccharset);
|
||||
FcPatternDestroy(fcpattern);
|
||||
|
||||
if (match) {
|
||||
usedfont = xfont_create(drw, NULL, match);
|
||||
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
||||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
||||
; /* NOP */
|
||||
curfont->next = usedfont;
|
||||
} else {
|
||||
xfont_free(usedfont);
|
||||
usedfont = drw->fonts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d)
|
||||
XftDrawDestroy(d);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
void
|
||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||
{
|
||||
|
|
423
drw.c.orig
423
drw.c.orig
|
@ -1,423 +0,0 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
#define UTF_INVALID 0xFFFD
|
||||
#define UTF_SIZ 4
|
||||
|
||||
static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
|
||||
static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
|
||||
static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
|
||||
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
||||
|
||||
static long
|
||||
utf8decodebyte(const char c, size_t *i)
|
||||
{
|
||||
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
|
||||
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
|
||||
return (unsigned char)c & ~utfmask[*i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t
|
||||
utf8validate(long *u, size_t i)
|
||||
{
|
||||
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
|
||||
*u = UTF_INVALID;
|
||||
for (i = 1; *u > utfmax[i]; ++i)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
static size_t
|
||||
utf8decode(const char *c, long *u, size_t clen)
|
||||
{
|
||||
size_t i, j, len, type;
|
||||
long udecoded;
|
||||
|
||||
*u = UTF_INVALID;
|
||||
if (!clen)
|
||||
return 0;
|
||||
udecoded = utf8decodebyte(c[0], &len);
|
||||
if (!BETWEEN(len, 1, UTF_SIZ))
|
||||
return 1;
|
||||
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
|
||||
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
|
||||
if (type)
|
||||
return j;
|
||||
}
|
||||
if (j < len)
|
||||
return 0;
|
||||
*u = udecoded;
|
||||
utf8validate(u, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
Drw *
|
||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
||||
{
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
|
||||
drw->dpy = dpy;
|
||||
drw->screen = screen;
|
||||
drw->root = root;
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
||||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
|
||||
return drw;
|
||||
}
|
||||
|
||||
void
|
||||
drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||
{
|
||||
if (!drw)
|
||||
return;
|
||||
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
if (drw->drawable)
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
||||
}
|
||||
|
||||
void
|
||||
drw_free(Drw *drw)
|
||||
{
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
XFreeGC(drw->dpy, drw->gc);
|
||||
drw_fontset_free(drw->fonts);
|
||||
free(drw);
|
||||
}
|
||||
|
||||
/* This function is an implementation detail. Library users should use
|
||||
* drw_fontset_create instead.
|
||||
*/
|
||||
static Fnt *
|
||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
||||
{
|
||||
Fnt *font;
|
||||
XftFont *xfont = NULL;
|
||||
FcPattern *pattern = NULL;
|
||||
|
||||
if (fontname) {
|
||||
/* Using the pattern found at font->xfont->pattern does not yield the
|
||||
* same substitution results as using the pattern returned by
|
||||
* FcNameParse; using the latter results in the desired fallback
|
||||
* behaviour whereas the former just results in missing-character
|
||||
* rectangles being drawn, at least with some fonts. */
|
||||
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
|
||||
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
|
||||
return NULL;
|
||||
}
|
||||
if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
|
||||
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
|
||||
XftFontClose(drw->dpy, xfont);
|
||||
return NULL;
|
||||
}
|
||||
} else if (fontpattern) {
|
||||
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
|
||||
fprintf(stderr, "error, cannot load font from pattern.\n");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
die("no font specified.");
|
||||
}
|
||||
|
||||
font = ecalloc(1, sizeof(Fnt));
|
||||
font->xfont = xfont;
|
||||
font->pattern = pattern;
|
||||
font->h = xfont->ascent + xfont->descent;
|
||||
font->dpy = drw->dpy;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
static void
|
||||
xfont_free(Fnt *font)
|
||||
{
|
||||
if (!font)
|
||||
return;
|
||||
if (font->pattern)
|
||||
FcPatternDestroy(font->pattern);
|
||||
XftFontClose(font->dpy, font->xfont);
|
||||
free(font);
|
||||
}
|
||||
|
||||
Fnt*
|
||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
{
|
||||
Fnt *cur, *ret = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!drw || !fonts)
|
||||
return NULL;
|
||||
|
||||
for (i = 1; i <= fontcount; i++) {
|
||||
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
|
||||
cur->next = ret;
|
||||
ret = cur;
|
||||
}
|
||||
}
|
||||
return (drw->fonts = ret);
|
||||
}
|
||||
|
||||
void
|
||||
drw_fontset_free(Fnt *font)
|
||||
{
|
||||
if (font) {
|
||||
drw_fontset_free(font->next);
|
||||
xfont_free(font);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||
{
|
||||
if (!drw || !dest || !clrname)
|
||||
return;
|
||||
|
||||
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen),
|
||||
clrname, dest))
|
||||
die("error, cannot allocate color '%s'", clrname);
|
||||
}
|
||||
|
||||
/* 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[], size_t clrcount)
|
||||
{
|
||||
size_t i;
|
||||
Clr *ret;
|
||||
|
||||
/* need at least two colors for a scheme */
|
||||
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor))))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < clrcount; i++)
|
||||
drw_clr_create(drw, &ret[i], clrnames[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
drw_setfontset(Drw *drw, Fnt *set)
|
||||
{
|
||||
if (drw)
|
||||
drw->fonts = set;
|
||||
}
|
||||
|
||||
void
|
||||
drw_setscheme(Drw *drw, Clr *scm)
|
||||
{
|
||||
if (drw)
|
||||
drw->scheme = scm;
|
||||
}
|
||||
|
||||
void
|
||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
|
||||
{
|
||||
if (!drw || !drw->scheme)
|
||||
return;
|
||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
|
||||
if (filled)
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
else
|
||||
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
|
||||
}
|
||||
|
||||
int
|
||||
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];
|
||||
int ty;
|
||||
unsigned int ew;
|
||||
XftDraw *d = NULL;
|
||||
Fnt *usedfont, *curfont, *nextfont;
|
||||
size_t i, len;
|
||||
int utf8strlen, utf8charlen, render = x || y || w || h;
|
||||
long utf8codepoint = 0;
|
||||
const char *utf8str;
|
||||
FcCharSet *fccharset;
|
||||
FcPattern *fcpattern;
|
||||
FcPattern *match;
|
||||
XftResult result;
|
||||
int charexists = 0;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~w;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
x += lpad;
|
||||
w -= lpad;
|
||||
}
|
||||
|
||||
usedfont = drw->fonts;
|
||||
while (1) {
|
||||
utf8strlen = 0;
|
||||
utf8str = text;
|
||||
nextfont = NULL;
|
||||
while (*text) {
|
||||
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
|
||||
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||
if (charexists) {
|
||||
if (curfont == usedfont) {
|
||||
utf8strlen += utf8charlen;
|
||||
text += utf8charlen;
|
||||
} else {
|
||||
nextfont = curfont;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!charexists || nextfont)
|
||||
break;
|
||||
else
|
||||
charexists = 0;
|
||||
}
|
||||
|
||||
if (utf8strlen) {
|
||||
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
|
||||
/* shorten text if necessary */
|
||||
for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
|
||||
drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||
|
||||
if (len) {
|
||||
memcpy(buf, utf8str, len);
|
||||
buf[len] = '\0';
|
||||
if (len < utf8strlen)
|
||||
for (i = len; i && i > len - 3; buf[--i] = '.')
|
||||
; /* NOP */
|
||||
|
||||
if (render) {
|
||||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
usedfont->xfont, x, ty, (XftChar8 *)buf, len);
|
||||
}
|
||||
x += ew;
|
||||
w -= ew;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*text) {
|
||||
break;
|
||||
} else if (nextfont) {
|
||||
charexists = 0;
|
||||
usedfont = nextfont;
|
||||
} else {
|
||||
/* Regardless of whether or not a fallback font is found, the
|
||||
* character must be drawn. */
|
||||
charexists = 1;
|
||||
|
||||
fccharset = FcCharSetCreate();
|
||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
|
||||
if (!drw->fonts->pattern) {
|
||||
/* Refer to the comment in xfont_create for more information. */
|
||||
die("the first font in the cache must be loaded from a font string.");
|
||||
}
|
||||
|
||||
fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
||||
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
||||
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
||||
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
|
||||
|
||||
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
|
||||
FcDefaultSubstitute(fcpattern);
|
||||
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
|
||||
|
||||
FcCharSetDestroy(fccharset);
|
||||
FcPatternDestroy(fcpattern);
|
||||
|
||||
if (match) {
|
||||
usedfont = xfont_create(drw, NULL, match);
|
||||
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
||||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
||||
; /* NOP */
|
||||
curfont->next = usedfont;
|
||||
} else {
|
||||
xfont_free(usedfont);
|
||||
usedfont = drw->fonts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d)
|
||||
XftDrawDestroy(d);
|
||||
|
||||
return x + (render ? w : 0);
|
||||
}
|
||||
|
||||
void
|
||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||
{
|
||||
if (!drw)
|
||||
return;
|
||||
|
||||
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
|
||||
XSync(drw->dpy, False);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
drw_fontset_getwidth(Drw *drw, const char *text)
|
||||
{
|
||||
if (!drw || !drw->fonts || !text)
|
||||
return 0;
|
||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
||||
}
|
||||
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
XGlyphInfo ext;
|
||||
|
||||
if (!font || !text)
|
||||
return;
|
||||
|
||||
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
|
||||
if (w)
|
||||
*w = ext.xOff;
|
||||
if (h)
|
||||
*h = font->h;
|
||||
}
|
||||
|
||||
Cur *
|
||||
drw_cur_create(Drw *drw, int shape)
|
||||
{
|
||||
Cur *cur;
|
||||
|
||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
||||
return NULL;
|
||||
|
||||
cur->cursor = XCreateFontCursor(drw->dpy, shape);
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
void
|
||||
drw_cur_free(Drw *drw, Cur *cursor)
|
||||
{
|
||||
if (!cursor)
|
||||
return;
|
||||
|
||||
XFreeCursor(drw->dpy, cursor->cursor);
|
||||
free(cursor);
|
||||
}
|
2
drw.h
2
drw.h
|
@ -13,7 +13,6 @@ typedef struct Fnt {
|
|||
} Fnt;
|
||||
|
||||
enum { ColFg, ColBg }; /* Clr scheme index */
|
||||
enum { AlignL, AlignR };
|
||||
typedef XftColor Clr;
|
||||
|
||||
typedef struct {
|
||||
|
@ -53,7 +52,6 @@ void drw_setscheme(Drw *drw, Clr *scm);
|
|||
/* Drawing functions */
|
||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
|
||||
int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align);
|
||||
|
||||
/* Map functions */
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 5c835dd..71efe52 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -131,9 +131,10 @@ drawitem(struct item *item, int x, int y, int w)
|
||||
static void
|
||||
drawmenu(void)
|
||||
{
|
||||
- unsigned int curpos;
|
||||
+ static int curpos, oldcurlen;
|
||||
struct item *item;
|
||||
int x = 0, y = 0, w;
|
||||
+ int curlen, rcurlen;
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||
@@ -144,14 +145,21 @@ drawmenu(void)
|
||||
}
|
||||
/* draw input field */
|
||||
w = (lines > 0 || !matches) ? mw - x : inputw;
|
||||
- drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
|
||||
+ w -= lrpad / 2;
|
||||
+ x += lrpad / 2;
|
||||
|
||||
- curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||
- if ((curpos += lrpad / 2 - 1) < w) {
|
||||
- drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
||||
- }
|
||||
+ rcurlen = drw_fontset_getwidth(drw, text + cursor);
|
||||
+ curlen = drw_fontset_getwidth(drw, text) - rcurlen;
|
||||
+ curpos += curlen - oldcurlen;
|
||||
+ curpos = MIN(w, MAX(0, curpos));
|
||||
+ curpos = MAX(curpos, w - rcurlen);
|
||||
+ curpos = MIN(curpos, curlen);
|
||||
+ oldcurlen = curlen;
|
||||
+
|
||||
+ drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
+ drw_text_align(drw, x, 0, curpos, bh, text, cursor, AlignR);
|
||||
+ drw_text_align(drw, x + curpos, 0, w - curpos, bh, text + cursor, strlen(text) - cursor, AlignL);
|
||||
+ drw_rect(drw, x + curpos - 1, 2, 2, bh - 4, 1, 0);
|
||||
|
||||
if (lines > 0) {
|
||||
/* draw vertical list */
|
||||
diff --git a/drw.c b/drw.c
|
||||
index c638323..bfffbc1 100644
|
||||
--- a/drw.c
|
||||
+++ b/drw.c
|
||||
@@ -364,6 +364,175 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
return x + (render ? w : 0);
|
||||
}
|
||||
|
||||
+int
|
||||
+utf8nextchar(const char *str, int len, int i, int inc)
|
||||
+{
|
||||
+ int n;
|
||||
+
|
||||
+ for (n = i + inc; n + inc >= 0 && n + inc <= len
|
||||
+ && (str[n] & 0xc0) == 0x80; n += inc)
|
||||
+ ;
|
||||
+ return n;
|
||||
+}
|
||||
+
|
||||
+int
|
||||
+drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align)
|
||||
+{
|
||||
+ int ty;
|
||||
+ unsigned int ew;
|
||||
+ XftDraw *d = NULL;
|
||||
+ Fnt *usedfont, *curfont, *nextfont;
|
||||
+ size_t len;
|
||||
+ int utf8strlen, utf8charlen, render = x || y || w || h;
|
||||
+ long utf8codepoint = 0;
|
||||
+ const char *utf8str;
|
||||
+ FcCharSet *fccharset;
|
||||
+ FcPattern *fcpattern;
|
||||
+ FcPattern *match;
|
||||
+ XftResult result;
|
||||
+ int charexists = 0;
|
||||
+ int i, n;
|
||||
+
|
||||
+ if (!drw || (render && !drw->scheme) || !text || !drw->fonts || textlen <= 0
|
||||
+ || (align != AlignL && align != AlignR))
|
||||
+ return 0;
|
||||
+
|
||||
+ if (!render) {
|
||||
+ w = ~w;
|
||||
+ } else {
|
||||
+ XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
|
||||
+ XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
+ d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
+ DefaultVisual(drw->dpy, drw->screen),
|
||||
+ DefaultColormap(drw->dpy, drw->screen));
|
||||
+ }
|
||||
+
|
||||
+ usedfont = drw->fonts;
|
||||
+ i = align == AlignL ? 0 : textlen;
|
||||
+ x = align == AlignL ? x : x + w;
|
||||
+ while (1) {
|
||||
+ utf8strlen = 0;
|
||||
+ nextfont = NULL;
|
||||
+ /* if (align == AlignL) */
|
||||
+ utf8str = text + i;
|
||||
+
|
||||
+ while ((align == AlignL && i < textlen) || (align == AlignR && i > 0)) {
|
||||
+ if (align == AlignL) {
|
||||
+ utf8charlen = utf8decode(text + i, &utf8codepoint, MIN(textlen - i, UTF_SIZ));
|
||||
+ if (!utf8charlen) {
|
||||
+ textlen = i;
|
||||
+ break;
|
||||
+ }
|
||||
+ } else {
|
||||
+ n = utf8nextchar(text, textlen, i, -1);
|
||||
+ utf8charlen = utf8decode(text + n, &utf8codepoint, MIN(textlen - n, UTF_SIZ));
|
||||
+ if (!utf8charlen) {
|
||||
+ textlen -= i;
|
||||
+ text += i;
|
||||
+ i = 0;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||
+ charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||
+ if (charexists) {
|
||||
+ if (curfont == usedfont) {
|
||||
+ utf8strlen += utf8charlen;
|
||||
+ i += align == AlignL ? utf8charlen : -utf8charlen;
|
||||
+ } else {
|
||||
+ nextfont = curfont;
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (!charexists || nextfont)
|
||||
+ break;
|
||||
+ else
|
||||
+ charexists = 0;
|
||||
+ }
|
||||
+
|
||||
+ if (align == AlignR)
|
||||
+ utf8str = text + i;
|
||||
+
|
||||
+ if (utf8strlen) {
|
||||
+ drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
|
||||
+ /* shorten text if necessary */
|
||||
+ if (align == AlignL) {
|
||||
+ for (len = utf8strlen; len && ew > w; ) {
|
||||
+ len = utf8nextchar(utf8str, len, len, -1);
|
||||
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||
+ }
|
||||
+ } else {
|
||||
+ for (len = utf8strlen; len && ew > w; ) {
|
||||
+ n = utf8nextchar(utf8str, len, 0, +1);
|
||||
+ utf8str += n;
|
||||
+ len -= n;
|
||||
+ drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (len) {
|
||||
+ if (render) {
|
||||
+ ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||
+ XftDrawStringUtf8(d, &drw->scheme[ColFg],
|
||||
+ usedfont->xfont, align == AlignL ? x : x - ew, ty, (XftChar8 *)utf8str, len);
|
||||
+ }
|
||||
+ x += align == AlignL ? ew : -ew;
|
||||
+ w -= ew;
|
||||
+ }
|
||||
+ if (len < utf8strlen)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if ((align == AlignR && i <= 0) || (align == AlignL && i >= textlen)) {
|
||||
+ break;
|
||||
+ } else if (nextfont) {
|
||||
+ charexists = 0;
|
||||
+ usedfont = nextfont;
|
||||
+ } else {
|
||||
+ /* Regardless of whether or not a fallback font is found, the
|
||||
+ * character must be drawn. */
|
||||
+ charexists = 1;
|
||||
+
|
||||
+ fccharset = FcCharSetCreate();
|
||||
+ FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
+
|
||||
+ if (!drw->fonts->pattern) {
|
||||
+ /* Refer to the comment in xfont_create for more information. */
|
||||
+ die("the first font in the cache must be loaded from a font string.");
|
||||
+ }
|
||||
+
|
||||
+ fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
||||
+ FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
||||
+ FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
||||
+
|
||||
+ FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
|
||||
+ FcDefaultSubstitute(fcpattern);
|
||||
+ match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
|
||||
+
|
||||
+ FcCharSetDestroy(fccharset);
|
||||
+ FcPatternDestroy(fcpattern);
|
||||
+
|
||||
+ if (match) {
|
||||
+ usedfont = xfont_create(drw, NULL, match);
|
||||
+ if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
||||
+ for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
||||
+ ; /* NOP */
|
||||
+ curfont->next = usedfont;
|
||||
+ } else {
|
||||
+ xfont_free(usedfont);
|
||||
+ usedfont = drw->fonts;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ if (d)
|
||||
+ XftDrawDestroy(d);
|
||||
+
|
||||
+ return x;
|
||||
+}
|
||||
+
|
||||
void
|
||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||
{
|
||||
diff --git a/drw.h b/drw.h
|
||||
index 4c67419..b66a83e 100644
|
||||
--- a/drw.h
|
||||
+++ b/drw.h
|
||||
@@ -13,6 +13,7 @@ typedef struct Fnt {
|
||||
} Fnt;
|
||||
|
||||
enum { ColFg, ColBg }; /* Clr scheme index */
|
||||
+enum { AlignL, AlignR };
|
||||
typedef XftColor Clr;
|
||||
|
||||
typedef struct {
|
||||
@@ -52,6 +53,7 @@ void drw_setscheme(Drw *drw, Clr *scm);
|
||||
/* Drawing functions */
|
||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
|
||||
+int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int textlen, int align);
|
||||
|
||||
/* Map functions */
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
|
@ -0,0 +1,58 @@
|
|||
From 6d0751e2eed6bfbed3cab0c87c8cb01e0b066be8 Mon Sep 17 00:00:00 2001
|
||||
From: aleks <aleks.stier@icloud.com>
|
||||
Date: Sun, 11 Aug 2019 02:01:11 +0200
|
||||
Subject: [PATCH] Add settings to define symbols for too many options
|
||||
|
||||
Add the settings *symbol_1* and *symbol_2* to config.def.h. These enable
|
||||
to define the symbols which are printed in dmenu to indicate that either
|
||||
the input is too long or there are too many options to be shown in dmenu
|
||||
in one line.
|
||||
---
|
||||
config.def.h | 2 ++
|
||||
dmenu.c | 8 ++++----
|
||||
2 files changed, 6 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1edb647..f58a50c 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -7,6 +7,8 @@ static const char *fonts[] = {
|
||||
"monospace:size=10"
|
||||
};
|
||||
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||
+static const char *symbol_1 = "<";
|
||||
+static const char *symbol_2 = ">";
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 6b8f51b..ff398a7 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -79,7 +79,7 @@ calcoffsets(void)
|
||||
if (lines > 0)
|
||||
n = lines * bh;
|
||||
else
|
||||
- n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
|
||||
+ n = mw - (promptw + inputw + TEXTW(symbol_1) + TEXTW(symbol_2));
|
||||
/* calculate which items will begin the next page and previous page */
|
||||
for (i = 0, next = curr; next; next = next->right)
|
||||
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
|
||||
@@ -165,11 +165,11 @@ drawmenu(void)
|
||||
}
|
||||
x += w;
|
||||
for (item = curr; item != next; item = item->right)
|
||||
- x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
|
||||
+ x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2)));
|
||||
if (next) {
|
||||
- w = TEXTW(">");
|
||||
+ w = TEXTW(symbol_2);
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
- drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
|
||||
+ drw_text(drw, mw - w, 0, w, bh, lrpad / 2, symbol_2, 0);
|
||||
}
|
||||
}
|
||||
drw_map(drw, win, 0, 0, mw, mh);
|
||||
--
|
||||
2.22.0
|
||||
|
Loading…
Reference in New Issue