implemented urgent hint handling (with multihead support) 012710a3
anselm@aab · 2008-02-11 20:34 1 file(s) · +37 −11
dwm.c +37 −11
68 68
	int minax, maxax, minay, maxay;
69 69
	long flags;
70 70
	unsigned int border, oldborder;
71 -
	Bool isbanned, isfixed, isfloating;
71 +
	Bool isbanned, isfixed, isfloating, isurgent;
72 72
	Bool *tags;
73 73
	Client *next;
74 74
	Client *prev;
146 146
void detachstack(Client *c);
147 147
void drawbar(void);
148 148
void drawsquare(Monitor *, Bool filled, Bool empty, unsigned long col[ColLast]);
149 -
void drawtext(Monitor *, const char *text, unsigned long col[ColLast]);
149 +
void drawtext(Monitor *, const char *text, unsigned long col[ColLast], Bool invert);
150 150
void *emallocz(unsigned int size);
151 151
void enternotify(XEvent *e);
152 152
void eprint(const char *errstr, ...);
166 166
void initfont(Monitor*, const char *fontstr);
167 167
Bool isoccupied(Monitor *m, unsigned int t);
168 168
Bool isprotodel(Client *c);
169 +
Bool isurgent(int monitor, unsigned int t);
169 170
Bool isvisible(Client *c, int monitor);
170 171
void keypress(XEvent *e);
171 172
void killclient(const char *arg);
201 202
void updatebarpos(Monitor *m);
202 203
void updatesizehints(Client *c);
203 204
void updatetitle(Client *c);
205 +
void updatewmhints(Client *c);
204 206
void view(const char *arg);
205 207
void viewprevtag(const char *arg);	/* views previous selected tags */
206 208
int xerror(Display *dpy, XErrorEvent *ee);
573 575
		for(j = 0; j < LENGTH(tags); j++) {
574 576
			m->dc.w = textw(m, tags[j]);
575 577
			if(m->seltags[j]) {
576 -
				drawtext(m, tags[j], m->dc.sel);
578 +
				drawtext(m, tags[j], m->dc.sel, isurgent(i, j));
577 579
				drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, isoccupied(m, j), m->dc.sel);
578 580
			}
579 581
			else {
580 -
				drawtext(m, tags[j], m->dc.norm);
582 +
				drawtext(m, tags[j], m->dc.norm, isurgent(i, j));
581 583
				drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, isoccupied(m, j), m->dc.norm);
582 584
			}
583 585
			m->dc.x += m->dc.w;
584 586
		}
585 587
		m->dc.w = blw;
586 -
		drawtext(m, m->layout->symbol, m->dc.norm);
588 +
		drawtext(m, m->layout->symbol, m->dc.norm, False);
587 589
		x = m->dc.x + m->dc.w;
588 590
		m->dc.w = textw(m, stext);
589 591
		m->dc.x = m->sw - m->dc.w;
591 593
			m->dc.x = x;
592 594
			m->dc.w = m->sw - x;
593 595
		}
594 -
		drawtext(m, stext, m->dc.norm);
596 +
		drawtext(m, stext, m->dc.norm, False);
595 597
		if((m->dc.w = m->dc.x - x) > bh) {
596 598
			m->dc.x = x;
597 599
			if(sel && sel->monitor == selmonitor) {
598 -
				drawtext(m, sel->name, m->dc.sel);
600 +
				drawtext(m, sel->name, m->dc.sel, False);
599 601
				drawsquare(m, False, sel->isfloating, m->dc.sel);
600 602
			}
601 603
			else
602 -
				drawtext(m, NULL, m->dc.norm);
604 +
				drawtext(m, NULL, m->dc.norm, False);
603 605
		}
604 606
		XCopyArea(dpy, m->dc.drawable, m->barwin, m->dc.gc, 0, 0, m->sw, bh, 0, 0);
605 607
		XSync(dpy, False);
628 630
}
629 631
630 632
void
631 -
drawtext(Monitor *m, const char *text, unsigned long col[ColLast]) {
633 +
drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert) {
632 634
	int x, y, w, h;
633 635
	static char buf[256];
634 636
	unsigned int len, olen;
635 637
	XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h };
636 638
637 -
	XSetForeground(dpy, m->dc.gc, col[ColBG]);
639 +
	XSetForeground(dpy, m->dc.gc, col[invert ? ColFG : ColBG]);
638 640
	XFillRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1);
639 641
	if(!text)
640 642
		return;
660 662
	}
661 663
	if(w > m->dc.w)
662 664
		return; /* too long */
663 -
	XSetForeground(dpy, m->dc.gc, col[ColFG]);
665 +
	XSetForeground(dpy, m->dc.gc, col[invert ? ColBG : ColFG]);
664 666
	if(m->dc.font.set)
665 667
		XmbDrawString(dpy, m->dc.drawable, m->dc.font.set, m->dc.gc, x, y, buf, len);
666 668
	else
999 1001
}
1000 1002
1001 1003
Bool
1004 +
isurgent(int monitor, unsigned int t) {
1005 +
	Client *c;
1006 +
1007 +
	for(c = clients; c; c = c->next)
1008 +
		if(c->monitor == monitor && c->isurgent && c->tags[t])
1009 +
			return True;
1010 +
	return False;
1011 +
}
1012 +
1013 +
Bool
1002 1014
isvisible(Client *c, int monitor) {
1003 1015
	unsigned int i;
1004 1016
1214 1226
				break;
1215 1227
			case XA_WM_NORMAL_HINTS:
1216 1228
				updatesizehints(c);
1229 +
				break;
1230 +
			case XA_WM_HINTS:
1231 +
				updatewmhints(c);
1232 +
				drawbar();
1217 1233
				break;
1218 1234
		}
1219 1235
		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
1914 1930
updatetitle(Client *c) {
1915 1931
	if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
1916 1932
		gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);
1933 +
}
1934 +
1935 +
void
1936 +
updatewmhints(Client *c) {
1937 +
	XWMHints *wmh;
1938 +
1939 +
	if((wmh = XGetWMHints(dpy, c->win))) {
1940 +
		c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
1941 +
		XFree(wmh);
1942 +
	}
1917 1943
}
1918 1944
1919 1945
/* There's no way to check accesses to destroyed windows, thus those cases are