sites

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

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


      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 5f16260..202038f 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 (1u << sizeof tags / sizeof * tags)
     41 +#define SCRATCHPAD_MASK_2 (1u << (sizeof tags / sizeof * tags + 1))
     42 +#define SCRATCHPAD_MASK_3 (1u << (sizeof tags / sizeof * tags + 2))
     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) > 28 ? -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 @@ -1412,6 +1427,124 @@ 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 +            scratchpad_hide_flag--;
    107 +        }
    108 +        else if(scratchpad_last_showed_2 == selmon->sel) {
    109 +            scratchpad_last_showed_2 = NULL;
    110 +            scratchpad_hide_flag--;
    111 +        }
    112 +        else if(scratchpad_last_showed_3 == selmon->sel) {
    113 +            scratchpad_last_showed_3 = NULL;
    114 +            scratchpad_hide_flag--;
    115 +        }
    116 +    }
    117 +}
    118 +
    119 +static void scratchpad_show(const Arg *arg) {
    120 +    if(arg->i == 1) {
    121 +        if(scratchpad_last_showed_1 == NULL) {
    122 +            scratchpad_show_first(arg->i);
    123 +        }
    124 +        else {
    125 +            if(scratchpad_last_showed_1->tags != SCRATCHPAD_MASK_1) {
    126 +                scratchpad_last_showed_1->tags = SCRATCHPAD_MASK_1;
    127 +                focus(NULL);
    128 +                arrange(selmon);
    129 +            }
    130 +            else {
    131 +                scratchpad_show_first(arg->i);
    132 +            }
    133 +        }
    134 +    }
    135 +    else if(arg->i == 2) {
    136 +        if(scratchpad_last_showed_2 == NULL) {
    137 +            scratchpad_show_first(arg->i);
    138 +        }
    139 +        else {
    140 +            if(scratchpad_last_showed_2->tags != SCRATCHPAD_MASK_2) {
    141 +                scratchpad_last_showed_2->tags = SCRATCHPAD_MASK_2;
    142 +                focus(NULL);
    143 +                arrange(selmon);
    144 +            }
    145 +            else {
    146 +                scratchpad_show_first(arg->i);
    147 +            }
    148 +        }
    149 +    }
    150 +    else if(arg->i == 3) {
    151 +        if(scratchpad_last_showed_3 == NULL) {
    152 +            scratchpad_show_first(arg->i);
    153 +        }
    154 +        else {
    155 +            if(scratchpad_last_showed_3->tags != SCRATCHPAD_MASK_3) {
    156 +                scratchpad_last_showed_3->tags = SCRATCHPAD_MASK_3;
    157 +                focus(NULL);
    158 +                arrange(selmon);
    159 +            }
    160 +            else {
    161 +                scratchpad_show_first(arg->i);
    162 +            }
    163 +        }
    164 +    }
    165 +}
    166 +
    167 +static void scratchpad_show_client(Client *c) {
    168 +    c->tags = selmon->tagset[selmon->seltags];
    169 +    focus(c);
    170 +    arrange(selmon);
    171 +}
    172 +
    173 +static void scratchpad_show_first(int scratchNum) {
    174 +    for(Client *c = selmon->clients; c !=NULL; c = c->next) {
    175 +        if(c->tags == SCRATCHPAD_MASK_1 && scratchNum == 1) {
    176 +            scratchpad_last_showed_1 = c;
    177 +            scratchpad_show_client(c);
    178 +        } else if(c->tags == SCRATCHPAD_MASK_2 && scratchNum == 2) {
    179 +            scratchpad_last_showed_2 = c;
    180 +            scratchpad_show_client(c);
    181 +        } else if(c->tags == SCRATCHPAD_MASK_3 && scratchNum == 3) {
    182 +            scratchpad_last_showed_3 = c;
    183 +            scratchpad_show_client(c);
    184 +        }
    185 +    }
    186 +}
    187 +
    188  void
    189  sendmon(Client *c, Monitor *m)
    190  {
    191 @@ -1785,6 +1918,16 @@ unmanage(Client *c, int destroyed)
    192  		XSetErrorHandler(xerror);
    193  		XUngrabServer(dpy);
    194  	}
    195 +    if(scratchpad_last_showed_1 == c) {
    196 +        scratchpad_last_showed_1 = NULL;
    197 +    }
    198 +    if(scratchpad_last_showed_2 == c) {
    199 +        scratchpad_last_showed_2 = NULL;
    200 +    }
    201 +    if(scratchpad_last_showed_3 == c) {
    202 +        scratchpad_last_showed_3 = NULL;
    203 +    }
    204 +
    205  	free(c);
    206  	focus(NULL);
    207  	updateclientlist();