2020-06-21 13:33:29 +00:00
|
|
|
void
|
|
|
|
floatpos(const Arg *arg)
|
|
|
|
{
|
|
|
|
Client *c = selmon->sel;
|
|
|
|
|
2020-06-23 10:11:01 +00:00
|
|
|
if (!c || (selmon->lt[selmon->sellt]->arrange && !c->isfloating))
|
2020-06-21 13:33:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
setfloatpos(c, (char *)arg->v);
|
|
|
|
resizeclient(c, c->x, c->y, c->w, c->h);
|
|
|
|
|
|
|
|
#if !FOCUSONCLICK_PATCH
|
|
|
|
XRaiseWindow(dpy, c->win);
|
|
|
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
|
|
|
|
#endif // FOCUSONCLICK_PATCH
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setfloatpos(Client *c, const char *floatpos)
|
|
|
|
{
|
|
|
|
char xCh, yCh, wCh, hCh;
|
2020-06-23 08:15:37 +00:00
|
|
|
int x, y, w, h, wx, ww, wy, wh;
|
2021-04-05 06:14:27 +00:00
|
|
|
#if FLOATPOS_RESPECT_GAPS_PATCH && VANITYGAPS_PATCH
|
2020-06-21 13:33:29 +00:00
|
|
|
int oh, ov, ih, iv;
|
|
|
|
unsigned int n;
|
2021-04-05 06:14:27 +00:00
|
|
|
#endif // FLOATPOS_RESPECT_GAPS_PATCH | VANITYGAPS_PATCH
|
2020-06-21 13:33:29 +00:00
|
|
|
|
|
|
|
if (!c || !floatpos)
|
|
|
|
return;
|
|
|
|
if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
|
|
|
|
return;
|
2020-08-28 16:17:09 +00:00
|
|
|
|
2020-06-21 13:33:29 +00:00
|
|
|
switch(sscanf(floatpos, "%d%c %d%c %d%c %d%c", &x, &xCh, &y, &yCh, &w, &wCh, &h, &hCh)) {
|
|
|
|
case 4:
|
|
|
|
if (xCh == 'w' || xCh == 'W') {
|
|
|
|
w = x; wCh = xCh;
|
|
|
|
h = y; hCh = yCh;
|
2020-06-22 15:53:33 +00:00
|
|
|
x = -1; xCh = 'C';
|
|
|
|
y = -1; yCh = 'C';
|
2020-06-21 13:33:29 +00:00
|
|
|
} else if (xCh == 'p' || xCh == 'P') {
|
|
|
|
w = x; wCh = xCh;
|
|
|
|
h = y; hCh = yCh;
|
|
|
|
x = 0; xCh = 'G';
|
|
|
|
y = 0; yCh = 'G';
|
2020-08-28 16:17:09 +00:00
|
|
|
} else if (xCh == 'm' || xCh == 'M') {
|
|
|
|
getrootptr(&x, &y);
|
2020-06-21 13:33:29 +00:00
|
|
|
} else {
|
2020-06-22 15:53:33 +00:00
|
|
|
w = 0; wCh = 0;
|
|
|
|
h = 0; hCh = 0;
|
2020-06-21 13:33:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-08-28 16:17:09 +00:00
|
|
|
if (xCh == 'm' || xCh == 'M')
|
|
|
|
getrootptr(&x, &y);
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-05 06:14:27 +00:00
|
|
|
#if FLOATPOS_RESPECT_GAPS_PATCH && VANITYGAPS_PATCH
|
2020-06-21 13:33:29 +00:00
|
|
|
getgaps(c->mon, &oh, &ov, &ih, &iv, &n);
|
|
|
|
wx = c->mon->wx + ov;
|
|
|
|
wy = c->mon->wy + oh;
|
|
|
|
ww = c->mon->ww - 2*ov;
|
|
|
|
wh = c->mon->wh - 2*oh;
|
|
|
|
#else
|
|
|
|
wx = c->mon->wx;
|
|
|
|
wy = c->mon->wy;
|
|
|
|
ww = c->mon->ww;
|
|
|
|
wh = c->mon->wh;
|
2021-04-05 06:14:27 +00:00
|
|
|
#endif // FLOATPOS_RESPECT_GAPS_PATCH | VANITYGAPS_PATCH
|
2020-06-21 13:33:29 +00:00
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
getfloatpos(x, xCh, w, wCh, wx, ww, c->x, c->w, c->bw, floatposgrid_x, &c->x, &c->w);
|
|
|
|
getfloatpos(y, yCh, h, hCh, wy, wh, c->y, c->h, c->bw, floatposgrid_y, &c->y, &c->h);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* p - position, s - size, cp and cs represents current position and size */
|
|
|
|
void
|
|
|
|
getfloatpos(int pos, char pCh, int size, char sCh, int min_p, int max_s, int cp, int cs, int cbw, int defgrid, int *out_p, int *out_s)
|
|
|
|
{
|
|
|
|
int abs_p, abs_s, i, delta, rest;
|
|
|
|
|
|
|
|
abs_p = pCh == 'A' || pCh == 'a';
|
|
|
|
abs_s = sCh == 'A' || sCh == 'a';
|
|
|
|
|
|
|
|
cs += 2*cbw;
|
2020-06-21 13:33:29 +00:00
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
switch(pCh) {
|
2020-06-21 13:33:29 +00:00
|
|
|
case 'A': // absolute position
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = pos;
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
|
|
|
case 'a': // absolute relative position
|
2020-06-23 08:15:37 +00:00
|
|
|
cp += pos;
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
case 'y':
|
2020-06-21 13:33:29 +00:00
|
|
|
case 'x': // client relative position
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = MIN(cp + pos, min_p + max_s);
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
case 'Y':
|
2020-06-21 13:33:29 +00:00
|
|
|
case 'X': // client position relative to monitor
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = min_p + MIN(pos, max_s);
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
|
|
|
case 'S': // fixed client position (sticky)
|
|
|
|
case 'C': // fixed client position (center)
|
2020-06-23 08:15:37 +00:00
|
|
|
case 'Z': // fixed client right-hand position (position + size)
|
|
|
|
if (pos == -1)
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 09:55:55 +00:00
|
|
|
pos = MAX(MIN(pos, max_s), 0);
|
2020-06-23 08:15:37 +00:00
|
|
|
if (pCh == 'Z')
|
|
|
|
cs = abs((cp + cs) - (min_p + pos));
|
|
|
|
else if (pCh == 'C')
|
|
|
|
cs = abs((cp + cs / 2) - (min_p + pos));
|
2020-06-21 13:33:29 +00:00
|
|
|
else
|
2020-06-23 08:15:37 +00:00
|
|
|
cs = abs(cp - (min_p + pos));
|
|
|
|
cp = min_p + pos;
|
|
|
|
sCh = 0; // size determined by position, override defined size
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
|
|
|
case 'G': // grid
|
2020-06-23 08:15:37 +00:00
|
|
|
if (pos <= 0)
|
|
|
|
pos = defgrid; // default configurable
|
|
|
|
if (size == 0 || pos < 2 || (sCh != 'p' && sCh != 'P'))
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
delta = (max_s - cs) / (pos - 1);
|
|
|
|
rest = max_s - cs - delta * (pos - 1);
|
|
|
|
if (sCh == 'P') {
|
|
|
|
if (size < 1 || size > pos)
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = min_p + delta * (size - 1);
|
2020-06-21 13:33:29 +00:00
|
|
|
} else {
|
2020-06-23 09:55:55 +00:00
|
|
|
for (i = 0; i < pos && cp >= min_p + delta * i + (i > pos - rest ? i + rest - pos + 1 : 0); i++);
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = min_p + delta * (MAX(MIN(i + size, pos), 1) - 1) + (i > pos - rest ? i + rest - pos + 1 : 0);
|
2020-06-21 13:33:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
switch(sCh) {
|
|
|
|
case 'A': // absolute size
|
|
|
|
cs = size;
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
case 'a': // absolute relative size
|
|
|
|
cs = MAX(1, cs + size);
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
case '%': // client size percentage in relation to monitor window area size
|
|
|
|
if (size <= 0)
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
size = max_s * MIN(size, 100) / 100;
|
2020-06-21 13:33:29 +00:00
|
|
|
/* falls through */
|
2020-06-23 08:15:37 +00:00
|
|
|
case 'h':
|
|
|
|
case 'w': // size relative to client
|
|
|
|
if (sCh == 'w' || sCh == 'h') {
|
|
|
|
if (size == 0)
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
2020-06-23 08:15:37 +00:00
|
|
|
size += cs;
|
2020-06-21 13:33:29 +00:00
|
|
|
}
|
|
|
|
/* falls through */
|
2020-06-23 08:15:37 +00:00
|
|
|
case 'H':
|
|
|
|
case 'W': // normal size, position takes precedence
|
|
|
|
if (pCh == 'S' && cp + size > min_p + max_s)
|
|
|
|
size = min_p + max_s - cp;
|
|
|
|
else if (size > max_s)
|
|
|
|
size = max_s;
|
|
|
|
|
|
|
|
if (pCh == 'C') { // fixed client center, expand or contract client
|
|
|
|
delta = size - cs;
|
|
|
|
if (delta < 0 || (cp - delta / 2 + size <= min_p + max_s))
|
|
|
|
cp -= delta / 2;
|
|
|
|
else if (cp - delta / 2 < min_p)
|
|
|
|
cp = min_p;
|
2020-06-21 13:33:29 +00:00
|
|
|
else if (delta)
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = min_p + max_s;
|
2021-03-30 11:13:15 +00:00
|
|
|
} else if (pCh == 'Z')
|
|
|
|
cp -= size - cs;
|
2020-06-21 13:33:29 +00:00
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
cs = size;
|
2020-06-21 13:33:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
if (pCh == '%') // client mid-point position in relation to monitor window area size
|
|
|
|
cp = min_p + max_s * MAX(MIN(pos, 100), 0) / 100 - (cs) / 2;
|
2020-08-28 16:17:09 +00:00
|
|
|
if (pCh == 'm' || pCh == 'M')
|
|
|
|
cp = pos - cs / 2;
|
2020-06-21 13:33:29 +00:00
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
if (!abs_p && cp < min_p)
|
|
|
|
cp = min_p;
|
|
|
|
if (cp + cs > min_p + max_s && !(abs_p && abs_s)) {
|
|
|
|
if (abs_p || cp == min_p)
|
|
|
|
cs = min_p + max_s - cp;
|
2020-06-21 13:33:29 +00:00
|
|
|
else
|
2020-06-23 08:15:37 +00:00
|
|
|
cp = min_p + max_s - cs;
|
2020-06-21 13:33:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 08:15:37 +00:00
|
|
|
*out_p = cp;
|
|
|
|
*out_s = MAX(cs - 2*cbw, 1);
|
|
|
|
}
|
2021-06-14 05:16:17 +00:00
|
|
|
|