X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=7b5fa4e318e9eca013b138725cc4ea7f5905dd44;hp=4b43a18a6e7f8598ddcef86266e4fbf4b6fcc8c6;hb=3c48858ffada0825b62e52ac14b1feba4b7654a4;hpb=1529058f27821d50d7a1ea085b6362b6b353b399 diff --git a/dwm.c b/dwm.c index 4b43a18..7b5fa4e 100644 --- a/dwm.c +++ b/dwm.c @@ -267,7 +267,6 @@ static void (*handler[LASTEvent]) (XEvent *) = { [UnmapNotify] = unmapnotify }; static Atom wmatom[WMLast], netatom[NetLast]; -static Bool otherwm; static Bool running = True; static Cursor cursor[CurLast]; static Display *dpy; @@ -372,10 +371,8 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) { if(c->inch) *h -= *h % c->inch; /* restore base dimensions */ - *w += c->basew; - *h += c->baseh; - *w = MAX(*w, c->minw); - *h = MAX(*h, c->minh); + *w = MAX(*w + c->basew, c->minw); + *h = MAX(*h + c->baseh, c->minh); if(c->maxw) *w = MIN(*w, c->maxw); if(c->maxh) @@ -460,13 +457,10 @@ buttonpress(XEvent *e) { void checkotherwm(void) { - otherwm = False; xerrorxlib = XSetErrorHandler(xerrorstart); /* this causes an error if some other window manager is running */ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); XSync(dpy, False); - if(otherwm) - die("dwm: another window manager is already running\n"); XSetErrorHandler(xerror); XSync(dpy, False); } @@ -799,7 +793,7 @@ enternotify(XEvent *e) { unfocus(selmon->sel, True); selmon = m; } - focus(wintoclient(ev->window)); + focus((wintoclient(ev->window))); } void @@ -845,7 +839,7 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */ void focusmon(const Arg *arg) { - Monitor *m = NULL; + Monitor *m; if(!mons->next) return; @@ -986,7 +980,7 @@ grabkeys(void) { void initfont(const char *fontstr) { char *def, **missing; - int i, n; + int n; missing = NULL; dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); @@ -996,14 +990,13 @@ initfont(const char *fontstr) { XFreeStringList(missing); } if(dc.font.set) { - XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; dc.font.ascent = dc.font.descent = 0; - font_extents = XExtentsOfFontSet(dc.font.set); + XExtentsOfFontSet(dc.font.set); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); - for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { + while(n--) { dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent); xfonts++; @@ -1021,14 +1014,13 @@ initfont(const char *fontstr) { Bool isprotodel(Client *c) { - int i, n; + int n; Atom *protocols; Bool ret = False; if(XGetWMProtocols(dpy, c->win, &protocols, &n)) { - for(i = 0; !ret && i < n; i++) - if(protocols[i] == wmatom[WMDelete]) - ret = True; + while(!ret && n--) + ret = protocols[n] == wmatom[WMDelete]; XFree(protocols); } return ret; @@ -1036,12 +1028,10 @@ isprotodel(Client *c) { #ifdef XINERAMA static Bool -isuniquegeom(XineramaScreenInfo *unique, size_t len, XineramaScreenInfo *info) { - unsigned int i; - - for(i = 0; i < len; i++) - if(unique[i].x_org == info->x_org && unique[i].y_org == info->y_org - && unique[i].width == info->width && unique[i].height == info->height) +isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { + while(n--) + if(unique[n].x_org == info->x_org && unique[n].y_org == info->y_org + && unique[n].width == info->width && unique[n].height == info->height) return False; return True; } @@ -1090,19 +1080,15 @@ killclient(const Arg *arg) { void manage(Window w, XWindowAttributes *wa) { - static Client cz; Client *c, *t = NULL; Window trans = None; XWindowChanges wc; - if(!(c = malloc(sizeof(Client)))) + if(!(c = calloc(1, sizeof(Client)))) 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) { + if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { c->mon = t->mon; c->tags = t->tags; } @@ -1117,7 +1103,7 @@ manage(Window w, XWindowAttributes *wa) { c->h = c->oldh = wa->height; c->oldbw = wa->border_width; if(c->w == c->mon->mw && c->h == c->mon->mh) { - c->isfloating = 1; + c->isfloating = True; c->x = c->mon->mx; c->y = c->mon->my; c->bw = 0; @@ -1216,7 +1202,7 @@ movemouse(const Arg *arg) { case MotionNotify: nx = ocx + (ev.xmotion.x - x); ny = ocy + (ev.xmotion.y - y); - if(snap && nx >= selmon->wx && nx <= selmon->wx + selmon->ww + if(nx >= selmon->wx && nx <= selmon->wx + selmon->ww && ny >= selmon->wy && ny <= selmon->wy + selmon->wh) { if(abs(selmon->wx - nx) < snap) nx = selmon->wx; @@ -1273,8 +1259,8 @@ propertynotify(XEvent *e) { switch (ev->atom) { default: break; case XA_WM_TRANSIENT_FOR: - XGetTransientForHint(dpy, c->win, &trans); - if(!c->isfloating && (c->isfloating = (wintoclient(trans) != NULL))) + if(!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) && + (c->isfloating = (wintoclient(trans)) != NULL)) arrange(c->mon); break; case XA_WM_NORMAL_HINTS: @@ -1307,7 +1293,7 @@ clientmessage(XEvent *e) { c->oldstate = c->isfloating; c->oldbw = c->bw; c->bw = 0; - c->isfloating = 1; + c->isfloating = True; resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); XRaiseWindow(dpy, c->win); } @@ -1379,8 +1365,8 @@ resizemouse(const Arg *arg) { case MotionNotify: nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); - if(snap && nw >= selmon->wx && nw <= selmon->wx + selmon->ww - && nh >= selmon->wy && nh <= selmon->wy + selmon->wh) + if(snap && c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww + && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) { if(!c->isfloating && selmon->lt[selmon->sellt]->arrange && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) @@ -1583,7 +1569,6 @@ showhide(Client *c) { } } - void sigchld(int unused) { if(signal(SIGCHLD, sigchld) == SIG_ERR) @@ -2019,7 +2004,7 @@ xerrordummy(Display *dpy, XErrorEvent *ee) { * is already running. */ int xerrorstart(Display *dpy, XErrorEvent *ee) { - otherwm = True; + die("dwm: another window manager is already running\n"); return -1; }