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

88
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,44 +66,63 @@ 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(;;)
{ {
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
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:
handle_event_configurerequest(&ev); handle_event_configurerequest(&ev);
break; break;
case Expose: case Expose:
handle_event_expose(&ev); handle_event_expose(&ev);
break; break;
case MapRequest: case MapRequest:
handle_event_maprequest(&ev); handle_event_maprequest(&ev);
break; break;
case MotionNotify: case EnterNotify:
geometry.x = ocx + (ev.xmotion.x - x1); handle_event_enternotify(&ev);
geometry.y = ocy + (ev.xmotion.y - y); break;
if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x) case MotionNotify:
geometry.x = area.x; if(c->isfloating || layout->arrange == layout_floating)
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 = ocx + (ev.xmotion.x - x);
if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > area.y) geometry.y = ocy + (ev.xmotion.y - y);
geometry.y = area.y; if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x)
else if(abs((area.y + area.height) - (geometry.y + c->geometry.height + 2 * c->border)) < globalconf.screens[screen].snap) geometry.x = area.x;
geometry.y = area.y + area.height - c->geometry.height - 2 * c->border; else if(abs((area.x + area.width) - (geometry.x + c->geometry.width + 2 * c->border))
geometry.width = c->geometry.width; < globalconf.screens[screen].snap)
geometry.height = c->geometry.height; geometry.x = area.x + area.width - c->geometry.width - 2 * c->border;
client_resize(c, geometry, False); if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > area.y)
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev)); 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);
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)
@ -182,19 +194,19 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
switch (ev.type) switch (ev.type)
{ {
case ButtonRelease: case ButtonRelease:
XUngrabPointer(globalconf.display, CurrentTime); XUngrabPointer(globalconf.display, CurrentTime);
return; return;
case ConfigureRequest: case ConfigureRequest:
handle_event_configurerequest(&ev); handle_event_configurerequest(&ev);
break; break;
case Expose: case Expose:
handle_event_expose(&ev); handle_event_expose(&ev);
break; break;
case MapRequest: case MapRequest:
handle_event_maprequest(&ev); handle_event_maprequest(&ev);
break; break;
case MotionNotify: case MotionNotify:
if(layout->arrange == layout_floating || c->isfloating) if(layout->arrange == layout_floating || c->isfloating)
{ {
if((geometry.width = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0) if((geometry.width = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)