dwm.c
changeset 1391 1409113e7808
parent 1390 c0534213fc52
child 1392 ee12ffbf93df
equal deleted inserted replaced
1390:c0534213fc52 1391:1409113e7808
   168 static void monocle(void);
   168 static void monocle(void);
   169 static void movemouse(const Arg *arg);
   169 static void movemouse(const Arg *arg);
   170 static Client *nexttiled(Client *c);
   170 static Client *nexttiled(Client *c);
   171 static void propertynotify(XEvent *e);
   171 static void propertynotify(XEvent *e);
   172 static void quit(const Arg *arg);
   172 static void quit(const Arg *arg);
   173 static void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
   173 static void resize(Client *c, int x, int y, int w, int h);
   174 static void resizemouse(const Arg *arg);
   174 static void resizemouse(const Arg *arg);
   175 static void restack(void);
   175 static void restack(void);
   176 static void run(void);
   176 static void run(void);
   177 static void scan(void);
   177 static void scan(void);
   178 static void setclientstate(Client *c, long state);
   178 static void setclientstate(Client *c, long state);
   273 
   273 
   274 void
   274 void
   275 applysizehints(Client *c, int *w, int *h) {
   275 applysizehints(Client *c, int *w, int *h) {
   276 	Bool baseismin;
   276 	Bool baseismin;
   277 
   277 
       
   278 	if(!resizehints && !c->isfloating)
       
   279 		return;
       
   280 
   278 	/* see last two sentences in ICCCM 4.1.2.3 */
   281 	/* see last two sentences in ICCCM 4.1.2.3 */
   279 	baseismin = c->basew == c->minw && c->baseh == c->minh;
   282 	baseismin = c->basew == c->minw && c->baseh == c->minh;
   280 
   283 
   281 	/* set minimum possible */
   284 	/* set minimum possible */
   282 	*w = MAX(1, *w);
   285 	*w = MAX(1, *w);
   979 void
   982 void
   980 monocle(void) {
   983 monocle(void) {
   981 	Client *c;
   984 	Client *c;
   982 
   985 
   983 	for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
   986 	for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
   984 		resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
   987 		resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
   985 	}
   988 	}
   986 }
   989 }
   987 
   990 
   988 void
   991 void
   989 movemouse(const Arg *arg) {
   992 movemouse(const Arg *arg) {
  1027 					ny = wy + wh - HEIGHT(c);
  1030 					ny = wy + wh - HEIGHT(c);
  1028 				if(!c->isfloating && lt[sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1031 				if(!c->isfloating && lt[sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1029 					togglefloating(NULL);
  1032 					togglefloating(NULL);
  1030 			}
  1033 			}
  1031 			if(!lt[sellt]->arrange || c->isfloating)
  1034 			if(!lt[sellt]->arrange || c->isfloating)
  1032 				resize(c, nx, ny, c->w, c->h, False);
  1035 				resize(c, nx, ny, c->w, c->h);
  1033 			break;
  1036 			break;
  1034 		}
  1037 		}
  1035 	}
  1038 	}
  1036 	while(ev.type != ButtonRelease);
  1039 	while(ev.type != ButtonRelease);
  1037 	if(usegrab)
  1040 	if(usegrab)
  1083 quit(const Arg *arg) {
  1086 quit(const Arg *arg) {
  1084 	running = False;
  1087 	running = False;
  1085 }
  1088 }
  1086 
  1089 
  1087 void
  1090 void
  1088 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1091 resize(Client *c, int x, int y, int w, int h) {
  1089 	XWindowChanges wc;
  1092 	XWindowChanges wc;
  1090 
  1093 
  1091 	if(sizehints)
  1094 	applysizehints(c, &w, &h);
  1092 		applysizehints(c, &w, &h);
       
  1093 	if(w <= 0 || h <= 0)
  1095 	if(w <= 0 || h <= 0)
  1094 		return;
  1096 		return;
  1095 	if(x > sx + sw)
  1097 	if(x > sx + sw)
  1096 		x = sw - WIDTH(c);
  1098 		x = sw - WIDTH(c);
  1097 	if(y > sy + sh)
  1099 	if(y > sy + sh)
  1152 				if(!c->isfloating && lt[sellt]->arrange
  1154 				if(!c->isfloating && lt[sellt]->arrange
  1153 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1155 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1154 					togglefloating(NULL);
  1156 					togglefloating(NULL);
  1155 			}
  1157 			}
  1156 			if(!lt[sellt]->arrange || c->isfloating)
  1158 			if(!lt[sellt]->arrange || c->isfloating)
  1157 				resize(c, c->x, c->y, nw, nh, True);
  1159 				resize(c, c->x, c->y, nw, nh);
  1158 			break;
  1160 			break;
  1159 		}
  1161 		}
  1160 	}
  1162 	}
  1161 	while(ev.type != ButtonRelease);
  1163 	while(ev.type != ButtonRelease);
  1162 	if(usegrab)
  1164 	if(usegrab)
  1342 	if(!c)
  1344 	if(!c)
  1343 		return;
  1345 		return;
  1344 	if(ISVISIBLE(c)) { /* show clients top down */
  1346 	if(ISVISIBLE(c)) { /* show clients top down */
  1345 		XMoveWindow(dpy, c->win, c->x, c->y);
  1347 		XMoveWindow(dpy, c->win, c->x, c->y);
  1346 		if(!lt[sellt]->arrange || c->isfloating)
  1348 		if(!lt[sellt]->arrange || c->isfloating)
  1347 			resize(c, c->x, c->y, c->w, c->h, True);
  1349 			resize(c, c->x, c->y, c->w, c->h);
  1348 		showhide(c->snext, ntiled);
  1350 		showhide(c->snext, ntiled);
  1349 	}
  1351 	}
  1350 	else { /* hide clients bottom up */
  1352 	else { /* hide clients bottom up */
  1351 		showhide(c->snext, ntiled);
  1353 		showhide(c->snext, ntiled);
  1352 		XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  1354 		XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  1403 		return;
  1405 		return;
  1404 
  1406 
  1405 	/* master */
  1407 	/* master */
  1406 	c = nexttiled(clients);
  1408 	c = nexttiled(clients);
  1407 	mw = mfact * ww;
  1409 	mw = mfact * ww;
  1408 	resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);
  1410 	resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw);
  1409 
  1411 
  1410 	if(--n == 0)
  1412 	if(--n == 0)
  1411 		return;
  1413 		return;
  1412 
  1414 
  1413 	/* tile stack */
  1415 	/* tile stack */
  1418 	if(h < bh)
  1420 	if(h < bh)
  1419 		h = wh;
  1421 		h = wh;
  1420 
  1422 
  1421 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1423 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1422 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1424 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1423 		       ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints);
  1425 		       ? wy + wh - y - 2 * c->bw : h - 2 * c->bw));
  1424 		if(h != wh)
  1426 		if(h != wh)
  1425 			y = c->y + HEIGHT(c);
  1427 			y = c->y + HEIGHT(c);
  1426 	}
  1428 	}
  1427 }
  1429 }
  1428 
  1430 
  1438 togglefloating(const Arg *arg) {
  1440 togglefloating(const Arg *arg) {
  1439 	if(!sel)
  1441 	if(!sel)
  1440 		return;
  1442 		return;
  1441 	sel->isfloating = !sel->isfloating || sel->isfixed;
  1443 	sel->isfloating = !sel->isfloating || sel->isfixed;
  1442 	if(sel->isfloating)
  1444 	if(sel->isfloating)
  1443 		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
  1445 		resize(sel, sel->x, sel->y, sel->w, sel->h);
  1444 	arrange();
  1446 	arrange();
  1445 }
  1447 }
  1446 
  1448 
  1447 void
  1449 void
  1448 toggletag(const Arg *arg) {
  1450 toggletag(const Arg *arg) {