Improve code of func "applysizehints"

This commit is contained in:
Alex Kotov 2021-11-20 22:28:07 +05:00
parent 1cbd188b5b
commit afb3bc91b5
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 41 additions and 18 deletions

View File

@ -289,31 +289,40 @@ int applysizehints(
int bw, int bw,
int interact int interact
) { ) {
int baseismin;
Monitor *m = c->mon; Monitor *m = c->mon;
/* set minimum possible */ /* set minimum possible */
*w = MAX(1, *w); *w = MAX(1, *w);
*h = MAX(1, *h); *h = MAX(1, *h);
if (interact) { if (interact) {
if (*x > sw) if (*x > sw) {
*x = sw - WIDTH(c); *x = sw - WIDTH(c);
if (*y > sh) }
if (*y > sh) {
*y = sh - HEIGHT(c); *y = sh - HEIGHT(c);
if (*x + *w + 2 * bw < 0) }
if (*x + *w + 2 * bw < 0) {
*x = 0; *x = 0;
if (*y + *h + 2 * bw < 0) }
if (*y + *h + 2 * bw < 0) {
*y = 0; *y = 0;
}
} else { } else {
if (*x >= m->wx + m->ww) if (*x >= m->wx + m->ww) {
*x = m->wx + m->ww - WIDTH(c); *x = m->wx + m->ww - WIDTH(c);
if (*y >= m->wy + m->wh) }
if (*y >= m->wy + m->wh) {
*y = m->wy + m->wh - HEIGHT(c); *y = m->wy + m->wh - HEIGHT(c);
if (*x + *w + 2 * bw <= m->wx) }
if (*x + *w + 2 * bw <= m->wx) {
*x = m->wx; *x = m->wx;
if (*y + *h + 2 * bw <= m->wy) }
if (*y + *h + 2 * bw <= m->wy) {
*y = m->wy; *y = m->wy;
}
} }
if ( if (
c->isfloating c->isfloating
|| ||
@ -324,35 +333,49 @@ int applysizehints(
) )
) { ) {
/* see last two sentences in ICCCM 4.1.2.3 */ /* see last two sentences in ICCCM 4.1.2.3 */
baseismin = c->basew == c->minw && c->baseh == c->minh; const int baseismin = c->basew == c->minw && c->baseh == c->minh;
if (!baseismin) { /* temporarily remove base dimensions */
/* temporarily remove base dimensions */
if (!baseismin) {
*w -= c->basew; *w -= c->basew;
*h -= c->baseh; *h -= c->baseh;
} }
/* adjust for aspect limits */ /* adjust for aspect limits */
if (c->mina > 0 && c->maxa > 0) { if (c->mina > 0 && c->maxa > 0) {
if (c->maxa < (float)*w / *h) if (c->maxa < (float)*w / *h) {
*w = *h * c->maxa + 0.5; *w = *h * c->maxa + 0.5;
else if (c->mina < (float)*h / *w) } else if (c->mina < (float)*h / *w) {
*h = *w * c->mina + 0.5; *h = *w * c->mina + 0.5;
}
} }
if (baseismin) { /* increment calculation requires this */
/* increment calculation requires this */
if (baseismin) {
*w -= c->basew; *w -= c->basew;
*h -= c->baseh; *h -= c->baseh;
} }
/* adjust for increment value */ /* adjust for increment value */
if (c->incw) if (c->incw) {
*w -= *w % c->incw; *w -= *w % c->incw;
if (c->inch) }
if (c->inch) {
*h -= *h % c->inch; *h -= *h % c->inch;
}
/* restore base dimensions */ /* restore base dimensions */
*w = MAX(*w + c->basew, c->minw); *w = MAX(*w + c->basew, c->minw);
*h = MAX(*h + c->baseh, c->minh); *h = MAX(*h + c->baseh, c->minh);
if (c->maxw)
if (c->maxw) {
*w = MIN(*w, c->maxw); *w = MIN(*w, c->maxw);
if (c->maxh) }
if (c->maxh) {
*h = MIN(*h, c->maxh); *h = MIN(*h, c->maxh);
}
} }
return *x != c->x || *y != c->y || *w != c->w || *h != c->h || bw != c->bw; return *x != c->x || *y != c->y || *w != c->w || *h != c->h || bw != c->bw;
} }