Introduction
Introduction Statistics Contact Development Disclaimer Help
dwm-bidi-20220219-302953a.diff - sites - public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log
Files
Refs
---
dwm-bidi-20220219-302953a.diff (4790B)
---
1 From 302953ae637ffa4d106ca9b6567c2b5fc082f2b5 Mon Sep 17 00:00:00 2001
2 From: MahdiMirzadeh <[email protected]>
3 Date: Sat, 19 Feb 2022 07:37:39 +0330
4 Subject: [PATCH] Added support for RTL languages (Farsi, Arabic and Hebr…
5 using the FriBiDi library)
6
7 ---
8 config.mk | 8 ++++++--
9 dwm.c | 45 ++++++++++++++++++++++++++++++++++++---------
10 2 files changed, 42 insertions(+), 11 deletions(-)
11
12 diff --git a/config.mk b/config.mk
13 index b6eb7e0..5b60a24 100644
14 --- a/config.mk
15 +++ b/config.mk
16 @@ -10,6 +10,8 @@ MANPREFIX = ${PREFIX}/share/man
17 X11INC = /usr/X11R6/include
18 X11LIB = /usr/X11R6/lib
19
20 +BDINC = /usr/include/fribidi
21 +
22 # Xinerama, comment if you don't want it
23 XINERAMALIBS = -lXinerama
24 XINERAMAFLAGS = -DXINERAMA
25 @@ -20,9 +22,11 @@ FREETYPEINC = /usr/include/freetype2
26 # OpenBSD (uncomment)
27 #FREETYPEINC = ${X11INC}/freetype2
28
29 +BDLIBS = -lfribidi
30 +
31 # includes and libs
32 -INCS = -I${X11INC} -I${FREETYPEINC}
33 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
34 +INCS = -I${X11INC} -I${FREETYPEINC} -I$(BDINC)
35 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} $(BDLIBS)
36
37 # flags
38 CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -D…
39 diff --git a/dwm.c b/dwm.c
40 index a96f33c..2e7b8eb 100644
41 --- a/dwm.c
42 +++ b/dwm.c
43 @@ -40,6 +40,7 @@
44 #include <X11/extensions/Xinerama.h>
45 #endif /* XINERAMA */
46 #include <X11/Xft/Xft.h>
47 +#include <fribidi.h>
48
49 #include "drw.h"
50 #include "util.h"
51 @@ -238,6 +239,7 @@ static void zoom(const Arg *arg);
52 /* variables */
53 static const char broken[] = "broken";
54 static char stext[256];
55 +static char fribidi_text[BUFSIZ] = "";
56 static int screen;
57 static int sw, sh; /* X display screen geometry width, height…
58 static int bh, blw = 0; /* bar geometry */
59 @@ -276,6 +278,26 @@ static Window root, wmcheckwin;
60 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
61
62 /* function implementations */
63 +static void
64 +apply_fribidi(char *str)
65 +{
66 + FriBidiStrIndex len = strlen(str);
67 + FriBidiChar logical[BUFSIZ];
68 + FriBidiChar visual[BUFSIZ];
69 + FriBidiParType base = FRIBIDI_PAR_ON;
70 + FriBidiCharSet charset;
71 + fribidi_boolean result;
72 +
73 + fribidi_text[0] = 0;
74 + if (len>0)
75 + {
76 + charset = fribidi_parse_charset("UTF-8");
77 + len = fribidi_charset_to_unicode(charset, str, len, log…
78 + result = fribidi_log2vis(logical, len, &base, visual, N…
79 + len = fribidi_unicode_to_charset(charset, visual, len, …
80 + }
81 +}
82 +
83 void
84 applyrules(Client *c)
85 {
86 @@ -708,8 +730,9 @@ drawbar(Monitor *m)
87 /* draw status first so it can be overdrawn by tags later */
88 if (m == selmon) { /* status is only drawn on selected monitor …
89 drw_setscheme(drw, scheme[SchemeNorm]);
90 - tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
91 - drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
92 + apply_fribidi(stext);
93 + tw = TEXTW(fribidi_text) - lrpad + 2; /* 2px right padd…
94 + drw_text(drw, m->ww - tw, 0, tw, bh, 0, fribidi_text, 0…
95 }
96
97 for (c = m->clients; c; c = c->next) {
98 @@ -719,23 +742,26 @@ drawbar(Monitor *m)
99 }
100 x = 0;
101 for (i = 0; i < LENGTH(tags); i++) {
102 - w = TEXTW(tags[i]);
103 + apply_fribidi(tags[i]);
104 + w = TEXTW(fribidi_text);
105 drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << …
106 - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 …
107 + drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, urg…
108 if (occ & 1 << i)
109 drw_rect(drw, x + boxs, boxs, boxw, boxw,
110 m == selmon && selmon->sel && selmon->s…
111 urg & 1 << i);
112 x += w;
113 }
114 - w = blw = TEXTW(m->ltsymbol);
115 + apply_fribidi(m->ltsymbol);
116 + w = blw = TEXTW(fribidi_text);
117 drw_setscheme(drw, scheme[SchemeNorm]);
118 - x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
119 + x = drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0);
120
121 if ((w = m->ww - tw - x) > bh) {
122 if (m->sel) {
123 drw_setscheme(drw, scheme[m == selmon ? SchemeS…
124 - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->n…
125 + apply_fribidi(m->sel->name);
126 + drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_t…
127 if (m->sel->isfloating)
128 drw_rect(drw, x + boxs, boxs, boxw, box…
129 } else {
130 @@ -1993,8 +2019,9 @@ updatesizehints(Client *c)
131 void
132 updatestatus(void)
133 {
134 - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
135 - strcpy(stext, "dwm-"VERSION);
136 + apply_fribidi(stext);
137 + if (!gettextprop(root, XA_WM_NAME, fribidi_text, sizeof(fribidi…
138 + strcpy(fribidi_text, "dwm-"VERSION);
139 drawbar(selmon);
140 }
141
142 --
143 2.35.1
144
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.