X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=79a3a33b66c559a54c657c7dc982abe87161e2d9;hb=954db46bac481fd3f514f7af50d2af7e73fb9115;hp=a3439bccdbbae324de1392c1b15fd435cee80d68;hpb=c2c54cc0faad89483edf3ffddee3e3ff20cf8263;p=dwm.git diff --git a/dwm.c b/dwm.c index a3439bc..79a3a33 100644 --- a/dwm.c +++ b/dwm.c @@ -68,7 +68,7 @@ struct Client { int minax, maxax, minay, maxay; long flags; unsigned int border, oldborder; - Bool isbanned, isfixed, isfloating; + Bool isbanned, isfixed, isfloating, isurgent; Bool *tags; Client *next; Client *prev; @@ -146,7 +146,7 @@ void detach(Client *c); void detachstack(Client *c); void drawbar(void); void drawsquare(Monitor *, Bool filled, Bool empty, unsigned long col[ColLast]); -void drawtext(Monitor *, const char *text, unsigned long col[ColLast]); +void drawtext(Monitor *, const char *text, unsigned long col[ColLast], Bool invert); void *emallocz(unsigned int size); void enternotify(XEvent *e); void eprint(const char *errstr, ...); @@ -166,6 +166,7 @@ unsigned int idxoftag(const char *tag); void initfont(Monitor*, const char *fontstr); Bool isoccupied(Monitor *m, unsigned int t); Bool isprotodel(Client *c); +Bool isurgent(int monitor, unsigned int t); Bool isvisible(Client *c, int monitor); void keypress(XEvent *e); void killclient(const char *arg); @@ -201,6 +202,7 @@ void unmapnotify(XEvent *e); void updatebarpos(Monitor *m); void updatesizehints(Client *c); void updatetitle(Client *c); +void updatewmhints(Client *c); void view(const char *arg); void viewprevtag(const char *arg); /* views previous selected tags */ int xerror(Display *dpy, XErrorEvent *ee); @@ -366,10 +368,7 @@ buttonpress(XEvent *e) { if(CLEANMASK(ev->state) != MODKEY) return; if(ev->button == Button1) { - if((m->layout->arrange == floating) || c->isfloating) - restack(); - else - togglefloating(NULL); + restack(); movemouse(c); } else if(ev->button == Button2) { @@ -379,10 +378,7 @@ buttonpress(XEvent *e) { zoom(NULL); } else if(ev->button == Button3 && !c->isfixed) { - if((floating == m->layout->arrange) || c->isfloating) - restack(); - else - togglefloating(NULL); + restack(); resizemouse(c); } } @@ -573,17 +569,17 @@ drawbar(void) { for(j = 0; j < LENGTH(tags); j++) { m->dc.w = textw(m, tags[j]); if(m->seltags[j]) { - drawtext(m, tags[j], m->dc.sel); + drawtext(m, tags[j], m->dc.sel, isurgent(i, j)); drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, isoccupied(m, j), m->dc.sel); } else { - drawtext(m, tags[j], m->dc.norm); + drawtext(m, tags[j], m->dc.norm, isurgent(i, j)); drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, isoccupied(m, j), m->dc.norm); } m->dc.x += m->dc.w; } m->dc.w = blw; - drawtext(m, m->layout->symbol, m->dc.norm); + drawtext(m, m->layout->symbol, m->dc.norm, False); x = m->dc.x + m->dc.w; m->dc.w = textw(m, stext); m->dc.x = m->sw - m->dc.w; @@ -591,15 +587,15 @@ drawbar(void) { m->dc.x = x; m->dc.w = m->sw - x; } - drawtext(m, stext, m->dc.norm); + drawtext(m, stext, m->dc.norm, False); if((m->dc.w = m->dc.x - x) > bh) { m->dc.x = x; if(sel && sel->monitor == selmonitor) { - drawtext(m, sel->name, m->dc.sel); + drawtext(m, sel->name, m->dc.sel, False); drawsquare(m, False, sel->isfloating, m->dc.sel); } else - drawtext(m, NULL, m->dc.norm); + drawtext(m, NULL, m->dc.norm, False); } XCopyArea(dpy, m->dc.drawable, m->barwin, m->dc.gc, 0, 0, m->sw, bh, 0, 0); XSync(dpy, False); @@ -628,13 +624,13 @@ drawsquare(Monitor *m, Bool filled, Bool empty, unsigned long col[ColLast]) { } void -drawtext(Monitor *m, const char *text, unsigned long col[ColLast]) { +drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert) { int x, y, w, h; static char buf[256]; unsigned int len, olen; XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h }; - XSetForeground(dpy, m->dc.gc, col[ColBG]); + XSetForeground(dpy, m->dc.gc, col[invert ? ColFG : ColBG]); XFillRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); if(!text) return; @@ -660,7 +656,7 @@ drawtext(Monitor *m, const char *text, unsigned long col[ColLast]) { } if(w > m->dc.w) return; /* too long */ - XSetForeground(dpy, m->dc.gc, col[ColFG]); + XSetForeground(dpy, m->dc.gc, col[invert ? ColBG : ColFG]); if(m->dc.font.set) XmbDrawString(dpy, m->dc.drawable, m->dc.font.set, m->dc.gc, x, y, buf, len); else @@ -999,6 +995,16 @@ isprotodel(Client *c) { } Bool +isurgent(int monitor, unsigned int t) { + Client *c; + + for(c = clients; c; c = c->next) + if(c->monitor == monitor && c->isurgent && c->tags[t]) + return True; + return False; +} + +Bool isvisible(Client *c, int monitor) { unsigned int i; @@ -1183,7 +1189,10 @@ movemouse(Client *c) { ny = m->way; else if(abs((m->way + m->wah) - (ny + c->h + 2 * c->border)) < SNAP) ny = m->way + m->wah - c->h - 2 * c->border; - resize(c, nx, ny, c->w, c->h, False); + if((monitors[selmonitor].layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) + togglefloating(NULL); + if((monitors[selmonitor].layout->arrange == floating) || c->isfloating) + resize(c, nx, ny, c->w, c->h, False); memcpy(c->tags, monitors[monitorat()].seltags, sizeof initags); break; } @@ -1215,6 +1224,10 @@ propertynotify(XEvent *e) { case XA_WM_NORMAL_HINTS: updatesizehints(c); break; + case XA_WM_HINTS: + updatewmhints(c); + drawbar(); + break; } if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); @@ -1342,7 +1355,10 @@ resizemouse(Client *c) { nw = 1; if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0) nh = 1; - resize(c, c->x, c->y, nw, nh, True); + if((monitors[selmonitor].layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) + togglefloating(NULL); + if((monitors[selmonitor].layout->arrange == floating) || c->isfloating) + resize(c, c->x, c->y, nw, nh, True); break; } } @@ -1708,12 +1724,13 @@ tile(void) { for(n = 0, c = nexttiled(clients, i); c; c = nexttiled(c->next, i)) n++; + /* window geoms */ + mw = (n == 1) ? m->waw : m->mwfact * m->waw; + th = (n > 1) ? m->wah / (n - 1) : 0; + if(n > 1 && th < bh) + th = m->wah; + for(j = 0, c = mc = nexttiled(clients, i); c; c = nexttiled(c->next, i)) { - /* window geoms */ - mw = (n == 1) ? m->waw : m->mwfact * m->waw; - th = (n > 1) ? m->wah / (n - 1) : 0; - if(n > 1 && th < bh) - th = m->wah; if(j == 0) { /* master */ nx = m->wax; ny = m->way; @@ -1916,6 +1933,16 @@ updatetitle(Client *c) { gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name); } +void +updatewmhints(Client *c) { + XWMHints *wmh; + + if((wmh = XGetWMHints(dpy, c->win))) { + c->isurgent = (wmh->flags & XUrgencyHint) ? True : False; + XFree(wmh); + } +} + /* There's no way to check accesses to destroyed windows, thus those cases are * ignored (especially on UnmapNotify's). Other types of errors call Xlibs * default error handler, which may call exit. */ @@ -1951,14 +1978,17 @@ xerrorstart(Display *dsply, XErrorEvent *ee) { void view(const char *arg) { unsigned int i; - + Bool tmp[LENGTH(tags)]; Monitor *m = &monitors[monitorat()]; - memcpy(m->prevtags, m->seltags, sizeof initags); for(i = 0; i < LENGTH(tags); i++) - m->seltags[i] = (NULL == arg); - m->seltags[idxoftag(arg)] = True; - arrange(); + tmp[i] = (NULL == arg); + tmp[idxoftag(arg)] = True; + if(memcmp(m->seltags, tmp, sizeof initags) != 0) { + memcpy(m->prevtags, m->seltags, sizeof initags); + memcpy(m->seltags, tmp, sizeof initags); + arrange(); + } } void