2007-11-13 22:57:57 +01:00
|
|
|
/*
|
|
|
|
* mouse.c - mouse managing
|
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-12-28 17:37:41 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2007-11-13 22:57:57 +01:00
|
|
|
#include "mouse.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "window.h"
|
2007-12-27 23:50:19 +01:00
|
|
|
#include "statusbar.h"
|
2007-11-13 22:57:57 +01:00
|
|
|
#include "layouts/floating.h"
|
2007-12-28 17:11:20 +01:00
|
|
|
#include "layouts/tile.h"
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2007-12-19 04:39:59 +01:00
|
|
|
/** Move client with mouse
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-11-13 22:57:57 +01:00
|
|
|
void
|
2007-12-17 01:17:54 +01:00
|
|
|
uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
2007-12-28 17:37:41 +01:00
|
|
|
int x1, y, ocx, ocy, di, nx, ny;
|
2007-11-13 22:57:57 +01:00
|
|
|
unsigned int dui;
|
|
|
|
Window dummy;
|
|
|
|
XEvent ev;
|
2007-12-23 00:54:59 +01:00
|
|
|
Area area;
|
2007-12-16 02:45:38 +01:00
|
|
|
Client *c = globalconf.focus->client;
|
2007-12-27 12:50:55 +01:00
|
|
|
Tag **curtags = get_current_tags(screen);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-28 20:48:29 +01:00
|
|
|
if(!c || (c && c->isfixed))
|
2007-11-13 22:57:57 +01:00
|
|
|
return;
|
|
|
|
|
2007-12-27 12:50:55 +01:00
|
|
|
if((curtags[0]->layout->arrange != layout_floating)
|
2007-11-13 22:57:57 +01:00
|
|
|
&& !c->isfloating)
|
2007-12-27 12:50:55 +01:00
|
|
|
uicb_client_togglefloating(screen, NULL);
|
|
|
|
else
|
|
|
|
restack(screen);
|
|
|
|
|
|
|
|
p_delete(&curtags);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-23 00:54:59 +01:00
|
|
|
area = get_screen_area(c->screen,
|
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
|
|
|
ocx = nx = c->x;
|
|
|
|
ocy = ny = c->y;
|
2007-12-27 23:10:43 +01:00
|
|
|
if(XGrabPointer(globalconf.display,
|
|
|
|
RootWindow(globalconf.display, c->phys_screen),
|
2007-12-19 04:39:59 +01:00
|
|
|
False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
2007-12-16 02:45:38 +01:00
|
|
|
None, globalconf.cursor[CurMove], CurrentTime) != GrabSuccess)
|
2007-11-13 22:57:57 +01:00
|
|
|
return;
|
2007-12-27 23:10:43 +01:00
|
|
|
XQueryPointer(globalconf.display,
|
|
|
|
RootWindow(globalconf.display, c->phys_screen),
|
2007-12-28 17:37:41 +01:00
|
|
|
&dummy, &dummy, &x1, &y, &di, &di, &dui);
|
2007-12-27 23:50:19 +01:00
|
|
|
c->ismax = False;
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_draw_all(c->screen);
|
2007-11-13 22:57:57 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
2007-12-27 23:10:43 +01:00
|
|
|
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonRelease:
|
2007-12-27 23:10:43 +01:00
|
|
|
XUngrabPointer(globalconf.display, CurrentTime);
|
2007-11-13 22:57:57 +01:00
|
|
|
return;
|
|
|
|
case ConfigureRequest:
|
2007-12-16 02:45:38 +01:00
|
|
|
handle_event_configurerequest(&ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case Expose:
|
2007-12-16 02:45:38 +01:00
|
|
|
handle_event_expose(&ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MapRequest:
|
2007-12-16 02:45:38 +01:00
|
|
|
handle_event_maprequest(&ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
nx = ocx + (ev.xmotion.x - x1);
|
2007-12-28 17:37:41 +01:00
|
|
|
ny = ocy + (ev.xmotion.y - y);
|
2007-12-23 00:54:59 +01:00
|
|
|
if(abs(nx) < globalconf.screens[screen].snap + 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)
|
|
|
|
nx = area.x + area.width - c->w - 2 * c->border;
|
|
|
|
if(abs(ny) < globalconf.screens[screen].snap + 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)
|
|
|
|
ny = area.y + area.height - c->h - 2 * c->border;
|
2007-12-16 02:45:38 +01:00
|
|
|
client_resize(c, nx, ny, c->w, c->h, False, False);
|
2007-12-28 17:39:29 +01:00
|
|
|
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-19 04:39:59 +01:00
|
|
|
/** Resize client with mouse
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-11-13 22:57:57 +01:00
|
|
|
void
|
2007-12-17 01:17:54 +01:00
|
|
|
uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
2007-12-28 17:11:20 +01:00
|
|
|
int ocx, ocy, nw, nh, n;
|
2007-11-13 22:57:57 +01:00
|
|
|
XEvent ev;
|
2007-12-16 02:45:38 +01:00
|
|
|
Client *c = globalconf.focus->client;
|
2007-12-27 12:50:55 +01:00
|
|
|
Tag **curtags = get_current_tags(screen);
|
2007-12-28 17:11:20 +01:00
|
|
|
Area area;
|
|
|
|
double mwfact;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-28 17:11:20 +01:00
|
|
|
/* only handle floating and tiled layouts */
|
2007-12-28 20:48:29 +01:00
|
|
|
if(c && !c->isfixed)
|
2007-12-28 17:11:20 +01:00
|
|
|
{
|
|
|
|
if((curtags[0]->layout->arrange == layout_floating) || c->isfloating)
|
|
|
|
{
|
|
|
|
restack(screen);
|
|
|
|
ocx = c->x;
|
|
|
|
ocy = c->y;
|
|
|
|
c->ismax = False;
|
|
|
|
}
|
|
|
|
else if (curtags[0]->layout->arrange == layout_tile
|
|
|
|
|| curtags[0]->layout->arrange == layout_tileleft)
|
|
|
|
{
|
|
|
|
for(n = 0, c = globalconf.clients; c; c = c->next)
|
|
|
|
if(IS_TILED(c, screen))
|
|
|
|
n++;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-28 17:11:20 +01:00
|
|
|
if(n <= curtags[0]->nmaster) return;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-28 17:11:20 +01:00
|
|
|
for(c = globalconf.clients; c && !IS_TILED(c, screen); c = c->next);
|
|
|
|
if(!c) return;
|
|
|
|
|
|
|
|
area = get_screen_area(screen,
|
|
|
|
globalconf.screens[c->screen].statusbar,
|
|
|
|
&globalconf.screens[c->screen].padding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
2007-12-27 12:50:55 +01:00
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
if(XGrabPointer(globalconf.display, RootWindow(globalconf.display, c->phys_screen),
|
2007-11-13 22:57:57 +01:00
|
|
|
False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
2007-12-16 02:45:38 +01:00
|
|
|
None, globalconf.cursor[CurResize], CurrentTime) != GrabSuccess)
|
2007-11-13 22:57:57 +01:00
|
|
|
return;
|
2007-12-28 17:11:20 +01:00
|
|
|
|
|
|
|
if(curtags[0]->layout->arrange == layout_tileleft)
|
|
|
|
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0, c->h + c->border - 1);
|
|
|
|
else
|
|
|
|
XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
|
|
|
|
|
2007-11-13 22:57:57 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
2007-12-27 23:10:43 +01:00
|
|
|
XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonRelease:
|
2007-12-27 23:10:43 +01:00
|
|
|
XUngrabPointer(globalconf.display, CurrentTime);
|
|
|
|
while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
|
2007-11-13 22:57:57 +01:00
|
|
|
return;
|
|
|
|
case ConfigureRequest:
|
2007-12-16 02:45:38 +01:00
|
|
|
handle_event_configurerequest(&ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case Expose:
|
2007-12-16 02:45:38 +01:00
|
|
|
handle_event_expose(&ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MapRequest:
|
2007-12-16 02:45:38 +01:00
|
|
|
handle_event_maprequest(&ev);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2007-12-28 17:11:20 +01:00
|
|
|
if(curtags[0]->layout->arrange == layout_floating || c->isfloating)
|
|
|
|
{
|
|
|
|
if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
|
|
|
|
nw = 1;
|
|
|
|
if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
|
|
|
|
nh = 1;
|
|
|
|
client_resize(c, c->x, c->y, nw, nh, True, False);
|
|
|
|
}
|
|
|
|
else if(curtags[0]->layout->arrange == layout_tile
|
|
|
|
|| curtags[0]->layout->arrange == layout_tileleft)
|
|
|
|
{
|
|
|
|
if(curtags[0]->layout->arrange == layout_tile)
|
|
|
|
mwfact = (double) (ev.xmotion.x - area.x) / area.width;
|
|
|
|
else
|
|
|
|
mwfact = 1 - (double) (ev.xmotion.x - area.x) / area.width;
|
|
|
|
if(mwfact < 0.1) mwfact = 0.1;
|
|
|
|
else if(mwfact > 0.9) mwfact = 0.9;
|
2007-12-28 17:37:41 +01:00
|
|
|
if(fabs(curtags[0]->mwfact - mwfact) >= 0.05)
|
|
|
|
{
|
|
|
|
curtags[0]->mwfact = mwfact;
|
|
|
|
arrange(screen);
|
|
|
|
/* drop possibly arrived events while we where arrange()ing */
|
|
|
|
while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
|
|
|
|
}
|
2007-12-28 17:11:20 +01:00
|
|
|
}
|
|
|
|
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-28 17:11:20 +01:00
|
|
|
p_delete(&curtags);
|
2007-11-13 22:57:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|