dwm.c
changeset 1040 b8408fc315df
parent 1039 5fa681ba70ae
child 1041 ee04fab6ff9c
equal deleted inserted replaced
1039:5fa681ba70ae 1040:b8408fc315df
   230 Regs *regs = NULL;
   230 Regs *regs = NULL;
   231 
   231 
   232 /* configuration, allows nested code to access above variables */
   232 /* configuration, allows nested code to access above variables */
   233 #include "config.h"
   233 #include "config.h"
   234 
   234 
   235 /* statically define the number of tags. */
   235 #define NTAGS (sizeof tags / sizeof tags[0])
   236 unsigned int ntags = sizeof tags / sizeof tags[0];
   236 Bool seltags[NTAGS] = {[0] = True};
   237 Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True};
   237 Bool prevtags[NTAGS] = {[0] = True};
   238 Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True};
       
   239 
   238 
   240 /* function implementations */
   239 /* function implementations */
   241 void
   240 void
   242 applyrules(Client *c) {
   241 applyrules(Client *c) {
   243 	static char buf[512];
   242 	static char buf[512];
   252 			ch.res_class ? ch.res_class : "",
   251 			ch.res_class ? ch.res_class : "",
   253 			ch.res_name ? ch.res_name : "", c->name);
   252 			ch.res_name ? ch.res_name : "", c->name);
   254 	for(i = 0; i < nrules; i++)
   253 	for(i = 0; i < nrules; i++)
   255 		if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
   254 		if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
   256 			c->isfloating = rules[i].isfloating;
   255 			c->isfloating = rules[i].isfloating;
   257 			for(j = 0; regs[i].tagregex && j < ntags; j++) {
   256 			for(j = 0; regs[i].tagregex && j < NTAGS; j++) {
   258 				if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
   257 				if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
   259 					matched = True;
   258 					matched = True;
   260 					c->tags[j] = True;
   259 					c->tags[j] = True;
   261 				}
   260 				}
   262 			}
   261 			}
   311 	Client *c;
   310 	Client *c;
   312 	XButtonPressedEvent *ev = &e->xbutton;
   311 	XButtonPressedEvent *ev = &e->xbutton;
   313 
   312 
   314 	if(barwin == ev->window) {
   313 	if(barwin == ev->window) {
   315 		x = 0;
   314 		x = 0;
   316 		for(i = 0; i < ntags; i++) {
   315 		for(i = 0; i < NTAGS; i++) {
   317 			x += textw(tags[i]);
   316 			x += textw(tags[i]);
   318 			if(ev->x < x) {
   317 			if(ev->x < x) {
   319 				if(ev->button == Button1) {
   318 				if(ev->button == Button1) {
   320 					if(ev->state & MODKEY)
   319 					if(ev->state & MODKEY)
   321 						tag(tags[i]);
   320 						tag(tags[i]);
   535 void
   534 void
   536 drawbar(void) {
   535 drawbar(void) {
   537 	int i, x;
   536 	int i, x;
   538 
   537 
   539 	dc.x = dc.y = 0;
   538 	dc.x = dc.y = 0;
   540 	for(i = 0; i < ntags; i++) {
   539 	for(i = 0; i < NTAGS; i++) {
   541 		dc.w = textw(tags[i]);
   540 		dc.w = textw(tags[i]);
   542 		if(seltags[i]) {
   541 		if(seltags[i]) {
   543 			drawtext(tags[i], dc.sel);
   542 			drawtext(tags[i], dc.sel);
   544 			drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
   543 			drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
   545 		}
   544 		}
   845 
   844 
   846 unsigned int
   845 unsigned int
   847 idxoftag(const char *tag) {
   846 idxoftag(const char *tag) {
   848 	unsigned int i;
   847 	unsigned int i;
   849 
   848 
   850 	for(i = 0; i < ntags; i++)
   849 	for(i = 0; (i < NTAGS) && (tags[i] != tag); i++);
   851 		if(tags[i] == tag)
   850 	return (i < NTAGS) ? i : 0;
   852 			return i;
       
   853 	return 0;
       
   854 }
   851 }
   855 
   852 
   856 void
   853 void
   857 initfont(const char *fontstr) {
   854 initfont(const char *fontstr) {
   858 	char *def, **missing;
   855 	char *def, **missing;
   928 
   925 
   929 Bool
   926 Bool
   930 isvisible(Client *c) {
   927 isvisible(Client *c) {
   931 	unsigned int i;
   928 	unsigned int i;
   932 
   929 
   933 	for(i = 0; i < ntags; i++)
   930 	for(i = 0; i < NTAGS; i++)
   934 		if(c->tags[i] && seltags[i])
   931 		if(c->tags[i] && seltags[i])
   935 			return True;
   932 			return True;
   936 	return False;
   933 	return False;
   937 }
   934 }
   938 
   935 
  1138 	if((c = getclient(ev->window))) {
  1135 	if((c = getclient(ev->window))) {
  1139 		switch (ev->atom) {
  1136 		switch (ev->atom) {
  1140 			default: break;
  1137 			default: break;
  1141 			case XA_WM_TRANSIENT_FOR:
  1138 			case XA_WM_TRANSIENT_FOR:
  1142 				XGetTransientForHint(dpy, c->win, &trans);
  1139 				XGetTransientForHint(dpy, c->win, &trans);
  1143 				if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
  1140 				if(!c->isfloating && (c->isfloating = (NULL != getclient(trans))))
  1144 					arrange();
  1141 					arrange();
  1145 				break;
  1142 				break;
  1146 			case XA_WM_NORMAL_HINTS:
  1143 			case XA_WM_NORMAL_HINTS:
  1147 				updatesizehints(c);
  1144 				updatesizehints(c);
  1148 				break;
  1145 				break;
  1540 tag(const char *arg) {
  1537 tag(const char *arg) {
  1541 	unsigned int i;
  1538 	unsigned int i;
  1542 
  1539 
  1543 	if(!sel)
  1540 	if(!sel)
  1544 		return;
  1541 		return;
  1545 	for(i = 0; i < ntags; i++)
  1542 	for(i = 0; i < NTAGS; i++)
  1546 		sel->tags[i] = arg == NULL;
  1543 		sel->tags[i] = (NULL == arg);
  1547 	i = idxoftag(arg);
  1544 	sel->tags[idxoftag(arg)] = True;
  1548 	if(i >= 0 && i < ntags)
       
  1549 		sel->tags[i] = True;
       
  1550 	arrange();
  1545 	arrange();
  1551 }
  1546 }
  1552 
  1547 
  1553 unsigned int
  1548 unsigned int
  1554 textnw(const char *text, unsigned int len) {
  1549 textnw(const char *text, unsigned int len) {
  1660 
  1655 
  1661 	if(!sel)
  1656 	if(!sel)
  1662 		return;
  1657 		return;
  1663 	i = idxoftag(arg);
  1658 	i = idxoftag(arg);
  1664 	sel->tags[i] = !sel->tags[i];
  1659 	sel->tags[i] = !sel->tags[i];
  1665 	for(j = 0; j < ntags && !sel->tags[j]; j++);
  1660 	for(j = 0; j < NTAGS && !sel->tags[j]; j++);
  1666 	if(j == ntags)
  1661 	if(j == NTAGS)
  1667 		sel->tags[i] = True;
  1662 		sel->tags[i] = True; /* at least one tag must be enabled */
  1668 	arrange();
  1663 	arrange();
  1669 }
  1664 }
  1670 
  1665 
  1671 void
  1666 void
  1672 toggleview(const char *arg) {
  1667 toggleview(const char *arg) {
  1673 	unsigned int i, j;
  1668 	unsigned int i, j;
  1674 
  1669 
  1675 	i = idxoftag(arg);
  1670 	i = idxoftag(arg);
  1676 	seltags[i] = !seltags[i];
  1671 	seltags[i] = !seltags[i];
  1677 	for(j = 0; j < ntags && !seltags[j]; j++);
  1672 	for(j = 0; j < NTAGS && !seltags[j]; j++);
  1678 	if(j == ntags)
  1673 	if(j == NTAGS)
  1679 		seltags[i] = True; /* at least one tag must be viewed */
  1674 		seltags[i] = True; /* at least one tag must be viewed */
  1680 	arrange();
  1675 	arrange();
  1681 }
  1676 }
  1682 
  1677 
  1683 void
  1678 void
  1839 void
  1834 void
  1840 view(const char *arg) {
  1835 view(const char *arg) {
  1841 	unsigned int i;
  1836 	unsigned int i;
  1842 
  1837 
  1843 	memcpy(prevtags, seltags, sizeof seltags);
  1838 	memcpy(prevtags, seltags, sizeof seltags);
  1844 	for(i = 0; i < ntags; i++)
  1839 	for(i = 0; i < NTAGS; i++)
  1845 		seltags[i] = arg == NULL;
  1840 		seltags[i] = arg == NULL;
  1846 	i = idxoftag(arg);
  1841 	seltags[idxoftag(arg)] = True;
  1847 	if(i >= 0 && i < ntags)
       
  1848 		seltags[i] = True;
       
  1849 	arrange();
  1842 	arrange();
  1850 }
  1843 }
  1851 
  1844 
  1852 void
  1845 void
  1853 viewprevtag(const char *arg) {
  1846 viewprevtag(const char *arg) {