[wiki] [sites] [dwm][PATCH] Add bidirectional support patch for to dwm.suckless.org/patches || Mahdi Mirzade

From: <git_AT_suckless.org>
Date: Sat, 19 Feb 2022 13:17:04 +0100

commit 4596cf2cb75a2d66c87243c876cb4677ea774d33
Author: Mahdi Mirzade <me_AT_mahdym.ir>
Date: Sat Feb 19 15:46:09 2022 +0330

    [dwm][PATCH] Add bidirectional support patch for to dwm.suckless.org/patches

diff --git a/dwm.suckless.org/patches/bidi/dwm-bidi-20220219-302953a.diff b/dwm.suckless.org/patches/bidi/dwm-bidi-20220219-302953a.diff
new file mode 100644
index 00000000..f7925ece
--- /dev/null
+++ b/dwm.suckless.org/patches/bidi/dwm-bidi-20220219-302953a.diff
_AT_@ -0,0 +1,144 @@
+From 302953ae637ffa4d106ca9b6567c2b5fc082f2b5 Mon Sep 17 00:00:00 2001
+From: mahdymirzade <me_AT_mahdym.ir>
+Date: Sat, 19 Feb 2022 07:37:39 +0330
+Subject: [PATCH] Added support for RTL languages (Farsi, Arabic and Hebrew
+ using the FriBiDi library)
+
+---
+ config.mk | 8 ++++++--
+ dwm.c | 45 ++++++++++++++++++++++++++++++++++++---------
+ 2 files changed, 42 insertions(+), 11 deletions(-)
+
+diff --git a/config.mk b/config.mk
+index b6eb7e0..5b60a24 100644
+--- a/config.mk
++++ b/config.mk
+_AT_@ -10,6 +10,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
+_AT_@ -20,9 +22,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}
++INCS = -I${X11INC} -I${FREETYPEINC} -I$(BDINC)
++LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} $(BDLIBS)
+
+ # flags
+ CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+diff --git a/dwm.c b/dwm.c
+index a96f33c..2e7b8eb 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -40,6 +40,7 @@
+ #include <X11/extensions/Xinerama.h>
+ #endif /* XINERAMA */
+ #include <X11/Xft/Xft.h>
++#include <fribidi.h>
+
+ #include "drw.h"
+ #include "util.h"
+_AT_@ -238,6 +239,7 @@ static void zoom(const Arg *arg);
+ /* variables */
+ static const char broken[] = "broken";
+ static char stext[256];
++static char fribidi_text[BUFSIZ] = "";
+ static int screen;
+ static int sw, sh; /* X display screen geometry width, height */
+ static int bh, blw = 0; /* bar geometry */
+_AT_@ -276,6 +278,26 @@ static Window root, wmcheckwin;
+ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+
+ /* function implementations */
++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);
++ }
++}
++
+ void
+ applyrules(Client *c)
+ {
+_AT_@ -708,8 +730,9 @@ drawbar(Monitor *m)
+ /* draw status first so it can be overdrawn by tags later */
+ if (m == selmon) { /* status is only drawn on selected monitor */
+ drw_setscheme(drw, scheme[SchemeNorm]);
+- tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
++ apply_fribidi(stext);
++ tw = TEXTW(fribidi_text) - lrpad + 2; /* 2px right padding */
++ drw_text(drw, m->ww - tw, 0, tw, bh, 0, fribidi_text, 0);
+ }
+
+ for (c = m->clients; c; c = c->next) {
+_AT_@ -719,23 +742,26 @@ drawbar(Monitor *m)
+ }
+ x = 0;
+ for (i = 0; i < LENGTH(tags); i++) {
+- w = TEXTW(tags[i]);
++ apply_fribidi(tags[i]);
++ w = TEXTW(fribidi_text);
+ drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
+- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
++ drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, urg & 1 << i);
+ if (occ & 1 << i)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw,
+ m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
+ urg & 1 << i);
+ x += w;
+ }
+- w = blw = TEXTW(m->ltsymbol);
++ apply_fribidi(m->ltsymbol);
++ w = blw = TEXTW(fribidi_text);
+ drw_setscheme(drw, scheme[SchemeNorm]);
+- x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
++ x = drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0);
+
+ if ((w = m->ww - tw - x) > bh) {
+ if (m->sel) {
+ drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
++ apply_fribidi(m->sel->name);
++ drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0);
+ if (m->sel->isfloating)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
+ } else {
+_AT_@ -1993,8 +2019,9 @@ updatesizehints(Client *c)
+ void
+ updatestatus(void)
+ {
+- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+- strcpy(stext, "dwm-"VERSION);
++ apply_fribidi(stext);
++ if (!gettextprop(root, XA_WM_NAME, fribidi_text, sizeof(fribidi_text)))
++ strcpy(fribidi_text, "dwm-"VERSION);
+ drawbar(selmon);
+ }
+
+--
+2.35.1
+
diff --git a/dwm.suckless.org/patches/bidi/dwm-bidi-fix.png b/dwm.suckless.org/patches/bidi/dwm-bidi-fix.png
new file mode 100644
index 00000000..ca15ec33
Binary files /dev/null and b/dwm.suckless.org/patches/bidi/dwm-bidi-fix.png differ
diff --git a/dwm.suckless.org/patches/bidi/dwm-bidi-without-fix.png b/dwm.suckless.org/patches/bidi/dwm-bidi-without-fix.png
new file mode 100644
index 00000000..d20533da
Binary files /dev/null and b/dwm.suckless.org/patches/bidi/dwm-bidi-without-fix.png differ
diff --git a/dwm.suckless.org/patches/bidi/index.md b/dwm.suckless.org/patches/bidi/index.md
new file mode 100644
index 00000000..e77d450e
--- /dev/null
+++ b/dwm.suckless.org/patches/bidi/index.md
_AT_@ -0,0 +1,24 @@
+Bidirectional Text
+==================
+
+Description
+-----------
+This patch adds proper support for Right-To-Left languages. (such as Farsi, Arabic or Hebrew)
+
+Texts combining both RTL and LTR languages are displayed correctly. This is achieved using the GNU FriBiDi library, which is an additional dependency for this patch.
+
+without dwm-bidi:
+
+![dwm with no bidi](dwm-bidi-without-fix.png)
+
+with dwm-bidi:
+
+![dwm with bidi](dwm-bidi-fix.png)
+
+Download
+--------
+* [dwm-bidi-20220219-302953a.diff](dwm-bidi-20220219-302953a.diff)
+
+Authors
+-------
+* Mahdi Mirzade - <http://mahdi.pw>
Received on Sat Feb 19 2022 - 13:17:04 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 19 2022 - 13:24:50 CET