dwm.c
changeset 1398 597063a22a73
parent 1397 4498d81938b0
child 1399 0decadd79fd5
equal deleted inserted replaced
1397:4498d81938b0 1398:597063a22a73
    36 #include <X11/Xlib.h>
    36 #include <X11/Xlib.h>
    37 #include <X11/Xproto.h>
    37 #include <X11/Xproto.h>
    38 #include <X11/Xutil.h>
    38 #include <X11/Xutil.h>
    39 #ifdef XINERAMA
    39 #ifdef XINERAMA
    40 #include <X11/extensions/Xinerama.h>
    40 #include <X11/extensions/Xinerama.h>
    41 #endif
    41 #endif /* XINERAMA */
    42 
    42 
    43 /* macros */
    43 /* macros */
    44 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    44 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    45 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    45 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    46 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    46 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    47 #define ISVISIBLE(x)            (x->tags & tagset[selmon->seltags])
    47 #define ISVISIBLE(x)            (x->tags & tagset[mon[x->mon].seltags])
    48 #define LENGTH(x)               (sizeof x / sizeof x[0])
    48 #define LENGTH(x)               (sizeof x / sizeof x[0])
    49 #define MAX(a, b)               ((a) > (b) ? (a) : (b))
    49 #define MAX(a, b)               ((a) > (b) ? (a) : (b))
    50 #define MIN(a, b)               ((a) < (b) ? (a) : (b))
    50 #define MIN(a, b)               ((a) < (b) ? (a) : (b))
    51 #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
    51 #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
    52 #define WIDTH(x)                ((x)->w + 2 * (x)->bw)
    52 #define WIDTH(x)                ((x)->w + 2 * (x)->bw)
   113 	void (*func)(const Arg *);
   113 	void (*func)(const Arg *);
   114 	const Arg arg;
   114 	const Arg arg;
   115 } Key;
   115 } Key;
   116 
   116 
   117 typedef struct {
   117 typedef struct {
   118 	const char *symbol;
   118 	char symbol[4];
   119 	void (*arrange)(void);
   119 	int by, btx;          /* bar geometry */
   120 } Layout;
   120 	int wx, wy, ww, wh;   /* window area  */
   121 
       
   122 typedef struct {
       
   123 	int wx, wy, ww, wh;
       
   124 	unsigned int seltags;
   121 	unsigned int seltags;
   125 	unsigned int sellt;
   122 	unsigned int sellt;
       
   123 	Bool showbar;
       
   124 	Bool topbar;
       
   125 	Window barwin;
   126 } Monitor;
   126 } Monitor;
       
   127 
       
   128 typedef struct {
       
   129 	const char *symbol;
       
   130 	void (*arrange)(Monitor *);
       
   131 } Layout;
   127 
   132 
   128 typedef struct {
   133 typedef struct {
   129 	const char *class;
   134 	const char *class;
   130 	const char *instance;
   135 	const char *instance;
   131 	const char *title;
   136 	const char *title;
   148 static void configurerequest(XEvent *e);
   153 static void configurerequest(XEvent *e);
   149 static void destroynotify(XEvent *e);
   154 static void destroynotify(XEvent *e);
   150 static void detach(Client *c);
   155 static void detach(Client *c);
   151 static void detachstack(Client *c);
   156 static void detachstack(Client *c);
   152 static void die(const char *errstr, ...);
   157 static void die(const char *errstr, ...);
   153 static void drawbar(void);
   158 static void drawbar(Monitor *m);
       
   159 static void drawbars();
   154 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
   160 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
   155 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
   161 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
   156 static void enternotify(XEvent *e);
   162 static void enternotify(XEvent *e);
   157 static void expose(XEvent *e);
   163 static void expose(XEvent *e);
   158 static void focus(Client *c);
   164 static void focus(Client *c);
   169 static void keypress(XEvent *e);
   175 static void keypress(XEvent *e);
   170 static void killclient(const Arg *arg);
   176 static void killclient(const Arg *arg);
   171 static void manage(Window w, XWindowAttributes *wa);
   177 static void manage(Window w, XWindowAttributes *wa);
   172 static void mappingnotify(XEvent *e);
   178 static void mappingnotify(XEvent *e);
   173 static void maprequest(XEvent *e);
   179 static void maprequest(XEvent *e);
   174 static void monocle(void);
   180 static void monocle(Monitor *m);
   175 static void movemouse(const Arg *arg);
   181 static void movemouse(const Arg *arg);
   176 static Client *nexttiled(Client *c);
   182 static Client *nexttiled(Monitor *m, Client *c);
   177 static void propertynotify(XEvent *e);
   183 static void propertynotify(XEvent *e);
   178 static void quit(const Arg *arg);
   184 static void quit(const Arg *arg);
   179 static void resize(Client *c, int x, int y, int w, int h);
   185 static void resize(Client *c, int x, int y, int w, int h);
   180 static void resizemouse(const Arg *arg);
   186 static void resizemouse(const Arg *arg);
   181 static void restack(void);
   187 static void restack(Monitor *m);
   182 static void run(void);
   188 static void run(void);
   183 static void scan(void);
   189 static void scan(void);
   184 static void setclientstate(Client *c, long state);
   190 static void setclientstate(Client *c, long state);
   185 static void setlayout(const Arg *arg);
   191 static void setlayout(const Arg *arg);
   186 static void setmfact(const Arg *arg);
   192 static void setmfact(const Arg *arg);
   188 static void showhide(Client *c);
   194 static void showhide(Client *c);
   189 static void sigchld(int signal);
   195 static void sigchld(int signal);
   190 static void spawn(const Arg *arg);
   196 static void spawn(const Arg *arg);
   191 static void tag(const Arg *arg);
   197 static void tag(const Arg *arg);
   192 static int textnw(const char *text, unsigned int len);
   198 static int textnw(const char *text, unsigned int len);
   193 static void tile(void);
   199 static void tile(Monitor *);
   194 static void togglebar(const Arg *arg);
   200 static void togglebar(const Arg *arg);
   195 static void togglefloating(const Arg *arg);
   201 static void togglefloating(const Arg *arg);
   196 static void toggletag(const Arg *arg);
   202 static void toggletag(const Arg *arg);
   197 static void toggleview(const Arg *arg);
   203 static void toggleview(const Arg *arg);
   198 static void unmanage(Client *c);
   204 static void unmanage(Client *c);
   199 static void unmapnotify(XEvent *e);
   205 static void unmapnotify(XEvent *e);
   200 static void updatebar(void);
       
   201 static void updategeom(void);
   206 static void updategeom(void);
   202 static void updatenumlockmask(void);
   207 static void updatenumlockmask(void);
   203 static void updatesizehints(Client *c);
   208 static void updatesizehints(Client *c);
   204 static void updatestatus(void);
   209 static void updatestatus(void);
   205 static void updatetitle(Client *c);
   210 static void updatetitle(Client *c);
   207 static void view(const Arg *arg);
   212 static void view(const Arg *arg);
   208 static int xerror(Display *dpy, XErrorEvent *ee);
   213 static int xerror(Display *dpy, XErrorEvent *ee);
   209 static int xerrordummy(Display *dpy, XErrorEvent *ee);
   214 static int xerrordummy(Display *dpy, XErrorEvent *ee);
   210 static int xerrorstart(Display *dpy, XErrorEvent *ee);
   215 static int xerrorstart(Display *dpy, XErrorEvent *ee);
   211 static void zoom(const Arg *arg);
   216 static void zoom(const Arg *arg);
       
   217 #ifdef XINERAMA
       
   218 static void focusmon(const Arg *arg);
       
   219 static void tagmon(const Arg *arg);
       
   220 #endif /* XINERAMA */
   212 
   221 
   213 /* variables */
   222 /* variables */
   214 static char stext[256];
   223 static char stext[256];
   215 static int screen;
   224 static int screen;
   216 static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */ 
   225 static int sx, sy, sw, sh;   /* X display screen geometry x, y, width, height */
   217 static int by, bh, blw;    /* bar geometry y, height and layout symbol width */
   226 static int bh, blw = 0;      /* bar geometry */
   218 static int (*xerrorxlib)(Display *, XErrorEvent *);
   227 static int (*xerrorxlib)(Display *, XErrorEvent *);
   219 static unsigned int numlockmask = 0;
   228 static unsigned int numlockmask = 0;
   220 static void (*handler[LASTEvent]) (XEvent *) = {
   229 static void (*handler[LASTEvent]) (XEvent *) = {
   221 	[ButtonPress] = buttonpress,
   230 	[ButtonPress] = buttonpress,
   222 	[ConfigureRequest] = configurerequest,
   231 	[ConfigureRequest] = configurerequest,
   241 static Display *dpy;
   250 static Display *dpy;
   242 static DC dc;
   251 static DC dc;
   243 static Layout *lt[] = { NULL, NULL };
   252 static Layout *lt[] = { NULL, NULL };
   244 static Monitor *mon = NULL, *selmon = NULL;
   253 static Monitor *mon = NULL, *selmon = NULL;
   245 static unsigned int nmons;
   254 static unsigned int nmons;
   246 static Window root, barwin;
   255 static Window root;
   247 /* configuration, allows nested code to access above variables */
   256 /* configuration, allows nested code to access above variables */
   248 #include "config.h"
   257 #include "config.h"
   249 
   258 
   250 /* compile-time check if all tags fit into an unsigned int bit array. */
   259 /* compile-time check if all tags fit into an unsigned int bit array. */
   251 struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
   260 struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
   264 			r = &rules[i];
   273 			r = &rules[i];
   265 			if((!r->title || strstr(c->name, r->title))
   274 			if((!r->title || strstr(c->name, r->title))
   266 			&& (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
   275 			&& (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
   267 			&& (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
   276 			&& (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
   268 				c->isfloating = r->isfloating;
   277 				c->isfloating = r->isfloating;
   269 				c->tags |= r->tags; 
   278 				c->tags |= r->tags;
   270 			}
   279 			}
   271 		}
   280 		}
   272 		if(ch.res_class)
   281 		if(ch.res_class)
   273 			XFree(ch.res_class);
   282 			XFree(ch.res_class);
   274 		if(ch.res_name)
   283 		if(ch.res_name)
   342 	return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
   351 	return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
   343 }
   352 }
   344 
   353 
   345 void
   354 void
   346 arrange(void) {
   355 arrange(void) {
       
   356 	unsigned int i;
   347 	showhide(stack);
   357 	showhide(stack);
   348 	focus(NULL);
   358 	focus(NULL);
   349 	if(lt[selmon->sellt]->arrange)
   359 	for(i = 0; i < nmons; i++) {
   350 		lt[selmon->sellt]->arrange();
   360 		if(lt[mon[i].sellt]->arrange)
   351 	restack();
   361 			lt[mon[i].sellt]->arrange(&mon[i]);
       
   362 		restack(&mon[i]);
       
   363 	}
   352 }
   364 }
   353 
   365 
   354 void
   366 void
   355 attach(Client *c) {
   367 attach(Client *c) {
   356 	c->next = clients;
   368 	c->next = clients;
   369 	Arg arg = {0};
   381 	Arg arg = {0};
   370 	Client *c;
   382 	Client *c;
   371 	XButtonPressedEvent *ev = &e->xbutton;
   383 	XButtonPressedEvent *ev = &e->xbutton;
   372 
   384 
   373 	click = ClkRootWin;
   385 	click = ClkRootWin;
   374 	if(ev->window == barwin) {
   386 	if(ev->window == selmon->barwin) {
   375 		i = x = 0;
   387 		i = 0;
   376 		do x += TEXTW(tags[i]); while(ev->x >= x && ++i < LENGTH(tags));
   388 		x = selmon->btx;
       
   389 		do
       
   390 			x += TEXTW(tags[i]);
       
   391 		while(ev->x >= x && ++i < LENGTH(tags));
   377 		if(i < LENGTH(tags)) {
   392 		if(i < LENGTH(tags)) {
   378 			click = ClkTagBar;
   393 			click = ClkTagBar;
   379 			arg.ui = 1 << i;
   394 			arg.ui = 1 << i;
   380 		}
   395 		}
   381 		else if(ev->x < x + blw)
   396 		else if(ev->x < x + blw)
   410 	XSync(dpy, False);
   425 	XSync(dpy, False);
   411 }
   426 }
   412 
   427 
   413 void
   428 void
   414 cleanup(void) {
   429 cleanup(void) {
       
   430 	unsigned int i;
   415 	Arg a = {.ui = ~0};
   431 	Arg a = {.ui = ~0};
   416 	Layout foo = { "", NULL };
   432 	Layout foo = { "", NULL };
   417 
   433 
   418 	view(&a);
   434 	view(&a);
   419 	lt[selmon->sellt] = &foo;
   435 	lt[selmon->sellt] = &foo;
   427 	XFreePixmap(dpy, dc.drawable);
   443 	XFreePixmap(dpy, dc.drawable);
   428 	XFreeGC(dpy, dc.gc);
   444 	XFreeGC(dpy, dc.gc);
   429 	XFreeCursor(dpy, cursor[CurNormal]);
   445 	XFreeCursor(dpy, cursor[CurNormal]);
   430 	XFreeCursor(dpy, cursor[CurResize]);
   446 	XFreeCursor(dpy, cursor[CurResize]);
   431 	XFreeCursor(dpy, cursor[CurMove]);
   447 	XFreeCursor(dpy, cursor[CurMove]);
   432 	XDestroyWindow(dpy, barwin);
   448 	for(i = 0; i < nmons; i++)
       
   449 		XDestroyWindow(dpy, mon[i].barwin);
       
   450 	free(mon);
   433 	XSync(dpy, False);
   451 	XSync(dpy, False);
   434 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   452 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   435 }
   453 }
   436 
   454 
   437 void
   455 void
   464 	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
   482 	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
   465 }
   483 }
   466 
   484 
   467 void
   485 void
   468 configurenotify(XEvent *e) {
   486 configurenotify(XEvent *e) {
       
   487 	unsigned int i;
   469 	XConfigureEvent *ev = &e->xconfigure;
   488 	XConfigureEvent *ev = &e->xconfigure;
   470 
   489 
   471 	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
   490 	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
   472 		sw = ev->width;
   491 		sw = ev->width;
   473 		sh = ev->height;
   492 		sh = ev->height;
   474 		updategeom();
   493 		updategeom();
   475 		updatebar();
   494 		if(dc.drawable != 0)
       
   495 			XFreePixmap(dpy, dc.drawable);
       
   496 		dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
       
   497 		for(i = 0; i < nmons; i++)
       
   498 			XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh);
   476 		arrange();
   499 		arrange();
   477 	}
   500 	}
   478 }
   501 }
   479 
   502 
   480 void
   503 void
   554 	va_end(ap);
   577 	va_end(ap);
   555 	exit(EXIT_FAILURE);
   578 	exit(EXIT_FAILURE);
   556 }
   579 }
   557 
   580 
   558 void
   581 void
   559 drawbar(void) {
   582 drawbar(Monitor *m) {
   560 	int x;
   583 	int x;
   561 	unsigned int i, occ = 0, urg = 0;
   584 	unsigned int i, occ = 0, urg = 0;
   562 	unsigned long *col;
   585 	unsigned long *col;
   563 	Client *c;
   586 	Client *c;
   564 
   587 
   565 	for(c = clients; c; c = c->next) {
   588 	for(c = clients; c; c = c->next) {
   566 		occ |= c->tags;
   589 		if(m == &mon[c->mon]) {
   567 		if(c->isurgent)
   590 			occ |= c->tags;
   568 			urg |= c->tags;
   591 			if(c->isurgent)
       
   592 				urg |= c->tags;
       
   593 		}
   569 	}
   594 	}
   570 
   595 
   571 	dc.x = 0;
   596 	dc.x = 0;
       
   597 #ifdef XINERAMA
       
   598 	{
       
   599 		dc.w = TEXTW(m->symbol);
       
   600 		drawtext(m->symbol, selmon == m ? dc.sel : dc.norm, False);
       
   601 		dc.x += dc.w;
       
   602 	}
       
   603 #endif /* XINERAMA */
       
   604 	m->btx = dc.x;
   572 	for(i = 0; i < LENGTH(tags); i++) {
   605 	for(i = 0; i < LENGTH(tags); i++) {
   573 		dc.w = TEXTW(tags[i]);
   606 		dc.w = TEXTW(tags[i]);
   574 		col = tagset[selmon->seltags] & 1 << i ? dc.sel : dc.norm;
   607 		col = tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
   575 		drawtext(tags[i], col, urg & 1 << i);
   608 		drawtext(tags[i], col, urg & 1 << i);
   576 		drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col);
   609 		drawsquare(m == selmon && sel && sel->tags & 1 << i,
       
   610 		           occ & 1 << i, urg & 1 << i, col);
   577 		dc.x += dc.w;
   611 		dc.x += dc.w;
   578 	}
   612 	}
   579 	if(blw > 0) {
   613 	if(blw > 0) {
   580 		dc.w = blw;
   614 		dc.w = blw;
   581 		drawtext(lt[selmon->sellt]->symbol, dc.norm, False);
   615 		drawtext(lt[m->sellt]->symbol, dc.norm, False);
   582 		x = dc.x + dc.w;
   616 		x = dc.x + dc.w;
   583 	}
   617 	}
   584 	else
   618 	else
   585 		x = dc.x;
   619 		x = dc.x;
   586 	dc.w = TEXTW(stext);
   620 	if(m == selmon) {
   587 	dc.x = selmon->ww - dc.w;
   621 		dc.w = TEXTW(stext);
   588 	if(dc.x < x) {
   622 		dc.x = m->ww - dc.w;
   589 		dc.x = x;
   623 		if(dc.x < x) {
   590 		dc.w = selmon->ww - x;
   624 			dc.x = x;
   591 	}
   625 			dc.w = m->ww - x;
   592 	drawtext(stext, dc.norm, False);
   626 		}
   593 	if((dc.w = dc.x - x) > bh) {
   627 		drawtext(stext, dc.norm, False);
   594 		dc.x = x;
   628 		if((dc.w = dc.x - x) > bh) {
   595 		if(sel) {
   629 			dc.x = x;
   596 			drawtext(sel->name, dc.sel, False);
   630 			if(sel) {
   597 			drawsquare(sel->isfixed, sel->isfloating, False, dc.sel);
   631 				drawtext(sel->name, dc.sel, False);
   598 		}
   632 				drawsquare(sel->isfixed, sel->isfloating, False, dc.sel);
   599 		else
   633 			}
   600 			drawtext(NULL, dc.norm, False);
   634 			else
   601 	}
   635 				drawtext(NULL, dc.norm, False);
   602 	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, selmon->ww, bh, 0, 0);
   636 		}
       
   637 	}
       
   638 	else {
       
   639 		dc.w = m->ww - x;
       
   640 		drawtext(NULL, dc.norm, False);
       
   641 	}
       
   642 	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
   603 	XSync(dpy, False);
   643 	XSync(dpy, False);
       
   644 }
       
   645 
       
   646 void
       
   647 drawbars() {
       
   648 	unsigned int i;
       
   649 
       
   650 	for(i = 0; i < nmons; i++)
       
   651 		drawbar(&mon[i]);
   604 }
   652 }
   605 
   653 
   606 void
   654 void
   607 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
   655 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
   608 	int x;
   656 	int x;
   665 		focus(NULL);
   713 		focus(NULL);
   666 }
   714 }
   667 
   715 
   668 void
   716 void
   669 expose(XEvent *e) {
   717 expose(XEvent *e) {
       
   718 	unsigned int i;
   670 	XExposeEvent *ev = &e->xexpose;
   719 	XExposeEvent *ev = &e->xexpose;
   671 
   720 
   672 	if(ev->count == 0 && (ev->window == barwin))
   721 	for(i = 0; i < nmons; i++)
   673 		drawbar();
   722 		if(ev->count == 0 && (ev->window == mon[i].barwin)) {
       
   723 			drawbar(&mon[i]);
       
   724 			break;
       
   725 		}
   674 }
   726 }
   675 
   727 
   676 void
   728 void
   677 focus(Client *c) {
   729 focus(Client *c) {
   678 	if(!c || !ISVISIBLE(c))
   730 	if(!c || !ISVISIBLE(c))
   691 		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
   743 		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
   692 	}
   744 	}
   693 	else
   745 	else
   694 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
   746 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
   695 	sel = c;
   747 	sel = c;
   696 	drawbar();
   748 	if(c)
       
   749 		selmon = &mon[c->mon];
       
   750 	drawbars();
   697 }
   751 }
   698 
   752 
   699 void
   753 void
   700 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
   754 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
   701 	XFocusChangeEvent *ev = &e->xfocus;
   755 	XFocusChangeEvent *ev = &e->xfocus;
   702 
   756 
   703 	if(sel && ev->window != sel->win)
   757 	if(sel && ev->window != sel->win)
   704 		XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
   758 		XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
   705 }
   759 }
   706 
   760 
       
   761 #ifdef XINERAMA
       
   762 void
       
   763 focusmon(const Arg *arg) {
       
   764 	if(arg->ui >= nmons)
       
   765 		return;
       
   766 	selmon = &mon[arg->ui];
       
   767 	focus(NULL);
       
   768 	drawbars();
       
   769 }
       
   770 #endif /* XINERAMA */
       
   771 
   707 void
   772 void
   708 focusstack(const Arg *arg) {
   773 focusstack(const Arg *arg) {
   709 	Client *c = NULL, *i;
   774 	Client *c = NULL, *i;
   710 
   775 
   711 	if(!sel)
   776 	if(!sel)
   712 		return;
   777 		return;
   713 	if (arg->i > 0) {
   778 	if(arg->i > 0) {
   714 		for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
   779 		for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
   715 		if(!c)
   780 		if(!c)
   716 			for(c = clients; c && !ISVISIBLE(c); c = c->next);
   781 			for(c = clients; c && !ISVISIBLE(c); c = c->next);
   717 	}
   782 	}
   718 	else {
   783 	else {
   724 				if(ISVISIBLE(i))
   789 				if(ISVISIBLE(i))
   725 					c = i;
   790 					c = i;
   726 	}
   791 	}
   727 	if(c) {
   792 	if(c) {
   728 		focus(c);
   793 		focus(c);
   729 		restack();
   794 		restack(selmon);
   730 	}
   795 	}
   731 }
   796 }
   732 
   797 
   733 Client *
   798 Client *
   734 getclient(Window w) {
   799 getclient(Window w) {
   944 			c->x = sx + sw - WIDTH(c);
  1009 			c->x = sx + sw - WIDTH(c);
   945 		if(c->y + HEIGHT(c) > sy + sh)
  1010 		if(c->y + HEIGHT(c) > sy + sh)
   946 			c->y = sy + sh - HEIGHT(c);
  1011 			c->y = sy + sh - HEIGHT(c);
   947 		c->x = MAX(c->x, sx);
  1012 		c->x = MAX(c->x, sx);
   948 		/* only fix client y-offset, if the client center might cover the bar */
  1013 		/* only fix client y-offset, if the client center might cover the bar */
   949 		/* TODO: is c always attached to selmon? */
  1014 		c->y = MAX(c->y, ((selmon->by == 0) && (c->x + (c->w / 2) >= selmon->wx)
   950 		c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= selmon->wx)
  1015 		           && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy);
   951 		                            && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy);
       
   952 		c->bw = borderpx;
  1016 		c->bw = borderpx;
   953 	}
  1017 	}
   954 
  1018 
   955 	wc.border_width = c->bw;
  1019 	wc.border_width = c->bw;
   956 	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
  1020 	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
   999 	if(!getclient(ev->window))
  1063 	if(!getclient(ev->window))
  1000 		manage(ev->window, &wa);
  1064 		manage(ev->window, &wa);
  1001 }
  1065 }
  1002 
  1066 
  1003 void
  1067 void
  1004 monocle(void) {
  1068 monocle(Monitor *m) {
  1005 	Client *c;
  1069 	Client *c;
  1006 	Monitor *m;
  1070 
  1007 
  1071 	for(c = nexttiled(m, clients); c; c = nexttiled(m, c->next))
  1008 	for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
       
  1009 		m = &mon[c->mon];
       
  1010 		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw);
  1072 		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw);
  1011 	}
       
  1012 }
  1073 }
  1013 
  1074 
  1014 void
  1075 void
  1015 movemouse(const Arg *arg) {
  1076 movemouse(const Arg *arg) {
  1016 	int x, y, ocx, ocy, di, nx, ny;
  1077 	int x, y, ocx, ocy, di, nx, ny;
  1019 	Window dummy;
  1080 	Window dummy;
  1020 	XEvent ev;
  1081 	XEvent ev;
  1021 
  1082 
  1022 	if(!(c = sel))
  1083 	if(!(c = sel))
  1023 		return;
  1084 		return;
  1024 	restack();
  1085 	restack(selmon);
  1025 	ocx = c->x;
  1086 	ocx = c->x;
  1026 	ocy = c->y;
  1087 	ocy = c->y;
  1027 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1088 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1028 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
  1089 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
  1029 		return;
  1090 		return;
  1061 	while(ev.type != ButtonRelease);
  1122 	while(ev.type != ButtonRelease);
  1062 	XUngrabPointer(dpy, CurrentTime);
  1123 	XUngrabPointer(dpy, CurrentTime);
  1063 }
  1124 }
  1064 
  1125 
  1065 Client *
  1126 Client *
  1066 nexttiled(Client *c) {
  1127 nexttiled(Monitor *m, Client *c) {
  1067 	for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
  1128 	// TODO: m handling
       
  1129 	for(; c && (c->isfloating || m != &mon[c->mon] || !ISVISIBLE(c)); c = c->next);
  1068 	return c;
  1130 	return c;
  1069 }
  1131 }
  1070 
  1132 
  1071 void
  1133 void
  1072 propertynotify(XEvent *e) {
  1134 propertynotify(XEvent *e) {
  1089 		case XA_WM_NORMAL_HINTS:
  1151 		case XA_WM_NORMAL_HINTS:
  1090 			updatesizehints(c);
  1152 			updatesizehints(c);
  1091 			break;
  1153 			break;
  1092 		case XA_WM_HINTS:
  1154 		case XA_WM_HINTS:
  1093 			updatewmhints(c);
  1155 			updatewmhints(c);
  1094 			drawbar();
  1156 			drawbars();
  1095 			break;
  1157 			break;
  1096 		}
  1158 		}
  1097 		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
  1159 		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
  1098 			updatetitle(c);
  1160 			updatetitle(c);
  1099 			if(c == sel)
  1161 			if(c == sel)
  1100 				drawbar();
  1162 				drawbars();
  1101 		}
  1163 		}
  1102 	}
  1164 	}
  1103 }
  1165 }
  1104 
  1166 
  1105 void
  1167 void
  1131 	Client *c;
  1193 	Client *c;
  1132 	XEvent ev;
  1194 	XEvent ev;
  1133 
  1195 
  1134 	if(!(c = sel))
  1196 	if(!(c = sel))
  1135 		return;
  1197 		return;
  1136 	restack();
  1198 	restack(selmon);
  1137 	ocx = c->x;
  1199 	ocx = c->x;
  1138 	ocy = c->y;
  1200 	ocy = c->y;
  1139 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1201 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1140 	None, cursor[CurResize], CurrentTime) != GrabSuccess)
  1202 	None, cursor[CurResize], CurrentTime) != GrabSuccess)
  1141 		return;
  1203 		return;
  1168 	XUngrabPointer(dpy, CurrentTime);
  1230 	XUngrabPointer(dpy, CurrentTime);
  1169 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1231 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1170 }
  1232 }
  1171 
  1233 
  1172 void
  1234 void
  1173 restack(void) {
  1235 restack(Monitor *m) {
  1174 	Client *c;
  1236 	Client *c;
  1175 	XEvent ev;
  1237 	XEvent ev;
  1176 	XWindowChanges wc;
  1238 	XWindowChanges wc;
  1177 
  1239 
  1178 	drawbar();
  1240 	drawbars();
  1179 	if(!sel)
  1241 	if(!sel)
  1180 		return;
  1242 		return;
  1181 	if(sel->isfloating || !lt[selmon->sellt]->arrange)
  1243 	if(m == selmon && (sel->isfloating || !lt[m->sellt]->arrange))
  1182 		XRaiseWindow(dpy, sel->win);
  1244 		XRaiseWindow(dpy, sel->win);
  1183 	if(lt[selmon->sellt]->arrange) {
  1245 	if(lt[m->sellt]->arrange) {
  1184 		wc.stack_mode = Below;
  1246 		wc.stack_mode = Below;
  1185 		wc.sibling = barwin;
  1247 		wc.sibling = m->barwin;
  1186 		for(c = stack; c; c = c->snext)
  1248 		for(c = stack; c; c = c->snext)
  1187 			if(!c->isfloating && ISVISIBLE(c)) {
  1249 			if(!c->isfloating && m == &mon[c->mon] && ISVISIBLE(c)) {
  1188 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1250 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1189 				wc.sibling = c->win;
  1251 				wc.sibling = c->win;
  1190 			}
  1252 			}
  1191 	}
  1253 	}
  1192 	XSync(dpy, False);
  1254 	XSync(dpy, False);
  1246 	if(arg && arg->v)
  1308 	if(arg && arg->v)
  1247 		lt[selmon->sellt] = (Layout *)arg->v;
  1309 		lt[selmon->sellt] = (Layout *)arg->v;
  1248 	if(sel)
  1310 	if(sel)
  1249 		arrange();
  1311 		arrange();
  1250 	else
  1312 	else
  1251 		drawbar();
  1313 		drawbars();
  1252 }
  1314 }
  1253 
  1315 
  1254 /* arg > 1.0 will set mfact absolutly */
  1316 /* arg > 1.0 will set mfact absolutly */
  1255 void
  1317 void
  1256 setmfact(const Arg *arg) {
  1318 setmfact(const Arg *arg) {
  1307 	dc.gc = XCreateGC(dpy, root, 0, NULL);
  1369 	dc.gc = XCreateGC(dpy, root, 0, NULL);
  1308 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1370 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1309 	if(!dc.font.set)
  1371 	if(!dc.font.set)
  1310 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1372 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1311 
  1373 
  1312 	/* init bar */
  1374 	/* init bars */
       
  1375 	wa.override_redirect = True;
       
  1376 	wa.background_pixmap = ParentRelative;
       
  1377 	wa.event_mask = ButtonPressMask|ExposureMask;
  1313 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1378 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1314 		w = TEXTW(layouts[i].symbol);
  1379 		w = TEXTW(layouts[i].symbol);
  1315 		blw = MAX(blw, w);
  1380 		blw = MAX(blw, w);
  1316 	}
  1381 	}
  1317 
  1382 
  1318 	wa.override_redirect = True;
  1383 	for(i = 0; i < nmons; i++) {
  1319 	wa.background_pixmap = ParentRelative;
  1384 		mon[i].barwin = XCreateWindow(dpy, root, mon[i].wx, mon[i].by, mon[i].ww, bh, 0, DefaultDepth(dpy, screen),
  1320 	wa.event_mask = ButtonPressMask|ExposureMask;
  1385 
  1321 
  1386 		                              CopyFromParent, DefaultVisual(dpy, screen),
  1322 	barwin = XCreateWindow(dpy, root, selmon->wx, by, selmon->ww, bh, 0, DefaultDepth(dpy, screen),
  1387 		                              CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
  1323 			CopyFromParent, DefaultVisual(dpy, screen),
  1388 		XDefineCursor(dpy, mon[i].barwin, cursor[CurNormal]);
  1324 			CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
  1389 		XMapRaised(dpy, mon[i].barwin);
  1325 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
  1390 	}
  1326 	XMapRaised(dpy, barwin);
       
  1327 	updatestatus();
  1391 	updatestatus();
  1328 
  1392 
  1329 	/* EWMH support per view */
  1393 	/* EWMH support per view */
  1330 	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
  1394 	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
  1331 			PropModeReplace, (unsigned char *) netatom, NetLast);
  1395 			PropModeReplace, (unsigned char *) netatom, NetLast);
  1382 		sel->tags = arg->ui & TAGMASK;
  1446 		sel->tags = arg->ui & TAGMASK;
  1383 		arrange();
  1447 		arrange();
  1384 	}
  1448 	}
  1385 }
  1449 }
  1386 
  1450 
       
  1451 #ifdef XINERAMA
       
  1452 void
       
  1453 tagmon(const Arg *arg) {
       
  1454 	if(!sel || arg->ui >= nmons)
       
  1455 		return;
       
  1456 	sel->mon = arg->ui;
       
  1457 	arrange();
       
  1458 }
       
  1459 #endif /* XINERAMA */
       
  1460 
  1387 int
  1461 int
  1388 textnw(const char *text, unsigned int len) {
  1462 textnw(const char *text, unsigned int len) {
  1389 	XRectangle r;
  1463 	XRectangle r;
  1390 
  1464 
  1391 	if(dc.font.set) {
  1465 	if(dc.font.set) {
  1394 	}
  1468 	}
  1395 	return XTextWidth(dc.font.xfont, text, len);
  1469 	return XTextWidth(dc.font.xfont, text, len);
  1396 }
  1470 }
  1397 
  1471 
  1398 void
  1472 void
  1399 tile(void) {
  1473 tile(Monitor *m) {
  1400 	int x, y, h, w, mw;
  1474 	int x, y, h, w, mw;
  1401 	unsigned int i, n;
  1475 	unsigned int i, n;
  1402 	Client *c;
  1476 	Client *c;
  1403 	Monitor *m;
  1477 
  1404 
  1478 	for(n = 0, c = nexttiled(m, clients); c; c = nexttiled(m, c->next), n++);
  1405 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
       
  1406 	if(n == 0)
  1479 	if(n == 0)
  1407 		return;
  1480 		return;
  1408 
  1481 
  1409 	/* master */
  1482 	/* master */
  1410 	c = nexttiled(clients);
  1483 	c = nexttiled(m, clients);
  1411 	m = &mon[c->mon];
       
  1412 	mw = mfact * m->ww;
  1484 	mw = mfact * m->ww;
  1413 	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
  1485 	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
  1414 
  1486 
  1415 	if(--n == 0)
  1487 	if(--n == 0)
  1416 		return;
  1488 		return;
  1421 	w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw;
  1493 	w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw;
  1422 	h = m->wh / n;
  1494 	h = m->wh / n;
  1423 	if(h < bh)
  1495 	if(h < bh)
  1424 		h = m->wh;
  1496 		h = m->wh;
  1425 
  1497 
  1426 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1498 	for(i = 0, c = nexttiled(m, c->next); c; c = nexttiled(m, c->next), i++) {
  1427 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1499 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1428 		       ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw));
  1500 		       ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw));
  1429 		if(h != m->wh)
  1501 		if(h != m->wh)
  1430 			y = c->y + HEIGHT(c);
  1502 			y = c->y + HEIGHT(c);
  1431 	}
  1503 	}
  1432 }
  1504 }
  1433 
  1505 
  1434 void
  1506 void
  1435 togglebar(const Arg *arg) {
  1507 togglebar(const Arg *arg) {
  1436 	showbar = !showbar;
  1508 	selmon->showbar = !selmon->showbar;
  1437 	updategeom();
  1509 	updategeom();
  1438 	updatebar();
  1510 	XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
  1439 	arrange();
  1511 	arrange();
  1440 }
  1512 }
  1441 
  1513 
  1442 void
  1514 void
  1443 togglefloating(const Arg *arg) {
  1515 togglefloating(const Arg *arg) {
  1451 
  1523 
  1452 void
  1524 void
  1453 toggletag(const Arg *arg) {
  1525 toggletag(const Arg *arg) {
  1454 	unsigned int mask;
  1526 	unsigned int mask;
  1455 
  1527 
  1456 	if (!sel)
  1528 	if(!sel)
  1457 		return;
  1529 		return;
  1458 	
  1530 	
  1459 	mask = sel->tags ^ (arg->ui & TAGMASK);
  1531 	mask = sel->tags ^ (arg->ui & TAGMASK);
  1460 	if(mask) {
  1532 	if(mask) {
  1461 		sel->tags = mask;
  1533 		sel->tags = mask;
  1503 	if((c = getclient(ev->window)))
  1575 	if((c = getclient(ev->window)))
  1504 		unmanage(c);
  1576 		unmanage(c);
  1505 }
  1577 }
  1506 
  1578 
  1507 void
  1579 void
  1508 updatebar(void) {
       
  1509 	if(dc.drawable != 0)
       
  1510 		XFreePixmap(dpy, dc.drawable);
       
  1511 	dc.drawable = XCreatePixmap(dpy, root, selmon->ww, bh, DefaultDepth(dpy, screen));
       
  1512 	XMoveResizeWindow(dpy, barwin, selmon->wx, by, selmon->ww, bh);
       
  1513 }
       
  1514 
       
  1515 void
       
  1516 updategeom(void) {
  1580 updategeom(void) {
  1517 #ifdef XINERAMA
  1581 #ifdef XINERAMA
  1518 	int di, x, y, n;
  1582 	int di, x, y, n;
  1519 	unsigned int dui, i = 0;
  1583 	unsigned int dui, i = 0;
  1520 	Bool pquery;
  1584 	Bool pquery;
  1521 	Client *c;
  1585 	Client *c;
  1522 	Window dummy;
  1586 	Window dummy;
  1523 	XineramaScreenInfo *info = NULL;
  1587 	XineramaScreenInfo *info = NULL;
  1524 
  1588 
  1525 	/* window area geometry */
  1589 	/* window area geometry */
  1526 	if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { 
  1590 	if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
  1527 		nmons = (unsigned int)n;
  1591 		nmons = (unsigned int)n;
  1528 		for(c = clients; c; c = c->next)
  1592 		for(c = clients; c; c = c->next)
  1529 			if(c->mon >= nmons)
  1593 			if(c->mon >= nmons)
  1530 				c->mon = nmons - 1;
  1594 				c->mon = nmons - 1;
  1531 		if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * nmons)))
  1595 		if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * nmons)))
  1532 			die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
  1596 			die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
  1533 		pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
  1597 		pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
  1534 		for(i = 0; i < nmons; i++) {
  1598 		for(i = 0; i < nmons; i++) {
  1535 			/* TODO: consider re-using XineramaScreenInfo */
  1599 			/* TODO: consider re-using XineramaScreenInfo */
       
  1600 			mon[i].symbol[0] = '[';
       
  1601 			mon[i].symbol[1] = '0' + info[i].screen_number;
       
  1602 			mon[i].symbol[2] = ']';
       
  1603 			mon[i].symbol[3] = 0;
       
  1604 			mon[i].showbar = showbar;
       
  1605 			mon[i].topbar = topbar;
  1536 			mon[i].wx = info[i].x_org;
  1606 			mon[i].wx = info[i].x_org;
  1537 			mon[i].wy = info[i].y_org;
  1607 			mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org;
  1538 			mon[i].ww = info[i].width;
  1608 			mon[i].ww = info[i].width;
  1539 			mon[i].wh = info[i].height;
  1609 			mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height;
  1540 			mon[i].seltags = 0;
  1610 			mon[i].seltags = 0;
  1541 			mon[i].sellt = 0;
  1611 			mon[i].sellt = 0;
       
  1612 			if(mon[i].showbar)
       
  1613 				mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh;
       
  1614 			else
       
  1615 				mon[i].by = -bh;
  1542 			if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
  1616 			if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
  1543 				selmon = &mon[i];
  1617 				selmon = &mon[i];
  1544 		}
  1618 		}
  1545 		/* bar adjustments of selmon */
       
  1546 		selmon->wy = showbar && topbar ?  selmon->wy + bh : selmon->wy;
       
  1547 		selmon->wh = showbar ? selmon->wh - bh : selmon->wh;
       
  1548 		XFree(info);
  1619 		XFree(info);
  1549 	}
  1620 	}
  1550 	else
  1621 	else
  1551 #endif
  1622 #endif /* XINERAMA */
  1552 	{
  1623 	{
  1553 		nmons = 1;
  1624 		nmons = 1;
  1554 		if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor))))
  1625 		if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor))))
  1555 			die("fatal: could not realloc() %u bytes\n", sizeof(Monitor));
  1626 			die("fatal: could not realloc() %u bytes\n", sizeof(Monitor));
  1556 		selmon = &mon[0];
  1627 		selmon = &mon[0];
       
  1628 		mon[0].symbol[0] = '[';
       
  1629 		mon[0].symbol[1] = '0';
       
  1630 		mon[0].symbol[2] = ']';
       
  1631 		mon[0].symbol[3] = 0;
       
  1632 		mon[0].showbar = showbar;
       
  1633 		mon[0].topbar = topbar;
  1557 		mon[0].wx = sx;
  1634 		mon[0].wx = sx;
  1558 		mon[0].wy = showbar && topbar ? sy + bh : sy;
  1635 		mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy;
  1559 		mon[0].ww = sw;
  1636 		mon[0].ww = sw;
  1560 		mon[0].wh = showbar ? sh - bh : sh;
  1637 		mon[0].wh = mon[0].showbar ? sh - bh : sh;
  1561 		mon[0].seltags = 0;
  1638 		mon[0].seltags = 0;
  1562 		mon[0].sellt = 0;
  1639 		mon[0].sellt = 0;
  1563 	}
  1640 		if(mon[0].showbar)
  1564 
  1641 			mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh;
  1565 	/* bar position */
  1642 		else
  1566 	by = showbar ? (topbar ? selmon->wy - bh : selmon->wy + selmon->wh) : -bh;
  1643 			mon[0].by = -bh;
       
  1644 	}
  1567 }
  1645 }
  1568 
  1646 
  1569 void
  1647 void
  1570 updatenumlockmask(void) {
  1648 updatenumlockmask(void) {
  1571 	unsigned int i, j;
  1649 	unsigned int i, j;
  1586 	long msize;
  1664 	long msize;
  1587 	XSizeHints size;
  1665 	XSizeHints size;
  1588 
  1666 
  1589 	if(!XGetWMNormalHints(dpy, c->win, &size, &msize))
  1667 	if(!XGetWMNormalHints(dpy, c->win, &size, &msize))
  1590 		/* size is uninitialized, ensure that size.flags aren't used */
  1668 		/* size is uninitialized, ensure that size.flags aren't used */
  1591 		size.flags = PSize; 
  1669 		size.flags = PSize;
  1592 	if(size.flags & PBaseSize) {
  1670 	if(size.flags & PBaseSize) {
  1593 		c->basew = size.base_width;
  1671 		c->basew = size.base_width;
  1594 		c->baseh = size.base_height;
  1672 		c->baseh = size.base_height;
  1595 	}
  1673 	}
  1596 	else if(size.flags & PMinSize) {
  1674 	else if(size.flags & PMinSize) {
  1639 
  1717 
  1640 void
  1718 void
  1641 updatestatus() {
  1719 updatestatus() {
  1642 	if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
  1720 	if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
  1643 		strcpy(stext, "dwm-"VERSION);
  1721 		strcpy(stext, "dwm-"VERSION);
  1644 	drawbar();
  1722 	drawbar(selmon);
  1645 }
  1723 }
  1646 
  1724 
  1647 void
  1725 void
  1648 updatewmhints(Client *c) {
  1726 updatewmhints(Client *c) {
  1649 	XWMHints *wmh;
  1727 	XWMHints *wmh;
  1707 zoom(const Arg *arg) {
  1785 zoom(const Arg *arg) {
  1708 	Client *c = sel;
  1786 	Client *c = sel;
  1709 
  1787 
  1710 	if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating))
  1788 	if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating))
  1711 		return;
  1789 		return;
  1712 	if(c == nexttiled(clients))
  1790 	if(c == nexttiled(selmon, clients))
  1713 		if(!c || !(c = nexttiled(c->next)))
  1791 		if(!c || !(c = nexttiled(selmon, c->next)))
  1714 			return;
  1792 			return;
  1715 	detach(c);
  1793 	detach(c);
  1716 	attach(c);
  1794 	attach(c);
  1717 	focus(c);
  1795 	focus(c);
  1718 	arrange();
  1796 	arrange();