dwm-attachasideandbelow-20200702-f04cac6.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-attachasideandbelow-20200702-f04cac6.diff (3231B)
       ---
            1 diff -up b/dwm.c a/dwm.c
            2 --- b/dwm.c        2020-07-05 16:05:02.555947738 -0300
            3 +++ a/dwm.c        2020-07-05 16:06:19.592609932 -0300
            4 @@ -49,7 +49,8 @@
            5  #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
            6  #define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
            7                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
            8 -#define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
            9 +#define ISVISIBLEONTAG(C, T)    ((C->tags & T))
           10 +#define ISVISIBLE(C)            ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags])
           11  #define LENGTH(X)               (sizeof X / sizeof X[0])
           12  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
           13  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
           14 @@ -147,6 +148,7 @@ static int applysizehints(Client *c, int
           15  static void arrange(Monitor *m);
           16  static void arrangemon(Monitor *m);
           17  static void attach(Client *c);
           18 +static void attachBelow(Client *c);
           19  static void attachstack(Client *c);
           20  static void buttonpress(XEvent *e);
           21  static void checkotherwm(void);
           22 @@ -184,6 +186,7 @@ static void maprequest(XEvent *e);
           23  static void monocle(Monitor *m);
           24  static void motionnotify(XEvent *e);
           25  static void movemouse(const Arg *arg);
           26 +static Client *nexttagged(Client *c);
           27  static Client *nexttiled(Client *c);
           28  static void pop(Client *);
           29  static void propertynotify(XEvent *e);
           30 @@ -406,6 +409,27 @@ attach(Client *c)
           31          c->next = c->mon->clients;
           32          c->mon->clients = c;
           33  }
           34 +void
           35 +attachBelow(Client *c)
           36 +{
           37 +        //If there is nothing on the monitor or the selected client is floating, attach as normal
           38 +        if(c->mon->sel == NULL || c->mon->sel->isfloating) {
           39 +        Client *at = nexttagged(c);
           40 +        if(!at) {
           41 +            attach(c);
           42 +            return;
           43 +            }
           44 +        c->next = at->next;
           45 +        at->next = c;
           46 +                return;
           47 +        }
           48 +
           49 +        //Set the new client's next property to the same as the currently selected clients next
           50 +        c->next = c->mon->sel->next;
           51 +        //Set the currently selected clients next property to the new client
           52 +        c->mon->sel->next = c;
           53 +
           54 +}
           55  
           56  void
           57  attachstack(Client *c)
           58 @@ -1063,7 +1087,7 @@ manage(Window w, XWindowAttributes *wa)
           59                  c->isfloating = c->oldstate = trans != None || c->isfixed;
           60          if (c->isfloating)
           61                  XRaiseWindow(dpy, c->win);
           62 -        attach(c);
           63 +        attachBelow(c);
           64          attachstack(c);
           65          XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
           66                  (unsigned char *) &(c->win), 1);
           67 @@ -1193,6 +1217,16 @@ movemouse(const Arg *arg)
           68          }
           69  }
           70  
           71 + Client *
           72 +nexttagged(Client *c) {
           73 +        Client *walked = c->mon->clients;
           74 +        for(;
           75 +                walked && (walked->isfloating || !ISVISIBLEONTAG(walked, c->tags));
           76 +                walked = walked->next
           77 +        );
           78 +        return walked;
           79 +}
           80 +
           81  Client *
           82  nexttiled(Client *c)
           83  {
           84 @@ -1418,7 +1452,7 @@ sendmon(Client *c, Monitor *m)
           85          detachstack(c);
           86          c->mon = m;
           87          c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
           88 -        attach(c);
           89 +        attachBelow(c);
           90          attachstack(c);
           91          focus(NULL);
           92          arrange(NULL);
           93 @@ -1901,6 +1935,7 @@ updategeom(void)
           94                                          detachstack(c);
           95                                          c->mon = mons;
           96                                          attach(c);
           97 +                                        attachBelow(c);
           98                                          attachstack(c);
           99                                  }
          100                                  if (m == selmon)