Rewrite everything about client geoemtry, resize, etc.

This commit is contained in:
Julien Danjou 2008-01-06 14:40:23 +01:00
parent 633d7c07ee
commit af708d2fbc
11 changed files with 155 additions and 116 deletions

119
client.c
View File

@ -434,13 +434,15 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
* \param h height * \param h height
* \param sizehints respect size hints * \param sizehints respect size hints
* \param volatile_coords register coords in rx/ry/rw/rh * \param volatile_coords register coords in rx/ry/rw/rh
* \param return True if resize has been done
*/ */
void Bool
client_resize(Client *c, Area geometry, Bool sizehints, Bool volatile_coords) client_resize(Client *c, Area geometry, Bool sizehints)
{ {
int new_screen;
double dx, dy, max, min, ratio; double dx, dy, max, min, ratio;
Area area; Area area;
Tag **curtags; XWindowChanges wc;
if(sizehints) if(sizehints)
{ {
@ -484,7 +486,7 @@ client_resize(Client *c, Area geometry, Bool sizehints, Bool volatile_coords)
geometry.height -= (geometry.height - c->baseh) % c->inch; geometry.height -= (geometry.height - c->baseh) % c->inch;
} }
if(geometry.width <= 0 || geometry.height <= 0) if(geometry.width <= 0 || geometry.height <= 0)
return; return False;
/* offscreen appearance fixes */ /* offscreen appearance fixes */
area = get_display_area(get_phys_screen(c->screen), area = get_display_area(get_phys_screen(c->screen),
NULL, NULL,
@ -497,33 +499,35 @@ client_resize(Client *c, Area geometry, Bool sizehints, Bool volatile_coords)
geometry.x = 0; geometry.x = 0;
if(geometry.y + geometry.height + 2 * c->border < 0) if(geometry.y + geometry.height + 2 * c->border < 0)
geometry.y = 0; geometry.y = 0;
if(c->geometry.x != geometry.x || c->geometry.y != geometry.y if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
|| c->geometry.width != geometry.width || c->geometry.height != geometry.height) || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
{ {
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 = 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, geometry.x, geometry.y,
geometry.width, geometry.height);
window_configure(c->win, geometry, c->border);
if(XineramaIsActive(globalconf.display)) if(XineramaIsActive(globalconf.display))
{ new_screen = get_screen_bycoord(geometry.x, geometry.y);
int new_screen = get_screen_bycoord(geometry.x, geometry.y); else
if(c->screen != new_screen) new_screen = c->screen;
move_client_to_screen(c, new_screen, False);
} c->geometry.x = wc.x = geometry.x;
c->geometry.y = wc.y = geometry.y;
c->geometry.width = wc.width = geometry.width;
c->geometry.height = wc.height = geometry.height;
wc.border_width = c->border;
if(c->isfloating ||
get_current_layout(new_screen)->arrange == layout_floating)
c->f_geometry = geometry;
XConfigureWindow(globalconf.display, c->win,
CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
window_configure(c->win, geometry, c->border);
if(c->screen != new_screen)
move_client_to_screen(c, new_screen, False);
return True;
} }
return False;
} }
/** Save client properties as an X property /** Save client properties as an X property
@ -819,7 +823,7 @@ uicb_client_moveresize(int screen, char *arg)
RootWindow(globalconf.display, RootWindow(globalconf.display,
get_phys_screen(screen)), get_phys_screen(screen)),
&dummy, &dummy, &mx, &my, &dx, &dy, &dui); &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
client_resize(sel, area, True, False); client_resize(sel, area, True);
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->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1; nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
@ -864,36 +868,30 @@ uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((
client_kill(sel); client_kill(sel);
} }
void static void
client_maximize(Client *c, int x, int y, int w, int h, Bool borders) client_maximize(Client *c, Area geometry)
{ {
Area area;
area.x = x;
area.y = y;
area.width = w;
area.height = h;
if((c->ismax = !c->ismax)) if((c->ismax = !c->ismax))
{ {
if(borders)
{
c->oldborder = c->border;
c->border = 0;
}
c->wasfloating = c->isfloating; c->wasfloating = c->isfloating;
c->m_geometry = c->geometry;
client_resize(c, geometry, False);
/* set floating after resizing so it won't save
* coords */
c->isfloating = True; c->isfloating = True;
client_resize(c, area, False, True);
} }
else if(c->wasfloating) else if(c->wasfloating)
client_resize(c, c->f_geometry, True, False); {
c->isfloating = True;
client_resize(c, c->m_geometry, False);
}
else else
{
c->isfloating = False; c->isfloating = False;
arrange(c->screen);
if(borders) }
c->border = c->oldborder; statusbar_draw_all(c->screen);
arrange(c->screen);
} }
/** Toggle maximize for client /** Toggle maximize for client
@ -908,10 +906,13 @@ uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
Area area = get_screen_area(screen, Area area = get_screen_area(screen,
globalconf.screens[screen].statusbar, globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
if(sel) if(sel)
client_maximize(sel, area.x, area.y, {
area.width - 2 * sel->border, area.width -= 2 * sel->border;
area.height - 2 * sel->border, False); area.height -= 2 * sel->border;
client_maximize(sel, area);
}
} }
/** Toggle vertical maximize for client /** Toggle vertical maximize for client
@ -928,9 +929,11 @@ 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->geometry.x, area.y, {
sel->geometry.width, area.x = sel->geometry.x;
area.height - 2 * sel->border, False); area.height -= 2 * sel->border;
client_maximize(sel, area);
}
} }
@ -948,9 +951,11 @@ 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->geometry.y, {
area.height - 2 * sel->border, area.y = sel->geometry.y;
sel->geometry.height, False); area.width -= 2 * sel->border;
client_maximize(sel, area);
}
} }
/** Zoom client /** Zoom client

View File

@ -32,7 +32,7 @@ void client_detach(Client *);
void client_ban(Client *); void client_ban(Client *);
void focus(Client *, Bool, int); void focus(Client *, Bool, int);
void client_manage(Window, XWindowAttributes *, int); void client_manage(Window, XWindowAttributes *, int);
void client_resize(Client *, Area, Bool, Bool); Bool client_resize(Client *, Area, Bool);
void client_unban(Client *); void client_unban(Client *);
void client_unmanage(Client *, long); void client_unmanage(Client *, long);
void client_updatewmhints(Client *); void client_updatewmhints(Client *);
@ -40,7 +40,6 @@ void client_updatesizehints(Client *);
void client_updatetitle(Client *); void client_updatetitle(Client *);
void client_saveprops(Client *); void client_saveprops(Client *);
void client_kill(Client *); void client_kill(Client *);
void client_maximize(Client *c, int, int, int, int, Bool);
Uicb uicb_client_kill; Uicb uicb_client_kill;
Uicb uicb_client_moveresize; Uicb uicb_client_moveresize;

44
event.c
View File

@ -139,39 +139,41 @@ handle_event_configurerequest(XEvent * e)
Client *c; Client *c;
XConfigureRequestEvent *ev = &e->xconfigurerequest; XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc; XWindowChanges wc;
int old_screen; int old_screen, new_screen;
Area geometry;
if((c = get_client_bywin(globalconf.clients, ev->window))) if((c = get_client_bywin(globalconf.clients, ev->window)))
{ {
if(c->isfixed) geometry = c->geometry;
if(ev->value_mask & CWX)
geometry.x = ev->x;
if(ev->value_mask & CWY)
geometry.y = ev->y;
if(ev->value_mask & CWWidth)
geometry.width = ev->width;
if(ev->value_mask & CWHeight)
geometry.height = ev->height;
if(geometry.x != c->geometry.x || geometry.y != c->geometry.y
|| geometry.width != c->geometry.width || geometry.height != c->geometry.height)
{ {
if(ev->value_mask & CWX)
c->f_geometry.x = c->geometry.x = ev->x - c->border;
if(ev->value_mask & CWY)
c->f_geometry.y = c->f_geometry.y = ev->y - c->border;
if(ev->value_mask & CWWidth)
c->f_geometry.width = c->geometry.width = ev->width;
if(ev->value_mask & CWHeight)
c->f_geometry.height = c->geometry.height = ev->height;
if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight)))
window_configure(c->win, c->geometry, c->border);
/* recompute screen */
old_screen = c->screen; old_screen = c->screen;
c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
if(get_current_layout(c->screen)->arrange != layout_floating)
c->isfloating = True;
client_resize(c, geometry, False);
if(old_screen != c->screen) if(old_screen != c->screen)
{ {
move_client_to_screen(c, c->screen, False);
statusbar_draw_all(old_screen); statusbar_draw_all(old_screen);
statusbar_draw_all(c->screen); arrange(old_screen);
} }
tag_client_with_rules(c); statusbar_draw_all(c->screen);
XMoveResizeWindow(e->xany.display, c->win, c->f_geometry.x, c->f_geometry.y,
c->f_geometry.width, c->f_geometry.height);
window_configure(c->win, c->f_geometry, c->border);
arrange(c->screen); arrange(c->screen);
} }
else else
window_configure(c->win, c->geometry, c->border); window_configure(c->win, geometry, c->border);
} }
else else
{ {

27
ewmh.c
View File

@ -28,6 +28,7 @@
#include "focus.h" #include "focus.h"
#include "screen.h" #include "screen.h"
#include "client.h" #include "client.h"
#include "statusbar.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -241,13 +242,29 @@ ewmh_process_state_atom(Client *c, Atom state, int set)
} }
else if(state == net_wm_state_fullscreen) else if(state == net_wm_state_fullscreen)
{ {
Area area = get_screen_area(c->screen, NULL, NULL); Area geometry;
/* reset max attribute */
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
c->ismax = True; {
else if(set == _NET_WM_STATE_ADD) /* restore geometry */
geometry = c->m_geometry;
c->border = c->oldborder;
c->ismax = False; c->ismax = False;
client_maximize(c, area.x, area.y, area.width, area.height, True); c->isfloating = c->wasfloating;
}
else if(set == _NET_WM_STATE_ADD)
{
geometry = get_screen_area(c->screen, NULL, NULL);
/* save geometry */
c->m_geometry = c->geometry;
c->wasfloating = c->isfloating;
c->oldborder = c->border;
c->border = 0;
c->ismax = True;
c->isfloating = True;
}
statusbar_draw_all(c->screen);
client_resize(c, geometry, False);
XRaiseWindow(globalconf.display, c->win);
} }
} }

View File

@ -82,7 +82,7 @@ layout_fibonacci(int screen, int shape)
} }
geometry.width -= 2 * c->border; geometry.width -= 2 * c->border;
geometry.height -= 2 * c->border; geometry.height -= 2 * c->border;
client_resize(c, geometry, globalconf.screens[screen].resize_hints, False); client_resize(c, geometry, globalconf.screens[screen].resize_hints);
} }
} }

View File

@ -32,6 +32,6 @@ 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->f_geometry, True, False); client_resize(c, c->f_geometry, True);
} }
// 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

View File

@ -40,7 +40,7 @@ layout_max(int screen)
{ {
area.width -= 2 * c->border; area.width -= 2 * c->border;
area.height -= 2 * c->border; area.height -= 2 * c->border;
client_resize(c, area, globalconf.screens[screen].resize_hints, False); client_resize(c, area, globalconf.screens[screen].resize_hints);
area.width += 2 * c->border; area.width += 2 * c->border;
area.height += 2 * c->border; area.height += 2 * c->border;
} }

View File

@ -145,15 +145,15 @@ _tile(int screen, const Bool right)
c->ismax = False; c->ismax = False;
if(i < curtags[0]->nmaster) if(i < curtags[0]->nmaster)
{ /* master */ {
geometry.y = way + i * mh; geometry.y = way + i * mh;
geometry.x = wax + (right ? 0 : waw - mw); geometry.x = wax + (right ? 0 : waw - mw);
geometry.width = mw - 2 * c->border; geometry.width = mw - 2 * c->border;
geometry.height = mh - 2 * c->border; geometry.height = mh - 2 * c->border;
client_resize(c, geometry, globalconf.screens[screen].resize_hints, False); client_resize(c, geometry, globalconf.screens[screen].resize_hints);
} }
else else
{ /* tile window */ {
if(real_ncol) if(real_ncol)
win_by_col = otherwin / real_ncol; win_by_col = otherwin / real_ncol;
@ -176,7 +176,7 @@ _tile(int screen, const Bool right)
geometry.y = way + ((i - curtags[0]->nmaster) % win_by_col) * (geometry.height + 2 * c->border); geometry.y = way + ((i - curtags[0]->nmaster) % win_by_col) * (geometry.height + 2 * c->border);
geometry.x = wax + current_col * (geometry.width + 2 * c->border) + (right ? mw : 0); geometry.x = wax + current_col * (geometry.width + 2 * c->border) + (right ? mw : 0);
client_resize(c, geometry, globalconf.screens[screen].resize_hints, False); client_resize(c, geometry, globalconf.screens[screen].resize_hints);
} }
i++; i++;
} }

View File

@ -109,7 +109,7 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
geometry.y = area.y + area.height - c->geometry.height - 2 * c->border; geometry.y = area.y + area.height - c->geometry.height - 2 * c->border;
geometry.width = c->geometry.width; geometry.width = c->geometry.width;
geometry.height = c->geometry.height; geometry.height = c->geometry.height;
client_resize(c, geometry, False, False); client_resize(c, geometry, False);
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev)); while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
break; break;
} }
@ -199,7 +199,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
geometry.height = 1; geometry.height = 1;
geometry.x = c->geometry.x; geometry.x = c->geometry.x;
geometry.y = c->geometry.y; geometry.y = c->geometry.y;
client_resize(c, geometry, True, False); client_resize(c, geometry, True);
} }
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)
@ -225,5 +225,4 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
p_delete(&curtags); p_delete(&curtags);
} }
// 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

View File

@ -27,6 +27,7 @@
#include "focus.h" #include "focus.h"
#include "statusbar.h" #include "statusbar.h"
#include "client.h" #include "client.h"
#include "layouts/floating.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -142,7 +143,6 @@ get_screen_bycoord(int x, int y)
if(!XineramaIsActive(globalconf.display)) if(!XineramaIsActive(globalconf.display))
return DefaultScreen(globalconf.display); return DefaultScreen(globalconf.display);
for(i = 0; i < get_screen_count(); i++) for(i = 0; i < get_screen_count(); i++)
{ {
area = get_screen_area(i, NULL, NULL); area = get_screen_area(i, NULL, NULL);
@ -203,25 +203,46 @@ move_client_to_screen(Client *c, int new_screen, Bool doresize)
/* tag client with new screen tags */ /* tag client with new screen tags */
tag_client_with_current_selected(c); tag_client_with_current_selected(c);
/* resize the windows if it's floating */
if(doresize && old_screen != c->screen) if(doresize && old_screen != c->screen)
{ {
Area new_f_geometry = c->f_geometry;
to = get_screen_area(c->screen, NULL, NULL); to = get_screen_area(c->screen, NULL, NULL);
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->f_geometry.x = (c->f_geometry.x - from.x) + to.x; new_f_geometry.x = (c->f_geometry.x - from.x) + to.x;
c->f_geometry.y = (c->f_geometry.y - from.y) + to.y; new_f_geometry.y = (c->f_geometry.y - from.y) + to.y;
/* check that new coords are still in the screen */
if(c->f_geometry.width > to.width)
c->f_geometry.width = to.width;
if(c->f_geometry.height > to.height)
c->f_geometry.height = to.height;
if(c->f_geometry.x + c->f_geometry.width >= to.x + to.width)
c->f_geometry.x = to.x + to.width - c->f_geometry.width - 2 * c->border;
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, True, False); /* check that new coords are still in the screen */
if(new_f_geometry.width > to.width)
new_f_geometry.width = to.width;
if(new_f_geometry.height > to.height)
new_f_geometry.height = to.height;
if(new_f_geometry.x + new_f_geometry.width >= to.x + to.width)
new_f_geometry.x = to.x + to.width - new_f_geometry.width - 2 * c->border;
if(new_f_geometry.y + new_f_geometry.height >= to.y + to.height)
new_f_geometry.y = to.y + to.height - new_f_geometry.height - 2 * c->border;
if(c->ismax)
{
/* compute new coords for max in new screen */
c->m_geometry.x = (c->m_geometry.x - from.x) + to.x;
c->m_geometry.y = (c->m_geometry.y - from.y) + to.y;
/* check that new coords are still in the screen */
if(c->m_geometry.width > to.width)
c->m_geometry.width = to.width;
if(c->m_geometry.height > to.height)
c->m_geometry.height = to.height;
if(c->m_geometry.x + c->m_geometry.width >= to.x + to.width)
c->m_geometry.x = to.x + to.width - c->m_geometry.width - 2 * c->border;
if(c->m_geometry.y + c->m_geometry.height >= to.y + to.height)
c->m_geometry.y = to.y + to.height - c->m_geometry.height - 2 * c->border;
}
client_resize(c, new_f_geometry, False);
} }
focus(c, True, c->screen); focus(c, True, c->screen);

10
tag.c
View File

@ -206,19 +206,15 @@ uicb_client_tag(int screen, char *arg)
* \ingroup ui_callback * \ingroup ui_callback
*/ */
void void
uicb_client_togglefloating(int screen, char *arg __attribute__ ((unused))) uicb_client_togglefloating(int screen, char *arg __attribute__((unused)))
{ {
Client *sel = globalconf.focus->client; Client *sel = globalconf.focus->client;
if(!sel) if(!sel)
return; return;
sel->isfloating = !sel->isfloating; if((sel->isfloating = !sel->isfloating))
client_resize(sel, sel->f_geometry, True);
if (arg == NULL)
client_resize(sel, sel->f_geometry, True, False);
else
client_resize(sel, sel->geometry, True, True);
client_saveprops(sel); client_saveprops(sel);
arrange(screen); arrange(screen);