| dwm-mutlimonitorscratchpads-20211210-a786211.diff - sites - public wiki content… | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| dwm-mutlimonitorscratchpads-20211210-a786211.diff (5125B) | |
| --- | |
| 1 From 8c32f5ce2ed65cdb47452d658578bfe3f1dba81b Mon Sep 17 00:00:00 2001 | |
| 2 From: Hai Nguyen <[email protected]> | |
| 3 Date: Fri, 10 Dec 2021 20:19:56 -0500 | |
| 4 Subject: [PATCH] added scratchpad struct, added togglescratch program, c… | |
| 5 struct Rule to have floating dimensions | |
| 6 | |
| 7 --- | |
| 8 config.def.h | 11 +++++--- | |
| 9 dwm.c | 72 +++++++++++++++++++++++++++++++++++++++++++++------- | |
| 10 2 files changed, 71 insertions(+), 12 deletions(-) | |
| 11 | |
| 12 diff --git a/config.def.h b/config.def.h | |
| 13 index a2ac963..bbd132a 100644 | |
| 14 --- a/config.def.h | |
| 15 +++ b/config.def.h | |
| 16 @@ -26,11 +26,14 @@ static const Rule rules[] = { | |
| 17 * WM_CLASS(STRING) = instance, class | |
| 18 * WM_NAME(STRING) = title | |
| 19 */ | |
| 20 - /* class instance title tags mask isfloating … | |
| 21 - { "Gimp", NULL, NULL, 0, 1, … | |
| 22 - { "Firefox", NULL, NULL, 1 << 8, 0, … | |
| 23 + | |
| 24 + /* class instance title tags mask … | |
| 25 + | |
| 26 + {"Gimp", NULL, NULL, 0, … | |
| 27 + {"Qalculate-gtk", NULL, NULL, 0, … | |
| 28 }; | |
| 29 | |
| 30 + | |
| 31 /* layout(s) */ | |
| 32 static const float mfact = 0.55; /* factor of master area size [0.0… | |
| 33 static const int nmaster = 1; /* number of clients in master are… | |
| 34 @@ -59,9 +62,11 @@ static const Layout layouts[] = { | |
| 35 static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in… | |
| 36 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", d… | |
| 37 static const char *termcmd[] = { "st", NULL }; | |
| 38 +static const scratchpad qalculate = {.class = "Qalculate-gtk", .v = (ch… | |
| 39 | |
| 40 static Key keys[] = { | |
| 41 /* modifier key function argu… | |
| 42 + {ControlMask, XK_s, … | |
| 43 { MODKEY, XK_p, spawn, {.v … | |
| 44 { MODKEY|ShiftMask, XK_Return, spawn, {.v … | |
| 45 { MODKEY, XK_b, togglebar, {0} … | |
| 46 diff --git a/dwm.c b/dwm.c | |
| 47 index 5e4d494..ba7dd1e 100644 | |
| 48 --- a/dwm.c | |
| 49 +++ b/dwm.c | |
| 50 @@ -82,6 +82,12 @@ typedef struct { | |
| 51 const Arg arg; | |
| 52 } Button; | |
| 53 | |
| 54 +typedef struct { | |
| 55 + const char* class; | |
| 56 + const char* title; | |
| 57 + const void* v; | |
| 58 +} scratchpad; | |
| 59 + | |
| 60 typedef struct Monitor Monitor; | |
| 61 typedef struct Client Client; | |
| 62 struct Client { | |
| 63 @@ -138,6 +144,7 @@ typedef struct { | |
| 64 const char *title; | |
| 65 unsigned int tags; | |
| 66 int isfloating; | |
| 67 + float floatx, floaty, floatw, floath; | |
| 68 int monitor; | |
| 69 } Rule; | |
| 70 | |
| 71 @@ -214,6 +221,7 @@ static void togglebar(const Arg *arg); | |
| 72 static void togglefloating(const Arg *arg); | |
| 73 static void toggletag(const Arg *arg); | |
| 74 static void toggleview(const Arg *arg); | |
| 75 +static void togglescratch(const Arg *arg); | |
| 76 static void unfocus(Client *c, int setfocus); | |
| 77 static void unmanage(Client *c, int destroyed); | |
| 78 static void unmapnotify(XEvent *e); | |
| 79 @@ -295,15 +303,21 @@ applyrules(Client *c) | |
| 80 for (i = 0; i < LENGTH(rules); i++) { | |
| 81 r = &rules[i]; | |
| 82 if ((!r->title || strstr(c->name, r->title)) | |
| 83 - && (!r->class || strstr(class, r->class)) | |
| 84 - && (!r->instance || strstr(instance, r->instance))) | |
| 85 - { | |
| 86 - c->isfloating = r->isfloating; | |
| 87 - c->tags |= r->tags; | |
| 88 - for (m = mons; m && m->num != r->monitor; m = m… | |
| 89 - if (m) | |
| 90 - c->mon = m; | |
| 91 - } | |
| 92 + && (!r->class || strstr(class, r->class)) | |
| 93 + && (!r->instance || strstr(instance, r->instanc… | |
| 94 + { | |
| 95 + c->isfloating = r->isfloating; | |
| 96 + c->tags |= r->tags; | |
| 97 + for (m = mons; m && m->num != r->monito… | |
| 98 + if (m) | |
| 99 + c->mon = m; | |
| 100 + if(c->isfloating){ | |
| 101 + if (r->floatx >= 0) c->x = c->m… | |
| 102 + if (r->floaty >= 0) c->y = c->m… | |
| 103 + if (r->floatw >= 0) c->w = (int… | |
| 104 + if (r->floath >= 0) c->h = (int… | |
| 105 + } | |
| 106 + } | |
| 107 } | |
| 108 if (ch.res_class) | |
| 109 XFree(ch.res_class); | |
| 110 @@ -1749,6 +1763,46 @@ toggleview(const Arg *arg) | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 +void | |
| 115 +togglescratch(const Arg *arg) | |
| 116 +{ | |
| 117 + Client *c; | |
| 118 + char found = 0; | |
| 119 + Monitor *m; | |
| 120 + for(m = mons; m; m = m->next){ | |
| 121 + for (c = m->clients; c; c = c->next){ | |
| 122 + const char *class; | |
| 123 + XClassHint ch = { NULL, NULL }; | |
| 124 + XGetClassHint(dpy, c->win, &ch); | |
| 125 + class = ch.res_class ? ch.res_class : broken; | |
| 126 + found = (((char *)((scratchpad *)arg->v)->class… | |
| 127 + if(found){ | |
| 128 + break; | |
| 129 + } | |
| 130 + } | |
| 131 + if(found){ | |
| 132 + break; | |
| 133 + } | |
| 134 + } | |
| 135 + if (found) { | |
| 136 + if(m != selmon){ | |
| 137 + sendmon(c, selmon); | |
| 138 + c->tags = selmon->tagset[selmon->seltags]; | |
| 139 + applyrules(c); | |
| 140 + }else{ | |
| 141 + c->tags = ISVISIBLE(c) ? 1 << 31 : selmon->tags… | |
| 142 + } | |
| 143 + focus(NULL); | |
| 144 + arrange(selmon); | |
| 145 + if (ISVISIBLE(c)) { | |
| 146 + restack(selmon); | |
| 147 + focus(c); | |
| 148 + } | |
| 149 + } else{ | |
| 150 + spawn(&((Arg){.v = ((scratchpad *)arg->v)->v})); | |
| 151 + } | |
| 152 +} | |
| 153 + | |
| 154 void | |
| 155 unfocus(Client *c, int setfocus) | |
| 156 { | |
| 157 -- | |
| 158 2.34.1 | |
| 159 |