diff --git a/README.md b/README.md index 5214a71..e88a305 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2019-10-07 - Added sortscreens patch + 2019-10-06 - Added statuscolors and statusallmons patches, fixed minor cross-compatibility issues for killunsel, fullscreen, noborder, tagintostack patches 2019-10-05 - Added killunsel, taggrid, hidevacanttags and cmdcustomize patches @@ -192,6 +194,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - [setborderpx](https://dwm.suckless.org/patches/statuspadding/) - this patch allows border pixels to be changed during runtime + - [sortscreens](https://www.mail-archive.com/hackers@suckless.org/msg09400.html) + - this patch aims to address some inconsistencies when it comes to focusmon, tagmon and similar functionality by explicitly sorting screens left to right (or top to bottom in a vertical layout) + - [statusallmons](https://dwm.suckless.org/patches/statuspadding/) - this patch draws and updates the statusbar on all monitors diff --git a/dwm.c b/dwm.c index aec0c2c..ce47e2f 100644 --- a/dwm.c +++ b/dwm.c @@ -3104,6 +3104,9 @@ updategeom(void) memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); XFree(info); nn = j; + #if SORTSCREENS_PATCH + sortscreens(unique, nn); + #endif // SORTSCREENS_PATCH if (n <= nn) { /* new monitors available */ for (i = 0; i < (nn - n); i++) { for (m = mons; m && m->next; m = m->next); diff --git a/patch/include.c b/patch/include.c index 8f4a0d0..1bc7fcb 100644 --- a/patch/include.c +++ b/patch/include.c @@ -94,6 +94,12 @@ #include "setborderpx.c" #endif +#ifdef XINERAMA +#if SORTSCREENS_PATCH +#include "sortscreens.c" +#endif +#endif + #if STICKY_PATCH #include "sticky.c" #endif diff --git a/patch/include.h b/patch/include.h index 237b725..35c6423 100644 --- a/patch/include.h +++ b/patch/include.h @@ -94,6 +94,12 @@ #include "setborderpx.h" #endif +#ifdef XINERAMA +#if SORTSCREENS_PATCH +#include "sortscreens.h" +#endif +#endif + #if STICKY_PATCH #include "sticky.h" #endif diff --git a/patch/sortscreens.c b/patch/sortscreens.c new file mode 100644 index 0000000..6250848 --- /dev/null +++ b/patch/sortscreens.c @@ -0,0 +1,15 @@ +void +sortscreens(XineramaScreenInfo *screens, int n) +{ + int i, j; + XineramaScreenInfo *screen = ecalloc(1, sizeof(XineramaScreenInfo)); + + for (i = 0; i < n; i++) + for (j = i + 1; j < n; j++) + if (RIGHTOF(screens[i], screens[j])) { + memcpy(&screen[0], &screens[i], sizeof(XineramaScreenInfo)); + memcpy(&screens[i], &screens[j], sizeof(XineramaScreenInfo)); + memcpy(&screens[j], &screen[0], sizeof(XineramaScreenInfo)); + } + XFree(screen); +} \ No newline at end of file diff --git a/patch/sortscreens.h b/patch/sortscreens.h new file mode 100644 index 0000000..d829cdf --- /dev/null +++ b/patch/sortscreens.h @@ -0,0 +1,3 @@ +#define RIGHTOF(a,b) (a.y_org > b.y_org) || ((a.y_org == b.y_org) && (a.x_org > b.x_org)) + +static void sortscreens(XineramaScreenInfo *screens, int n); \ No newline at end of file diff --git a/patches.h b/patches.h index 712a771..1b18ad0 100644 --- a/patches.h +++ b/patches.h @@ -298,6 +298,14 @@ */ #define SETBORDERPX_PATCH 0 +/* In a multi-head setup monitor 0 is by default the primary screen, with the left and right + * screen being monitor 1 and 2 respectively. This patch sorts screens left to right (or + * top to bottom in a vertical layout) which aims to address some inconsistencies when it + * comes to focusmon, tagmon and similar functionality. + * https://www.mail-archive.com/hackers@suckless.org/msg09400.html + */ +#define SORTSCREENS_PATCH 0 + /* This patch draws and updates the statusbar on all monitors. * https://dwm.suckless.org/patches/statusallmons/ */