use Area to store window geoms

This commit is contained in:
Julien Danjou 2008-01-05 19:38:50 +01:00
parent 5a66ffb2e7
commit 163acc8624
8 changed files with 99 additions and 85 deletions

View File

@ -315,20 +315,20 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
c = p_new(Client, 1); c = p_new(Client, 1);
c->win = w; c->win = w;
c->x = c->rx = wa->x; c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
c->y = c->ry = wa->y; c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
c->w = c->rw = wa->width; c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
c->h = c->rh = wa->height; c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
c->oldborder = wa->border_width; c->oldborder = wa->border_width;
c->screen = get_screen_bycoord(c->x, c->y); c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
move_client_to_screen(c, screen, True); move_client_to_screen(c, screen, True);
/* update window title */ /* update window title */
client_updatetitle(c); client_updatetitle(c);
if(c->w == area.width && c->h == area.height) if(c->geometry.width == area.width && c->geometry.height == area.height)
c->border = wa->border_width; c->border = wa->border_width;
else else
c->border = globalconf.screens[screen].borderpx; c->border = globalconf.screens[screen].borderpx;
@ -340,10 +340,10 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
/* if window request fullscreen mode */ /* if window request fullscreen mode */
if(c->w == area.width && c->h == area.height) if(c->geometry.width == area.width && c->geometry.height == area.height)
{ {
c->x = area.x; c->geometry.x = area.x;
c->y = area.y; c->geometry.y = area.y;
} }
else else
{ {
@ -351,23 +351,24 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
globalconf.screens[screen].statusbar, globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
if(c->x + c->w + 2 * c->border > darea.x + darea.width) if(c->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width)
c->x = c->rx = darea.x + darea.width - c->w - 2 * c->border; c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border;
if(c->y + c->h + 2 * c->border > darea.y + darea.height) if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height)
c->y = c->ry = darea.y + darea.height - c->h - 2 * c->border; c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border;
if(c->x < darea.x) if(c->geometry.x < darea.x)
c->x = c->rx = darea.x; c->geometry.x = c->f_geometry.x = darea.x;
if(c->y < darea.y) if(c->geometry.y < darea.y)
c->y = c->ry = darea.y; c->geometry.y = c->f_geometry.y = darea.y;
} }
/* XXX if this necessary ? */
/* set borders */ /* set borders */
wc.border_width = c->border; wc.border_width = c->border;
XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc); XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel); XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
/* propagates border_width, if size doesn't change */ /* propagates border_width, if size doesn't change */
window_configure(c->win, c->x, c->y, c->w, c->h, c->border); window_configure(c->win, c->geometry.x, c->geometry.y,
c->geometry.width, c->geometry.height, c->border);
/* update hints */ /* update hints */
client_updatesizehints(c); client_updatesizehints(c);
@ -415,7 +416,8 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
} }
/* some windows require this */ /* some windows require this */
XMoveResizeWindow(globalconf.display, c->win, c->x, c->y, c->w, c->h); XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
c->geometry.width, c->geometry.height);
focus(c, True, screen); focus(c, True, screen);
@ -496,27 +498,28 @@ client_resize(Client *c, int x, int y, int w, int h,
x = 0; x = 0;
if(y + h + 2 * c->border < 0) if(y + h + 2 * c->border < 0)
y = 0; y = 0;
if(c->x != x || c->y != y || c->w != w || c->h != h) if(c->geometry.x != x || c->geometry.y != y
|| c->geometry.width != w || c->geometry.height != h)
{ {
c->x = x; c->geometry.x = x;
c->y = y; c->geometry.y = y;
c->w = w; c->geometry.width = w;
c->h = h; c->geometry.height = h;
curtags = get_current_tags(c->screen); curtags = get_current_tags(c->screen);
if(!volatile_coords && (c->isfloating if(!volatile_coords && (c->isfloating
|| curtags[0]->layout->arrange == layout_floating)) || curtags[0]->layout->arrange == layout_floating))
{ {
c->rx = c->x; c->f_geometry.x = x;
c->ry = c->y; c->f_geometry.y = y;
c->rw = c->w; c->f_geometry.width = w;
c->rh = c->h; c->f_geometry.height = h;
} }
p_delete(&curtags); p_delete(&curtags);
XMoveResizeWindow(globalconf.display, c->win, c->x, c->y, c->w, c->h); XMoveResizeWindow(globalconf.display, c->win, x, y, w, h);
window_configure(c->win, c->x, c->y, c->w, c->h, c->border); window_configure(c->win, x, y, w, h, c->border);
if(XineramaIsActive(globalconf.display)) if(XineramaIsActive(globalconf.display))
{ {
int new_screen = get_screen_bycoord(c->x, c->y); int new_screen = get_screen_bycoord(x, y);
if(c->screen != new_screen) if(c->screen != new_screen)
move_client_to_screen(c, new_screen, False); move_client_to_screen(c, new_screen, False);
} }
@ -801,15 +804,15 @@ uicb_client_moveresize(int screen, char *arg)
p_delete(&curtags); p_delete(&curtags);
if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4) if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
return; return;
nx = (int) compute_new_value_from_arg(x, sel->x); nx = (int) compute_new_value_from_arg(x, sel->geometry.x);
ny = (int) compute_new_value_from_arg(y, sel->y); ny = (int) compute_new_value_from_arg(y, sel->geometry.y);
nw = (int) compute_new_value_from_arg(w, sel->w); nw = (int) compute_new_value_from_arg(w, sel->geometry.width);
nh = (int) compute_new_value_from_arg(h, sel->h); nh = (int) compute_new_value_from_arg(h, sel->geometry.height);
ox = sel->x; ox = sel->geometry.x;
oy = sel->y; oy = sel->geometry.y;
ow = sel->w; ow = sel->geometry.width;
oh = sel->h; oh = sel->geometry.height;
Bool xqp = XQueryPointer(globalconf.display, Bool xqp = XQueryPointer(globalconf.display,
RootWindow(globalconf.display, RootWindow(globalconf.display,
@ -818,8 +821,8 @@ uicb_client_moveresize(int screen, char *arg)
client_resize(sel, nx, ny, nw, nh, True, False); client_resize(sel, nx, ny, nw, nh, True, False);
if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my) if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
{ {
nmx = mx - ox + sel->w - ow - 1 < 0 ? 0 : mx - ox + sel->w - ow - 1; nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
nmy = my - oy + sel->h - oh - 1 < 0 ? 0 : my - oy + sel->h - oh - 1; nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
XWarpPointer(globalconf.display, XWarpPointer(globalconf.display,
None, sel->win, None, sel->win,
0, 0, 0, 0, nmx, nmy); 0, 0, 0, 0, nmx, nmy);
@ -875,7 +878,8 @@ client_maximize(Client *c, int x, int y, int w, int h, Bool borders)
client_resize(c, x, y, w, h, False, True); client_resize(c, x, y, w, h, False, True);
} }
else if(c->wasfloating) else if(c->wasfloating)
client_resize(c, c->rx, c->ry, c->rw, c->rh, True, False); client_resize(c, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height, True, False);
else else
c->isfloating = False; c->isfloating = False;
@ -917,8 +921,8 @@ uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
if(sel) if(sel)
client_maximize(sel, sel->x, area.y, client_maximize(sel, sel->geometry.x, area.y,
sel->w, sel->geometry.width,
area.height - 2 * sel->border, False); area.height - 2 * sel->border, False);
} }
@ -937,9 +941,9 @@ uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
if(sel) if(sel)
client_maximize(sel, area.x, sel->y, client_maximize(sel, area.x, sel->geometry.y,
area.height - 2 * sel->border, area.height - 2 * sel->border,
sel->h, False); sel->geometry.height, False);
} }
/** Zoom client /** Zoom client

View File

@ -152,9 +152,11 @@ struct Client
/** Client name */ /** Client name */
char name[256]; char name[256];
/** Window geometry */ /** Window geometry */
int x, y, w, h; Area geometry;
/** Real window geometry for floating */ /** Floating window geometry */
int rx, ry, rw, rh; Area f_geometry;
/** Max window geometry */
Area m_geometry;
int basew, baseh, incw, inch, maxw, maxh, minw, minh; int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int minax, maxax, minay, maxay; int minax, maxax, minay, maxay;
int border, oldborder; int border, oldborder;

19
event.c
View File

@ -146,18 +146,19 @@ handle_event_configurerequest(XEvent * e)
if(c->isfixed) if(c->isfixed)
{ {
if(ev->value_mask & CWX) if(ev->value_mask & CWX)
c->rx = c->x = ev->x - c->border; c->f_geometry.x = c->geometry.x = ev->x - c->border;
if(ev->value_mask & CWY) if(ev->value_mask & CWY)
c->ry = c->y = ev->y - c->border; c->f_geometry.y = c->f_geometry.y = ev->y - c->border;
if(ev->value_mask & CWWidth) if(ev->value_mask & CWWidth)
c->rw = c->w = ev->width; c->f_geometry.width = c->geometry.width = ev->width;
if(ev->value_mask & CWHeight) if(ev->value_mask & CWHeight)
c->rh = c->h = ev->height; c->f_geometry.height = c->geometry.height = ev->height;
if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight))) if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight)))
window_configure(c->win, c->x, c->y, c->w, c->h, c->border); window_configure(c->win, c->geometry.x, c->geometry.y,
c->geometry.width, c->geometry.height, c->border);
/* recompute screen */ /* recompute screen */
old_screen = c->screen; old_screen = c->screen;
c->screen = get_screen_bycoord(c->x, c->y); c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
if(old_screen != c->screen) if(old_screen != c->screen)
{ {
move_client_to_screen(c, c->screen, False); move_client_to_screen(c, c->screen, False);
@ -165,11 +166,13 @@ handle_event_configurerequest(XEvent * e)
statusbar_draw_all(c->screen); statusbar_draw_all(c->screen);
} }
tag_client_with_rules(c); tag_client_with_rules(c);
XMoveResizeWindow(e->xany.display, c->win, c->rx, c->ry, c->rw, c->rh); XMoveResizeWindow(e->xany.display, c->win, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height);
arrange(c->screen); arrange(c->screen);
} }
else else
window_configure(c->win, c->x, c->y, c->w, c->h, c->border); window_configure(c->win, c->geometry.x, c->geometry.y,
c->geometry.width, c->geometry.height, c->border);
} }
else else
{ {

View File

@ -181,7 +181,8 @@ restack(int screen)
p_delete(&curtags); p_delete(&curtags);
} }
if(globalconf.screens[screen].focus_move_pointer) if(globalconf.screens[screen].focus_move_pointer)
XWarpPointer(globalconf.display, None, sel->win, 0, 0, 0, 0, sel->w / 2, sel->h / 2); XWarpPointer(globalconf.display, None, sel->win, 0, 0, 0, 0,
sel->geometry.width / 2, sel->geometry.height / 2);
XSync(globalconf.display, False); XSync(globalconf.display, False);
while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev)); while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
} }

View File

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

24
mouse.c
View File

@ -66,8 +66,8 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
globalconf.screens[screen].statusbar, globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
ocx = nx = c->x; ocx = nx = c->geometry.x;
ocy = ny = c->y; ocy = ny = c->geometry.y;
phys_screen = get_phys_screen(c->screen); phys_screen = get_phys_screen(c->screen);
if(XGrabPointer(globalconf.display, if(XGrabPointer(globalconf.display,
RootWindow(globalconf.display, phys_screen), RootWindow(globalconf.display, phys_screen),
@ -101,13 +101,13 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
ny = ocy + (ev.xmotion.y - y); ny = ocy + (ev.xmotion.y - y);
if(abs(nx) < globalconf.screens[screen].snap + area.x && nx > area.x) if(abs(nx) < globalconf.screens[screen].snap + area.x && nx > area.x)
nx = area.x; nx = area.x;
else if(abs((area.x + area.width) - (nx + c->w + 2 * c->border)) < globalconf.screens[screen].snap) else if(abs((area.x + area.width) - (nx + c->geometry.width + 2 * c->border)) < globalconf.screens[screen].snap)
nx = area.x + area.width - c->w - 2 * c->border; nx = area.x + area.width - c->geometry.width - 2 * c->border;
if(abs(ny) < globalconf.screens[screen].snap + area.y && ny > area.y) if(abs(ny) < globalconf.screens[screen].snap + area.y && ny > area.y)
ny = area.y; ny = area.y;
else if(abs((area.y + area.height) - (ny + c->h + 2 * c->border)) < globalconf.screens[screen].snap) else if(abs((area.y + area.height) - (ny + c->geometry.height + 2 * c->border)) < globalconf.screens[screen].snap)
ny = area.y + area.height - c->h - 2 * c->border; ny = area.y + area.height - c->geometry.height - 2 * c->border;
client_resize(c, nx, ny, c->w, c->h, False, False); client_resize(c, nx, ny, c->geometry.width, c->geometry.height, False, False);
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev)); while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
break; break;
} }
@ -135,8 +135,8 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
if((curtags[0]->layout->arrange == layout_floating) || c->isfloating) if((curtags[0]->layout->arrange == layout_floating) || c->isfloating)
{ {
restack(screen); restack(screen);
ocx = c->x; ocx = c->geometry.x;
ocy = c->y; ocy = c->geometry.y;
c->ismax = False; c->ismax = False;
} }
else if (curtags[0]->layout->arrange == layout_tile else if (curtags[0]->layout->arrange == layout_tile
@ -166,9 +166,9 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
return; return;
if(curtags[0]->layout->arrange == layout_tileleft) if(curtags[0]->layout->arrange == layout_tileleft)
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0, c->h + c->border - 1); XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0, c->geometry.height + c->border - 1);
else else
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1); XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1);
for(;;) for(;;)
{ {
@ -195,7 +195,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
nw = 1; nw = 1;
if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0) if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
nh = 1; nh = 1;
client_resize(c, c->x, c->y, nw, nh, True, False); client_resize(c, c->geometry.x, c->geometry.y, nw, nh, True, False);
} }
else if(curtags[0]->layout->arrange == layout_tile else if(curtags[0]->layout->arrange == layout_tile
|| curtags[0]->layout->arrange == layout_tileleft) || curtags[0]->layout->arrange == layout_tileleft)

View File

@ -209,19 +209,20 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize)
from = get_screen_area(old_screen, NULL, NULL); from = get_screen_area(old_screen, NULL, NULL);
/* compute new coords in new screen */ /* compute new coords in new screen */
c->rx = (c->rx - from.x) + to.x; c->f_geometry.x = (c->f_geometry.x - from.x) + to.x;
c->ry = (c->ry - from.y) + to.y; c->f_geometry.y = (c->f_geometry.y - from.y) + to.y;
/* check that new coords are still in the screen */ /* check that new coords are still in the screen */
if(c->rw > to.width) if(c->f_geometry.width > to.width)
c->rw = to.width; c->f_geometry.width = to.width;
if(c->rh > to.height) if(c->f_geometry.height > to.height)
c->rh = to.height; c->f_geometry.height = to.height;
if(c->rx + c->rw >= to.x + to.width) if(c->f_geometry.x + c->f_geometry.width >= to.x + to.width)
c->rx = to.x + to.width - c->rw - 2 * c->border; c->f_geometry.x = to.x + to.width - c->f_geometry.width - 2 * c->border;
if(c->ry + c->rh >= to.y + to.height) if(c->f_geometry.y + c->f_geometry.height >= to.y + to.height)
c->ry = to.y + to.height - c->rh - 2 * c->border; c->f_geometry.y = to.y + to.height - c->f_geometry.height - 2 * c->border;
client_resize(c, c->rx, c->ry, c->rw, c->rh, True, False); client_resize(c, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height, True, False);
} }
focus(c, True, c->screen); focus(c, True, c->screen);

6
tag.c
View File

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