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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "layouts/floating.h"
|
|
|
|
|
|
|
|
void
|
2007-12-11 20:56:51 +01:00
|
|
|
uicb_client_movemouse(awesome_config *awesomeconf, int screen, const char *arg __attribute__ ((unused)))
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
|
|
|
int x1, y1, ocx, ocy, di, nx, ny;
|
|
|
|
unsigned int dui;
|
|
|
|
Window dummy;
|
|
|
|
XEvent ev;
|
|
|
|
ScreenInfo *si;
|
2007-12-14 21:51:54 +01:00
|
|
|
Client *c = awesomeconf->focus->client;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
|
|
|
if(!c)
|
|
|
|
return;
|
|
|
|
|
2007-12-14 02:27:10 +01:00
|
|
|
if((get_current_layout(awesomeconf->screens[screen])->arrange != layout_floating)
|
2007-11-13 22:57:57 +01:00
|
|
|
&& !c->isfloating)
|
2007-12-11 20:56:51 +01:00
|
|
|
uicb_client_togglefloating(awesomeconf, screen, "DUMMY");
|
2007-11-13 22:57:57 +01:00
|
|
|
else
|
2007-12-11 20:56:51 +01:00
|
|
|
restack(awesomeconf, screen);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2007-12-11 20:56:51 +01:00
|
|
|
si = get_screen_info(c->display, c->screen, &awesomeconf->screens[screen].statusbar, &awesomeconf->screens[screen].padding);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
|
|
|
ocx = nx = c->x;
|
|
|
|
ocy = ny = c->y;
|
|
|
|
if(XGrabPointer(c->display, RootWindow(c->display, c->phys_screen), False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
|
|
|
None, awesomeconf->cursor[CurMove], CurrentTime) != GrabSuccess)
|
|
|
|
return;
|
|
|
|
XQueryPointer(c->display, RootWindow(c->display, c->phys_screen), &dummy, &dummy, &x1, &y1, &di, &di, &dui);
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
XMaskEvent(c->display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonRelease:
|
|
|
|
XUngrabPointer(c->display, CurrentTime);
|
|
|
|
p_delete(&si);
|
|
|
|
return;
|
|
|
|
case ConfigureRequest:
|
2007-12-11 20:56:51 +01:00
|
|
|
handle_event_configurerequest(&ev, awesomeconf);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case Expose:
|
2007-12-11 20:56:51 +01:00
|
|
|
handle_event_expose(&ev, awesomeconf);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MapRequest:
|
2007-12-11 20:56:51 +01:00
|
|
|
handle_event_maprequest(&ev, awesomeconf);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
XSync(c->display, False);
|
|
|
|
nx = ocx + (ev.xmotion.x - x1);
|
|
|
|
ny = ocy + (ev.xmotion.y - y1);
|
2007-12-11 20:56:51 +01:00
|
|
|
if(abs(nx) < awesomeconf->screens[screen].snap + si[c->screen].x_org && nx > si[c->screen].x_org)
|
2007-11-13 22:57:57 +01:00
|
|
|
nx = si[c->screen].x_org;
|
2007-12-11 20:56:51 +01:00
|
|
|
else if(abs((si[c->screen].x_org + si[c->screen].width) - (nx + c->w + 2 * c->border)) < awesomeconf->screens[screen].snap)
|
2007-11-13 22:57:57 +01:00
|
|
|
nx = si[c->screen].x_org + si[c->screen].width - c->w - 2 * c->border;
|
2007-12-11 20:56:51 +01:00
|
|
|
if(abs(ny) < awesomeconf->screens[screen].snap + si[c->screen].y_org && ny > si[c->screen].y_org)
|
2007-11-13 22:57:57 +01:00
|
|
|
ny = si[c->screen].y_org;
|
2007-12-11 20:56:51 +01:00
|
|
|
else if(abs((si[c->screen].y_org + si[c->screen].height) - (ny + c->h + 2 * c->border)) < awesomeconf->screens[screen].snap)
|
2007-11-13 22:57:57 +01:00
|
|
|
ny = si[c->screen].y_org + si[c->screen].height - c->h - 2 * c->border;
|
|
|
|
client_resize(c, nx, ny, c->w, c->h, awesomeconf, False, False);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-11 20:56:51 +01:00
|
|
|
uicb_client_resizemouse(awesome_config *awesomeconf, int screen, const char *arg __attribute__ ((unused)))
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
|
|
|
int ocx, ocy, nw, nh;
|
|
|
|
XEvent ev;
|
2007-12-14 21:51:54 +01:00
|
|
|
Client *c = awesomeconf->focus->client;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
|
|
|
if(!c)
|
|
|
|
return;
|
|
|
|
|
2007-12-14 02:27:10 +01:00
|
|
|
if((get_current_layout(awesomeconf->screens[screen])->arrange != layout_floating)
|
2007-11-13 22:57:57 +01:00
|
|
|
&& !c->isfloating)
|
2007-12-11 20:56:51 +01:00
|
|
|
uicb_client_togglefloating(awesomeconf, screen, "DUMMY");
|
2007-11-13 22:57:57 +01:00
|
|
|
else
|
2007-12-11 20:56:51 +01:00
|
|
|
restack(awesomeconf, screen);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
|
|
|
ocx = c->x;
|
|
|
|
ocy = c->y;
|
|
|
|
if(XGrabPointer(c->display, RootWindow(c->display, c->phys_screen),
|
|
|
|
False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
|
|
|
None, awesomeconf->cursor[CurResize], CurrentTime) != GrabSuccess)
|
|
|
|
return;
|
|
|
|
c->ismax = False;
|
|
|
|
XWarpPointer(c->display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
XMaskEvent(c->display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonRelease:
|
|
|
|
XWarpPointer(c->display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
|
|
|
|
XUngrabPointer(c->display, CurrentTime);
|
|
|
|
while(XCheckMaskEvent(c->display, EnterWindowMask, &ev));
|
|
|
|
return;
|
|
|
|
case ConfigureRequest:
|
2007-12-11 20:56:51 +01:00
|
|
|
handle_event_configurerequest(&ev, awesomeconf);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case Expose:
|
2007-12-11 20:56:51 +01:00
|
|
|
handle_event_expose(&ev, awesomeconf);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MapRequest:
|
2007-12-11 20:56:51 +01:00
|
|
|
handle_event_maprequest(&ev, awesomeconf);
|
2007-11-13 22:57:57 +01:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
XSync(c->display, False);
|
|
|
|
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, awesomeconf, True, False);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|