diff options
-rw-r--r-- | config.mk | 8 | ||||
-rw-r--r-- | dmenu-bidi-20210723-b34d318.diff | 54 | ||||
-rw-r--r-- | dmenu.c | 27 |
3 files changed, 85 insertions, 4 deletions
@@ -8,6 +8,8 @@ MANPREFIX = $(PREFIX)/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib +BDINC = /usr/include/fribidi + # Xinerama, comment if you don't want it XINERAMALIBS = -lXinerama XINERAMAFLAGS = -DXINERAMA @@ -18,9 +20,11 @@ FREETYPEINC = /usr/include/freetype2 # OpenBSD (uncomment) #FREETYPEINC = $(X11INC)/freetype2 +BDLIBS = -lfribidi + # includes and libs -INCS = -I$(X11INC) -I$(FREETYPEINC) -LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lm +INCS = -I$(X11INC) -I$(FREETYPEINC) -I$(BDINC) +LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) $(BDLIBS) -lm # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) diff --git a/dmenu-bidi-20210723-b34d318.diff b/dmenu-bidi-20210723-b34d318.diff new file mode 100644 index 0000000..9e0465c --- /dev/null +++ b/dmenu-bidi-20210723-b34d318.diff @@ -0,0 +1,54 @@ +diff --git a/dmenu.c b/dmenu.c +index 65f25ce..389916b 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -113,6 +116,26 @@ cistrstr(const char *s, const char *sub) + return NULL; + } + ++static void ++apply_fribidi(char *str) ++{ ++ FriBidiStrIndex len = strlen(str); ++ FriBidiChar logical[BUFSIZ]; ++ FriBidiChar visual[BUFSIZ]; ++ FriBidiParType base = FRIBIDI_PAR_ON; ++ FriBidiCharSet charset; ++ fribidi_boolean result; ++ ++ fribidi_text[0] = 0; ++ if (len>0) ++ { ++ charset = fribidi_parse_charset("UTF-8"); ++ len = fribidi_charset_to_unicode(charset, str, len, logical); ++ result = fribidi_log2vis(logical, len, &base, visual, NULL, NULL, NULL); ++ len = fribidi_unicode_to_charset(charset, visual, len, fribidi_text); ++ } ++} ++ + static int + drawitem(struct item *item, int x, int y, int w) + { +@@ -123,7 +146,8 @@ drawitem(struct item *item, int x, int y, int w) + else + drw_setscheme(drw, scheme[SchemeNorm]); + +- return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); ++ apply_fribidi(item->text); ++ return drw_text(drw, x, y, w, bh, lrpad / 2, fribidi_text, 0); + } + + static void +@@ -143,7 +167,8 @@ 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); ++ apply_fribidi(text); ++ drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0); + + curpos = TEXTW(text) - TEXTW(&text[cursor]); + if ((curpos += lrpad / 2 - 1) < w) { +-- +2.32.0 + @@ -21,6 +21,8 @@ #include "drw.h" #include "util.h" +#include <fribidi.h> + /* macros */ #define INTERSECT(x, y, w, h, r) \ (MAX(0, MIN((x) + (w), (r).x_org + (r).width) - MAX((x), (r).x_org)) * \ @@ -50,6 +52,7 @@ struct item { static char numbers[NUMBERSBUFSIZE] = ""; static char text[BUFSIZ] = ""; +static char fribidi_text[BUFSIZ] = ""; static char *embed; static char separator; static int separator_greedy; @@ -149,6 +152,23 @@ static char *cistrstr(const char *h, const char *n) { return NULL; } +static void apply_fribidi(char *str) { + FriBidiStrIndex len = strlen(str); + FriBidiChar logical[BUFSIZ]; + FriBidiChar visual[BUFSIZ]; + FriBidiParType base = FRIBIDI_PAR_ON; + FriBidiCharSet charset; + fribidi_boolean result; + + fribidi_text[0] = 0; + if (len > 0) { + charset = fribidi_parse_charset("UTF-8"); + len = fribidi_charset_to_unicode(charset, str, len, logical); + result = fribidi_log2vis(logical, len, &base, visual, NULL, NULL, NULL); + len = fribidi_unicode_to_charset(charset, visual, len, fribidi_text); + } +} + static void drawhighlights(struct item *item, int x, int y, int maxw) { int i, indent; char *highlight; @@ -189,7 +209,8 @@ static int drawitem(struct item *item, int x, int y, int w) { else drw_setscheme(drw, scheme[SchemeNorm]); - r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); + apply_fribidi(item->text); + r = drw_text(drw, x, y, w, bh, lrpad / 2, fribidi_text, 0); drawhighlights(item, x, y, w); return r; } @@ -222,7 +243,9 @@ static void 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); + /* drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); */ + apply_fribidi(text); + drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0); curpos = TEXTW(text) - TEXTW(&text[cursor]); if ((curpos += lrpad / 2 - 1) < w) { |