dwm-sizehints-ruled-6.2.diff (2907B)
1 From c605c7f4c3f421ef5b6f12031b07abe713cd8183 Mon Sep 17 00:00:00 2001 2 From: MLquest8 <miskuzius@gmail.com> 3 Date: Sun, 14 Jun 2020 13:06:31 +0400 4 Subject: [PATCH] resizehints-ruled. Modified to properly read the rules and 5 apply as needed. Behavior for clients that aren't found in rules struct is 6 remains the same. 7 8 --- 9 config.def.h | 2 ++ 10 dwm.c | 34 +++++++++++++++++++++++++++++++++- 11 2 files changed, 35 insertions(+), 1 deletion(-) 12 13 diff --git a/config.def.h b/config.def.h 14 index 1c0b587..1d55286 100644 15 --- a/config.def.h 16 +++ b/config.def.h 17 @@ -29,6 +29,8 @@ static const Rule rules[] = { 18 /* class instance title tags mask isfloating monitor */ 19 { "Gimp", NULL, NULL, 0, 1, -1 }, 20 { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, 21 + { "st", NULL, NULL, 0, 0, -1 }, 22 + { "St", NULL, NULL, 0, 0, -1 }, /* if Xresources[st] is patched in */ 23 }; 24 25 /* layout(s) */ 26 diff --git a/dwm.c b/dwm.c 27 index 9fd0286..f0f569e 100644 28 --- a/dwm.c 29 +++ b/dwm.c 30 @@ -149,6 +149,7 @@ static void arrangemon(Monitor *m); 31 static void attach(Client *c); 32 static void attachstack(Client *c); 33 static void buttonpress(XEvent *e); 34 +static void checkfloatingrules(Client *c); 35 static void checkotherwm(void); 36 static void cleanup(void); 37 static void cleanupmon(Monitor *mon); 38 @@ -456,6 +457,31 @@ buttonpress(XEvent *e) 39 buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); 40 } 41 42 +void 43 +checkfloatingrules(Client *c) 44 +{ 45 + const char *class, *instance; 46 + unsigned int i; 47 + const Rule *r; 48 + XClassHint ch = { NULL, NULL }; 49 + 50 + XGetClassHint(dpy, c->win, &ch); 51 + class = ch.res_class ? ch.res_class : broken; 52 + instance = ch.res_name ? ch.res_name : broken; 53 + 54 + for (i = 0; i < LENGTH(rules); i++) { 55 + r = &rules[i]; 56 + if ((!r->title || strstr(c->name, r->title)) 57 + && (!r->class || strstr(class, r->class)) 58 + && (!r->instance || strstr(instance, r->instance))) 59 + c->isfloating = r->isfloating; 60 + } 61 + if (ch.res_class) 62 + XFree(ch.res_class); 63 + if (ch.res_name) 64 + XFree(ch.res_name); 65 +} 66 + 67 void 68 checkotherwm(void) 69 { 70 @@ -1952,7 +1978,7 @@ updatesizehints(Client *c) 71 72 if (!XGetWMNormalHints(dpy, c->win, &size, &msize)) 73 /* size is uninitialized, ensure that size.flags aren't used */ 74 - size.flags = PSize; 75 + size.flags = 0; 76 if (size.flags & PBaseSize) { 77 c->basew = size.base_width; 78 c->baseh = size.base_height; 79 @@ -1984,6 +2010,12 @@ updatesizehints(Client *c) 80 c->maxa = (float)size.max_aspect.x / size.max_aspect.y; 81 } else 82 c->maxa = c->mina = 0.0; 83 + if(size.flags & PSize) { 84 + c->basew = size.base_width; 85 + c->baseh = size.base_height; 86 + c->isfloating = 1; 87 + } 88 + checkfloatingrules(c); 89 c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh); 90 } 91 92 -- 93 2.26.2 94