Sync dmenu-flexipatch from upstream

This commit is contained in:
Alexis Jhon Gaspar 2023-10-03 19:17:39 +08:00
parent d619bdf356
commit 8eaacc23bd
7 changed files with 22 additions and 23 deletions

View file

@ -6,13 +6,7 @@ include config.mk
SRC = drw.c dmenu.c stest.c util.c SRC = drw.c dmenu.c stest.c util.c
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
all: options dmenu stest all: dmenu stest
options:
@echo dmenu build options:
@echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "CC = $(CC)"
.c.o: .c.o:
$(CC) -c $(CFLAGS) $< $(CC) -c $(CFLAGS) $<
@ -64,4 +58,4 @@ uninstall:
$(DESTDIR)$(MANPREFIX)/man1/dmenu.1\ $(DESTDIR)$(MANPREFIX)/man1/dmenu.1\
$(DESTDIR)$(MANPREFIX)/man1/stest.1 $(DESTDIR)$(MANPREFIX)/man1/stest.1
.PHONY: all options clean dist install uninstall .PHONY: all clean dist install uninstall

View file

@ -1,5 +1,5 @@
Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this dmenu 5.2 (0fe460d, Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this dmenu 5.2 (8df553e,
2023-04-05) project has a different take on patching. It uses preprocessor directives to decide 2023-09-22) project has a different take on patching. It uses preprocessor directives to decide
whether or not to include a patch during build time. Essentially this means that this build, for whether or not to include a patch during build time. Essentially this means that this build, for
better or worse, contains both the patched _and_ the original code. The aim being that you can better or worse, contains both the patched _and_ the original code. The aim being that you can
select which patches to include and the build will contain that code and nothing more. select which patches to include and the build will contain that code and nothing more.

View file

@ -33,7 +33,6 @@
/* macros */ /* macros */
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ #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((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define LENGTH(X) (sizeof X / sizeof X[0])
#if PANGO_PATCH #if PANGO_PATCH
#define TEXTW(X) (drw_font_getwidth(drw, (X), False) + lrpad) #define TEXTW(X) (drw_font_getwidth(drw, (X), False) + lrpad)
#define TEXTWM(X) (drw_font_getwidth(drw, (X), True) + lrpad) #define TEXTWM(X) (drw_font_getwidth(drw, (X), True) + lrpad)

View file

@ -430,8 +430,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
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)
{ {
int i, ty, ellipsis_x = 0; int ty, ellipsis_x = 0;
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len; unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1;
XftDraw *d = NULL; XftDraw *d = NULL;
Fnt *usedfont, *curfont, *nextfont; Fnt *usedfont, *curfont, *nextfont;
int utf8strlen, utf8charlen, render = x || y || w || h; int utf8strlen, utf8charlen, render = x || y || w || h;
@ -443,10 +443,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
XftResult result; XftResult result;
int charexists = 0, overflow = 0; int charexists = 0, overflow = 0;
/* keep track of a couple codepoints for which we have no match. */ /* keep track of a couple codepoints for which we have no match. */
enum { nomatches_len = 64 }; static unsigned int nomatches[128], ellipsis_width;
static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches;
const char *ellipsis = "..."; const char *ellipsis = "...";
static unsigned int ellipsis_width = 0;
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts) if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
return 0; return 0;
@ -535,11 +533,14 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
* character must be drawn. */ * character must be drawn. */
charexists = 1; charexists = 1;
for (i = 0; i < nomatches_len; ++i) { hash = (unsigned int)utf8codepoint;
/* avoid calling XftFontMatch if we know we won't find a match */ hash = ((hash >> 16) ^ hash) * 0x21F0AAAD;
if (utf8codepoint == nomatches.codepoint[i]) hash = ((hash >> 15) ^ hash) * 0xD35A2D97;
goto no_match; h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches);
} h1 = (hash >> 17) % LENGTH(nomatches);
/* avoid expensive XftFontMatch call when we know we won't find a match */
if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint)
goto no_match;
fccharset = FcCharSetCreate(); fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, utf8codepoint); FcCharSetAddChar(fccharset, utf8codepoint);
@ -571,7 +572,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
curfont->next = usedfont; curfont->next = usedfont;
} else { } else {
xfont_free(usedfont); xfont_free(usedfont);
nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint; nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint;
no_match: no_match:
usedfont = drw->fonts; usedfont = drw->fonts;
} }

View file

@ -36,9 +36,13 @@ drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h, const cha
} else { } else {
XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel); XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
#if ALPHA_PATCH
d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
#else
d = XftDrawCreate(drw->dpy, drw->drawable, d = XftDrawCreate(drw->dpy, drw->drawable,
DefaultVisual(drw->dpy, drw->screen), DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen)); DefaultColormap(drw->dpy, drw->screen));
#endif // ALPHA_PATCH
} }
usedfont = drw->fonts; usedfont = drw->fonts;

View file

@ -299,7 +299,7 @@
* it can handle long text. * it can handle long text.
* https://tools.suckless.org/dmenu/patches/scroll/ * https://tools.suckless.org/dmenu/patches/scroll/
*/ */
#define SCROLL_PATCH 0 #define SCROLL_PATCH 1
/* This patch adds -d and -D flags which separates the input into two halves; one half to be /* This patch adds -d and -D flags which separates the input into two halves; one half to be
* displayed in dmenu and the other to be printed to stdout. This patch takes precedence over * displayed in dmenu and the other to be printed to stdout. This patch takes precedence over

View file

@ -7,6 +7,7 @@
#define MIN(A, B) ((A) < (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B))
#endif #endif
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
#define LENGTH(X) (sizeof (X) / sizeof (X)[0])
void die(const char *fmt, ...); void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); void *ecalloc(size_t nmemb, size_t size);