sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-multiple-dynamic-scratchpads.diff (6881B)


      1 diff --git a/config.def.h b/config.def.h
      2 index a2ac963..1c82453 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -95,6 +95,13 @@ static Key keys[] = {
      6  	TAGKEYS(                        XK_8,                      7)
      7  	TAGKEYS(                        XK_9,                      8)
      8  	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
      9 +    { MODKEY,                       XK_s, scratchpad_show, {.i = 1} },
     10 +    { MODKEY,                       XK_y, scratchpad_show, {.i = 2} },
     11 +    { MODKEY,                       XK_u, scratchpad_show, {.i = 3} },
     12 +    { MODKEY|ShiftMask,                       XK_s, scratchpad_hide, {.i = 1} },
     13 +    { MODKEY|ShiftMask,                       XK_y, scratchpad_hide, {.i = 2} },
     14 +    { MODKEY|ShiftMask,                       XK_u, scratchpad_hide, {.i = 3} },
     15 +	{ MODKEY|ShiftMask,             XK_r,      scratchpad_remove,           {0} },
     16  };
     17  
     18  /* button definitions */
     19 diff --git a/dwm.c b/dwm.c
     20 index 5e4d494..8e6fe18 100644
     21 --- a/dwm.c
     22 +++ b/dwm.c
     23 @@ -195,6 +195,11 @@ static void resizemouse(const Arg *arg);
     24  static void restack(Monitor *m);
     25  static void run(void);
     26  static void scan(void);
     27 +static void scratchpad_hide();
     28 +static void scratchpad_remove();
     29 +static void scratchpad_show();
     30 +static void scratchpad_show_client(Client *c);
     31 +static void scratchpad_show_first(int scratchNum);
     32  static int sendevent(Client *c, Atom proto);
     33  static void sendmon(Client *c, Monitor *m);
     34  static void setclientstate(Client *c, long state);
     35 @@ -269,11 +274,19 @@ static Drw *drw;
     36  static Monitor *mons, *selmon;
     37  static Window root, wmcheckwin;
     38  
     39 +/* scratchpad */
     40 +#define SCRATCHPAD_MASK_1 512
     41 +#define SCRATCHPAD_MASK_2 1024
     42 +#define SCRATCHPAD_MASK_3 2048
     43 +static int scratchpad_hide_flag = 0;
     44 +static Client *scratchpad_last_showed_1 = NULL;
     45 +static Client *scratchpad_last_showed_2 = NULL;
     46 +static Client *scratchpad_last_showed_3 = NULL;
     47  /* configuration, allows nested code to access above variables */
     48  #include "config.h"
     49  
     50  /* compile-time check if all tags fit into an unsigned int bit array. */
     51 -struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     52 +struct NumTags { char limitexceeded[LENGTH(tags) > 30 ? -1 : 1]; };
     53  
     54  /* function implementations */
     55  void
     56 @@ -309,7 +322,9 @@ applyrules(Client *c)
     57  		XFree(ch.res_class);
     58  	if (ch.res_name)
     59  		XFree(ch.res_name);
     60 +    if(c->tags != SCRATCHPAD_MASK_1 && c->tags != SCRATCHPAD_MASK_2 && c->tags != SCRATCHPAD_MASK_3) {
     61  	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
     62 +    }
     63  }
     64  
     65  int
     66 @@ -1408,6 +1423,121 @@ scan(void)
     67  	}
     68  }
     69  
     70 +static void scratchpad_hide(const Arg *arg) {
     71 +    if(scratchpad_hide_flag < 4) {
     72 +        if(arg->i == 1) {
     73 +            if(selmon->sel) {
     74 +                selmon->sel->tags = SCRATCHPAD_MASK_1;
     75 +                selmon->sel->isfloating = 1;
     76 +                focus(NULL);
     77 +                arrange(selmon);
     78 +                scratchpad_hide_flag++;
     79 +            }
     80 +        }
     81 +        else if(arg->i == 2) {
     82 +            if(selmon->sel) {
     83 +                selmon->sel->tags = SCRATCHPAD_MASK_2;
     84 +                selmon->sel->isfloating = 1;
     85 +                focus(NULL);
     86 +                arrange(selmon);
     87 +                scratchpad_hide_flag++;
     88 +            }
     89 +        }
     90 +        else if(arg->i == 3) {
     91 +            if(selmon->sel) {
     92 +                selmon->sel->tags = SCRATCHPAD_MASK_3;
     93 +                selmon->sel->isfloating = 1;
     94 +                focus(NULL);
     95 +                arrange(selmon);
     96 +                scratchpad_hide_flag++;
     97 +            }
     98 +        }
     99 +    }
    100 +}
    101 +
    102 +static void scratchpad_remove() {
    103 +    if(selmon->sel && (scratchpad_last_showed_1 != NULL || scratchpad_last_showed_2 != NULL ||scratchpad_last_showed_3 != NULL) && (selmon->sel == scratchpad_last_showed_1 || selmon->sel == scratchpad_last_showed_2 || selmon->sel == scratchpad_last_showed_3))  {
    104 +        if(scratchpad_last_showed_1 == selmon->sel) {
    105 +            scratchpad_last_showed_1 = NULL;
    106 +        }
    107 +        else if(scratchpad_last_showed_2 == selmon->sel) {
    108 +            scratchpad_last_showed_2 = NULL;
    109 +        }
    110 +        else if(scratchpad_last_showed_3 == selmon->sel) {
    111 +            scratchpad_last_showed_3 = NULL;
    112 +        }
    113 +    }
    114 +}
    115 +
    116 +static void scratchpad_show(const Arg *arg) {
    117 +    if(arg->i == 1) {
    118 +        if(scratchpad_last_showed_1 == NULL) {
    119 +            scratchpad_show_first(arg->i);
    120 +        }
    121 +        else {
    122 +            if(scratchpad_last_showed_1->tags != SCRATCHPAD_MASK_1) {
    123 +                scratchpad_last_showed_1->tags = SCRATCHPAD_MASK_1;
    124 +                focus(NULL);
    125 +                arrange(selmon);
    126 +            }
    127 +            else {
    128 +                scratchpad_show_first(arg->i);
    129 +            }
    130 +        }
    131 +    }
    132 +    else if(arg->i == 2) {
    133 +        if(scratchpad_last_showed_2 == NULL) {
    134 +            scratchpad_show_first(arg->i);
    135 +        }
    136 +        else {
    137 +            if(scratchpad_last_showed_2->tags != SCRATCHPAD_MASK_2) {
    138 +                scratchpad_last_showed_2->tags = SCRATCHPAD_MASK_2;
    139 +                focus(NULL);
    140 +                arrange(selmon);
    141 +            }
    142 +            else {
    143 +                scratchpad_show_first(arg->i);
    144 +            }
    145 +        }
    146 +    }
    147 +    else if(arg->i == 3) {
    148 +        if(scratchpad_last_showed_3 == NULL) {
    149 +            scratchpad_show_first(arg->i);
    150 +        }
    151 +        else {
    152 +            if(scratchpad_last_showed_3->tags != SCRATCHPAD_MASK_3) {
    153 +                scratchpad_last_showed_3->tags = SCRATCHPAD_MASK_3;
    154 +                focus(NULL);
    155 +                arrange(selmon);
    156 +            }
    157 +            else {
    158 +                scratchpad_show_first(arg->i);
    159 +            }
    160 +        }
    161 +    }
    162 +}
    163 +
    164 +static void scratchpad_show_client(Client *c) {
    165 +    c->tags = selmon->tagset[selmon->seltags];
    166 +    focus(c);
    167 +    arrange(selmon);
    168 +}
    169 +
    170 +static void scratchpad_show_first(int scratchNum) {
    171 +    for(Client *c = selmon->clients; c !=NULL; c = c->next) {
    172 +        if(c->tags == SCRATCHPAD_MASK_1 && scratchNum == 1) {
    173 +            scratchpad_last_showed_1 = c;
    174 +            scratchpad_show_client(c);
    175 +        } else if(c->tags == SCRATCHPAD_MASK_2 && scratchNum == 2) {
    176 +            scratchpad_last_showed_2 = c;
    177 +            scratchpad_show_client(c);
    178 +        } else if(c->tags == SCRATCHPAD_MASK_3 && scratchNum == 3) {
    179 +            scratchpad_last_showed_3 = c;
    180 +            scratchpad_show_client(c);
    181 +        }
    182 +    }
    183 +}
    184 +
    185  void
    186  sendmon(Client *c, Monitor *m)
    187  {
    188 @@ -1781,6 +1911,16 @@ unmanage(Client *c, int destroyed)
    189  		XSetErrorHandler(xerror);
    190  		XUngrabServer(dpy);
    191  	}
    192 +    if(scratchpad_last_showed_1 == c) {
    193 +        scratchpad_last_showed_1 = NULL;
    194 +    }
    195 +    if(scratchpad_last_showed_2 == c) {
    196 +        scratchpad_last_showed_2 = NULL; 
    197 +    }
    198 +    if(scratchpad_last_showed_3 == c) {
    199 +        scratchpad_last_showed_3 = NULL;
    200 +    }
    201 +
    202  	free(c);
    203  	focus(NULL);
    204  	updateclientlist();