use Area as arg for client_resize

This commit is contained in:
Julien Danjou 2008-01-05 20:18:30 +01:00
parent 163acc8624
commit 70a3114dba
9 changed files with 131 additions and 120 deletions

109
client.c
View File

@ -437,8 +437,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
* \param volatile_coords register coords in rx/ry/rw/rh
*/
void
client_resize(Client *c, int x, int y, int w, int h,
Bool sizehints, Bool volatile_coords)
client_resize(Client *c, Area geometry, Bool sizehints, Bool volatile_coords)
{
double dx, dy, max, min, ratio;
Area area;
@ -446,10 +445,11 @@ client_resize(Client *c, int x, int y, int w, int h,
if(sizehints)
{
if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0)
if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
&& (geometry.width - c->basew) > 0)
{
dx = (double) (w - c->basew);
dy = (double) (h - c->baseh);
dx = (double) (geometry.width - c->basew);
dy = (double) (geometry.height - c->baseh);
min = (double) (c->minax) / (double) (c->minay);
max = (double) (c->maxax) / (double) (c->maxay);
ratio = dx / dy;
@ -459,67 +459,69 @@ client_resize(Client *c, int x, int y, int w, int h,
{
dy = (dx * min + dy) / (min * min + 1);
dx = dy * min;
w = (int) dx + c->basew;
h = (int) dy + c->baseh;
geometry.width = (int) dx + c->basew;
geometry.height = (int) dy + c->baseh;
}
else if(ratio > max)
{
dy = (dx * min + dy) / (max * max + 1);
dx = dy * min;
w = (int) dx + c->basew;
h = (int) dy + c->baseh;
geometry.width = (int) dx + c->basew;
geometry.height = (int) dy + c->baseh;
}
}
}
if(c->minw && w < c->minw)
w = c->minw;
if(c->minh && h < c->minh)
h = c->minh;
if(c->maxw && w > c->maxw)
w = c->maxw;
if(c->maxh && h > c->maxh)
h = c->maxh;
if(c->minw && geometry.width < c->minw)
geometry.width = c->minw;
if(c->minh && geometry.height < c->minh)
geometry.height = c->minh;
if(c->maxw && geometry.width > c->maxw)
geometry.width = c->maxw;
if(c->maxh && geometry.height > c->maxh)
geometry.height = c->maxh;
if(c->incw)
w -= (w - c->basew) % c->incw;
geometry.width -= (geometry.width - c->basew) % c->incw;
if(c->inch)
h -= (h - c->baseh) % c->inch;
geometry.height -= (geometry.height - c->baseh) % c->inch;
}
if(w <= 0 || h <= 0)
if(geometry.width <= 0 || geometry.height <= 0)
return;
/* offscreen appearance fixes */
area = get_display_area(get_phys_screen(c->screen),
NULL,
&globalconf.screens[c->screen].padding);
if(x > area.width)
x = area.width - w - 2 * c->border;
if(y > area.height)
y = area.height - h - 2 * c->border;
if(x + w + 2 * c->border < 0)
x = 0;
if(y + h + 2 * c->border < 0)
y = 0;
if(c->geometry.x != x || c->geometry.y != y
|| c->geometry.width != w || c->geometry.height != h)
if(geometry.x > area.width)
geometry.x = area.width - geometry.width - 2 * c->border;
if(geometry.y > area.height)
geometry.y = area.height - geometry.height - 2 * c->border;
if(geometry.x + geometry.width + 2 * c->border < 0)
geometry.x = 0;
if(geometry.y + geometry.height + 2 * c->border < 0)
geometry.y = 0;
if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
|| c->geometry.width != geometry.width || c->geometry.height != geometry.height)
{
c->geometry.x = x;
c->geometry.y = y;
c->geometry.width = w;
c->geometry.height = h;
c->geometry.x = geometry.x;
c->geometry.y = geometry.y;
c->geometry.width = geometry.width;
c->geometry.height = geometry.height;
curtags = get_current_tags(c->screen);
if(!volatile_coords && (c->isfloating
|| curtags[0]->layout->arrange == layout_floating))
{
c->f_geometry.x = x;
c->f_geometry.y = y;
c->f_geometry.width = w;
c->f_geometry.height = h;
c->f_geometry.x = geometry.x;
c->f_geometry.y = geometry.y;
c->f_geometry.width = geometry.width;
c->f_geometry.height = geometry.height;
}
p_delete(&curtags);
XMoveResizeWindow(globalconf.display, c->win, x, y, w, h);
window_configure(c->win, x, y, w, h, c->border);
XMoveResizeWindow(globalconf.display, c->win, geometry.x, geometry.y,
geometry.width, geometry.height);
window_configure(c->win, geometry.x, geometry.y,
geometry.width, geometry.height, c->border);
if(XineramaIsActive(globalconf.display))
{
int new_screen = get_screen_bycoord(x, y);
int new_screen = get_screen_bycoord(geometry.x, geometry.y);
if(c->screen != new_screen)
move_client_to_screen(c, new_screen, False);
}
@ -787,11 +789,12 @@ uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
void
uicb_client_moveresize(int screen, char *arg)
{
int nx, ny, nw, nh, ox, oy, ow, oh;
int ox, oy, ow, oh;
char x[8], y[8], w[8], h[8];
int mx, my, dx, dy, nmx, nmy;
unsigned int dui;
Window dummy;
Area area;
Client *sel = globalconf.focus->client;
Tag **curtags = get_current_tags(screen);
@ -804,10 +807,10 @@ uicb_client_moveresize(int screen, char *arg)
p_delete(&curtags);
if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
return;
nx = (int) compute_new_value_from_arg(x, sel->geometry.x);
ny = (int) compute_new_value_from_arg(y, sel->geometry.y);
nw = (int) compute_new_value_from_arg(w, sel->geometry.width);
nh = (int) compute_new_value_from_arg(h, sel->geometry.height);
area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
ox = sel->geometry.x;
oy = sel->geometry.y;
@ -818,7 +821,7 @@ uicb_client_moveresize(int screen, char *arg)
RootWindow(globalconf.display,
get_phys_screen(screen)),
&dummy, &dummy, &mx, &my, &dx, &dy, &dui);
client_resize(sel, nx, ny, nw, nh, True, False);
client_resize(sel, area, True, False);
if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
{
nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
@ -866,6 +869,13 @@ uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((
void
client_maximize(Client *c, int x, int y, int w, int h, Bool borders)
{
Area area;
area.x = x;
area.y = y;
area.width = w;
area.height = h;
if((c->ismax = !c->ismax))
{
if(borders)
@ -875,11 +885,10 @@ client_maximize(Client *c, int x, int y, int w, int h, Bool borders)
}
c->wasfloating = c->isfloating;
c->isfloating = True;
client_resize(c, x, y, w, h, False, True);
client_resize(c, area, False, True);
}
else if(c->wasfloating)
client_resize(c, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height, True, False);
client_resize(c, c->f_geometry, True, False);
else
c->isfloating = False;

View File

@ -32,7 +32,7 @@ void client_detach(Client *);
void client_ban(Client *);
void focus(Client *, Bool, int);
void client_manage(Window, XWindowAttributes *, int);
void client_resize(Client *, int, int, int, int, Bool, Bool);
void client_resize(Client *, Area, Bool, Bool);
void client_unban(Client *);
void client_unmanage(Client *, long);
void client_updatewmhints(Client *);

View File

@ -30,16 +30,12 @@ extern AwesomeConf globalconf;
static void
layout_fibonacci(int screen, int shape)
{
int n = 0, i = 0, nx, ny, nw, nh;
int n = 0, i = 0;
Client *c;
Area area = get_screen_area(screen,
globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding);
nx = area.x;
ny = area.y;
nw = area.width;
nh = area.height;
Area geometry, area;
geometry = area = get_screen_area(screen,
globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding);
for(c = globalconf.clients; c; c = c->next)
if(IS_TILED(c, screen))
@ -48,44 +44,45 @@ layout_fibonacci(int screen, int shape)
if(IS_TILED(c, screen))
{
c->ismax = False;
if((i % 2 && nh / 2 > 2 * c->border)
|| (!(i % 2) && nw / 2 > 2 * c->border))
if((i % 2 && geometry.height / 2 > 2 * c->border)
|| (!(i % 2) && geometry.width / 2 > 2 * c->border))
{
if(i < n - 1)
{
if(i % 2)
nh /= 2;
geometry.height /= 2;
else
nw /= 2;
geometry.width /= 2;
if((i % 4) == 2 && !shape)
nx += nw;
geometry.x += geometry.width;
else if((i % 4) == 3 && !shape)
ny += nh;
geometry.y += geometry.height;
}
if((i % 4) == 0)
{
if(shape)
ny += nh;
geometry.y += geometry.height;
else
ny -= nh;
geometry.y -= geometry.height;
}
else if((i % 4) == 1)
nx += nw;
geometry.x += geometry.width;
else if((i % 4) == 2)
ny += nh;
geometry.y += geometry.height;
else if((i % 4) == 3)
{
if(shape)
nx += nw;
geometry.x += geometry.width;
else
nx -= nw;
geometry.x -= geometry.width;
}
if(i == 0)
ny = area.y;
geometry.y = area.y;
i++;
}
client_resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border,
globalconf.screens[screen].resize_hints, False);
geometry.width -= 2 * c->border;
geometry.height -= 2 * c->border;
client_resize(c, geometry, globalconf.screens[screen].resize_hints, False);
}
}

View File

@ -32,7 +32,6 @@ layout_floating(int screen)
for(c = globalconf.clients; c; c = c->next)
if(client_isvisible(c, screen) && !c->ismax)
client_resize(c, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height, True, False);
client_resize(c, c->f_geometry, True, False);
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -37,8 +37,12 @@ layout_max(int screen)
for(c = globalconf.clients; c; c = c->next)
if(IS_TILED(c, screen))
client_resize(c, area.x, area.y,
area.width - 2 * c->border,
area.height - 2 * c->border, globalconf.screens[screen].resize_hints, False);
{
area.width -= 2 * c->border;
area.height -= 2 * c->border;
client_resize(c, area, globalconf.screens[screen].resize_hints, False);
area.width += 2 * c->border;
area.height += 2 * c->border;
}
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -100,12 +100,11 @@ _tile(int screen, const Bool right)
/* windows area geometry */
int wah = 0, waw = 0, wax = 0, way = 0;
/* new coordinates */
unsigned int nx, ny, nw, nh;
/* master size */
unsigned int mw = 0, mh = 0;
int n, i, masterwin = 0, otherwin = 0;
int real_ncol = 1, win_by_col = 1, current_col = 0;
Area area;
Area area, geometry;
Client *c;
Tag **curtags = get_current_tags(screen);
@ -147,9 +146,11 @@ _tile(int screen, const Bool right)
c->ismax = False;
if(i < curtags[0]->nmaster)
{ /* master */
ny = way + i * mh;
nx = wax + (right ? 0 : waw - mw);
client_resize(c, nx, ny, mw - 2 * c->border, mh - 2 * c->border, globalconf.screens[screen].resize_hints, False);
geometry.y = way + i * mh;
geometry.x = wax + (right ? 0 : waw - mw);
geometry.width = mw - 2 * c->border;
geometry.height = mh - 2 * c->border;
client_resize(c, geometry, globalconf.screens[screen].resize_hints, False);
}
else
{ /* tile window */
@ -163,19 +164,19 @@ _tile(int screen, const Bool right)
win_by_col += otherwin % real_ncol;
if(otherwin <= real_ncol)
nh = wah - 2 * c->border;
geometry.height = wah - 2 * c->border;
else
nh = (wah / win_by_col) - 2 * c->border;
geometry.height = (wah / win_by_col) - 2 * c->border;
nw = (waw - mw) / real_ncol - 2 * c->border;
geometry.width = (waw - mw) / real_ncol - 2 * c->border;
if(i == curtags[0]->nmaster || otherwin <= real_ncol || (i - curtags[0]->nmaster) % win_by_col == 0)
ny = way;
geometry.y = way;
else
ny = way + ((i - curtags[0]->nmaster) % win_by_col) * (nh + 2 * c->border);
geometry.y = way + ((i - curtags[0]->nmaster) % win_by_col) * (geometry.height + 2 * c->border);
nx = wax + current_col * (nw + 2 * c->border) + (right ? mw : 0);
client_resize(c, nx, ny, nw, nh, globalconf.screens[screen].resize_hints, False);
geometry.x = wax + current_col * (geometry.width + 2 * c->border) + (right ? mw : 0);
client_resize(c, geometry, globalconf.screens[screen].resize_hints, False);
}
i++;
}

48
mouse.c
View File

@ -43,11 +43,11 @@ extern AwesomeConf globalconf;
void
uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
{
int x1, y, ocx, ocy, di, nx, ny, phys_screen;
int x1, y, ocx, ocy, di, phys_screen;
unsigned int dui;
Window dummy;
XEvent ev;
Area area;
Area area, geometry;
Client *c = globalconf.focus->client;
Tag **curtags = get_current_tags(screen);
@ -66,8 +66,8 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding);
ocx = nx = c->geometry.x;
ocy = ny = c->geometry.y;
ocx = geometry.x = c->geometry.x;
ocy = geometry.y = c->geometry.y;
phys_screen = get_phys_screen(c->screen);
if(XGrabPointer(globalconf.display,
RootWindow(globalconf.display, phys_screen),
@ -97,17 +97,19 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
handle_event_maprequest(&ev);
break;
case MotionNotify:
nx = ocx + (ev.xmotion.x - x1);
ny = ocy + (ev.xmotion.y - y);
if(abs(nx) < globalconf.screens[screen].snap + area.x && nx > area.x)
nx = area.x;
else if(abs((area.x + area.width) - (nx + c->geometry.width + 2 * c->border)) < globalconf.screens[screen].snap)
nx = area.x + area.width - c->geometry.width - 2 * c->border;
if(abs(ny) < globalconf.screens[screen].snap + area.y && ny > area.y)
ny = area.y;
else if(abs((area.y + area.height) - (ny + c->geometry.height + 2 * c->border)) < globalconf.screens[screen].snap)
ny = area.y + area.height - c->geometry.height - 2 * c->border;
client_resize(c, nx, ny, c->geometry.width, c->geometry.height, False, False);
geometry.x = ocx + (ev.xmotion.x - x1);
geometry.y = ocy + (ev.xmotion.y - y);
if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x)
geometry.x = area.x;
else if(abs((area.x + area.width) - (geometry.x + c->geometry.width + 2 * c->border)) < globalconf.screens[screen].snap)
geometry.x = area.x + area.width - c->geometry.width - 2 * c->border;
if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > area.y)
geometry.y = area.y;
else if(abs((area.y + area.height) - (geometry.y + c->geometry.height + 2 * c->border)) < globalconf.screens[screen].snap)
geometry.y = area.y + area.height - c->geometry.height - 2 * c->border;
geometry.width = c->geometry.width;
geometry.height = c->geometry.height;
client_resize(c, geometry, False, False);
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
break;
}
@ -122,11 +124,11 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
void
uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
{
int ocx = 0, ocy = 0, nw, nh, n;
int ocx = 0, ocy = 0, n;
XEvent ev;
Client *c = globalconf.focus->client;
Tag **curtags = get_current_tags(screen);
Area area = { 0, 0, 0, 0 };
Area area = { 0, 0, 0, 0 }, geometry;
double mwfact;
/* only handle floating and tiled layouts */
@ -191,11 +193,13 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
case MotionNotify:
if(curtags[0]->layout->arrange == layout_floating || c->isfloating)
{
if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
nw = 1;
if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
nh = 1;
client_resize(c, c->geometry.x, c->geometry.y, nw, nh, True, False);
if((geometry.width = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
geometry.width = 1;
if((geometry.height = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
geometry.height = 1;
geometry.x = c->geometry.x;
geometry.y = c->geometry.y;
client_resize(c, geometry, True, False);
}
else if(curtags[0]->layout->arrange == layout_tile
|| curtags[0]->layout->arrange == layout_tileleft)

View File

@ -221,8 +221,7 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize)
if(c->f_geometry.y + c->f_geometry.height >= to.y + to.height)
c->f_geometry.y = to.y + to.height - c->f_geometry.height - 2 * c->border;
client_resize(c, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height, True, False);
client_resize(c, c->f_geometry, True, False);
}
focus(c, True, c->screen);

6
tag.c
View File

@ -216,11 +216,9 @@ uicb_client_togglefloating(int screen, char *arg __attribute__ ((unused)))
sel->isfloating = !sel->isfloating;
if (arg == NULL)
client_resize(sel, sel->f_geometry.x, sel->f_geometry.y,
sel->f_geometry.width, sel->f_geometry.height, True, False);
client_resize(sel, sel->f_geometry, True, False);
else
client_resize(sel, sel->geometry.x, sel->geometry.y,
sel->geometry.width, sel->geometry.height, True, True);
client_resize(sel, sel->geometry, True, True);
client_saveprops(sel);
arrange(screen);