dwm.c
changeset 1109 55e2f7e96b71
parent 1108 aab1c3addbaf
child 1110 227f2d07c63f
equal deleted inserted replaced
1108:aab1c3addbaf 1109:55e2f7e96b71
   225 	[MapRequest] = maprequest,
   225 	[MapRequest] = maprequest,
   226 	[PropertyNotify] = propertynotify,
   226 	[PropertyNotify] = propertynotify,
   227 	[UnmapNotify] = unmapnotify
   227 	[UnmapNotify] = unmapnotify
   228 };
   228 };
   229 Atom wmatom[WMLast], netatom[NetLast];
   229 Atom wmatom[WMLast], netatom[NetLast];
   230 Bool isxinerama = False;
       
   231 Bool domwfact = True;
   230 Bool domwfact = True;
   232 Bool dozoom = True;
   231 Bool dozoom = True;
   233 Bool otherwm, readin;
   232 Bool otherwm, readin;
   234 Bool running = True;
   233 Bool running = True;
   235 Bool *prevtags;
   234 Bool *prevtags;
   244 View *selview;
   243 View *selview;
   245 Window root;
   244 Window root;
   246 
   245 
   247 /* configuration, allows nested code to access above variables */
   246 /* configuration, allows nested code to access above variables */
   248 #include "config.h"
   247 #include "config.h"
       
   248 #define TAGSZ (LENGTH(tags) * sizeof(Bool))
   249 
   249 
   250 /* function implementations */
   250 /* function implementations */
   251 void
   251 void
   252 addtag(Client *c, const char *t) {
   252 addtag(Client *c, const char *t) {
   253 	unsigned int i, tidx = idxoftag(t);
   253 	unsigned int i, tidx = idxoftag(t);
   284 	if(ch.res_class)
   284 	if(ch.res_class)
   285 		XFree(ch.res_class);
   285 		XFree(ch.res_class);
   286 	if(ch.res_name)
   286 	if(ch.res_name)
   287 		XFree(ch.res_name);
   287 		XFree(ch.res_name);
   288 	if(!matched) {
   288 	if(!matched) {
   289 		memcpy(c->tags, seltags, sizeof initags);
   289 		memcpy(c->tags, seltags, TAGSZ);
   290 		c->view = selview;
   290 		c->view = selview;
   291 	}
   291 	}
   292 }
   292 }
   293 
   293 
   294 void
   294 void
   652 void
   652 void
   653 enternotify(XEvent *e) {
   653 enternotify(XEvent *e) {
   654 	Client *c;
   654 	Client *c;
   655 	XCrossingEvent *ev = &e->xcrossing;
   655 	XCrossingEvent *ev = &e->xcrossing;
   656 
   656 
   657 	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) {
   657 	if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
   658 		if(!isxinerama || ev->window != root)
   658 		return;
   659 			return;
       
   660 	}
       
   661 	if((c = getclient(ev->window)))
   659 	if((c = getclient(ev->window)))
   662 		focus(c);
   660 		focus(c);
   663 	else
   661 	else
   664 		focus(NULL);
   662 		focus(NULL);
   665 }
   663 }
  1040 	Status rettrans;
  1038 	Status rettrans;
  1041 	Window trans;
  1039 	Window trans;
  1042 	XWindowChanges wc;
  1040 	XWindowChanges wc;
  1043 
  1041 
  1044 	c = emallocz(sizeof(Client));
  1042 	c = emallocz(sizeof(Client));
  1045 	c->tags = emallocz(sizeof initags);
  1043 	c->tags = emallocz(TAGSZ);
  1046 	c->win = w;
  1044 	c->win = w;
  1047 
  1045 
  1048 	applyrules(c);
  1046 	applyrules(c);
  1049 
  1047 
  1050 	v = c->view;
  1048 	v = c->view;
  1080 	grabbuttons(c, False);
  1078 	grabbuttons(c, False);
  1081 	updatetitle(c);
  1079 	updatetitle(c);
  1082 	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
  1080 	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
  1083 		for(t = clients; t && t->win != trans; t = t->next);
  1081 		for(t = clients; t && t->win != trans; t = t->next);
  1084 	if(t)
  1082 	if(t)
  1085 		memcpy(c->tags, t->tags, sizeof initags);
  1083 		memcpy(c->tags, t->tags, TAGSZ);
  1086 	if(!c->isfloating)
  1084 	if(!c->isfloating)
  1087 		c->isfloating = (rettrans == Success) || c->isfixed;
  1085 		c->isfloating = (rettrans == Success) || c->isfixed;
  1088 	attach(c);
  1086 	attach(c);
  1089 	attachstack(c);
  1087 	attachstack(c);
  1090 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
  1088 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
  1499 	arrange();
  1497 	arrange();
  1500 }
  1498 }
  1501 
  1499 
  1502 void
  1500 void
  1503 setup(void) {
  1501 setup(void) {
  1504 	unsigned int i;
  1502 	unsigned int i, j;
  1505 	View *v;
  1503 	View *v;
  1506 	XSetWindowAttributes wa;
  1504 	XSetWindowAttributes wa;
  1507 	XineramaScreenInfo *info = NULL;
  1505 	XineramaScreenInfo *info = NULL;
  1508 
  1506 
  1509 	/* init atoms */
  1507 	/* init atoms */
  1517 	/* init cursors */
  1515 	/* init cursors */
  1518 	wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  1516 	wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  1519 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  1517 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  1520 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  1518 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  1521 
  1519 
  1522 	if((isxinerama = XineramaIsActive(dpy)))
  1520 	if(XineramaIsActive(dpy))
  1523 		info = XineramaQueryScreens(dpy, &nviews);
  1521 		info = XineramaQueryScreens(dpy, &nviews);
       
  1522 
  1524 #if defined(AIM_XINERAMA)
  1523 #if defined(AIM_XINERAMA)
  1525 isxinerama = True;
       
  1526 nviews = 2; /* aim Xinerama */
  1524 nviews = 2; /* aim Xinerama */
  1527 #endif
  1525 #endif
  1528 	views = emallocz(nviews * sizeof(View));
  1526 	views = emallocz(nviews * sizeof(View));
  1529 
  1527 
  1530 	screen = DefaultScreen(dpy);
  1528 	screen = DefaultScreen(dpy);
  1549 		i = textw(layouts[i].symbol);
  1547 		i = textw(layouts[i].symbol);
  1550 		if(i > blw)
  1548 		if(i > blw)
  1551 			blw = i;
  1549 			blw = i;
  1552 	}
  1550 	}
  1553 
  1551 
  1554 	seltags = emallocz(sizeof initags);
  1552 	seltags = emallocz(TAGSZ);
  1555 	prevtags = emallocz(sizeof initags);
  1553 	prevtags = emallocz(TAGSZ);
  1556 	memcpy(seltags, initags, sizeof initags);
  1554 
  1557 	memcpy(prevtags, initags, sizeof initags);
  1555 	/* check, if vtags need assistance, because there is only 1 view */
       
  1556 	if(nviews == 1)
       
  1557 		for(i = 0; i < LENGTH(tags); i++)
       
  1558 			vtags[i] = 0;
  1558 
  1559 
  1559 	for(i = 0; i < nviews; i++) {
  1560 	for(i = 0; i < nviews; i++) {
  1560 		/* init geometry */
  1561 		/* init geometry */
  1561 		v = &views[i];
  1562 		v = &views[i];
  1562 
  1563 
  1563 		if(nviews != 1 && isxinerama) {
  1564 		/* select first tag in each view */
       
  1565 		for(j = 0; j < LENGTH(tags); j++)
       
  1566 			if(vtags[j] == i) {
       
  1567 				seltags[j] = prevtags[j] = True; 
       
  1568 				break;
       
  1569 			}
       
  1570 
       
  1571 
       
  1572 		if(info) {
  1564 
  1573 
  1565 #if defined(AIM_XINERAMA)
  1574 #if defined(AIM_XINERAMA)
  1566 v->w = DisplayWidth(dpy, screen) / 2;
  1575 v->w = DisplayWidth(dpy, screen) / 2;
  1567 v->x = (i == 0) ? 0 : v->w;
  1576 v->x = (i == 0) ? 0 : v->w;
  1568 v->y = 0;
  1577 v->y = 0;
  1691 	if(n > 1 && th < bh)
  1700 	if(n > 1 && th < bh)
  1692 		th = v->wah;
  1701 		th = v->wah;
  1693 
  1702 
  1694 	for(i = 0, c = mc = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
  1703 	for(i = 0, c = mc = nexttiled(clients, v); c; c = nexttiled(c->next, v)) {
  1695 		if(i == 0) { /* master */
  1704 		if(i == 0) { /* master */
  1696 			nx = v->wax;
       
  1697 			ny = v->way;
       
  1698 			nw = mw - 2 * c->border;
  1705 			nw = mw - 2 * c->border;
  1699 			nh = v->wah - 2 * c->border;
  1706 			nh = v->wah - 2 * c->border;
  1700 		}
  1707 		}
  1701 		else {  /* tile window */
  1708 		else {  /* tile window */
  1702 			if(i == 1) {
  1709 			if(i == 1) {
  1906 
  1913 
  1907 	for(i = 0; i < LENGTH(tags); i++)
  1914 	for(i = 0; i < LENGTH(tags); i++)
  1908 		tmp[i] = (NULL == arg);
  1915 		tmp[i] = (NULL == arg);
  1909 	tmp[idxoftag(arg)] = True;
  1916 	tmp[idxoftag(arg)] = True;
  1910 
  1917 
  1911 	if(memcmp(seltags, tmp, sizeof initags) != 0) {
  1918 	if(memcmp(seltags, tmp, TAGSZ) != 0) {
  1912 		memcpy(prevtags, seltags, sizeof initags);
  1919 		memcpy(prevtags, seltags, TAGSZ);
  1913 		memcpy(seltags, tmp, sizeof initags);
  1920 		memcpy(seltags, tmp, TAGSZ);
  1914 		arrange();
  1921 		arrange();
  1915 	}
  1922 	}
  1916 }
  1923 }
  1917 
  1924 
  1918 View *
  1925 View *
  1932 
  1939 
  1933 void
  1940 void
  1934 viewprevtag(const char *arg) {
  1941 viewprevtag(const char *arg) {
  1935 	static Bool tmp[LENGTH(tags)];
  1942 	static Bool tmp[LENGTH(tags)];
  1936 
  1943 
  1937 	memcpy(tmp, seltags, sizeof initags);
  1944 	memcpy(tmp, seltags, TAGSZ);
  1938 	memcpy(seltags, prevtags, sizeof initags);
  1945 	memcpy(seltags, prevtags, TAGSZ);
  1939 	memcpy(prevtags, tmp, sizeof initags);
  1946 	memcpy(prevtags, tmp, TAGSZ);
  1940 	arrange();
  1947 	arrange();
  1941 }
  1948 }
  1942 
  1949 
  1943 /* There's no way to check accesses to destroyed windows, thus those cases are
  1950 /* There's no way to check accesses to destroyed windows, thus those cases are
  1944  * ignored (especially on UnmapNotify's).  Other types of errors call Xlibs
  1951  * ignored (especially on UnmapNotify's).  Other types of errors call Xlibs