dwm.c
changeset 1399 0decadd79fd5
parent 1398 597063a22a73
child 1400 a5312d498a58
equal deleted inserted replaced
1398:597063a22a73 1399:0decadd79fd5
    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[mon[x->mon].seltags])
    47 #define ISVISIBLE(M, C)         ((M) == (&mon[C->mon]) && (C->tags & tagset[M->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)
    53 #define HEIGHT(x)               ((x)->h + 2 * (x)->bw)
    53 #define HEIGHT(x)               ((x)->h + 2 * (x)->bw)
   491 		sw = ev->width;
   491 		sw = ev->width;
   492 		sh = ev->height;
   492 		sh = ev->height;
   493 		updategeom();
   493 		updategeom();
   494 		if(dc.drawable != 0)
   494 		if(dc.drawable != 0)
   495 			XFreePixmap(dpy, dc.drawable);
   495 			XFreePixmap(dpy, dc.drawable);
   496 		dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
   496 		dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
   497 		for(i = 0; i < nmons; i++)
   497 		for(i = 0; i < nmons; i++)
   498 			XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh);
   498 			XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh);
   499 		arrange();
   499 		arrange();
   500 	}
   500 	}
   501 }
   501 }
   522 				c->x = sx + (sw / 2 - c->w / 2); /* center in x direction */
   522 				c->x = sx + (sw / 2 - c->w / 2); /* center in x direction */
   523 			if((c->y - sy + c->h) > sh && c->isfloating)
   523 			if((c->y - sy + c->h) > sh && c->isfloating)
   524 				c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
   524 				c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
   525 			if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
   525 			if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
   526 				configure(c);
   526 				configure(c);
   527 			if(ISVISIBLE(c))
   527 			if(ISVISIBLE((&mon[c->mon]), c))
   528 				XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   528 				XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   529 		}
   529 		}
   530 		else
   530 		else
   531 			configure(c);
   531 			configure(c);
   532 	}
   532 	}
   634 			else
   634 			else
   635 				drawtext(NULL, dc.norm, False);
   635 				drawtext(NULL, dc.norm, False);
   636 		}
   636 		}
   637 	}
   637 	}
   638 	else {
   638 	else {
       
   639 		dc.x = x;
   639 		dc.w = m->ww - x;
   640 		dc.w = m->ww - x;
   640 		drawtext(NULL, dc.norm, False);
   641 		drawtext(NULL, dc.norm, False);
   641 	}
   642 	}
   642 	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
   643 	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
   643 	XSync(dpy, False);
   644 	XSync(dpy, False);
   716 void
   717 void
   717 expose(XEvent *e) {
   718 expose(XEvent *e) {
   718 	unsigned int i;
   719 	unsigned int i;
   719 	XExposeEvent *ev = &e->xexpose;
   720 	XExposeEvent *ev = &e->xexpose;
   720 
   721 
   721 	for(i = 0; i < nmons; i++)
   722 	if(ev->count == 0)
   722 		if(ev->count == 0 && (ev->window == mon[i].barwin)) {
   723 		for(i = 0; i < nmons; i++)
   723 			drawbar(&mon[i]);
   724 			if(ev->window == mon[i].barwin) {
   724 			break;
   725 				drawbar(&mon[i]);
   725 		}
   726 				break;
       
   727 			}
   726 }
   728 }
   727 
   729 
   728 void
   730 void
   729 focus(Client *c) {
   731 focus(Client *c) {
   730 	if(!c || !ISVISIBLE(c))
   732 	if(!c || !ISVISIBLE((&mon[c->mon]), c))
   731 		for(c = stack; c && !ISVISIBLE(c); c = c->snext);
   733 		for(c = stack; c && !ISVISIBLE(selmon, c); c = c->snext);
   732 	if(sel && sel != c) {
   734 	if(sel && sel != c) {
   733 		grabbuttons(sel, False);
   735 		grabbuttons(sel, False);
   734 		XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
   736 		XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
   735 	}
   737 	}
   736 	if(c) {
   738 	if(c) {
   774 	Client *c = NULL, *i;
   776 	Client *c = NULL, *i;
   775 
   777 
   776 	if(!sel)
   778 	if(!sel)
   777 		return;
   779 		return;
   778 	if(arg->i > 0) {
   780 	if(arg->i > 0) {
   779 		for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
   781 		for(c = sel->next; c && !ISVISIBLE(selmon, c); c = c->next);
   780 		if(!c)
   782 		if(!c)
   781 			for(c = clients; c && !ISVISIBLE(c); c = c->next);
   783 			for(c = clients; c && !ISVISIBLE(selmon, c); c = c->next);
   782 	}
   784 	}
   783 	else {
   785 	else {
   784 		for(i = clients; i != sel; i = i->next)
   786 		for(i = clients; i != sel; i = i->next)
   785 			if(ISVISIBLE(i))
   787 			if(ISVISIBLE(selmon, i))
   786 				c = i;
   788 				c = i;
   787 		if(!c)
   789 		if(!c)
   788 			for(; i; i = i->next)
   790 			for(; i; i = i->next)
   789 				if(ISVISIBLE(i))
   791 				if(ISVISIBLE(selmon, i))
   790 					c = i;
   792 					c = i;
   791 	}
   793 	}
   792 	if(c) {
   794 	if(c) {
   793 		focus(c);
   795 		focus(c);
   794 		restack(selmon);
   796 		restack(selmon);
  1124 }
  1126 }
  1125 
  1127 
  1126 Client *
  1128 Client *
  1127 nexttiled(Monitor *m, Client *c) {
  1129 nexttiled(Monitor *m, Client *c) {
  1128 	// TODO: m handling
  1130 	// TODO: m handling
  1129 	for(; c && (c->isfloating || m != &mon[c->mon] || !ISVISIBLE(c)); c = c->next);
  1131 	for(; c && (c->isfloating || !ISVISIBLE(m, c)); c = c->next);
  1130 	return c;
  1132 	return c;
  1131 }
  1133 }
  1132 
  1134 
  1133 void
  1135 void
  1134 propertynotify(XEvent *e) {
  1136 propertynotify(XEvent *e) {
  1244 		XRaiseWindow(dpy, sel->win);
  1246 		XRaiseWindow(dpy, sel->win);
  1245 	if(lt[m->sellt]->arrange) {
  1247 	if(lt[m->sellt]->arrange) {
  1246 		wc.stack_mode = Below;
  1248 		wc.stack_mode = Below;
  1247 		wc.sibling = m->barwin;
  1249 		wc.sibling = m->barwin;
  1248 		for(c = stack; c; c = c->snext)
  1250 		for(c = stack; c; c = c->snext)
  1249 			if(!c->isfloating && m == &mon[c->mon] && ISVISIBLE(c)) {
  1251 			if(!c->isfloating && ISVISIBLE(m, c)) {
  1250 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1252 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1251 				wc.sibling = c->win;
  1253 				wc.sibling = c->win;
  1252 			}
  1254 			}
  1253 	}
  1255 	}
  1254 	XSync(dpy, False);
  1256 	XSync(dpy, False);
  1406 
  1408 
  1407 void
  1409 void
  1408 showhide(Client *c) {
  1410 showhide(Client *c) {
  1409 	if(!c)
  1411 	if(!c)
  1410 		return;
  1412 		return;
  1411 	if(ISVISIBLE(c)) { /* show clients top down */
  1413 	if(ISVISIBLE((&mon[c->mon]), c)) { /* show clients top down */
  1412 		XMoveWindow(dpy, c->win, c->x, c->y);
  1414 		XMoveWindow(dpy, c->win, c->x, c->y);
  1413 		if(!lt[selmon->sellt]->arrange || c->isfloating)
  1415 		if(!lt[selmon->sellt]->arrange || c->isfloating)
  1414 			resize(c, c->x, c->y, c->w, c->h);
  1416 			resize(c, c->x, c->y, c->w, c->h);
  1415 		showhide(c->snext);
  1417 		showhide(c->snext);
  1416 	}
  1418 	}