2007-11-13 22:57:57 +01:00
|
|
|
/*
|
|
|
|
* mouse.c - mouse managing
|
|
|
|
*
|
2008-03-15 09:10:32 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-11-13 22:57:57 +01:00
|
|
|
*
|
|
|
|
* 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>
|
2008-06-04 19:05:46 +02:00
|
|
|
#include <stdbool.h>
|
2007-12-28 17:37:41 +01:00
|
|
|
|
2008-03-23 18:48:07 +01:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
|
2007-11-13 22:57:57 +01:00
|
|
|
#include "mouse.h"
|
|
|
|
#include "screen.h"
|
2008-06-09 16:30:46 +02:00
|
|
|
#include "workspace.h"
|
2007-11-13 22:57:57 +01:00
|
|
|
#include "event.h"
|
2008-01-01 17:25:48 +01:00
|
|
|
#include "client.h"
|
2008-03-25 14:56:38 +01:00
|
|
|
#include "titlebar.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
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
#define MOUSEMASK (XCB_EVENT_MASK_BUTTON_PRESS \
|
|
|
|
| XCB_EVENT_MASK_BUTTON_RELEASE \
|
|
|
|
| XCB_EVENT_MASK_POINTER_MOTION)
|
2008-01-29 08:23:20 +01:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-06-08 18:15:53 +02:00
|
|
|
/** Define corners. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
AutoCorner,
|
|
|
|
TopRightCorner,
|
|
|
|
TopLeftCorner,
|
|
|
|
BottomLeftCorner,
|
|
|
|
BottomRightCorner
|
|
|
|
} corner_t;
|
|
|
|
|
|
|
|
/** Convert a corner name into a corner type.
|
|
|
|
* \param str A string.
|
|
|
|
* \return A corner type.
|
|
|
|
*/
|
|
|
|
static corner_t
|
|
|
|
a_strtocorner(const char *str)
|
|
|
|
{
|
|
|
|
if(!a_strcmp(str, "bottomright"))
|
|
|
|
return BottomRightCorner;
|
|
|
|
else if(!a_strcmp(str, "bottomleft"))
|
|
|
|
return BottomLeftCorner;
|
|
|
|
else if(!a_strcmp(str, "topleft"))
|
|
|
|
return TopLeftCorner;
|
|
|
|
else if(!a_strcmp(str, "topright"))
|
|
|
|
return TopRightCorner;
|
|
|
|
return AutoCorner;
|
|
|
|
}
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
/** Snap an area to the outside of an area.
|
|
|
|
* \param geometry geometry of the area to snap
|
|
|
|
* \param snap_geometry geometry of snapping area
|
|
|
|
* \param snap snap trigger in pixel
|
|
|
|
* \return snapped geometry
|
|
|
|
*/
|
2008-03-25 15:24:45 +01:00
|
|
|
static area_t
|
|
|
|
mouse_snapclienttogeometry_outside(area_t geometry, area_t snap_geometry, int snap)
|
|
|
|
{
|
|
|
|
if(geometry.x < snap + snap_geometry.x + snap_geometry.width
|
|
|
|
&& geometry.x > snap_geometry.x + snap_geometry.width)
|
|
|
|
geometry.x = snap_geometry.x + snap_geometry.width;
|
|
|
|
else if(geometry.x + geometry.width < snap_geometry.x
|
|
|
|
&& geometry.x + geometry.width > snap_geometry.x - snap)
|
|
|
|
geometry.x = snap_geometry.x - geometry.width;
|
|
|
|
|
|
|
|
if(geometry.y < snap + snap_geometry.y + snap_geometry.height
|
|
|
|
&& geometry.y > snap_geometry.y + snap_geometry.height)
|
|
|
|
geometry.y = snap_geometry.y + snap_geometry.height;
|
|
|
|
else if(geometry.y + geometry.height < snap_geometry.y
|
|
|
|
&& geometry.y + geometry.height > snap_geometry.y - snap)
|
|
|
|
geometry.y = snap_geometry.y - geometry.height;
|
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
/** Snap an area to the inside of an area.
|
|
|
|
* \param geometry geometry of the area to snap
|
|
|
|
* \param snap_geometry geometry of snapping area
|
|
|
|
* \param snap snap trigger in pixel
|
|
|
|
* \return snapped geometry
|
|
|
|
*/
|
2008-03-25 15:24:45 +01:00
|
|
|
static area_t
|
|
|
|
mouse_snapclienttogeometry_inside(area_t geometry, area_t snap_geometry, int snap)
|
|
|
|
{
|
|
|
|
if(abs(geometry.x) < snap + snap_geometry.x && geometry.x > snap_geometry.x)
|
|
|
|
geometry.x = snap_geometry.x;
|
|
|
|
else if(abs((snap_geometry.x + snap_geometry.width) - (geometry.x + geometry.width))
|
|
|
|
< snap)
|
|
|
|
geometry.x = snap_geometry.x + snap_geometry.width - geometry.width;
|
|
|
|
if(abs(geometry.y) < snap + snap_geometry.y && geometry.y > snap_geometry.y)
|
|
|
|
geometry.y = snap_geometry.y;
|
|
|
|
else if(abs((snap_geometry.y + snap_geometry.height) - (geometry.y + geometry.height))
|
|
|
|
< snap)
|
|
|
|
geometry.y = snap_geometry.y + snap_geometry.height - geometry.height;
|
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
/** Snap a client with a futur geometry to the screen and other clients.
|
2008-06-04 11:50:21 +02:00
|
|
|
* \param c The client.
|
|
|
|
* \param geometry Geometry the client will get.
|
|
|
|
* \return Geometry to set to the client.
|
2008-04-09 15:32:55 +02:00
|
|
|
*/
|
2008-03-25 14:41:06 +01:00
|
|
|
static area_t
|
2008-05-20 15:39:47 +02:00
|
|
|
mouse_snapclient(client_t *c, area_t geometry, int snap)
|
2008-03-25 14:41:06 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *snapper;
|
2008-06-09 16:30:46 +02:00
|
|
|
int screen = workspace_screen_get(workspace_client_get(c));
|
2008-03-25 15:24:45 +01:00
|
|
|
area_t snapper_geometry;
|
2008-03-25 14:41:06 +01:00
|
|
|
area_t screen_geometry =
|
2008-06-09 16:30:46 +02:00
|
|
|
screen_area_get(screen,
|
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
2008-03-25 14:41:06 +01:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
geometry = titlebar_geometry_add(c->titlebar, geometry);
|
2008-03-25 15:24:45 +01:00
|
|
|
geometry.width += 2 * c->border;
|
|
|
|
geometry.height += 2 * c->border;
|
2008-03-25 14:56:38 +01:00
|
|
|
|
2008-03-25 15:24:45 +01:00
|
|
|
geometry =
|
|
|
|
mouse_snapclienttogeometry_inside(geometry, screen_geometry, snap);
|
|
|
|
|
|
|
|
for(snapper = globalconf.clients; snapper; snapper = snapper->next)
|
2008-06-09 16:30:46 +02:00
|
|
|
if(snapper != c && client_isvisible(c, screen))
|
2008-03-25 15:24:45 +01:00
|
|
|
{
|
|
|
|
snapper_geometry = snapper->geometry;
|
|
|
|
snapper_geometry.width += 2 * c->border;
|
|
|
|
snapper_geometry.height += 2 * c->border;
|
2008-06-04 11:50:21 +02:00
|
|
|
snapper_geometry = titlebar_geometry_add(c->titlebar, snapper_geometry);
|
2008-03-25 15:24:45 +01:00
|
|
|
geometry =
|
|
|
|
mouse_snapclienttogeometry_outside(geometry,
|
|
|
|
snapper_geometry,
|
|
|
|
snap);
|
|
|
|
}
|
2008-03-25 14:41:06 +01:00
|
|
|
|
2008-03-25 15:24:45 +01:00
|
|
|
geometry.width -= 2 * c->border;
|
|
|
|
geometry.height -= 2 * c->border;
|
2008-06-04 11:50:21 +02:00
|
|
|
return titlebar_geometry_remove(c->titlebar, geometry);
|
2008-03-25 14:41:06 +01:00
|
|
|
}
|
|
|
|
|
2008-04-29 11:51:59 +02:00
|
|
|
/** Redraw the resizebar.
|
|
|
|
* \param ctx Draw context.
|
2008-06-08 15:27:05 +02:00
|
|
|
* \param sw The simple window.
|
2008-04-29 11:51:59 +02:00
|
|
|
* \param geometry The geometry to use for the box.
|
|
|
|
* \param border The client border size.
|
2008-04-09 15:32:55 +02:00
|
|
|
*/
|
2008-03-25 16:10:12 +01:00
|
|
|
static void
|
2008-05-20 15:39:47 +02:00
|
|
|
mouse_resizebar_draw(draw_context_t *ctx,
|
|
|
|
simple_window_t *sw,
|
|
|
|
area_t geometry, int border)
|
2008-03-25 16:10:12 +01:00
|
|
|
{
|
|
|
|
area_t draw_geometry = { 0, 0, ctx->width, ctx->height, NULL, NULL };
|
2008-04-28 13:24:23 +02:00
|
|
|
char size[64];
|
2008-03-25 16:10:12 +01:00
|
|
|
|
2008-04-28 13:24:23 +02:00
|
|
|
snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
2008-06-03 14:16:44 +02:00
|
|
|
geometry.width, geometry.height, geometry.x, geometry.y);
|
2008-05-20 15:39:47 +02:00
|
|
|
draw_rectangle(ctx, draw_geometry, 1.0, true, globalconf.colors.bg);
|
2008-06-02 12:18:17 +02:00
|
|
|
draw_text(ctx, globalconf.font, draw_geometry, size);
|
2008-03-25 16:10:12 +01:00
|
|
|
simplewindow_move(sw,
|
|
|
|
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
|
|
|
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
2008-06-04 16:13:41 +02:00
|
|
|
simplewindow_refresh_pixmap(sw);
|
2008-03-25 16:10:12 +01:00
|
|
|
}
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
/** Initialize the resizebar window.
|
2008-04-29 11:51:59 +02:00
|
|
|
* \param phys_screen Physical screen number.
|
|
|
|
* \param border Border size of the client.
|
|
|
|
* \param geometry Client geometry.
|
|
|
|
* \param ctx Draw context to create.
|
|
|
|
* \return The simple window.
|
2008-04-09 15:32:55 +02:00
|
|
|
*/
|
2008-04-09 19:41:28 +02:00
|
|
|
static simple_window_t *
|
2008-04-29 11:51:59 +02:00
|
|
|
mouse_resizebar_new(int phys_screen, int border, area_t geometry,
|
2008-05-20 15:39:47 +02:00
|
|
|
draw_context_t **ctx)
|
2008-04-09 15:32:55 +02:00
|
|
|
{
|
2008-04-09 19:41:28 +02:00
|
|
|
simple_window_t *sw;
|
2008-04-09 15:32:55 +02:00
|
|
|
area_t geom;
|
|
|
|
|
2008-04-23 17:44:09 +02:00
|
|
|
geom = draw_text_extents(globalconf.connection,
|
|
|
|
globalconf.default_screen,
|
2008-05-20 15:39:47 +02:00
|
|
|
globalconf.font,
|
2008-04-23 17:44:09 +02:00
|
|
|
"0000x0000+0000+0000");
|
2008-04-09 15:32:55 +02:00
|
|
|
geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2;
|
|
|
|
geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2;
|
|
|
|
|
|
|
|
sw = simplewindow_new(globalconf.connection, phys_screen,
|
|
|
|
geom.x, geom.y,
|
|
|
|
geom.width, geom.height, 0);
|
|
|
|
|
|
|
|
*ctx = draw_context_new(globalconf.connection, sw->phys_screen,
|
|
|
|
sw->geometry.width, sw->geometry.height,
|
2008-06-04 16:13:41 +02:00
|
|
|
sw->pixmap,
|
2008-06-02 12:18:17 +02:00
|
|
|
globalconf.colors.fg,
|
|
|
|
globalconf.colors.bg);
|
2008-04-09 15:32:55 +02:00
|
|
|
|
|
|
|
xcb_map_window(globalconf.connection, sw->window);
|
2008-05-20 15:39:47 +02:00
|
|
|
mouse_resizebar_draw(*ctx, sw, geometry, border);
|
2008-04-09 15:32:55 +02:00
|
|
|
|
|
|
|
return sw;
|
|
|
|
}
|
|
|
|
|
2008-06-04 19:05:46 +02:00
|
|
|
/** Get the Pointer position
|
|
|
|
* \param window
|
|
|
|
* \param x will be set to the Pointer-x-coordinate relative to window
|
|
|
|
* \param y will be set to the Pointer-y-coordinate relative to window
|
|
|
|
* \return true on success, false if an error occured
|
|
|
|
**/
|
|
|
|
static bool
|
|
|
|
mouse_query_pointer(xcb_window_t window, int *x, int *y)
|
|
|
|
{
|
|
|
|
xcb_query_pointer_cookie_t query_ptr_c;
|
|
|
|
xcb_query_pointer_reply_t *query_ptr_r;
|
|
|
|
|
|
|
|
query_ptr_c = xcb_query_pointer(globalconf.connection, window);
|
|
|
|
query_ptr_r = xcb_query_pointer_reply(globalconf.connection, query_ptr_c, NULL);
|
|
|
|
|
|
|
|
if(!query_ptr_r)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*x = query_ptr_r->win_x;
|
|
|
|
*y = query_ptr_r->win_y;
|
|
|
|
|
|
|
|
p_delete(&query_ptr_r);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-07 16:38:33 +02:00
|
|
|
/** Grab the Pointer.
|
|
|
|
* \param window The window grabbed.
|
|
|
|
* \param cursor The cursor to display (see struct.h CurNormal, CurResize, etc).
|
|
|
|
* \return True on success, false if an error occured.
|
2008-06-04 19:05:46 +02:00
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
mouse_grab_pointer(xcb_window_t window, size_t cursor)
|
|
|
|
{
|
|
|
|
xcb_grab_pointer_cookie_t grab_ptr_c;
|
|
|
|
xcb_grab_pointer_reply_t *grab_ptr_r;
|
|
|
|
|
|
|
|
if(cursor >= CurLast)
|
|
|
|
cursor = CurNormal;
|
|
|
|
|
|
|
|
grab_ptr_c = xcb_grab_pointer(globalconf.connection, false, window,
|
|
|
|
MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
|
|
|
|
window, globalconf.cursor[cursor], XCB_CURRENT_TIME);
|
|
|
|
grab_ptr_r = xcb_grab_pointer_reply(globalconf.connection, grab_ptr_c, NULL);
|
|
|
|
|
|
|
|
if(!grab_ptr_r)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
p_delete(&grab_ptr_r);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Ungrab the Pointer
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
mouse_ungrab_pointer()
|
|
|
|
{
|
|
|
|
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the Pointer position
|
|
|
|
* \param window the destination window
|
|
|
|
* \param x x-coordinate inside window
|
|
|
|
* \param y y-coordinate inside window
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
mouse_warp_pointer(xcb_window_t window, int x, int y)
|
|
|
|
{
|
|
|
|
xcb_warp_pointer(globalconf.connection, XCB_NONE, window,
|
|
|
|
0, 0, 0, 0, x, y );
|
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Move the focused window with the mouse.
|
2007-12-19 04:39:59 +01:00
|
|
|
*/
|
2008-05-26 16:17:57 +02:00
|
|
|
static void
|
|
|
|
mouse_client_move(client_t *c, int snap)
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
2008-03-25 14:41:06 +01:00
|
|
|
area_t geometry;
|
2008-05-26 16:17:57 +02:00
|
|
|
client_t *target;
|
2008-06-09 16:30:46 +02:00
|
|
|
workspace_t *ws = workspace_client_get(c);
|
2008-04-09 19:41:28 +02:00
|
|
|
simple_window_t *sw = NULL;
|
2008-04-28 15:32:30 +02:00
|
|
|
draw_context_t *ctx;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_generic_event_t *ev = NULL;
|
|
|
|
xcb_motion_notify_event_t *ev_motion = NULL;
|
|
|
|
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
2008-04-09 15:32:55 +02:00
|
|
|
xcb_grab_pointer_cookie_t grab_pointer_c;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_query_pointer_reply_t *query_pointer_r = NULL, *mquery_pointer_r = NULL;
|
2008-04-09 15:32:55 +02:00
|
|
|
xcb_query_pointer_cookie_t query_pointer_c;
|
2008-05-20 15:39:47 +02:00
|
|
|
xcb_screen_t *s;
|
2008-06-09 16:30:46 +02:00
|
|
|
int ocx, ocy, newscreen, screen = workspace_screen_get(ws);
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
s = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
/* Send pointer requests */
|
|
|
|
grab_pointer_c = xcb_grab_pointer(globalconf.connection, false, s->root,
|
|
|
|
MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
|
|
|
|
s->root, globalconf.cursor[CurMove], XCB_CURRENT_TIME);
|
2008-03-28 13:00:12 +01:00
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
query_pointer_c = xcb_query_pointer_unchecked(globalconf.connection, s->root);
|
2008-03-25 16:10:12 +01:00
|
|
|
|
|
|
|
geometry = c->geometry;
|
|
|
|
ocx = geometry.x;
|
|
|
|
ocy = geometry.y;
|
2008-04-09 15:32:55 +02:00
|
|
|
|
|
|
|
/* Get responses */
|
|
|
|
if(!(grab_pointer_r = xcb_grab_pointer_reply(globalconf.connection, grab_pointer_c, NULL)))
|
|
|
|
return;
|
|
|
|
|
2008-05-25 17:42:20 +02:00
|
|
|
c->ismax = false;
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
p_delete(&grab_pointer_r);
|
|
|
|
|
|
|
|
query_pointer_r = xcb_query_pointer_reply(globalconf.connection, query_pointer_c, NULL);
|
2008-03-28 13:22:26 +01:00
|
|
|
|
2008-06-09 16:30:46 +02:00
|
|
|
if(c->isfloating || ws->layout == layout_floating)
|
2008-03-25 16:10:12 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
sw = mouse_resizebar_new(c->phys_screen, c->border, c->geometry, &ctx);
|
2008-04-09 15:32:55 +02:00
|
|
|
xcb_aux_sync(globalconf.connection);
|
2008-03-25 16:10:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-29 17:34:43 +02:00
|
|
|
while(true)
|
2008-03-28 22:59:05 +01:00
|
|
|
/* XMaskEvent allows to retrieve only specified events from
|
|
|
|
* the queue and requeue the other events... */
|
2008-04-09 20:04:15 +02:00
|
|
|
while(ev || (ev = xcb_wait_for_event(globalconf.connection)))
|
2008-03-21 16:50:17 +01:00
|
|
|
switch((ev->response_type & 0x7f))
|
2008-01-28 10:37:47 +01:00
|
|
|
{
|
2008-04-09 20:04:15 +02:00
|
|
|
case XCB_BUTTON_RELEASE:
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
|
|
|
|
if(sw)
|
|
|
|
{
|
|
|
|
draw_context_delete(&ctx);
|
|
|
|
simplewindow_delete(&sw);
|
|
|
|
}
|
|
|
|
p_delete(&query_pointer_r);
|
|
|
|
p_delete(&ev);
|
|
|
|
return;
|
2008-04-09 20:04:15 +02:00
|
|
|
case XCB_MOTION_NOTIFY:
|
2008-06-09 16:30:46 +02:00
|
|
|
if(c->isfloating || ws->layout == layout_floating)
|
2008-01-28 11:32:55 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
ev_motion = (xcb_motion_notify_event_t *) ev;
|
|
|
|
|
|
|
|
geometry.x = ocx + (ev_motion->event_x - query_pointer_r->root_x);
|
|
|
|
geometry.y = ocy + (ev_motion->event_y - query_pointer_r->root_y);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
geometry = mouse_snapclient(c, geometry, snap);
|
2008-06-09 18:16:55 +02:00
|
|
|
if((newscreen = screen_get_bycoord(globalconf.screens_info, screen,
|
|
|
|
geometry.x, geometry.y)) != screen)
|
|
|
|
{
|
|
|
|
if((ws = globalconf.screens[newscreen].workspace))
|
|
|
|
{
|
|
|
|
screen = workspace_screen_get(ws);
|
|
|
|
workspace_client_set(c, ws);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p_delete(&ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 15:32:55 +02:00
|
|
|
c->ismoving = true;
|
|
|
|
client_resize(c, geometry, false);
|
|
|
|
c->ismoving = false;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
if(sw)
|
2008-05-20 15:39:47 +02:00
|
|
|
mouse_resizebar_draw(ctx, sw, c->geometry, c->border);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-03-23 18:48:07 +01:00
|
|
|
xcb_aux_sync(globalconf.connection);
|
2008-01-28 11:32:55 +01:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
else
|
2008-01-28 11:32:55 +01:00
|
|
|
{
|
2008-04-09 15:32:55 +02:00
|
|
|
query_pointer_c = xcb_query_pointer_unchecked(globalconf.connection, s->root);
|
|
|
|
mquery_pointer_r = xcb_query_pointer_reply(globalconf.connection, query_pointer_c, NULL);
|
2008-06-09 16:30:46 +02:00
|
|
|
if((newscreen = screen_get_bycoord(globalconf.screens_info,
|
|
|
|
screen,
|
2008-03-21 16:50:17 +01:00
|
|
|
mquery_pointer_r->root_x,
|
2008-06-09 16:30:46 +02:00
|
|
|
mquery_pointer_r->root_y)) != screen
|
|
|
|
&& globalconf.screens[newscreen].workspace)
|
2008-03-21 16:50:17 +01:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
ws->need_arrange = true;
|
|
|
|
ws = globalconf.screens[newscreen].workspace;
|
|
|
|
screen = workspace_screen_get(ws);
|
|
|
|
workspace_client_set(c, ws);
|
|
|
|
ws->need_arrange = true;
|
2008-05-27 11:01:57 +02:00
|
|
|
layout_refresh();
|
2008-03-21 16:50:17 +01:00
|
|
|
}
|
2008-06-05 09:25:38 +02:00
|
|
|
if((target = client_getbywin(mquery_pointer_r->child))
|
2008-03-21 16:50:17 +01:00
|
|
|
&& target != c && !target->isfloating)
|
|
|
|
{
|
|
|
|
client_list_swap(&globalconf.clients, c, target);
|
2008-06-09 16:30:46 +02:00
|
|
|
ws->need_arrange = true;
|
2008-05-27 11:01:57 +02:00
|
|
|
layout_refresh();
|
2008-03-21 16:50:17 +01:00
|
|
|
}
|
|
|
|
p_delete(&mquery_pointer_r);
|
2008-01-28 11:32:55 +01:00
|
|
|
}
|
2008-04-09 19:32:15 +02:00
|
|
|
p_delete(&ev);
|
|
|
|
while((ev = xcb_poll_for_event(globalconf.connection))
|
|
|
|
&& (ev->response_type & 0x7f) == XCB_MOTION_NOTIFY)
|
|
|
|
p_delete(&ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
break;
|
2008-04-09 20:04:15 +02:00
|
|
|
default:
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_handle_event(globalconf.evenths, ev);
|
2008-04-09 19:32:15 +02:00
|
|
|
p_delete(&ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
break;
|
2008-01-28 11:32:55 +01:00
|
|
|
}
|
2007-11-13 22:57:57 +01:00
|
|
|
}
|
|
|
|
|
2008-06-04 19:09:43 +02:00
|
|
|
|
|
|
|
/** Utility function to help with mouse-dragging
|
|
|
|
*
|
|
|
|
* \param x set to x-coordinate of the last event on return
|
|
|
|
* \param y set to y-coordinate of the last event on return
|
|
|
|
* \return true if an motion event was recieved
|
|
|
|
* false if an button release event was recieved
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
mouse_track_mouse_drag(int *x, int *y)
|
|
|
|
{
|
|
|
|
xcb_generic_event_t *ev;
|
|
|
|
xcb_motion_notify_event_t *ev_motion;
|
|
|
|
xcb_button_release_event_t *ev_button;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
while((ev = xcb_wait_for_event(globalconf.connection)))
|
|
|
|
{
|
|
|
|
switch((ev->response_type & 0x7F))
|
|
|
|
{
|
|
|
|
|
|
|
|
case XCB_MOTION_NOTIFY:
|
|
|
|
ev_motion = (xcb_motion_notify_event_t*) ev;
|
|
|
|
*x = ev_motion->event_x;
|
|
|
|
*y = ev_motion->event_y;
|
|
|
|
p_delete(&ev);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case XCB_BUTTON_RELEASE:
|
|
|
|
ev_button = (xcb_button_release_event_t*) ev;
|
|
|
|
*x = ev_button->event_x;
|
|
|
|
*y = ev_button->event_y;
|
|
|
|
p_delete(&ev);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
xcb_handle_event(globalconf.evenths, ev);
|
|
|
|
p_delete(&ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Resize a floating client with the mouse.
|
|
|
|
* \param c The client to resize.
|
2008-06-08 18:15:53 +02:00
|
|
|
* \param c The corner to resize with.
|
2008-06-04 19:09:43 +02:00
|
|
|
*/
|
|
|
|
static void
|
2008-06-08 18:15:53 +02:00
|
|
|
mouse_client_resize_floating(client_t *c, corner_t corner)
|
2008-06-04 19:09:43 +02:00
|
|
|
{
|
|
|
|
xcb_screen_t *screen;
|
|
|
|
/* one corner of the client has a fixed position */
|
|
|
|
int fixed_x, fixed_y;
|
|
|
|
/* the other is moved with the mouse */
|
|
|
|
int mouse_x = 0, mouse_y = 0;
|
|
|
|
/* the resize bar */
|
|
|
|
simple_window_t *sw;
|
|
|
|
draw_context_t *ctx;
|
2008-06-07 16:38:33 +02:00
|
|
|
size_t cursor = CurResize;
|
2008-06-08 18:15:53 +02:00
|
|
|
int top, bottom, left, right;
|
2008-06-04 19:09:43 +02:00
|
|
|
|
|
|
|
screen = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
|
|
|
|
|
2008-06-08 18:15:53 +02:00
|
|
|
/* get current mouse position */
|
2008-06-04 19:09:43 +02:00
|
|
|
mouse_query_pointer(screen->root, &mouse_x, &mouse_y);
|
|
|
|
|
2008-06-08 18:15:53 +02:00
|
|
|
top = c->geometry.y;
|
|
|
|
bottom = top + c->geometry.height;
|
|
|
|
left = c->geometry.x;
|
|
|
|
right = left + c->geometry.width;
|
|
|
|
|
2008-06-04 19:09:43 +02:00
|
|
|
/* figure out which corner to move */
|
2008-06-08 18:15:53 +02:00
|
|
|
if(corner == AutoCorner)
|
2008-06-04 19:09:43 +02:00
|
|
|
{
|
|
|
|
if(abs(top - mouse_y) < abs(bottom - mouse_y))
|
|
|
|
{
|
2008-06-07 16:38:33 +02:00
|
|
|
if(abs(left - mouse_x) < abs(right - mouse_x))
|
|
|
|
cursor = CurTopLeft;
|
|
|
|
else
|
2008-06-08 18:15:53 +02:00
|
|
|
corner = TopRightCorner;
|
2008-06-04 19:09:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-07 16:38:33 +02:00
|
|
|
if(abs(left - mouse_x) < abs(right - mouse_x))
|
2008-06-08 18:15:53 +02:00
|
|
|
corner = BottomLeftCorner;
|
2008-06-07 16:38:33 +02:00
|
|
|
else
|
2008-06-08 18:15:53 +02:00
|
|
|
corner = BottomRightCorner;
|
2008-06-04 19:09:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-08 18:15:53 +02:00
|
|
|
switch(corner)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
mouse_y = top;
|
|
|
|
fixed_y = bottom;
|
|
|
|
mouse_x = left;
|
|
|
|
fixed_x = right;
|
|
|
|
corner = TopLeftCorner;
|
|
|
|
break;
|
|
|
|
case TopRightCorner:
|
|
|
|
mouse_y = top;
|
|
|
|
fixed_y = bottom;
|
|
|
|
mouse_x = right;
|
|
|
|
fixed_x = left;
|
|
|
|
cursor = CurTopRight;
|
|
|
|
break;
|
|
|
|
case BottomLeftCorner:
|
|
|
|
mouse_y = bottom;
|
|
|
|
fixed_y = top;
|
|
|
|
mouse_x = left;
|
|
|
|
fixed_x = right;
|
|
|
|
cursor = CurBotLeft;
|
|
|
|
break;
|
|
|
|
case BottomRightCorner:
|
|
|
|
mouse_y = bottom;
|
|
|
|
fixed_y = top;
|
|
|
|
mouse_x = right;
|
|
|
|
fixed_x = left;
|
|
|
|
cursor = CurBotRight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-04 19:09:43 +02:00
|
|
|
/* grab the pointer */
|
2008-06-07 16:38:33 +02:00
|
|
|
if(!mouse_grab_pointer(screen->root, cursor))
|
2008-06-04 19:09:43 +02:00
|
|
|
return;
|
|
|
|
|
2008-06-05 22:17:44 +02:00
|
|
|
/* set pointer to the moveable corner */
|
|
|
|
mouse_warp_pointer(screen->root, mouse_x, mouse_y);
|
|
|
|
|
2008-06-04 19:09:43 +02:00
|
|
|
/* create the resizebar */
|
|
|
|
sw = mouse_resizebar_new(c->phys_screen, c->border, c->geometry, &ctx);
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
|
|
|
|
/* for each motion event */
|
|
|
|
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
|
|
|
{
|
|
|
|
/* new client geometry */
|
|
|
|
area_t geo = { .x = MIN(fixed_x, mouse_x),
|
|
|
|
.y = MIN(fixed_y, mouse_y),
|
|
|
|
.width = (MAX(fixed_x, mouse_x) - MIN(fixed_x, mouse_x)),
|
|
|
|
.height = (MAX(fixed_y, mouse_y) - MIN(fixed_y, mouse_y)) };
|
|
|
|
|
|
|
|
/* resize the client */
|
|
|
|
client_resize(c, geo, true);
|
|
|
|
|
|
|
|
/* draw the resizebar */
|
|
|
|
mouse_resizebar_draw(ctx, sw, c->geometry, c->border);
|
|
|
|
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* relase pointer */
|
|
|
|
mouse_ungrab_pointer();
|
|
|
|
|
|
|
|
/* free the resize bar */
|
|
|
|
draw_context_delete(&ctx);
|
|
|
|
simplewindow_delete(&sw);
|
|
|
|
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
}
|
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
/** Resize the master column/row of a tiled layout
|
2008-06-09 16:30:46 +02:00
|
|
|
* \param c A client on the workspace/layout to resize.
|
2008-06-07 22:44:16 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mouse_client_resize_tiled(client_t *c)
|
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
xcb_screen_t *xscreen;
|
2008-06-07 22:44:16 +02:00
|
|
|
/* screen area modulo statusbar */
|
|
|
|
area_t area;
|
2008-06-09 16:30:46 +02:00
|
|
|
/* current workspace */
|
|
|
|
workspace_t *ws = workspace_client_get(c);
|
|
|
|
int mouse_x, mouse_y, screen = workspace_screen_get(ws);
|
2008-06-07 23:37:24 +02:00
|
|
|
size_t cursor = CurResize;
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-06-09 16:30:46 +02:00
|
|
|
xscreen = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-06-09 16:30:46 +02:00
|
|
|
area = screen_area_get(screen,
|
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-06-09 16:30:46 +02:00
|
|
|
mouse_query_pointer(xscreen->root, &mouse_x, &mouse_y);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
|
|
|
/* select initial pointer position */
|
2008-06-09 16:30:46 +02:00
|
|
|
if(ws->layout == layout_tile)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
mouse_x = area.x + area.width * ws->mwfact;
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeH;
|
|
|
|
}
|
2008-06-09 16:30:46 +02:00
|
|
|
else if(ws->layout == layout_tileleft)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
mouse_x = area.x + area.width * (1. - ws->mwfact);
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeH;
|
|
|
|
}
|
2008-06-09 16:30:46 +02:00
|
|
|
else if(ws->layout == layout_tilebottom)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
mouse_y = area.y + area.height * ws->mwfact;
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeV;
|
|
|
|
}
|
2008-06-09 16:30:46 +02:00
|
|
|
else if(ws->layout == layout_tiletop)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
mouse_y = area.y + area.height * (1. - ws->mwfact);
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeV;
|
|
|
|
}
|
2008-06-07 22:44:16 +02:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* grab the pointer */
|
2008-06-09 16:30:46 +02:00
|
|
|
if(!mouse_grab_pointer(xscreen->root, cursor))
|
2008-06-07 22:44:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* set pointer to the moveable border */
|
2008-06-09 16:30:46 +02:00
|
|
|
mouse_warp_pointer(xscreen->root, mouse_x, mouse_y);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
|
|
|
|
/* for each motion event */
|
|
|
|
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
|
|
|
{
|
|
|
|
double mwfact, fact_x, fact_y;
|
|
|
|
|
|
|
|
/* calculate new master / rest ratio */
|
|
|
|
fact_x = (double) (mouse_x - area.x) / area.width;
|
|
|
|
fact_y = (double) (mouse_y - area.y) / area.height;
|
|
|
|
|
2008-06-09 16:30:46 +02:00
|
|
|
if(ws->layout == layout_tile)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = fact_x;
|
2008-06-09 16:30:46 +02:00
|
|
|
else if(ws->layout == layout_tileleft)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = 1. - fact_x;
|
2008-06-09 16:30:46 +02:00
|
|
|
else if(ws->layout == layout_tilebottom)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = fact_y;
|
2008-06-09 16:30:46 +02:00
|
|
|
else if(ws->layout == layout_tiletop)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = 1. - fact_y;
|
|
|
|
|
|
|
|
/* refresh layout */
|
2008-06-09 16:30:46 +02:00
|
|
|
if(fabs(ws->mwfact - mwfact) >= 0.01)
|
2008-06-07 22:44:16 +02:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
ws->mwfact = mwfact;
|
|
|
|
ws->need_arrange = true;
|
2008-06-07 22:44:16 +02:00
|
|
|
layout_refresh();
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* relase pointer */
|
|
|
|
mouse_ungrab_pointer();
|
|
|
|
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-28 16:37:47 +02:00
|
|
|
/** Resize a client with the mouse.
|
|
|
|
* \param c The client to resize.
|
2008-06-08 18:15:53 +02:00
|
|
|
* \param corner The corner to use.
|
2007-12-19 04:39:59 +01:00
|
|
|
*/
|
2008-05-26 16:17:57 +02:00
|
|
|
static void
|
2008-06-08 18:15:53 +02:00
|
|
|
mouse_client_resize(client_t *c, corner_t corner)
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
2008-06-04 19:09:43 +02:00
|
|
|
int n, screen;
|
2008-06-09 16:30:46 +02:00
|
|
|
workspace_t *ws = workspace_client_get(c);
|
2008-05-20 15:39:47 +02:00
|
|
|
xcb_screen_t *s;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
s = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
|
2008-03-28 13:22:26 +01:00
|
|
|
|
2008-05-26 16:17:57 +02:00
|
|
|
/* only handle floating and tiled layouts */
|
2008-06-09 16:30:46 +02:00
|
|
|
if(ws->layout == layout_floating || c->isfloating)
|
2007-12-28 17:11:20 +01:00
|
|
|
{
|
2008-05-28 16:37:47 +02:00
|
|
|
if(c->isfixed)
|
|
|
|
return;
|
|
|
|
|
2008-05-25 17:42:20 +02:00
|
|
|
c->ismax = false;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2008-06-08 18:15:53 +02:00
|
|
|
mouse_client_resize_floating(c, corner);
|
2008-03-28 13:22:26 +01:00
|
|
|
}
|
2008-06-09 16:30:46 +02:00
|
|
|
else if (ws->layout == layout_tile || ws->layout == layout_tileleft
|
|
|
|
|| ws->layout == layout_tilebottom || ws->layout == layout_tiletop)
|
2008-03-28 13:22:26 +01:00
|
|
|
{
|
2008-06-09 16:30:46 +02:00
|
|
|
screen = workspace_screen_get(ws);
|
2008-03-28 13:22:26 +01:00
|
|
|
for(n = 0, c = globalconf.clients; c; c = c->next)
|
2008-05-28 16:37:47 +02:00
|
|
|
if(IS_TILED(c, screen))
|
2008-03-28 13:22:26 +01:00
|
|
|
n++;
|
2007-12-28 17:11:20 +01:00
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
/* only masters on this screen? */
|
2008-06-09 16:30:46 +02:00
|
|
|
if(n <= ws->nmaster) return;
|
2008-03-28 13:22:26 +01:00
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
/* no tiled clients on this screen? */
|
2008-05-28 16:37:47 +02:00
|
|
|
for(c = globalconf.clients; c && !IS_TILED(c, screen); c = c->next);
|
2008-03-28 13:22:26 +01:00
|
|
|
if(!c) return;
|
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
mouse_client_resize_tiled(c);
|
2007-11-13 22:57:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-26 16:17:57 +02:00
|
|
|
/** Set mouse coordinates.
|
2008-06-08 19:56:01 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam The x coordinate.
|
|
|
|
* \lparam The y coordinate.
|
2008-05-26 16:17:57 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_mouse_coords_set(lua_State *L)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
x = luaL_checknumber(L, 1);
|
|
|
|
y = luaL_checknumber(L, 2);
|
|
|
|
xcb_warp_pointer(globalconf.connection, XCB_NONE,
|
|
|
|
xcb_aux_get_screen(globalconf.connection, globalconf.default_screen)->root,
|
|
|
|
0, 0, 0, 0, x, y);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 16:17:57 +02:00
|
|
|
/** Resize a client with mouse.
|
2008-06-08 19:56:01 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam An optionnal corner, such as bottomleft, topright, etc.
|
2008-05-26 16:17:57 +02:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_client_mouse_resize(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-06-08 18:15:53 +02:00
|
|
|
corner_t corner = AutoCorner;
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2 && lua_isstring(L, 2))
|
|
|
|
corner = a_strtocorner(lua_tostring(L, 2));
|
|
|
|
|
|
|
|
mouse_client_resize(*c, corner);
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 16:17:57 +02:00
|
|
|
/** Move a client with mouse.
|
2008-06-08 19:56:01 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam The pixel to snap.
|
2008-05-26 16:17:57 +02:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_client_mouse_move(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-05-26 16:17:57 +02:00
|
|
|
int snap = luaL_optnumber(L, 2, 8);
|
|
|
|
mouse_client_move(*c, snap);
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 16:17:57 +02:00
|
|
|
/** Get the screen number where the mouse ic.
|
2008-06-08 19:56:01 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lreturn The screen number.
|
2008-05-26 16:17:57 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_mouse_screen_get(lua_State *L)
|
|
|
|
{
|
|
|
|
int screen;
|
2008-06-09 18:16:55 +02:00
|
|
|
xcb_query_pointer_cookie_t qc;
|
|
|
|
xcb_query_pointer_reply_t *qr;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
qc = xcb_query_pointer(globalconf.connection,
|
|
|
|
xcb_aux_get_screen(globalconf.connection,
|
|
|
|
globalconf.default_screen)->root);
|
|
|
|
|
|
|
|
if(!(qr = xcb_query_pointer_reply(globalconf.connection, qc, NULL)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
screen = screen_get_bycoord(globalconf.screens_info,
|
|
|
|
globalconf.default_screen,
|
|
|
|
qr->root_x, qr->root_y);
|
|
|
|
p_delete(&qr);
|
|
|
|
lua_pushnumber(L, screen + 1);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct luaL_reg awesome_mouse_lib[] =
|
|
|
|
{
|
|
|
|
{ "screen_get", luaA_mouse_screen_get },
|
|
|
|
{ "coords_set", luaA_mouse_coords_set },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|