summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rw-r--r--dwm-single_tagset-6.2.diff517
-rw-r--r--dwm.c221
-rw-r--r--vanitygaps.c33
4 files changed, 702 insertions, 71 deletions
diff --git a/config.h b/config.h
index 90f6819..075f336 100644
--- a/config.h
+++ b/config.h
@@ -107,7 +107,7 @@ static const char *mic_down_cmd[] = { "pactl", "set-source-mute", "@DEFAULT_SOUR
static const Key keys[] = {
/* modifier key function argument */
- { MODKEY, XK_l, spawn, {.v = slock_cmd } },
+ { MODKEY, XK_w, spawn, {.v = slock_cmd } },
{ MODKEY, XK_u, spawn, {.v = trans_cmd } },
{ MODKEY, XK_d, spawn, {.v = dmenucmd } },
{ MODKEY, XK_p, spawn, {.v = passmenu_cmd } },
diff --git a/dwm-single_tagset-6.2.diff b/dwm-single_tagset-6.2.diff
new file mode 100644
index 0000000..272037f
--- /dev/null
+++ b/dwm-single_tagset-6.2.diff
@@ -0,0 +1,517 @@
+Author: Mohammad Zeinali <mzeinali@tutanota.com>
+URL: http://dwm.suckless.org/patches/single_tagset
+A new update for single_tagset which is compatible with dwm 6.2.
+
+diff --git a/dwm.c b/dwm.c
+index 4465af1..179328e 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -49,7 +49,7 @@
+ #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
+ #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
+ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
+-#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
++#define ISVISIBLE(C, M) ((C->tags & M->tagset[M->seltags]))
+ #define LENGTH(X) (sizeof X / sizeof X[0])
+ #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
+ #define WIDTH(X) ((X)->w + 2 * (X)->bw)
+@@ -82,6 +82,7 @@ typedef struct {
+ const Arg arg;
+ } Button;
+
++typedef struct Clientlist Clientlist;
+ typedef struct Monitor Monitor;
+ typedef struct Client Client;
+ struct Client {
+@@ -124,9 +125,8 @@ struct Monitor {
+ unsigned int tagset[2];
+ int showbar;
+ int topbar;
+- Client *clients;
++ Clientlist *cl;
+ Client *sel;
+- Client *stack;
+ Monitor *next;
+ Window barwin;
+ const Layout *lt[2];
+@@ -141,12 +141,18 @@ typedef struct {
+ Client *icons;
+ };
+
++struct Clientlist {
++ Client *clients;
++ Client *stack;
++};
++
+ /* function declarations */
+ static void applyrules(Client *c);
+ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
+ static void arrange(Monitor *m);
+ static void arrangemon(Monitor *m);
+ static void attach(Client *c);
++static void attachclients(Monitor *m);
+ static void attachstack(Client *c);
+ static void buttonpress(XEvent *e);
+ static void checkotherwm(void);
+@@ -183,7 +189,7 @@ static void maprequest(XEvent *e);
+ static void monocle(Monitor *m);
+ static void motionnotify(XEvent *e);
+ static void movemouse(const Arg *arg);
+-static Client *nexttiled(Client *c);
++static Client *nexttiled(Client *c, Monitor *m);
+ static void pop(Client *c);
+ static void propertynotify(XEvent *e);
+ static void quit(const Arg *arg);
+@@ -267,6 +273,7 @@ static Display *dpy;
+ static Drw *drw;
+ static Monitor *mons, *selmon;
+ static Window root, wmcheckwin;
++static Clientlist *cl;
+
+ static xcb_connection_t *xcon;
+
+@@ -299,7 +306,7 @@ applyrules(Client *c)
+ c->noswallow = r->noswallow;
+ c->isfloating = r->isfloating;
+ c->tags |= r->tags;
+- for (m = mons; m && m->num != r->monitor; m = m->next);
++ for (m = mons; m && (m->tagset[m->seltags] & c->tags) == 0; m = m->next);
+ if (m)
+ c->mon = m;
+ }
+@@ -381,9 +388,9 @@ void
+ arrange(Monitor *m)
+ {
+ if (m)
+- showhide(m->stack);
++ showhide(m->cl->stack);
+ else for (m = mons; m; m = m->next)
+- showhide(m->stack);
++ showhide(m->cl->stack);
+ if (m) {
+ arrangemon(m);
+ restack(m);
+@@ -402,15 +409,49 @@ arrangemon(Monitor *m)
+ void
+ attach(Client *c)
+ {
+- c->next = c->mon->clients;
+- c->mon->clients = c;
++ c->next = c->mon->cl->clients;
++ c->mon->cl->clients = c;
++}
++
++void
++attachclients(Monitor *m) {
++ /* attach clients to the specified monitor */
++ Monitor *tm;
++ Client *c;
++ unsigned int utags = 0;
++ Bool rmons = False;
++ if(!m)
++ return;
++
++ /* collect information about the tags in use */
++ for (tm = mons; tm; tm = tm->next)
++ if(tm != m)
++ utags |= tm->tagset[tm->seltags];
++
++ for (c = m->cl->clients; c; c = c->next)
++ if(ISVISIBLE(c, m)) {
++ /* if client is also visible on other tags that are displayed on
++ * other monitors, remove these tags */
++ if(c->tags & utags) {
++ c->tags = c->tags & m->tagset[m->seltags];
++ rmons = True;
++ }
++ unfocus(c, True);
++ c->mon = m;
++ }
++
++ if (rmons)
++ for (tm = mons; tm; tm = tm->next)
++ if(tm != m)
++ arrange(tm);
++
+ }
+
+ void
+ attachstack(Client *c)
+ {
+- c->snext = c->mon->stack;
+- c->mon->stack = c;
++ c->snext = c->mon->cl->stack;
++ c->mon->cl->stack = c;
+ }
+
+ void
+@@ -477,8 +518,8 @@ cleanup(void)
+ view(&a);
+ selmon->lt[selmon->sellt] = &foo;
+ for (m = mons; m; m = m->next)
+- while (m->stack)
+- unmanage(m->stack, 0);
++ while (m->cl->stack)
++ unmanage(m->cl->stack, 0);
+ XUngrabKey(dpy, AnyKey, AnyModifier, root);
+ while (mons)
+ cleanupmon(mons);
+@@ -564,7 +605,7 @@ configurenotify(XEvent *e)
+ drw_resize(drw, sw, bh);
+ updatebars();
+ for (m = mons; m; m = m->next) {
+- for (c = m->clients; c; c = c->next)
++ for (c = m->cl->clients; c; c = c->next)
+ if (c->isfullscreen)
+ resizeclient(c, m->mx, m->my, m->mw, m->mh);
+ resizebarwin(m);
+@@ -610,7 +651,7 @@ configurerequest(XEvent *e)
+ c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */
+ if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
+ configure(c);
+- if (ISVISIBLE(c))
++ if (ISVISIBLE(c, m))
+ XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+ } else
+ configure(c);
+@@ -630,10 +671,31 @@ configurerequest(XEvent *e)
+ Monitor *
+ createmon(void)
+ {
+- Monitor *m;
++ Monitor *m, *tm;
++ int i;
+
++ /* bail out if the number of monitors exceeds the number of tags */
++ for (i=1, tm=mons; tm; i++, tm=tm->next);
++ if (i > LENGTH(tags)) {
++ fprintf(stderr, "dwm: failed to add monitor, number of tags exceeded\n");
++ return NULL;
++ }
++ /* find the first tag that isn't in use */
++ for (i=0; i < LENGTH(tags); i++) {
++ for (tm=mons; tm && !(tm->tagset[tm->seltags] & (1<<i)); tm=tm->next);
++ if (!tm)
++ break;
++ }
++ /* reassign all tags to monitors since there's currently no free tag for the
++ * new monitor */
++ if (i >= LENGTH(tags))
++ for (i=0, tm=mons; tm; tm=tm->next, i++) {
++ tm->seltags ^= 1;
++ tm->tagset[tm->seltags] = (1<<i) & TAGMASK;
++ }
+ m = ecalloc(1, sizeof(Monitor));
+- m->tagset[0] = m->tagset[1] = 1;
++ m->cl = cl;
++ m->tagset[0] = m->tagset[1] = (1<<i) & TAGMASK;
+ m->mfact = mfact;
+ m->nmaster = nmaster;
+ m->showbar = showbar;
+@@ -659,7 +721,7 @@ detach(Client *c)
+ {
+ Client **tc;
+
+- for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
++ for (tc = &c->mon->cl->clients; *tc && *tc != c; tc = &(*tc)->next);
+ *tc = c->next;
+ }
+
+@@ -668,11 +730,11 @@ detachstack(Client *c)
+ {
+ Client **tc, *t;
+
+- for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
++ for (tc = &c->mon->cl->stack; *tc && *tc != c; tc = &(*tc)->snext);
+ *tc = c->snext;
+
+ if (c == c->mon->sel) {
+- for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext);
++ for (t = c->mon->cl->stack; t && !ISVISIBLE(t, c->mon); t = t->snext);
+ c->mon->sel = t;
+ }
+ }
+@@ -708,7 +770,7 @@ drawbar(Monitor *m)
+ }
+
+ resizebarwin(m);
+- for (c = m->clients; c; c = c->next) {
++ for (c = m->cl->clients; c; c = c->next) {
+ occ |= c->tags;
+ if (c->isurgent)
+ urg |= c->tags;
+@@ -783,8 +845,8 @@ expose(XEvent *e)
+ void
+ focus(Client *c)
+ {
+- if (!c || !ISVISIBLE(c))
+- for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
++ if (!c || !ISVISIBLE(c, selmon))
++ for (c = selmon->cl->stack; c && !ISVISIBLE(c, selmon); c = c->snext);
+ if (selmon->sel && selmon->sel != c)
+ unfocus(selmon->sel, 0);
+ if (c) {
+@@ -837,16 +899,16 @@ focusstack(const Arg *arg)
+ if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
+ return;
+ if (arg->i > 0) {
+- for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
++ for (c = selmon->sel->next; c && !ISVISIBLE(c, selmon); c = c->next);
+ if (!c)
+- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
++ for (c = selmon->cl->clients; c && !ISVISIBLE(c, selmon); c = c->next);
+ } else {
+- for (i = selmon->clients; i != selmon->sel; i = i->next)
+- if (ISVISIBLE(i))
++ for (i = selmon->cl->clients; i != selmon->sel; i = i->next)
++ if (ISVISIBLE(i, selmon))
+ c = i;
+ if (!c)
+ for (; i; i = i->next)
+- if (ISVISIBLE(i))
++ if (ISVISIBLE(i, selmon))
+ c = i;
+ }
+ if (c) {
+@@ -1106,12 +1168,12 @@ monocle(Monitor *m)
+ unsigned int n = 0;
+ Client *c;
+
+- for (c = m->clients; c; c = c->next)
+- if (ISVISIBLE(c))
++ for (c = m->cl->clients; c; c = c->next)
++ if (ISVISIBLE(c, m))
+ n++;
+ if (n > 0) /* override layout symbol */
+ snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
+- for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
++ for (c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m))
+ resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
+ }
+
+@@ -1193,9 +1255,9 @@ movemouse(const Arg *arg)
+ }
+
+ Client *
+-nexttiled(Client *c)
++nexttiled(Client *c, Monitor *m)
+ {
+- for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
++ for (; c && (c->isfloating || !ISVISIBLE(c, m)); c = c->next);
+ return c;
+ }
+
+@@ -1359,8 +1421,8 @@ restack(Monitor *m)
+ if (m->lt[m->sellt]->arrange) {
+ wc.stack_mode = Below;
+ wc.sibling = m->barwin;
+- for (c = m->stack; c; c = c->snext)
+- if (!c->isfloating && ISVISIBLE(c)) {
++ for (c = m->cl->stack; c; c = c->snext)
++ if (!c->isfloating && ISVISIBLE(c, m)) {
+ XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
+ wc.sibling = c->win;
+ }
+@@ -1413,11 +1475,9 @@ sendmon(Client *c, Monitor *m)
+ if (c->mon == m)
+ return;
+ unfocus(c, 1);
+- detach(c);
+ detachstack(c);
+ c->mon = m;
+ c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
+- attach(c);
+ attachstack(c);
+ setclienttagprop(c);
+ focus(NULL);
+@@ -1540,6 +1600,8 @@ setup(void)
+ screen = DefaultScreen(dpy);
+ sw = DisplayWidth(dpy, screen);
+ sh = DisplayHeight(dpy, screen);
++ if(!(cl = (Clientlist *)calloc(1, sizeof(Clientlist))))
++ die("fatal: could not malloc() %u bytes\n", sizeof(Clientlist));
+ root = RootWindow(dpy, screen);
+ drw = drw_create(dpy, screen, root, sw, sh);
+ if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
+@@ -1615,7 +1677,7 @@ showhide(Client *c)
+ {
+ if (!c)
+ return;
+- if (ISVISIBLE(c)) {
++ if (ISVISIBLE(c, c->mon)) {
+ /* show clients top down */
+ XMoveWindow(dpy, c->win, c->x, c->y);
+ if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
+@@ -1655,7 +1717,23 @@ spawn(const Arg *arg)
+ void
+ tag(const Arg *arg)
+ {
+ Client *c;
+- if (selmon->sel && arg->ui & TAGMASK) {
++ Monitor *m;
++ unsigned int newtags;
++ if (selmon->sel && arg->ui & TAGMASK) {
++ newtags = arg->ui & TAGMASK;
++ for (m = mons; m; m = m->next)
++ /* if tag is visible on another monitor, move client to the new monitor */
++ if (m != selmon && m->tagset[m->seltags] & newtags) {
++ /* prevent moving client to all tags (MODKEY-Shift-0) when multiple monitors are connected */
++ if(newtags & selmon->tagset[selmon->seltags])
++ return;
++ selmon->sel->tags = newtags;
++ selmon->sel->mon = m;
++ arrange(m);
++ break;
++ }
++ /* workaround in case just one monitor is connected */
++
+ c = selmon->sel;
+ selmon->sel->tags = arg->ui & TAGMASK;
+@@ -1722,12 +1800,17 @@ togglefloating(const Arg *arg)
+ void
+ toggletag(const Arg *arg)
+ {
+- unsigned int newtags;
+-
+- if (!selmon->sel)
+- return;
+- newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
+- if (newtags) {
++ Monitor *m;
++ unsigned int newtags;
++
++ if (!selmon->sel)
++ return;
++ newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
++ if (newtags) {
++ /* prevent adding tags that are in use on other monitors */
++ for (m = mons; m; m = m->next)
++ if (m != selmon && newtags & m->tagset[m->seltags])
++ return;
+ selmon->sel->tags = newtags;
+ setclienttagprop(selmon->sel);
+ focus(NULL);
+@@ -1737,6 +1820,18 @@ toggletag(const Arg *arg)
+ void
+ toggleview(const Arg *arg)
+ {
++ Monitor *m;
++ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
++
++ if (newtagset) {
++ /* prevent displaying the same tags on multiple monitors */
++ for(m = mons; m; m = m->next)
++ if(m != selmon && newtagset & m->tagset[m->seltags])
++ return;
++ selmon->tagset[selmon->seltags] = newtagset;
++ focus(NULL);
++ attachclients(selmon);
++
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+
+ if (newtagset) {
+@@ -1744,6 +1839,7 @@ toggleview(const Arg *arg)
+ focus(NULL);
+ arrange(selmon);
+ }
++ }
+ }
+
+ void
+@@ -1841,7 +1937,7 @@ updateclientlist()
+
+ XDeleteProperty(dpy, root, netatom[NetClientList]);
+ for (m = mons; m; m = m->next)
+- for (c = m->clients; c; c = c->next)
++ for (c = m->cl->clients; c; c = c->next)
+ XChangeProperty(dpy, root, netatom[NetClientList],
+ XA_WINDOW, 32, PropModeAppend,
+ (unsigned char *) &(c->win), 1);
+@@ -1871,8 +1967,10 @@ updategeom(void)
+ /* new monitors if nn > n */
+ for (i = n; i < nn; i++) {
+ for (m = mons; m && m->next; m = m->next);
+- if (m)
++ if (m) {
+ m->next = createmon();
++ attachclients(m->next);
++ }
+ else
+ mons = createmon();
+ }
+@@ -1892,16 +1990,13 @@ updategeom(void)
+ /* removed monitors if n > nn */
+ for (i = nn; i < n; i++) {
+ for (m = mons; m && m->next; m = m->next);
+- while ((c = m->clients)) {
+- dirty = 1;
+- m->clients = c->next;
+- detachstack(c);
+- c->mon = mons;
+- attach(c);
+- attachstack(c);
+- }
+ if (m == selmon)
+ selmon = mons;
++ for (c = m->cl->clients; c; c = c->next) {
++ dirty = True;
++ if (c->mon == m)
++ c->mon = selmon;
++ }
+ cleanupmon(m);
+ }
+ free(unique);
+@@ -2035,13 +2130,31 @@ updatewmhints(Client *c)
+ void
+ view(const Arg *arg)
+ {
+- if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+- return;
++ Monitor *m;
++ unsigned int newtagset = selmon->tagset[selmon->seltags ^ 1];
++ if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
++ return;
++ /* swap tags when trying to display a tag from another monitor */
++ if (arg->ui & TAGMASK)
++ newtagset = arg->ui & TAGMASK;
++ for (m = mons; m; m = m->next)
++ if (m != selmon && newtagset & m->tagset[m->seltags]) {
++ /* prevent displaying all tags (MODKEY-0) when multiple monitors
++ * are connected */
++ if (newtagset & selmon->tagset[selmon->seltags])
++ return;
++ m->sel = selmon->sel;
++ m->seltags ^= 1;
++ m->tagset[m->seltags] = selmon->tagset[selmon->seltags];
++ attachclients(m);
++ arrange(m);
++ break;
++ }
+ selmon->seltags ^= 1; /* toggle sel tagset */
+ if (arg->ui & TAGMASK)
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ focus(NULL);
+- arrange(selmon);
++ attachclients(selmon);
+ }
+
+ pid_t
+@@ -2051,7 +2164,7 @@ wintoclient(Window w)
+ Monitor *m;
+
+ for (m = mons; m; m = m->next)
+- for (c = m->clients; c; c = c->next)
++ for (c = m->cl->clients; c; c = c->next)
+ if (c->win == w)
+ return c;
+ return NULL;
+@@ -2118,8 +2231,8 @@ zoom(const Arg *arg)
+
+ if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
+ return;
+- if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
++ if (c == nexttiled(selmon->clients, selmon) && !(c = nexttiled(c->next, selmon)))
+ return;
+ pop(c);
+ }
+
diff --git a/dwm.c b/dwm.c
index db52dce..c8f7233 100644
--- a/dwm.c
+++ b/dwm.c
@@ -55,7 +55,7 @@
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
-#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
+#define ISVISIBLE(C, M) ((C->tags & M->tagset[M->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
@@ -103,6 +103,7 @@ typedef struct {
const Arg arg;
} Button;
+typedef struct Clientlist Clientlist;
typedef struct Monitor Monitor;
typedef struct Client Client;
struct Client {
@@ -151,9 +152,8 @@ struct Monitor {
unsigned int tagset[2];
int showbar;
int topbar;
- Client *clients;
+ Clientlist *cl;
Client *sel;
- Client *stack;
Monitor *next;
Window barwin;
const Layout *lt[2];
@@ -176,12 +176,18 @@ struct Systray {
Client *icons;
};
+struct Clientlist {
+ Client *clients;
+ Client *stack;
+};
+
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
static void arrange(Monitor *m);
static void arrangemon(Monitor *m);
static void attach(Client *c);
+static void attachclients(Monitor *m);
static void attachstack(Client *c);
static void buttonpress(XEvent *e);
static void checkotherwm(void);
@@ -221,7 +227,7 @@ static void maprequest(XEvent *e);
static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
-static Client *nexttiled(Client *c);
+static Client *nexttiled(Client *c, Monitor *m);
static void pop(Client *c);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
@@ -325,6 +331,7 @@ static Display *dpy;
static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
+static Clientlist *cl;
static xcb_connection_t *xcon;
@@ -361,7 +368,7 @@ applyrules(Client *c)
c->noswallow = r->noswallow;
c->isfloating = r->isfloating;
c->tags |= r->tags;
- for (m = mons; m && m->num != r->monitor; m = m->next);
+ for (m = mons; m && (m->tagset[m->seltags] & c->tags) == 0; m = m->next);
if (m)
c->mon = m;
}
@@ -445,9 +452,9 @@ void
arrange(Monitor *m)
{
if (m)
- showhide(m->stack);
+ showhide(m->cl->stack);
else for (m = mons; m; m = m->next)
- showhide(m->stack);
+ showhide(m->cl->stack);
if (m) {
arrangemon(m);
restack(m);
@@ -466,15 +473,49 @@ arrangemon(Monitor *m)
void
attach(Client *c)
{
- c->next = c->mon->clients;
- c->mon->clients = c;
+ c->next = c->mon->cl->clients;
+ c->mon->cl->clients = c;
+}
+
+void
+attachclients(Monitor *m) {
+ /* attach clients to the specified monitor */
+ Monitor *tm;
+ Client *c;
+ unsigned int utags = 0;
+ Bool rmons = False;
+ if(!m)
+ return;
+
+ /* collect information about the tags in use */
+ for (tm = mons; tm; tm = tm->next)
+ if(tm != m)
+ utags |= tm->tagset[tm->seltags];
+
+ for (c = m->cl->clients; c; c = c->next)
+ if(ISVISIBLE(c, m)) {
+ /* if client is also visible on other tags that are displayed on
+ * other monitors, remove these tags */
+ if(c->tags & utags) {
+ c->tags = c->tags & m->tagset[m->seltags];
+ rmons = True;
+ }
+ unfocus(c, True);
+ c->mon = m;
+ }
+
+ if (rmons)
+ for (tm = mons; tm; tm = tm->next)
+ if(tm != m)
+ arrange(tm);
+
}
void
attachstack(Client *c)
{
- c->snext = c->mon->stack;
- c->mon->stack = c;
+ c->snext = c->mon->cl->stack;
+ c->mon->cl->stack = c;
}
void
@@ -604,8 +645,8 @@ cleanup(void)
view(&a);
selmon->lt[selmon->sellt] = &foo;
for (m = mons; m; m = m->next)
- while (m->stack)
- unmanage(m->stack, 0);
+ while (m->cl->stack)
+ unmanage(m->cl->stack, 0);
XUngrabKey(dpy, AnyKey, AnyModifier, root);
while (mons)
cleanupmon(mons);
@@ -748,7 +789,7 @@ configurenotify(XEvent *e)
drw_resize(drw, sw, bh);
updatebars();
for (m = mons; m; m = m->next) {
- for (c = m->clients; c; c = c->next)
+ for (c = m->cl->clients; c; c = c->next)
if (c->isfullscreen)
resizeclient(c, m->mx, m->my, m->mw, m->mh);
resizebarwin(m);
@@ -794,7 +835,7 @@ configurerequest(XEvent *e)
c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */
if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
configure(c);
- if (ISVISIBLE(c))
+ if (ISVISIBLE(c, m))
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
} else
configure(c);
@@ -814,10 +855,31 @@ configurerequest(XEvent *e)
Monitor *
createmon(void)
{
- Monitor *m;
+ Monitor *m, *tm;
+ int i;
+ /* bail out if the number of monitors exceeds the number of tags */
+ for (i=1, tm=mons; tm; i++, tm=tm->next);
+ if (i > LENGTH(tags)) {
+ fprintf(stderr, "dwm: failed to add monitor, number of tags exceeded\n");
+ return NULL;
+ }
+ /* find the first tag that isn't in use */
+ for (i=0; i < LENGTH(tags); i++) {
+ for (tm=mons; tm && !(tm->tagset[tm->seltags] & (1<<i)); tm=tm->next);
+ if (!tm)
+ break;
+ }
+ /* reassign all tags to monitors since there's currently no free tag for the
+ * new monitor */
+ if (i >= LENGTH(tags))
+ for (i=0, tm=mons; tm; tm=tm->next, i++) {
+ tm->seltags ^= 1;
+ tm->tagset[tm->seltags] = (1<<i) & TAGMASK;
+ }
m = ecalloc(1, sizeof(Monitor));
- m->tagset[0] = m->tagset[1] = 1;
+ m->cl = cl;
+ m->tagset[0] = m->tagset[1] = (1<<i) & TAGMASK;
m->mfact = mfact;
m->nmaster = nmaster;
m->showbar = showbar;
@@ -854,7 +916,7 @@ detach(Client *c)
{
Client **tc;
- for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
+ for (tc = &c->mon->cl->clients; *tc && *tc != c; tc = &(*tc)->next);
*tc = c->next;
}
@@ -863,11 +925,11 @@ detachstack(Client *c)
{
Client **tc, *t;
- for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
+ for (tc = &c->mon->cl->stack; *tc && *tc != c; tc = &(*tc)->snext);
*tc = c->snext;
if (c == c->mon->sel) {
- for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext);
+ for (t = c->mon->cl->stack; t && !ISVISIBLE(t, c->mon); t = t->snext);
c->mon->sel = t;
}
}
@@ -925,7 +987,7 @@ drawbar(Monitor *m)
}
resizebarwin(m);
- for (c = m->clients; c; c = c->next) {
+ for (c = m->cl->clients; c; c = c->next) {
occ |= c->tags;
if (c->isurgent)
urg |= c->tags;
@@ -1003,8 +1065,8 @@ expose(XEvent *e)
void
focus(Client *c)
{
- if (!c || !ISVISIBLE(c))
- for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
+ if (!c || !ISVISIBLE(c, selmon))
+ for (c = selmon->cl->stack; c && !ISVISIBLE(c, selmon); c = c->snext);
if (selmon->sel && selmon->sel != c)
unfocus(selmon->sel, 0);
if (c) {
@@ -1057,16 +1119,16 @@ focusstack(const Arg *arg)
if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
return;
if (arg->i > 0) {
- for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
+ for (c = selmon->sel->next; c && !ISVISIBLE(c, selmon); c = c->next);
if (!c)
- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
+ for (c = selmon->cl->clients; c && !ISVISIBLE(c, selmon); c = c->next);
} else {
- for (i = selmon->clients; i != selmon->sel; i = i->next)
- if (ISVISIBLE(i))
+ for (i = selmon->cl->clients; i != selmon->sel; i = i->next)
+ if (ISVISIBLE(i, selmon))
c = i;
if (!c)
for (; i; i = i->next)
- if (ISVISIBLE(i))
+ if (ISVISIBLE(i, selmon))
c = i;
}
if (c) {
@@ -1404,12 +1466,12 @@ monocle(Monitor *m)
unsigned int n = 0;
Client *c;
- for (c = m->clients; c; c = c->next)
- if (ISVISIBLE(c))
+ for (c = m->cl->clients; c; c = c->next)
+ if (ISVISIBLE(c, m))
n++;
if (n > 0) /* override layout symbol */
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
- for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
+ for (c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m))
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
}
@@ -1491,9 +1553,9 @@ movemouse(const Arg *arg)
}
Client *
-nexttiled(Client *c)
+nexttiled(Client *c, Monitor *m)
{
- for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
+ for (; c && (c->isfloating || !ISVISIBLE(c, m)); c = c->next);
return c;
}
@@ -1702,8 +1764,8 @@ restack(Monitor *m)
if (m->lt[m->sellt]->arrange) {
wc.stack_mode = Below;
wc.sibling = m->barwin;
- for (c = m->stack; c; c = c->snext)
- if (!c->isfloating && ISVISIBLE(c)) {
+ for (c = m->cl->stack; c; c = c->snext)
+ if (!c->isfloating && ISVISIBLE(c, m)) {
XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
wc.sibling = c->win;
}
@@ -1756,11 +1818,9 @@ sendmon(Client *c, Monitor *m)
if (c->mon == m)
return;
unfocus(c, 1);
- detach(c);
detachstack(c);
c->mon = m;
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
- attach(c);
attachstack(c);
setclienttagprop(c);
focus(NULL);
@@ -1902,6 +1962,8 @@ setup(void)
screen = DefaultScreen(dpy);
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
+ if(!(cl = (Clientlist *)calloc(1, sizeof(Clientlist))))
+ die("fatal: could not malloc() %u bytes\n", sizeof(Clientlist));
root = RootWindow(dpy, screen);
drw = drw_create(dpy, screen, root, sw, sh);
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
@@ -1987,7 +2049,7 @@ showhide(Client *c)
{
if (!c)
return;
- if (ISVISIBLE(c)) {
+ if (ISVISIBLE(c, c->mon)) {
/* show clients top down */
XMoveWindow(dpy, c->win, c->x, c->y);
if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
@@ -2048,7 +2110,23 @@ void
tag(const Arg *arg)
{
Client *c;
+ Monitor *m;
+ unsigned int newtags;
if (selmon->sel && arg->ui & TAGMASK) {
+ newtags = arg->ui & TAGMASK;
+ for (m = mons; m; m = m->next)
+ /* if tag is visible on another monitor, move client to the new monitor */
+ if (m != selmon && m->tagset[m->seltags] & newtags) {
+ /* prevent moving client to all tags (MODKEY-Shift-0) when multiple monitors are connected */
+ if(newtags & selmon->tagset[selmon->seltags])
+ return;
+ selmon->sel->tags = newtags;
+ selmon->sel->mon = m;
+ arrange(m);
+ break;
+ }
+ /* workaround in case just one monitor is connected */
+
c = selmon->sel;
selmon->sel->tags = arg->ui & TAGMASK;
setclienttagprop(c);
@@ -2109,12 +2187,17 @@ togglefullscr(const Arg *arg)
void
toggletag(const Arg *arg)
{
+ Monitor *m;
unsigned int newtags;
if (!selmon->sel)
return;
newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
if (newtags) {
+ /* prevent adding tags that are in use on other monitors */
+ for (m = mons; m; m = m->next)
+ if (m != selmon && newtags & m->tagset[m->seltags])
+ return;
selmon->sel->tags = newtags;
setclienttagprop(selmon->sel);
focus(NULL);
@@ -2125,12 +2208,25 @@ toggletag(const Arg *arg)
void
toggleview(const Arg *arg)
{
+ Monitor *m;
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
if (newtagset) {
+ /* prevent displaying the same tags on multiple monitors */
+ for(m = mons; m; m = m->next)
+ if(m != selmon && newtagset & m->tagset[m->seltags])
+ return;
selmon->tagset[selmon->seltags] = newtagset;
focus(NULL);
- arrange(selmon);
+ attachclients(selmon);
+
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+
+ if (newtagset) {
+ selmon->tagset[selmon->seltags] = newtagset;
+ focus(NULL);
+ arrange(selmon);
+ }
}
}
@@ -2259,7 +2355,7 @@ updateclientlist()
XDeleteProperty(dpy, root, netatom[NetClientList]);
for (m = mons; m; m = m->next)
- for (c = m->clients; c; c = c->next)
+ for (c = m->cl->clients; c; c = c->next)
XChangeProperty(dpy, root, netatom[NetClientList],
XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
@@ -2290,8 +2386,10 @@ updategeom(void)
/* new monitors if nn > n */
for (i = n; i < nn; i++) {
for (m = mons; m && m->next; m = m->next);
- if (m)
+ if (m) {
m->next = createmon();
+ attachclients(m->next);
+ }
else
mons = createmon();
}
@@ -2311,16 +2409,13 @@ updategeom(void)
/* removed monitors if n > nn */
for (i = nn; i < n; i++) {
for (m = mons; m && m->next; m = m->next);
- while ((c = m->clients)) {
- dirty = 1;
- m->clients = c->next;
- detachstack(c);
- c->mon = mons;
- attach(c);
- attachstack(c);
- }
if (m == selmon)
selmon = mons;
+ for (c = m->cl->clients; c; c = c->next) {
+ dirty = True;
+ if (c->mon == m)
+ c->mon = selmon;
+ }
cleanupmon(m);
}
free(unique);
@@ -2590,13 +2685,31 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
+ Monitor *m;
+ unsigned int newtagset = selmon->tagset[selmon->seltags ^ 1];
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
+ /* swap tags when trying to display a tag from another monitor */
+ if (arg->ui & TAGMASK)
+ newtagset = arg->ui & TAGMASK;
+ for (m = mons; m; m = m->next)
+ if (m != selmon && newtagset & m->tagset[m->seltags]) {
+ /* prevent displaying all tags (MODKEY-0) when multiple monitors
+ * are connected */
+ if (newtagset & selmon->tagset[selmon->seltags])
+ return;
+ m->sel = selmon->sel;
+ m->seltags ^= 1;
+ m->tagset[m->seltags] = selmon->tagset[selmon->seltags];
+ attachclients(m);
+ arrange(m);
+ break;
+ }
selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focus(NULL);
- arrange(selmon);
+ attachclients(selmon);
}
pid_t
@@ -2704,7 +2817,7 @@ termforwin(const Client *w)
return NULL;
for (m = mons; m; m = m->next) {
- for (c = m->clients; c; c = c->next) {
+ for (c = m->cl->clients; c; c = c->next) {
if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
return c;
}
@@ -2720,7 +2833,7 @@ swallowingclient(Window w)
Monitor *m;
for (m = mons; m; m = m->next) {
- for (c = m->clients; c; c = c->next) {
+ for (c = m->cl->clients; c; c = c->next) {
if (c->swallowing && c->swallowing->win == w)
return c;
}
@@ -2736,7 +2849,7 @@ wintoclient(Window w)
Monitor *m;
for (m = mons; m; m = m->next)
- for (c = m->clients; c; c = c->next)
+ for (c = m->cl->clients; c; c = c->next)
if (c->win == w)
return c;
return NULL;
@@ -2828,7 +2941,7 @@ zoom(const Arg *arg)
if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
return;
- if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
+ if (c == nexttiled(selmon->cl->clients, selmon) && !(c = nexttiled(c->next, selmon)))
return;
pop(c);
}
diff --git a/vanitygaps.c b/vanitygaps.c
index 4111d1e..e1e955b 100644
--- a/vanitygaps.c
+++ b/vanitygaps.c
@@ -150,7 +150,7 @@ getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
#endif // PERTAG_PATCH
Client *c;
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ for (n = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), n++);
if (smartgaps && n == 1) {
oe = 0; // outer gaps disabled when only one client
}
@@ -170,11 +170,11 @@ getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *s
int mtotal = 0, stotal = 0;
Client *c;
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ for (n = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), n++);
mfacts = MIN(n, m->nmaster);
sfacts = n - m->nmaster;
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
+ for (n = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), n++)
if (n < m->nmaster)
mtotal += msize / mfacts;
else
@@ -224,7 +224,7 @@ bstack(Monitor *m)
getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++) {
if (i < m->nmaster) {
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
mx += WIDTH(c) + iv;
@@ -266,7 +266,7 @@ bstackhoriz(Monitor *m)
getfacts(m, mw, sh, &mfacts, &sfacts, &mrest, &srest);
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++) {
if (i < m->nmaster) {
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
mx += WIDTH(c) + iv;
@@ -327,7 +327,7 @@ centeredmaster(Monitor *m)
}
/* calculate facts */
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
+ for (n = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), n++) {
if (!m->nmaster || n < m->nmaster)
mfacts += 1;
else if ((n - m->nmaster) % 2)
@@ -336,7 +336,7 @@ centeredmaster(Monitor *m)
rfacts += 1; // total factor of right hand stack area
}
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
+ for (n = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), n++)
if (!m->nmaster || n < m->nmaster)
mtotal += mh / mfacts;
else if ((n - m->nmaster) % 2)
@@ -348,7 +348,7 @@ centeredmaster(Monitor *m)
lrest = lh - ltotal;
rrest = rh - rtotal;
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++) {
if (!m->nmaster || i < m->nmaster) {
/* nmaster clients are stacked vertically, in the center of the screen */
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
@@ -407,7 +407,7 @@ centeredfloatingmaster(Monitor *m)
getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++)
if (i < m->nmaster) {
/* nmaster clients are stacked horizontally, in the center of the screen */
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
@@ -455,7 +455,7 @@ deck(Monitor *m)
if (n - m->nmaster > 0) /* override layout symbol */
snprintf(m->ltsymbol, sizeof m->ltsymbol, "D %d", n - m->nmaster);
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++)
if (i < m->nmaster) {
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
my += HEIGHT(c) + ih;
@@ -486,7 +486,7 @@ fibonacci(Monitor *m, int s)
nw = m->ww - 2*ov;
nh = m->wh - 2*oh;
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m)) {
if (r) {
if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
|| (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
@@ -599,7 +599,7 @@ gaplessgrid(Monitor *m)
x = m->wx + ov;
y = m->wy + oh;
- for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; i++, c = nexttiled(c->next, m)) {
if (i/rows + 1 > cols - n%cols) {
rows = n/cols + 1;
ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
@@ -645,7 +645,7 @@ grid(Monitor *m)
cw = (m->ww - 2*ov - iv * (cols - 1)) / (cols ? cols : 1);
chrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
cwrest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++) {
cc = i / rows;
cr = i % rows;
cx = m->wx + ov + cc * (cw + iv) + MIN(cc, cwrest);
@@ -698,7 +698,7 @@ horizgrid(Monitor *m) {
mrest = mw - (mw / ntop) * ntop;
srest = sw - (sw / nbottom) * nbottom;
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++)
if (i < ntop) {
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
mx += WIDTH(c) + iv;
@@ -745,7 +745,7 @@ nrowgrid(Monitor *m)
ch = (m->wh - 2*oh - ih*(rows - 1)) / rows;
uh = ch;
- for (c = nexttiled(m->clients); c; c = nexttiled(c->next), ci++) {
+ for (c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), ci++) {
if (ci == cols) {
uw = 0;
ci = 0;
@@ -798,7 +798,8 @@ tile(Monitor *m)
getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+// for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++)
+ for (i = 0, c = nexttiled(m->cl->clients, m); c; c = nexttiled(c->next, m), i++);
if (i < m->nmaster) {
resize(c, sx, sy, sw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
sy += HEIGHT(c) + ih;
Software created with 💖