summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/dwm.c b/dwm.c
index 613b6f1..e1c0645 100644
--- a/dwm.c
+++ b/dwm.c
@@ -129,6 +129,7 @@ typedef struct {
129 129
130/* function declarations */ 130/* function declarations */
131static void applyrules(Client *c); 131static void applyrules(Client *c);
132static void applysizehints(Client *c, int *w, int *h);
132static void arrange(void); 133static void arrange(void);
133static void attach(Client *c); 134static void attach(Client *c);
134static void attachstack(Client *c); 135static void attachstack(Client *c);
@@ -271,6 +272,55 @@ applyrules(Client *c) {
271} 272}
272 273
273void 274void
275applysizehints(Client *c, int *w, int *h) {
276 Bool baseismin;
277
278 /* see last two sentences in ICCCM 4.1.2.3 */
279 baseismin = c->basew == c->minw && c->baseh == c->minh;
280
281 /* set minimum possible */
282 *w = MAX(1, *w);
283 *h = MAX(1, *h);
284
285 if(!baseismin) { /* temporarily remove base dimensions */
286 *w -= c->basew;
287 *h -= c->baseh;
288 }
289
290 /* adjust for aspect limits */
291 if(c->mina > 0 && c->maxa > 0) {
292 if(c->maxa < (float)*w / *h)
293 *w = *h * c->maxa;
294 else if(c->mina < (float)*h / *w)
295 *h = *w * c->mina;
296 }
297
298 if(baseismin) { /* increment calculation requires this */
299 *w -= c->basew;
300 *h -= c->baseh;
301 }
302
303 /* adjust for increment value */
304 if(c->incw)
305 *w -= *w % c->incw;
306 if(c->inch)
307 *h -= *h % c->inch;
308
309 /* restore base dimensions */
310 *w += c->basew;
311 *h += c->baseh;
312
313 *w = MAX(*w, c->minw);
314 *h = MAX(*h, c->minh);
315
316 if(c->maxw)
317 *w = MIN(*w, c->maxw);
318
319 if(c->maxh)
320 *h = MIN(*h, c->maxh);
321}
322
323void
274arrange(void) { 324arrange(void) {
275 unsigned int nt; 325 unsigned int nt;
276 Client *c; 326 Client *c;
@@ -1038,51 +1088,8 @@ void
1038resize(Client *c, int x, int y, int w, int h, Bool sizehints) { 1088resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
1039 XWindowChanges wc; 1089 XWindowChanges wc;
1040 1090
1041 if(sizehints) { 1091 if(sizehints)
1042 /* see last two sentences in ICCCM 4.1.2.3 */ 1092 applysizehints(c, &w, &h);
1043 Bool baseismin = c->basew == c->minw && c->baseh == c->minh;
1044
1045 /* set minimum possible */
1046 w = MAX(1, w);
1047 h = MAX(1, h);
1048
1049 if(!baseismin) { /* temporarily remove base dimensions */
1050 w -= c->basew;
1051 h -= c->baseh;
1052 }
1053
1054 /* adjust for aspect limits */
1055 if(c->mina > 0 && c->maxa > 0) {
1056 if(c->maxa < (float)w / h)
1057 w = h * c->maxa;
1058 else if(c->mina < (float)h / w)
1059 h = w * c->mina;
1060 }
1061
1062 if(baseismin) { /* increment calculation requires this */
1063 w -= c->basew;
1064 h -= c->baseh;
1065 }
1066
1067 /* adjust for increment value */
1068 if(c->incw)
1069 w -= w % c->incw;
1070 if(c->inch)
1071 h -= h % c->inch;
1072
1073 /* restore base dimensions */
1074 w += c->basew;
1075 h += c->baseh;
1076
1077 w = MAX(w, c->minw);
1078 h = MAX(h, c->minh);
1079
1080 if(c->maxw)
1081 w = MIN(w, c->maxw);
1082
1083 if(c->maxh)
1084 h = MIN(h, c->maxh);
1085 }
1086 if(w <= 0 || h <= 0) 1093 if(w <= 0 || h <= 0)
1087 return; 1094 return;
1088 if(x > sx + sw) 1095 if(x > sx + sw)