From c605c7f4c3f421ef5b6f12031b07abe713cd8183 Mon Sep 17 00:00:00 2001 From: MLquest8 Date: Sun, 14 Jun 2020 13:06:31 +0400 Subject: [PATCH] resizehints-ruled. Modified to properly read the rules and apply as needed. Behavior for clients that aren't found in rules struct is remains the same. --- config.def.h | 2 ++ dwm.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 1c0b587..1d55286 100644 --- a/config.def.h +++ b/config.def.h @@ -29,6 +29,8 @@ static const Rule rules[] = { /* class instance title tags mask isfloating monitor */ { "Gimp", NULL, NULL, 0, 1, -1 }, { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, + { "st", NULL, NULL, 0, 0, -1 }, + { "St", NULL, NULL, 0, 0, -1 }, /* if Xresources[st] is patched in */ }; /* layout(s) */ diff --git a/dwm.c b/dwm.c index 9fd0286..f0f569e 100644 --- a/dwm.c +++ b/dwm.c @@ -149,6 +149,7 @@ static void arrangemon(Monitor *m); static void attach(Client *c); static void attachstack(Client *c); static void buttonpress(XEvent *e); +static void checkfloatingrules(Client *c); static void checkotherwm(void); static void cleanup(void); static void cleanupmon(Monitor *mon); @@ -456,6 +457,31 @@ buttonpress(XEvent *e) buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); } +void +checkfloatingrules(Client *c) +{ + const char *class, *instance; + unsigned int i; + const Rule *r; + XClassHint ch = { NULL, NULL }; + + XGetClassHint(dpy, c->win, &ch); + class = ch.res_class ? ch.res_class : broken; + instance = ch.res_name ? ch.res_name : broken; + + for (i = 0; i < LENGTH(rules); i++) { + r = &rules[i]; + if ((!r->title || strstr(c->name, r->title)) + && (!r->class || strstr(class, r->class)) + && (!r->instance || strstr(instance, r->instance))) + c->isfloating = r->isfloating; + } + if (ch.res_class) + XFree(ch.res_class); + if (ch.res_name) + XFree(ch.res_name); +} + void checkotherwm(void) { @@ -1952,7 +1978,7 @@ updatesizehints(Client *c) if (!XGetWMNormalHints(dpy, c->win, &size, &msize)) /* size is uninitialized, ensure that size.flags aren't used */ - size.flags = PSize; + size.flags = 0; if (size.flags & PBaseSize) { c->basew = size.base_width; c->baseh = size.base_height; @@ -1984,6 +2010,12 @@ updatesizehints(Client *c) c->maxa = (float)size.max_aspect.x / size.max_aspect.y; } else c->maxa = c->mina = 0.0; + if(size.flags & PSize) { + c->basew = size.base_width; + c->baseh = size.base_height; + c->isfloating = 1; + } + checkfloatingrules(c); c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh); } -- 2.26.2