add rtl language support (im going to use this for dboard)

This commit is contained in:
speedie 2023-01-22 11:22:33 +01:00
parent 954a821dff
commit 38afcc6942
3 changed files with 67 additions and 8 deletions

View file

@ -34,5 +34,5 @@ XRENDERLIBS = -lXrender
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
CFLAGS = -std=c99 -pedantic -Wall -Ofast $(INCS) $(CPPFLAGS) CFLAGS = -std=c99 -pedantic -Wall -Ofast $(INCS) $(CPPFLAGS)
LDFLAGS = $(LIBS) LDFLAGS = $(LIBS)
INCS = -I$(X11INC) -I$(FREETYPEINC) `pkg-config --cflags $(XFT_CONF) $(PANGO_CONF) $(PANGOXFT_CONF)` INCS = -I$(X11INC) -I$(FREETYPEINC) `pkg-config --cflags $(XFT_CONF) $(PANGO_CONF) $(PANGOXFT_CONF)` $(BDINC)
LIBS = -L$(X11LIB) $(X11LIBS) $(XINERAMALIBS) $(FREETYPELIBS) $(XRENDERLIBS) -lm `pkg-config --libs $(XFT_CONF) $(PANGO_CONF) $(PANGOXFT_CONF)` LIBS = -L$(X11LIB) $(X11LIBS) $(XINERAMALIBS) $(FREETYPELIBS) $(XRENDERLIBS) -lm `pkg-config --libs $(XFT_CONF) $(PANGO_CONF) $(PANGOXFT_CONF)` $(BDLIBS)

View file

@ -9,6 +9,17 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef FRIBIDI
#define USERTL 1
#else
#define USERTL 0
#endif
#if USERTL
#include <fribidi.h>
static char fribidi_text[BUFSIZ] = "";
#endif
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
@ -148,6 +159,9 @@ static void selectitem(const Arg *arg);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void complete(const Arg *arg); static void complete(const Arg *arg);
#if USERTL
static void apply_fribidi(char *str);
#endif
#include "options.h" /* Include user configuration */ #include "options.h" /* Include user configuration */
#include "keybinds.h" /* Include keybinds */ #include "keybinds.h" /* Include keybinds */
@ -209,7 +223,7 @@ calcoffsets(void)
break; break;
} }
static int int
max_textw(void) max_textw(void)
{ {
int len = 0; int len = 0;
@ -231,7 +245,7 @@ cleanup(void)
XCloseDisplay(dpy); XCloseDisplay(dpy);
} }
static char * char *
cistrstr(const char *h, const char *n) cistrstr(const char *h, const char *n)
{ {
size_t i; size_t i;
@ -286,7 +300,7 @@ drawhighlights(struct item *item, int x, int y, int maxw)
} }
} }
static int int
drawitem(struct item *item, int x, int y, int w) drawitem(struct item *item, int x, int y, int w)
{ {
if (item == sel) if (item == sel)
@ -393,13 +407,19 @@ drawitem(struct item *item, int x, int y, int w)
} }
buffer[wr] = '\0'; buffer[wr] = '\0';
#if USERTL
apply_fribidi(buffer);
int r = drw_text(drw, x, y, w, bh, lrpad / 2, fribidi_text, 0, False);
#else
int r = drw_text(drw, x, y, w, bh, lrpad / 2, buffer, 0, False); int r = drw_text(drw, x, y, w, bh, lrpad / 2, buffer, 0, False);
#endif
drawhighlights(item, x, y, w); drawhighlights(item, x, y, w);
return r; return r;
} }
unsigned char char
sixd_to_8bit(int x) sixd_to_8bit(int x)
{ {
return x == 0 ? 0 : 0x37 + 0x28 * x; return x == 0 ? 0 : 0x37 + 0x28 * x;
@ -429,9 +449,21 @@ drawmenu(void)
if (passwd) { if (passwd) {
censort = ecalloc(1, sizeof(text)); censort = ecalloc(1, sizeof(text));
memset(censort, '.', strlen(text)); memset(censort, '.', strlen(text));
#if USERTL
apply_fribidi(censort);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, True);
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0, True); drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0, True);
#endif
free(censort); free(censort);
} else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0, True); } else {
#if USERTL
apply_fribidi(text);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, True);
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0, True);
#endif
}
curpos = TEXTW(text) - TEXTW(&text[cursor]); curpos = TEXTW(text) - TEXTW(&text[cursor]);
if ((curpos += lrpad / 2 - 1) < w) { if ((curpos += lrpad / 2 - 1) < w) {
@ -692,7 +724,7 @@ insert(const char *str, ssize_t n)
match(); match();
} }
static size_t size_t
nextrune(int inc) nextrune(int inc)
{ {
ssize_t n; ssize_t n;
@ -1291,6 +1323,28 @@ buttonpress(XEvent *e)
} }
} }
#if USERTL
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);
}
}
#endif
void void
pastesel(void) pastesel(void)
{ {

View file

@ -6,3 +6,8 @@
# Comment these lines if you don't need it. # Comment these lines if you don't need it.
XINERAMALIBS = -lXinerama XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA XINERAMAFLAGS = -DXINERAMA
# Right to left language support
# Comment these lines if you don't need it.
BDLIBS = -lfribidi
BDINC = /usr/include/fribidi