dwm.c
changeset 1184 bf63402f3b33
parent 1183 b20561489ffb
child 1185 e6b4b21680be
equal deleted inserted replaced
1183:b20561489ffb 1184:bf63402f3b33
   212 /* variables */
   212 /* variables */
   213 char stext[256];
   213 char stext[256];
   214 int screen, sx, sy, sw, sh;
   214 int screen, sx, sy, sw, sh;
   215 int (*xerrorxlib)(Display *, XErrorEvent *);
   215 int (*xerrorxlib)(Display *, XErrorEvent *);
   216 int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
   216 int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
   217 int viewtags_set = 0;
   217 int seltags = 0;
   218 double mfact;
   218 double mfact;
   219 unsigned int numlockmask = 0;
   219 unsigned int numlockmask = 0;
   220 void (*handler[LASTEvent]) (XEvent *) = {
   220 void (*handler[LASTEvent]) (XEvent *) = {
   221 	[ButtonPress] = buttonpress,
   221 	[ButtonPress] = buttonpress,
   222 	[ConfigureRequest] = configurerequest,
   222 	[ConfigureRequest] = configurerequest,
   232 	[UnmapNotify] = unmapnotify
   232 	[UnmapNotify] = unmapnotify
   233 };
   233 };
   234 Atom wmatom[WMLast], netatom[NetLast];
   234 Atom wmatom[WMLast], netatom[NetLast];
   235 Bool otherwm, readin;
   235 Bool otherwm, readin;
   236 Bool running = True;
   236 Bool running = True;
   237 Bool *seltags;
   237 Bool *tagset[2];
   238 Bool *viewtags[2];
       
   239 Client *clients = NULL;
   238 Client *clients = NULL;
   240 Client *sel = NULL;
   239 Client *sel = NULL;
   241 Client *stack = NULL;
   240 Client *stack = NULL;
   242 Cursor cursor[CurLast];
   241 Cursor cursor[CurLast];
   243 Display *dpy;
   242 Display *dpy;
   276 	if(ch.res_class)
   275 	if(ch.res_class)
   277 		XFree(ch.res_class);
   276 		XFree(ch.res_class);
   278 	if(ch.res_name)
   277 	if(ch.res_name)
   279 		XFree(ch.res_name);
   278 		XFree(ch.res_name);
   280 	if(!matched)
   279 	if(!matched)
   281 		memcpy(c->tags, seltags, TAGSZ);
   280 		memcpy(c->tags, tagset[seltags], TAGSZ);
   282 }
   281 }
   283 
   282 
   284 void
   283 void
   285 arrange(void) {
   284 arrange(void) {
   286 	Client *c;
   285 	Client *c;
   536 		dc.x += bgw;
   535 		dc.x += bgw;
   537 	}
   536 	}
   538 	for(c = stack; c && !isvisible(c); c = c->snext);
   537 	for(c = stack; c && !isvisible(c); c = c->snext);
   539 	for(i = 0; i < LENGTH(tags); i++) {
   538 	for(i = 0; i < LENGTH(tags); i++) {
   540 		dc.w = textw(tags[i]);
   539 		dc.w = textw(tags[i]);
   541 		if(seltags[i]) {
   540 		if(tagset[seltags][i]) {
   542 			drawtext(tags[i], dc.sel, isurgent(i));
   541 			drawtext(tags[i], dc.sel, isurgent(i));
   543 			drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel);
   542 			drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel);
   544 		}
   543 		}
   545 		else {
   544 		else {
   546 			drawtext(tags[i], dc.norm, isurgent(i));
   545 			drawtext(tags[i], dc.norm, isurgent(i));
   931 Bool
   930 Bool
   932 isvisible(Client *c) {
   931 isvisible(Client *c) {
   933 	unsigned int i;
   932 	unsigned int i;
   934 
   933 
   935 	for(i = 0; i < LENGTH(tags); i++)
   934 	for(i = 0; i < LENGTH(tags); i++)
   936 		if(c->tags[i] && seltags[i])
   935 		if(c->tags[i] && tagset[seltags][i])
   937 			return True;
   936 			return True;
   938 	return False;
   937 	return False;
   939 }
   938 }
   940 
   939 
   941 void
   940 void
  1503 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1502 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1504 	if(!dc.font.set)
  1503 	if(!dc.font.set)
  1505 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1504 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1506 
  1505 
  1507 	/* init tags */
  1506 	/* init tags */
  1508 	viewtags[0] = emallocz(TAGSZ);
  1507 	tagset[0] = emallocz(TAGSZ);
  1509 	viewtags[1] = emallocz(TAGSZ);
  1508 	tagset[1] = emallocz(TAGSZ);
  1510 	viewtags[0][0] = viewtags[1][0] = True;
  1509 	tagset[0][0] = tagset[1][0] = True;
  1511 	seltags = viewtags[0];
       
  1512 
  1510 
  1513 	/* init bar */
  1511 	/* init bar */
  1514 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1512 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1515 		w = textw(layouts[i].symbol);
  1513 		w = textw(layouts[i].symbol);
  1516 		blw = MAX(blw, w);
  1514 		blw = MAX(blw, w);
  1699 void
  1697 void
  1700 toggleview(const char *arg) {
  1698 toggleview(const char *arg) {
  1701 	unsigned int i, j;
  1699 	unsigned int i, j;
  1702 
  1700 
  1703 	i = idxoftag(arg);
  1701 	i = idxoftag(arg);
  1704 	seltags[i] = !seltags[i];
  1702 	tagset[seltags][i] = !tagset[seltags][i];
  1705 	for(j = 0; j < LENGTH(tags) && !seltags[j]; j++);
  1703 	for(j = 0; j < LENGTH(tags) && !tagset[seltags][j]; j++);
  1706 	if(j == LENGTH(tags))
  1704 	if(j == LENGTH(tags))
  1707 		seltags[i] = True; /* at least one tag must be viewed */
  1705 		tagset[seltags][i] = True; /* at least one tag must be viewed */
  1708 	arrange();
  1706 	arrange();
  1709 }
  1707 }
  1710 
  1708 
  1711 void
  1709 void
  1712 unban(Client *c) {
  1710 unban(Client *c) {
  1835 
  1833 
  1836 	for(i = 0; i < LENGTH(tags); i++)
  1834 	for(i = 0; i < LENGTH(tags); i++)
  1837 		tmp[i] = (NULL == arg);
  1835 		tmp[i] = (NULL == arg);
  1838 	tmp[idxoftag(arg)] = True;
  1836 	tmp[idxoftag(arg)] = True;
  1839 
  1837 
  1840 	if(memcmp(seltags, tmp, TAGSZ) != 0) {
  1838 	seltags ^= 1; /* toggle sel tagset */
  1841 		seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
  1839 	if(memcmp(tagset[seltags ^ 1], tmp, TAGSZ) != 0)
  1842 		memcpy(seltags, tmp, TAGSZ);
  1840 		memcpy(tagset[seltags], tmp, TAGSZ);
  1843 		arrange();
  1841 	arrange();
  1844 	}
       
  1845 	else
       
  1846 		viewprevtag(NULL);
       
  1847 }
  1842 }
  1848 
  1843 
  1849 void
  1844 void
  1850 viewprevtag(const char *arg) {
  1845 viewprevtag(const char *arg) {
  1851 	seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
  1846 	seltags ^= 1; /* toggle sel tagset */
  1852 	arrange();
  1847 	arrange();
  1853 }
  1848 }
  1854 
  1849 
  1855 /* There's no way to check accesses to destroyed windows, thus those cases are
  1850 /* There's no way to check accesses to destroyed windows, thus those cases are
  1856  * ignored (especially on UnmapNotify's).  Other types of errors call Xlibs
  1851  * ignored (especially on UnmapNotify's).  Other types of errors call Xlibs