Mouse/Client: Add client_geo_hints to transform the geometry of a client with its size hints and use it in mouse_resize.

This commit is contained in:
Martin Duquesnoy 2009-06-19 17:29:40 +02:00
parent 29bc1bc2f1
commit a80f6908b7
3 changed files with 63 additions and 55 deletions

View File

@ -486,6 +486,55 @@ client_manage(Window w, XWindowAttributes *wa, Bool ar)
return c; return c;
} }
/** Set a geometry with the client size hints
*\param geo Geometry pointer
*\param c Client pointer
*/
void
client_geo_hints(XRectangle *geo, Client *c)
{
/* minimum possible */
if(geo->width < 1)
geo->width = 1;
if(geo->height < 1)
geo->height = 1;
/* base */
geo->width -= c->basew;
geo->height -= c->baseh;
/* aspect */
if(c->minay > 0 && c->maxay > 0
&& c->minax > 0 && c->maxax > 0)
{
if(geo->width * c->maxay > geo->height * c->maxax)
geo->width = geo->height * c->maxax / c->maxay;
else if(geo->width * c->minay < geo->height * c->minax)
geo->height = geo->width * c->minay / c->minax;
}
/* incremental */
if(c->incw)
geo->width -= geo->width % c->incw;
if(c->inch)
geo->height -= geo->height % c->inch;
/* base dimension */
geo->width += c->basew;
geo->height += c->baseh;
if(c->minw > 0 && geo->width < c->minw)
geo->width = c->minw;
if(c->minh > 0 && geo->height < c->minh)
geo->height = c->minh;
if(c->maxw > 0 && geo->width > c->maxw)
geo->width = c->maxw;
if(c->maxh > 0 && geo->height > c->maxh)
geo->height = c->maxh;
return;
}
/** Move and Resize a client /** Move and Resize a client
* \param c Client pointer * \param c Client pointer
* \param geo Coordinate info for the future size * \param geo Coordinate info for the future size
@ -498,56 +547,12 @@ client_moveresize(Client *c, XRectangle geo, Bool r)
if(!c || c->state_dock) if(!c || c->state_dock)
return; return;
/* Resize hints {{{ */
if(r) if(r)
{ client_geo_hints(&geo, c);
/* minimum possible */
if(geo.width < 1)
geo.width = 1;
if(geo.height < 1)
geo.height = 1;
/* base */
geo.width -= c->basew;
geo.height -= c->baseh;
/* aspect */
if(c->minay > 0 && c->maxay > 0
&& c->minax > 0 && c->maxax > 0)
{
if(geo.width * c->maxay > geo.height * c->maxax)
geo.width = geo.height * c->maxax / c->maxay;
else if(geo.width * c->minay < geo.height * c->minax)
geo.height = geo.width * c->minay / c->minax;
}
/* incremental */
if(c->incw)
geo.width -= geo.width % c->incw;
if(c->inch)
geo.height -= geo.height % c->inch;
/* base dimension */
geo.width += c->basew;
geo.height += c->baseh;
if(c->minw > 0 && geo.width < c->minw)
geo.width = c->minw;
if(c->minh > 0 && geo.height < c->minh)
geo.height = c->minh;
if(c->maxw > 0 && geo.width > c->maxw)
geo.width = c->maxw;
if(c->maxh > 0 && geo.height > c->maxh)
geo.height = c->maxh;
if(geo.width <= 0 || geo.height <= 0)
return;
}
/* }}} */
c->max = False; c->max = False;
if(tags[selscreen][seltag[selscreen]].layout.func == freelayout if(r && (tags[selscreen][seltag[selscreen]].layout.func == freelayout || c->free));
|| c->free);
c->geo = c->ogeo = geo; c->geo = c->ogeo = geo;
c->screen = screen_get_with_geo(c->geo.x, c->geo.y); c->screen = screen_get_with_geo(c->geo.x, c->geo.y);
@ -693,9 +698,9 @@ client_swap(Client *c1, Client *c2)
if(c1->screen != c2->screen) if(c1->screen != c2->screen)
arrange(c2->screen); arrange(c2->screen);
/* Update frame to draw the right title */ /* Get the new client name */
frame_update(c1); client_get_name(c1);
frame_update(c2); client_get_name(c2);
return; return;
} }

View File

@ -165,6 +165,8 @@ void
mouse_resize(Client *c) mouse_resize(Client *c)
{ {
XRectangle geo = c->geo, ogeo = c->geo; XRectangle geo = c->geo, ogeo = c->geo;
int ocx = c->geo.x;
int ocy = c->geo.y;
XEvent ev; XEvent ev;
Window w; Window w;
int d, u, omx, omy; int d, u, omx, omy;
@ -191,7 +193,10 @@ mouse_resize(Client *c)
gci = XCreateGC(dpy, ROOT, GCFunction|GCSubwindowMode|GCLineWidth, &xgc); gci = XCreateGC(dpy, ROOT, GCFunction|GCSubwindowMode|GCLineWidth, &xgc);
if(!c->tile) if(!c->tile)
{
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->geo.width + conf.client.borderheight, c->geo.height);
mouse_dragborder(c->geo, gci); mouse_dragborder(c->geo, gci);
}
do do
{ {
@ -219,13 +224,10 @@ mouse_resize(Client *c)
{ {
mouse_dragborder(geo, gci); mouse_dragborder(geo, gci);
if((geo.width + ev.xmotion.x_root - omx) > 1) geo.width = ((ev.xmotion.x - ocx <= 1) ? 1 : ev.xmotion.x - ocx);
geo.width += ev.xmotion.x_root - omx; geo.height = ((ev.xmotion.y - ocy <= 1) ? 1 : ev.xmotion.y - ocy);
if((geo.height + ev.xmotion.y_root - omy) > 1)
geo.height += ev.xmotion.y_root - omy;
omx = ev.xmotion.x_root; client_geo_hints(&geo, c);
omy = ev.xmotion.y_root;
mouse_dragborder((ogeo = geo), gci); mouse_dragborder((ogeo = geo), gci);

View File

@ -142,6 +142,7 @@ void client_kill(Client *c);
Bool ishide(Client *c, int screen); Bool ishide(Client *c, int screen);
void client_map(Client *c); void client_map(Client *c);
Client* client_manage(Window w, XWindowAttributes *wa, Bool ar); Client* client_manage(Window w, XWindowAttributes *wa, Bool ar);
void client_geo_hints(XRectangle *geo, Client *c);
void client_moveresize(Client *c, XRectangle geo, Bool r); void client_moveresize(Client *c, XRectangle geo, Bool r);
void client_maximize(Client *c); void client_maximize(Client *c);
void client_size_hints(Client *c); void client_size_hints(Client *c);