dwm-xinerama-monitors-xorder-6.4.diff (1047B)
1 --- a/dwm.c 2025-07-14 22:37:49.738597862 +0800 2 +++ b/dwm.c 2025-07-14 22:37:08.706035689 +0800 3 @@ -1864,6 +1864,16 @@ updateclientlist() 4 (unsigned char *) &(c->win), 1); 5 } 6 7 +#ifdef XINERAMA 8 +// Custom comparator: sort monitors by x_org to match physical layout left-to-right 9 +static int 10 +compare_xinerama_x(const void *a, const void *b) { 11 + const XineramaScreenInfo *sa = (const XineramaScreenInfo *)a; 12 + const XineramaScreenInfo *sb = (const XineramaScreenInfo *)b; 13 + return sa->x_org - sb->x_org; 14 +} 15 +#endif /* XINERAMA */ 16 + 17 int 18 updategeom(void) 19 { 20 @@ -1880,6 +1890,8 @@ updategeom(void) 21 for (n = 0, m = mons; m; m = m->next, n++); 22 /* only consider unique geometries as separate screens */ 23 unique = ecalloc(nn, sizeof(XineramaScreenInfo)); 24 + // Sort monitors by x_org so dwm handles screens in left-to-right order 25 + qsort(info, nn, sizeof(XineramaScreenInfo), compare_xinerama_x); 26 for (i = 0, j = 0; i < nn; i++) 27 if (isuniquegeom(unique, j, &info[i])) 28 memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));