diff --git a/README.md b/README.md index 6b9c7dc..9b22a7e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This dwm 6.3 (9bffa84, 2022-07-14) side project has a different take on dwm patching. It uses preprocessor directives to decide 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 select which patches to include and the build will contain that code and nothing more. Due to the complexity of some of the patches dwm-flexipatch has diverged from mainstream dwm by making some core patches non-optional for maintenance reasons. For the classic dwm-flexipatch build refer to branch [dwm-flexipatch-1.0](https://github.com/bakkeby/dwm-flexipatch/tree/dwm-flexipatch-1.0). +This dwm 6.3 (5e76e7e, 2022-08-06) side project has a different take on dwm patching. It uses preprocessor directives to decide 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 select which patches to include and the build will contain that code and nothing more. Due to the complexity of some of the patches dwm-flexipatch has diverged from mainstream dwm by making some core patches non-optional for maintenance reasons. For the classic dwm-flexipatch build refer to branch [dwm-flexipatch-1.0](https://github.com/bakkeby/dwm-flexipatch/tree/dwm-flexipatch-1.0). For example to include the `alpha` patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/dwm-flexipatch/blob/master/patches.def.h): ```c @@ -19,6 +19,7 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 ### Changelog: +2022-08-02 - Added the bidi patch 2022-07-05 - Added the tagpreview patch @@ -287,6 +288,9 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 - [bartabgroups](https://dwm.suckless.org/patches/bartabgroups/) - turns the titlebar area into a mfact-respecting tab-bar showing each client's title + - [bidi](https://dwm.suckless.org/patches/bidi/) + - adds proper support for Right-To-Left (RTL) languages (such as Farsi, Arabic or Hebrew) + - [center](https://dwm.suckless.org/patches/center/) - adds an iscentered rule to automatically center clients on the current monitor diff --git a/README.org b/README.org index 4f73a9c..0de85f1 100644 --- a/README.org +++ b/README.org @@ -68,6 +68,7 @@ - [[#attach-bottom][Attach Bottom]] - [[#auto-start][Auto Start]] - [[#auto-resize][Auto Resize]] + - [[#bidi-right-to-left-languages][Bidi (Right to Left Languages)]] - [[#center][Center]] - [[#center-transient][Center Transient]] - [[#cfacts][CFacts]] @@ -276,7 +277,7 @@ exec dwm * dwm flexipatch -This dwm 6.3 (9bffa84, 2022-07-14) side project has a different take on dwm patching. It uses preprocessor directives to decide 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 select which patches to include and the build will contain that code and nothing more. Due to the complexity of some of the patches dwm-flexipatch has diverged from mainstream dwm by making some core patches non-optional for maintenance reasons. For the classic dwm-flexipatch build refer to branch [[https://github.com/bakkeby/dwm-flexipatch/tree/dwm-flexipatch-1.0][dwm-flexipatch-1.0]]. +This dwm 6.3 (5e76e7e, 2022-08-06) side project has a different take on dwm patching. It uses preprocessor directives to decide 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 select which patches to include and the build will contain that code and nothing more. Due to the complexity of some of the patches dwm-flexipatch has diverged from mainstream dwm by making some core patches non-optional for maintenance reasons. For the classic dwm-flexipatch build refer to branch [[https://github.com/bakkeby/dwm-flexipatch/tree/dwm-flexipatch-1.0][dwm-flexipatch-1.0]]. For example to include the ~alpha~ patch then you would only need to flip this setting from 0 to 1 in [[https://github.com/bakkeby/dwm-flexipatch/blob/master/patches.def.h][patches.h]]: @@ -296,6 +297,8 @@ Browsing patches? There is a [[https://coggle.it/diagram/X9IiSSM6PTWOM9Wz][map o ** Changelog +2022-08-02 - Added the bidi patch + 2022-07-05 - Added the tagpreview patch 2022-07-04 - Added the shift-tools patch(es) with individual toggles @@ -557,6 +560,9 @@ Browsing patches? There is a [[https://coggle.it/diagram/X9IiSSM6PTWOM9Wz][map o - [[https://dwm.suckless.org/patches/bartabgroups/][bartabgroups]] - turns the titlebar area into a mfact-respecting tab-bar showing each client's title + - [[https://dwm.suckless.org/patches/bidi/][bidi]] + - adds proper support for Right-To-Left (RTL) languages (such as Farsi, Arabic or Hebrew) + - [[https://dwm.suckless.org/patches/center/][center]] - adds an iscentered rule to automatically center clients on the current monitor @@ -1801,6 +1807,21 @@ https://dwm.suckless.org/patches/autoresize/ #define AUTORESIZE_PATCH 1 #+END_SRC +*** Bidi (Right to Left Languages) + +This patch adds proper support for Right-To-Left languages. (such as Farsi, Arabic or Hebrew). + +You need to uncomment the corresponding lines in =config.mk= to use the =-lfribidi= library when including this patch. + +This patch depends on the following additional library: + - fribidi + +https://dwm.suckless.org/patches/bidi/ + +#+BEGIN_SRC c :tangle patches.def.h +#define BIDI_PATCH 0 +#+END_SRC + *** Center This patch adds an iscentered rule to automatically center clients on the current monitor. @@ -3334,10 +3355,13 @@ XCBLIBS = -lX11-xcb -lxcb -lxcb-res # This is needed for the winicon and tagpreview patches / BAR_WINICON_PATCH / BAR_TAGPREVIEW_PATCH #IMLIB2LIBS = -lImlib2 -# includes and libs -INCS = -I${X11INC} -I${FREETYPEINC} ${YAJLINC} ${PANGOINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ${XRENDER} ${MPDCLIENT} ${XEXTLIB} ${XCBLIBS} ${KVMLIB} ${PANGOLIB} ${YAJLLIBS} ${IMLIB2LIBS} +# Uncomment for the bidi patch +#BDINC = -I/usr/include/fribidi +#BDLIBS = -lfribidi +# includes and libs +INCS = -I${X11INC} -I${FREETYPEINC} ${YAJLINC} ${PANGOINC} ${BDINC} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ${XRENDER} ${MPDCLIENT} ${XEXTLIB} ${XCBLIBS} ${KVMLIB} ${PANGOLIB} ${YAJLLIBS} ${IMLIB2LIBS} $(BDLIBS) # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} @@ -5143,6 +5167,9 @@ static Signal signals[] = { #if STACKER_PATCH { "pushstack", pushstack }, #endif // STACKER_PATCH + #if FLOATPOS_PATCH + { "floatpos", floatpos }, + #endif // FLOATPOS_PATCH #if FOCUSURGENT_PATCH { "focusurgent", focusurgent }, #endif // FOCUSURGENT_PATCH diff --git a/config.def.h b/config.def.h index ec937f8..fb3da42 100644 --- a/config.def.h +++ b/config.def.h @@ -1466,6 +1466,9 @@ static Signal signals[] = { #if STACKER_PATCH { "pushstack", pushstack }, #endif // STACKER_PATCH + #if FLOATPOS_PATCH + { "floatpos", floatpos }, + #endif // FLOATPOS_PATCH #if FOCUSURGENT_PATCH { "focusurgent", focusurgent }, #endif // FOCUSURGENT_PATCH diff --git a/config.mk b/config.mk index a535ca7..617fe27 100644 --- a/config.mk +++ b/config.mk @@ -51,10 +51,13 @@ XCBLIBS = -lX11-xcb -lxcb -lxcb-res # This is needed for the winicon and tagpreview patches / BAR_WINICON_PATCH / BAR_TAGPREVIEW_PATCH #IMLIB2LIBS = -lImlib2 -# includes and libs -INCS = -I${X11INC} -I${FREETYPEINC} ${YAJLINC} ${PANGOINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ${XRENDER} ${MPDCLIENT} ${XEXTLIB} ${XCBLIBS} ${KVMLIB} ${PANGOLIB} ${YAJLLIBS} ${IMLIB2LIBS} +# Uncomment for the bidi patch +#BDINC = -I/usr/include/fribidi +#BDLIBS = -lfribidi +# includes and libs +INCS = -I${X11INC} -I${FREETYPEINC} ${YAJLINC} ${PANGOINC} ${BDINC} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ${XRENDER} ${MPDCLIENT} ${XEXTLIB} ${XCBLIBS} ${KVMLIB} ${PANGOLIB} ${YAJLLIBS} ${IMLIB2LIBS} $(BDLIBS) # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} diff --git a/drw.c b/drw.c index 1e53132..68dd015 100644 --- a/drw.c +++ b/drw.c @@ -9,6 +9,30 @@ #include "drw.h" #include "util.h" +#if BIDI_PATCH +#include + +static char fribidi_text[BUFSIZ] = ""; + +static void +apply_fribidi(const char *str) +{ + FriBidiStrIndex len = strlen(str); + FriBidiChar logical[BUFSIZ]; + FriBidiChar visual[BUFSIZ]; + FriBidiParType base = FRIBIDI_PAR_ON; + FriBidiCharSet charset; + + fribidi_text[0] = 0; + if (len > 0) { + charset = fribidi_parse_charset("UTF-8"); + len = fribidi_charset_to_unicode(charset, str, len, logical); + fribidi_log2vis(logical, len, &base, visual, NULL, NULL, NULL); + len = fribidi_unicode_to_charset(charset, visual, len, fribidi_text); + } +} +#endif + #if !BAR_PANGO_PATCH #define UTF_INVALID 0xFFFD #define UTF_SIZ 4 @@ -394,10 +418,15 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); } -#if BAR_PANGO_PATCH +#if BIDI_PATCH +int +_drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup) +#else int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup) +#endif // BIDI_PATCH { +#if BAR_PANGO_PATCH char buf[1024]; int ty; unsigned int ew; @@ -458,11 +487,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp XftDrawDestroy(d); return x + (render ? w : 0); -} #else -int -drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool ignored) -{ char buf[1024]; int ty; unsigned int ew; @@ -593,8 +618,17 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp XftDrawDestroy(d); return x + (render ? w : 0); -} #endif // BAR_PANGO_PATCH +} + +#if BIDI_PATCH +int +drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup) +{ + apply_fribidi(text); + return _drw_text(drw, x, y, w, h, lpad, fribidi_text, invert, markup); +} +#endif // BIDI_PATCH #if BAR_POWERLINE_TAGS_PATCH || BAR_POWERLINE_STATUS_PATCH void diff --git a/dwm.c b/dwm.c index 67ced01..9a73159 100644 --- a/dwm.c +++ b/dwm.c @@ -2222,13 +2222,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) text[0] = '\0'; if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems) return 0; - if (name.encoding == XA_STRING) + if (name.encoding == XA_STRING) { strncpy(text, (char *)name.value, size - 1); - else { - if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { - strncpy(text, *list, size - 1); - XFreeStringList(list); - } + } else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { + strncpy(text, *list, size - 1); + XFreeStringList(list); } text[size - 1] = '\0'; XFree(name.value); @@ -2625,9 +2623,7 @@ maprequest(XEvent *e) } #endif // BAR_SYSTRAY_PATCH - if (!XGetWindowAttributes(dpy, ev->window, &wa)) - return; - if (wa.override_redirect) + if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect) return; #if BAR_ANYBAR_PATCH if (wmclasscontains(ev->window, altbarclass, "")) @@ -3990,9 +3986,7 @@ spawn(const Arg *arg) #endif // SPAWNCMD_PATCH setsid(); execvp(((char **)arg->v)[0], (char **)arg->v); - fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); - perror(" failed"); - exit(EXIT_SUCCESS); + die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]); } #if RIODRAW_PATCH return pid; @@ -4963,12 +4957,7 @@ zoom(const Arg *arg) c->mon->pertag->prevclient[c->mon->pertag->curtag] = nexttiled(c->mon->clients); #endif // SWAPFOCUS_PATCH - if (!c->mon->lt[c->mon->sellt]->arrange - || (c && c->isfloating) - #if ZOOMSWAP_PATCH - || !c - #endif // ZOOMSWAP_PATCH - ) + if (!c->mon->lt[c->mon->sellt]->arrange || !c || c->isfloating) return; #if ZOOMSWAP_PATCH @@ -5021,14 +5010,13 @@ zoom(const Arg *arg) } focus(c); arrange(c->mon); + #elif SWAPFOCUS_PATCH && PERTAG_PATCH + if (c == nexttiled(c->mon->clients) && !(c = c->mon->pertag->prevclient[c->mon->pertag->curtag] = nexttiled(c->next))) + return; + pop(c); #else - if (c == nexttiled(c->mon->clients)) - #if SWAPFOCUS_PATCH && PERTAG_PATCH - if (!c || !(c = c->mon->pertag->prevclient[c->mon->pertag->curtag] = nexttiled(c->next))) - #else - if (!c || !(c = nexttiled(c->next))) - #endif // SWAPFOCUS_PATCH - return; + if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) + return; pop(c); #endif // ZOOMSWAP_PATCH } diff --git a/patch/autostart.c b/patch/autostart.c index 03477bb..6053f1f 100644 --- a/patch/autostart.c +++ b/patch/autostart.c @@ -5,18 +5,19 @@ runautostart(void) char *path; char *xdgdatahome; char *home; + struct stat sb; if ((home = getenv("HOME")) == NULL) /* this is almost impossible */ return; - /* if $XDG_DATA_HOME is defined, use $XDG_DATA_HOME/dwm, + /* if $XDG_DATA_HOME is set and not empty, use $XDG_DATA_HOME/dwm, * otherwise use ~/.local/share/dwm as autostart script directory */ - if ((xdgdatahome = getenv("XDG_DATA_HOME")) != NULL) { + xdgdatahome = getenv("XDG_DATA_HOME"); + if (xdgdatahome != NULL && *xdgdatahome != '\0') { /* space for path segments, separators and nul */ - if ((pathpfx = malloc(strlen(xdgdatahome) + strlen(dwmdir) + 2)) == NULL) - return; + pathpfx = ecalloc(1, strlen(xdgdatahome) + strlen(dwmdir) + 2); if (sprintf(pathpfx, "%s/%s", xdgdatahome, dwmdir) <= 0) { free(pathpfx); @@ -24,8 +25,8 @@ runautostart(void) } } else { /* space for path segments, separators and nul */ - if ((pathpfx = malloc(strlen(home) + strlen(localshare) + strlen(dwmdir) + 3)) == NULL) - return; + pathpfx = ecalloc(1, strlen(home) + strlen(localshare) + + strlen(dwmdir) + 3); if (sprintf(pathpfx, "%s/%s/%s", home, localshare, dwmdir) < 0) { free(pathpfx); @@ -34,16 +35,16 @@ runautostart(void) } /* check if the autostart script directory exists */ - struct stat sb; - if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) { - /* the XDG conformant path does not exist or are not directories + /* the XDG conformant path does not exist or is no directory * so we try ~/.dwm instead */ - if (realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3) == NULL) { + char *pathpfx_new = realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3); + if(pathpfx_new == NULL) { free(pathpfx); return; } + pathpfx = pathpfx_new; if (sprintf(pathpfx, "%s/.%s", home, dwmdir) <= 0) { free(pathpfx); @@ -52,33 +53,24 @@ runautostart(void) } /* try the blocking script first */ - if ((path = malloc(strlen(pathpfx) + strlen(autostartblocksh) + 2)) == NULL) { + path = ecalloc(1, strlen(pathpfx) + strlen(autostartblocksh) + 2); + if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) { + free(path); free(pathpfx); - return; - } else - if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) { - free(path); - free(pathpfx); - } + } if (access(path, X_OK) == 0) system(path); /* now the non-blocking script */ - if ((path = realloc(path, strlen(pathpfx) + strlen(autostartsh) + 4)) == NULL) { - free(pathpfx); + if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) { free(path); - return; - } else - if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) { - free(path); - free(pathpfx); - } - - if (access(path, X_OK) == 0) { - system(strcat(path, " &")); free(pathpfx); - free(path); } -} + if (access(path, X_OK) == 0) + system(strcat(path, " &")); + + free(pathpfx); + free(path); +} diff --git a/patch/dwmc b/patch/dwmc index 3880428..9536367 100755 --- a/patch/dwmc +++ b/patch/dwmc @@ -100,6 +100,9 @@ case $# in setmfact) signal $1 f $2 ;; + floatpos) + signal $1 v $2 + ;; *) echo "Unknown command ($1) or too many arguments" exit 1 diff --git a/patch/dwmc.c b/patch/dwmc.c index 374944c..17f226f 100644 --- a/patch/dwmc.c +++ b/patch/dwmc.c @@ -83,6 +83,8 @@ fake_signal(void) #endif // IPC_PATCH else if (strncmp(param, "f", n - len_str_sig) == 0) sscanf(fsignal + len_indicator + n, "%f", &(arg.f)); + else if (strncmp(param, "v", n - len_str_sig) == 0) + arg.v = &(fsignal[len_indicator + n + 1]); else return 1; // Check if a signal was found, and if so handle it diff --git a/patches.def.h b/patches.def.h index dcc7a8c..53e0dd7 100644 --- a/patches.def.h +++ b/patches.def.h @@ -121,6 +121,8 @@ #define AUTORESIZE_PATCH 1 +#define BIDI_PATCH 0 + #define CENTER_PATCH 0 #define CENTER_TRANSIENT_WINDOWS_PATCH 0