From 5728e3bc46ef38cfcc0f2cbf04626a28ecc57379 Mon Sep 17 00:00:00 2001 From: Lars Niesen Date: Thu, 9 Dec 2021 13:40:17 +0100 Subject: [PATCH] rulerefresher --- dwm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/dwm.c b/dwm.c index 4465af1..5f8ba9c 100644 --- a/dwm.c +++ b/dwm.c @@ -223,6 +223,7 @@ static int updategeom(void); static void updatenumlockmask(void); static void updatesizehints(Client *c); static void updatestatus(void); +static void updaterules(Client *c); static void updatetitle(Client *c); static void updatewindowtype(Client *c); static void updatewmhints(Client *c); @@ -1237,6 +1238,7 @@ propertynotify(XEvent *e) } if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); + updaterules(c); if (c == c->mon->sel) drawbar(c->mon); } @@ -1992,6 +1994,54 @@ updatestatus(void) drawbar(selmon); } +void +updaterules(Client *c) +{ + //applyrules(c) + const char *class, *instance; + unsigned int i; + const Rule *r; + Monitor *m; + XClassHint ch = { NULL, NULL }; + + /* rule matching */ + XGetClassHint(dpy, c->win, &ch); + class = ch.res_class ? ch.res_class : broken; + instance = ch.res_name ? ch.res_name : broken; + char found_rule = 0; + + 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(!found_rule) + { + c->tags=0; + found_rule=1; + } + c->tags |= r->tags; + for (m = mons; m && m->num != r->monitor; m = m->next); + if (m) + c->mon = m; + } + } + if (ch.res_class) + XFree(ch.res_class); + if (ch.res_name) + XFree(ch.res_name); + c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; + + // end apply rules + if (c->isfloating) + resize(c, c->x, c->y, + c->w, c->h, 0); + arrange(c->mon); +} + void updatetitle(Client *c) { -- 2.34.1