X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=6ddf266fbcbaff8bd3bbdfa3bc47dcb3ae8c99aa;hp=4d1493b568cabc8487566296d96da0c1dee2d631;hb=da80487c070b4004bf7451b069472b66320030f8;hpb=758b100d12ba1c52b5d7479e3ed334ba89e701f8 diff --git a/dwm.c b/dwm.c index 4d1493b..6ddf266 100644 --- a/dwm.c +++ b/dwm.c @@ -51,7 +51,7 @@ #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(X) ((X)->w + 2 * (X)->bw) #define HEIGHT(X) ((X)->h + 2 * (X)->bw) -#define TAGMASK ((int)((1LL << LENGTH(tags)) - 1)) +#define TAGMASK ((1 << LENGTH(tags)) - 1) #define TEXTW(X) (textnw(X, strlen(X)) + dc.font.height) /* enums */ @@ -237,6 +237,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); /* variables */ +static const char broken[] = "broken"; static char stext[256], ntext[8]; static int screen; static int sw, sh; /* X display screen geometry width, height */ @@ -270,11 +271,12 @@ static Window root; #include "config.h" /* compile-time check if all tags fit into an unsigned int bit array. */ -struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; }; +struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; /* function implementations */ void applyrules(Client *c) { + const char *class, *instance; unsigned int i; const Rule *r; Monitor *m; @@ -283,11 +285,13 @@ applyrules(Client *c) { /* rule matching */ c->isfloating = c->tags = 0; if(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 || (ch.res_class && strstr(ch.res_class, r->class))) - && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) + && (!r->class || strstr(class, r->class)) + && (!r->instance || strstr(instance, r->instance))) { c->isfloating = r->isfloating; c->tags |= r->tags; @@ -416,9 +420,9 @@ buttonpress(XEvent *e) { } if(ev->window == selmon->barwin) { i = x = 0; - do + do { x += TEXTW(tags[i]); - while(ev->x >= x && ++i < LENGTH(tags)); + } while(ev->x >= x && ++i < LENGTH(tags)); if(i < LENGTH(tags)) { click = ClkTagBar; arg.ui = 1 << i; @@ -973,6 +977,7 @@ initfont(const char *fontstr) { XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; + dc.font.ascent = dc.font.descent = 0; font_extents = XExtentsOfFontSet(dc.font.set); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); @@ -1052,6 +1057,7 @@ manage(Window w, XWindowAttributes *wa) { die("fatal: could not malloc() %u bytes\n", sizeof(Client)); *c = cz; c->win = w; + updatetitle(c); if(XGetTransientForHint(dpy, w, &trans)) t = wintoclient(trans); if(t) { @@ -1091,7 +1097,6 @@ manage(Window w, XWindowAttributes *wa) { updatesizehints(c); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, False); - updatetitle(c); if(!c->isfloating) c->isfloating = trans != None || c->isfixed; if(c->isfloating) @@ -1180,8 +1185,7 @@ movemouse(const Arg *arg) { resize(c, nx, ny, c->w, c->h, True); break; } - } - while(ev.type != ButtonRelease); + } while(ev.type != ButtonRelease); XUngrabPointer(dpy, CurrentTime); if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) { sendmon(c, m); @@ -1299,8 +1303,7 @@ resizemouse(const Arg *arg) { resize(c, c->x, c->y, nw, nh, True); break; } - } - while(ev.type != ButtonRelease); + } while(ev.type != ButtonRelease); XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); XUngrabPointer(dpy, CurrentTime); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); @@ -1343,7 +1346,7 @@ run(void) { XSync(dpy, False); while(running && !XNextEvent(dpy, &ev)) if(handler[ev.type]) - (handler[ev.type])(&ev); /* call handler */ + handler[ev.type](&ev); /* call handler */ } void @@ -1819,6 +1822,8 @@ void updatetitle(Client *c) { if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); + if(c->name[0] == '\0') /* hack to mark broken clients */ + strcpy(c->name, broken); } void