windows can be swaped with mouse in tiled layout

This commit is contained in:
Julien Danjou 2008-01-28 10:37:47 +01:00
parent 7f93559939
commit a73d635146
1 changed files with 50 additions and 38 deletions

46
mouse.c
View File

@ -42,25 +42,17 @@ extern AwesomeConf globalconf;
void void
uicb_client_movemouse(int screen, char *arg __attribute__ ((unused))) uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
{ {
int x1, y, ocx, ocy, di, phys_screen; int x, y, ocx, ocy, di, phys_screen;
unsigned int dui; unsigned int dui;
Window dummy; Window dummy, child;
XEvent ev; XEvent ev;
Area area, geometry; Area area, geometry;
Client *c = globalconf.focus->client; Client *c = globalconf.focus->client, *target;
Layout *layout = get_current_layout(screen); Layout *layout = get_current_layout(screen);
if(!c) if(!c)
return; return;
if(layout->arrange != layout_floating && !c->isfloating)
{
/* ugly hack: copy current geom to be floating
* because mouse will be far away from window otherwise */
c->f_geometry = c->geometry;
client_setfloating(c, True);
}
/* go above everybody */ /* go above everybody */
XMapRaised(globalconf.display, c->win); XMapRaised(globalconf.display, c->win);
@ -74,11 +66,12 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
if(XGrabPointer(globalconf.display, if(XGrabPointer(globalconf.display,
RootWindow(globalconf.display, phys_screen), RootWindow(globalconf.display, phys_screen),
False, MOUSEMASK, GrabModeAsync, GrabModeAsync, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, globalconf.cursor[CurMove], CurrentTime) != GrabSuccess) RootWindow(globalconf.display, phys_screen),
globalconf.cursor[CurMove], CurrentTime) != GrabSuccess)
return; return;
XQueryPointer(globalconf.display, XQueryPointer(globalconf.display,
RootWindow(globalconf.display, phys_screen), RootWindow(globalconf.display, phys_screen),
&dummy, &dummy, &x1, &y, &di, &di, &dui); &dummy, &dummy, &x, &y, &di, &di, &dui);
c->ismax = False; c->ismax = False;
for(;;) for(;;)
{ {
@ -86,6 +79,16 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
switch (ev.type) switch (ev.type)
{ {
case ButtonRelease: case ButtonRelease:
if(!c->isfloating && layout->arrange != layout_floating)
{
XQueryPointer(globalconf.display, RootWindow(globalconf.display, phys_screen),
&dummy, &child, &x, &y, &di, &di, &dui);
if((target = get_client_bywin(globalconf.clients, child)) && target != c)
{
client_list_swap(&globalconf.clients, c, target);
globalconf.screens[screen].need_arrange = True;
}
}
XUngrabPointer(globalconf.display, CurrentTime); XUngrabPointer(globalconf.display, CurrentTime);
return; return;
case ConfigureRequest: case ConfigureRequest:
@ -97,21 +100,29 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
case MapRequest: case MapRequest:
handle_event_maprequest(&ev); handle_event_maprequest(&ev);
break; break;
case EnterNotify:
handle_event_enternotify(&ev);
break;
case MotionNotify: case MotionNotify:
geometry.x = ocx + (ev.xmotion.x - x1); if(c->isfloating || layout->arrange == layout_floating)
{
geometry.x = ocx + (ev.xmotion.x - x);
geometry.y = ocy + (ev.xmotion.y - y); geometry.y = ocy + (ev.xmotion.y - y);
if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x) if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > 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) 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; 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) if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > 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) 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.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); client_resize(c, geometry, False);
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev)); while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
}
break; break;
} }
} }
@ -165,7 +176,8 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
if(XGrabPointer(globalconf.display, RootWindow(globalconf.display, if(XGrabPointer(globalconf.display, RootWindow(globalconf.display,
get_phys_screen(c->screen)), get_phys_screen(c->screen)),
False, MOUSEMASK, GrabModeAsync, GrabModeAsync, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, globalconf.cursor[CurResize], CurrentTime) != GrabSuccess) RootWindow(globalconf.display,get_phys_screen(c->screen)),
globalconf.cursor[CurResize], CurrentTime) != GrabSuccess)
return; return;
if(curtags[0]->layout->arrange == layout_tileleft) if(curtags[0]->layout->arrange == layout_tileleft)