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-03-23 18:48:07 +01:00
|
|
|
|
2008-06-23 00:17:26 +02:00
|
|
|
#include "common/tokenize.h"
|
2007-11-13 22:57:57 +01:00
|
|
|
#include "screen.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.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"
|
2008-06-15 20:29:25 +02:00
|
|
|
#include "layouts/magnifier.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-08-12 13:23:10 +02:00
|
|
|
DO_LUA_NEW(extern, button_t, button, "button", button_ref)
|
|
|
|
DO_LUA_GC(button_t, button, "button", button_unref)
|
|
|
|
DO_LUA_EQ(button_t, button, "button")
|
2008-06-18 18:31:35 +02: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.
|
2008-06-23 14:01:33 +02:00
|
|
|
* \param len String length.
|
2008-06-08 18:15:53 +02:00
|
|
|
* \return A corner type.
|
|
|
|
*/
|
|
|
|
static corner_t
|
2008-06-23 14:01:33 +02:00
|
|
|
a_strtocorner(const char *str, size_t len)
|
2008-06-08 18:15:53 +02:00
|
|
|
{
|
2008-06-23 14:01:33 +02:00
|
|
|
switch (a_tokenize(str, len))
|
|
|
|
{
|
2008-06-23 00:17:26 +02:00
|
|
|
case A_TK_BOTTOMRIGHT: return BottomRightCorner;
|
|
|
|
case A_TK_BOTTOMLEFT: return BottomLeftCorner;
|
|
|
|
case A_TK_TOPLEFT: return TopLeftCorner;
|
|
|
|
case A_TK_TOPRIGHT: return TopRightCorner;
|
|
|
|
default: return AutoCorner;
|
|
|
|
}
|
2008-06-08 18:15:53 +02:00
|
|
|
}
|
|
|
|
|
2008-10-24 18:53:47 +02:00
|
|
|
/** Delete a button.
|
|
|
|
* \param button The button to destroy.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
button_delete(button_t **button)
|
|
|
|
{
|
|
|
|
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*button)->press);
|
|
|
|
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*button)->release);
|
|
|
|
p_delete(button);
|
|
|
|
}
|
|
|
|
|
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-06-15 20:30:19 +02:00
|
|
|
/** Snap a client with a future 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.
|
2008-06-13 19:17:35 +02:00
|
|
|
* \param snap The maximum distance in pixels to trigger a "snap".
|
2008-06-04 11:50:21 +02:00
|
|
|
* \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-03-25 15:24:45 +01:00
|
|
|
area_t snapper_geometry;
|
2008-03-25 14:41:06 +01:00
|
|
|
area_t screen_geometry =
|
2008-09-03 22:15:14 +02:00
|
|
|
screen_area_get(c->screen,
|
2008-09-24 12:13:21 +02:00
|
|
|
&globalconf.screens[c->screen].wiboxes,
|
2008-09-03 22:15:14 +02:00
|
|
|
&globalconf.screens[c->screen].padding,
|
|
|
|
false);
|
2008-03-25 14:41:06 +01:00
|
|
|
|
2008-08-18 10:56:40 +02:00
|
|
|
area_t screen_geometry_barless =
|
2008-09-03 22:15:14 +02:00
|
|
|
screen_area_get(c->screen,
|
2008-08-18 10:56:40 +02:00
|
|
|
NULL,
|
2008-09-03 22:15:14 +02:00
|
|
|
&globalconf.screens[c->screen].padding,
|
|
|
|
false);
|
2008-08-18 10:56:40 +02:00
|
|
|
|
2008-06-18 17:05:10 +02:00
|
|
|
geometry = titlebar_geometry_add(c->titlebar, c->border, geometry);
|
2008-03-25 14:56:38 +01:00
|
|
|
|
2008-03-25 15:24:45 +01:00
|
|
|
geometry =
|
|
|
|
mouse_snapclienttogeometry_inside(geometry, screen_geometry, snap);
|
|
|
|
|
2008-08-18 10:56:40 +02:00
|
|
|
geometry =
|
|
|
|
mouse_snapclienttogeometry_inside(geometry, screen_geometry_barless, snap);
|
|
|
|
|
2008-03-25 15:24:45 +01:00
|
|
|
for(snapper = globalconf.clients; snapper; snapper = snapper->next)
|
2008-08-18 11:04:50 +02:00
|
|
|
if(snapper != c && client_isvisible(snapper, c->screen))
|
2008-03-25 15:24:45 +01:00
|
|
|
{
|
|
|
|
snapper_geometry = snapper->geometry;
|
2008-08-18 11:04:50 +02:00
|
|
|
snapper_geometry = titlebar_geometry_add(snapper->titlebar, snapper->border, 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-06-18 17:05:10 +02:00
|
|
|
return titlebar_geometry_remove(c->titlebar, c->border, geometry);
|
2008-03-25 14:41:06 +01:00
|
|
|
}
|
|
|
|
|
2008-06-15 18:51:47 +02:00
|
|
|
/** Set coordinates to a corner of an area.
|
|
|
|
*
|
|
|
|
* \param a The area.
|
|
|
|
* \param[in,out] x The x coordinate.
|
|
|
|
* \param[in,out] y The y coordinate.
|
|
|
|
* \param corner The corner to snap to.
|
|
|
|
* \return The corner the coordinates have been set to. If corner != AutoCorner
|
|
|
|
* this is always equal to \em corner.
|
|
|
|
*
|
|
|
|
* \todo rename/move this is still awkward and might be useful somewhere else.
|
|
|
|
*/
|
|
|
|
static corner_t
|
|
|
|
mouse_snap_to_corner(area_t a, int *x, int *y, corner_t corner)
|
|
|
|
{
|
|
|
|
int top, bottom, left, right;
|
|
|
|
|
|
|
|
top = AREA_TOP(a);
|
|
|
|
bottom = AREA_BOTTOM(a);
|
|
|
|
left = AREA_LEFT(a);
|
|
|
|
right = AREA_RIGHT(a);
|
|
|
|
|
|
|
|
/* figure out the nearser corner */
|
|
|
|
if(corner == AutoCorner)
|
|
|
|
{
|
|
|
|
if(abs(top - *y) < abs(bottom - *y))
|
|
|
|
{
|
|
|
|
if(abs(left - *x) < abs(right - *x))
|
|
|
|
corner = TopLeftCorner;
|
|
|
|
else
|
|
|
|
corner = TopRightCorner;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(abs(left - *x) < abs(right - *x))
|
|
|
|
corner = BottomLeftCorner;
|
|
|
|
else
|
|
|
|
corner = BottomRightCorner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(corner)
|
|
|
|
{
|
|
|
|
case TopRightCorner:
|
|
|
|
*x = right;
|
|
|
|
*y = top;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TopLeftCorner:
|
|
|
|
*x = left;
|
|
|
|
*y = top;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BottomLeftCorner:
|
|
|
|
*x = left;
|
|
|
|
*y = bottom;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BottomRightCorner:
|
|
|
|
*x = right;
|
|
|
|
*y = bottom;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return corner;
|
|
|
|
}
|
|
|
|
|
2008-06-12 13:41:53 +02:00
|
|
|
/** Redraw the infobox.
|
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-09-24 12:13:21 +02:00
|
|
|
mouse_infobox_draw(simple_window_t *sw, area_t geometry, int border)
|
2008-03-25 16:10:12 +01:00
|
|
|
{
|
2008-09-20 19:31:38 +02:00
|
|
|
area_t draw_geometry = { 0, 0, sw->ctx.width, sw->ctx.height };
|
2008-04-28 13:24:23 +02:00
|
|
|
char size[64];
|
2008-07-10 15:35:19 +02:00
|
|
|
size_t len;
|
2008-03-25 16:10:12 +01:00
|
|
|
|
2008-07-10 15:35:19 +02:00
|
|
|
len = snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
|
|
|
geometry.width, geometry.height, geometry.x, geometry.y);
|
2008-09-20 19:31:38 +02:00
|
|
|
draw_rectangle(&sw->ctx, draw_geometry, 1.0, true, &globalconf.colors.bg);
|
|
|
|
draw_text(&sw->ctx, globalconf.font, draw_geometry, size, len, NULL);
|
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-08-26 19:35:37 +02:00
|
|
|
xcb_flush(globalconf.connection);
|
2008-03-25 16:10:12 +01:00
|
|
|
}
|
|
|
|
|
2008-07-10 15:06:09 +02:00
|
|
|
#define MOUSE_INFOBOX_STRING_DEFAULT "0000x0000+0000+0000"
|
|
|
|
|
2008-06-12 13:41:53 +02:00
|
|
|
/** Initialize the infobox window.
|
2008-09-20 21:24:16 +02:00
|
|
|
* \param sw The simple window to init.
|
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.
|
|
|
|
* \return The simple window.
|
2008-04-09 15:32:55 +02:00
|
|
|
*/
|
2008-09-20 21:24:16 +02:00
|
|
|
static void
|
|
|
|
mouse_infobox_new(simple_window_t *sw, int phys_screen, int border, area_t geometry)
|
2008-04-09 15:32:55 +02:00
|
|
|
{
|
|
|
|
area_t geom;
|
2008-06-23 16:15:24 +02:00
|
|
|
draw_parser_data_t pdata;
|
2008-07-02 09:14:17 +02:00
|
|
|
|
2008-06-23 16:15:24 +02:00
|
|
|
draw_parser_data_init(&pdata);
|
2008-04-09 15:32:55 +02:00
|
|
|
|
2008-09-11 14:11:13 +02:00
|
|
|
geom = draw_text_extents(globalconf.default_screen,
|
2008-05-20 15:39:47 +02:00
|
|
|
globalconf.font,
|
2008-07-10 15:06:09 +02:00
|
|
|
MOUSE_INFOBOX_STRING_DEFAULT,
|
2008-07-20 05:45:15 +02:00
|
|
|
sizeof(MOUSE_INFOBOX_STRING_DEFAULT)-1,
|
2008-07-10 15:06:09 +02:00
|
|
|
&pdata);
|
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;
|
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
p_clear(sw, 1);
|
|
|
|
simplewindow_init(sw, phys_screen, geom, 0, East,
|
|
|
|
&globalconf.colors.fg, &globalconf.colors.bg);
|
2008-04-09 15:32:55 +02:00
|
|
|
|
|
|
|
xcb_map_window(globalconf.connection, sw->window);
|
2008-09-20 19:31:38 +02:00
|
|
|
mouse_infobox_draw(sw, geometry, border);
|
2008-06-23 16:15:24 +02:00
|
|
|
|
|
|
|
draw_parser_data_wipe(&pdata);
|
2008-04-09 15:32:55 +02:00
|
|
|
}
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
/** Get the pointer position.
|
|
|
|
* \param window The window to get position on.
|
2008-06-04 19:05:46 +02:00
|
|
|
* \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
|
2008-06-19 16:51:33 +02:00
|
|
|
* \param mask will be set to the current buttons state
|
2008-06-04 19:05:46 +02:00
|
|
|
* \return true on success, false if an error occured
|
|
|
|
**/
|
|
|
|
static bool
|
2008-06-19 16:51:33 +02:00
|
|
|
mouse_query_pointer(xcb_window_t window, int *x, int *y, uint16_t *mask)
|
2008-06-04 19:05:46 +02:00
|
|
|
{
|
|
|
|
xcb_query_pointer_cookie_t query_ptr_c;
|
|
|
|
xcb_query_pointer_reply_t *query_ptr_r;
|
|
|
|
|
2008-06-13 21:33:38 +02:00
|
|
|
query_ptr_c = xcb_query_pointer_unchecked(globalconf.connection, window);
|
2008-06-04 19:05:46 +02:00
|
|
|
query_ptr_r = xcb_query_pointer_reply(globalconf.connection, query_ptr_c, NULL);
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
if(!query_ptr_r || !query_ptr_r->same_screen)
|
2008-06-04 19:05:46 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
*x = query_ptr_r->win_x;
|
|
|
|
*y = query_ptr_r->win_y;
|
2008-06-19 16:51:33 +02:00
|
|
|
if (mask)
|
|
|
|
*mask = query_ptr_r->mask;
|
2008-06-04 19:05:46 +02:00
|
|
|
|
|
|
|
p_delete(&query_ptr_r);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
/** Get the pointer position on the screen.
|
|
|
|
* \param screen This will be set to the screen number the mouse is on.
|
|
|
|
* \param x This will be set to the Pointer-x-coordinate relative to window.
|
|
|
|
* \param y This will be set to the Pointer-y-coordinate relative to window.
|
|
|
|
* \param mask This will be set to the current buttons state.
|
|
|
|
* \return True on success, false if an error occured.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
mouse_query_pointer_root(int *s, int *x, int *y, uint16_t *mask)
|
|
|
|
{
|
|
|
|
for(int screen = 0;
|
|
|
|
screen < xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
|
|
|
|
screen++)
|
|
|
|
{
|
|
|
|
xcb_window_t root = xutil_screen_get(globalconf.connection, screen)->root;
|
|
|
|
|
|
|
|
if(mouse_query_pointer(root, x, y, mask))
|
|
|
|
{
|
|
|
|
*s = screen;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2008-06-13 21:33:38 +02:00
|
|
|
grab_ptr_c = xcb_grab_pointer_unchecked(globalconf.connection, false, window,
|
|
|
|
MOUSEMASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
|
|
|
|
window, globalconf.cursor[cursor], XCB_CURRENT_TIME);
|
2008-06-04 19:05:46 +02:00
|
|
|
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
|
2008-06-16 23:06:11 +02:00
|
|
|
mouse_ungrab_pointer(void)
|
2008-06-04 19:05:46 +02:00
|
|
|
{
|
|
|
|
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
|
|
|
|
}
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
/** Set the pointer position.
|
|
|
|
* \param window The destination window.
|
|
|
|
* \param x X-coordinate inside window.
|
|
|
|
* \param y Y-coordinate inside window.
|
2008-06-04 19:05:46 +02:00
|
|
|
*/
|
|
|
|
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-06-15 15:20:12 +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
|
2008-06-15 20:30:19 +02:00
|
|
|
* \return true if an motion event was received
|
|
|
|
* false if an button release event was received
|
2008-06-15 15:20:12 +02:00
|
|
|
*/
|
|
|
|
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:
|
2008-09-16 15:36:44 +02:00
|
|
|
xcb_event_handle(&globalconf.evenths, ev);
|
2008-06-15 15:20:12 +02:00
|
|
|
p_delete(&ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
/** Get the client that contains the pointer.
|
2008-06-15 17:30:21 +02:00
|
|
|
*
|
2008-08-14 22:16:13 +02:00
|
|
|
* \return The client that contains the pointer or NULL.
|
2008-06-15 17:30:21 +02:00
|
|
|
*/
|
|
|
|
static client_t *
|
2008-08-14 22:16:13 +02:00
|
|
|
mouse_get_client_under_pointer(int phys_screen)
|
2008-06-15 17:30:21 +02:00
|
|
|
{
|
|
|
|
xcb_window_t root;
|
|
|
|
xcb_query_pointer_cookie_t query_ptr_c;
|
|
|
|
xcb_query_pointer_reply_t *query_ptr_r;
|
|
|
|
client_t *c = NULL;
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
root = xutil_screen_get(globalconf.connection, phys_screen)->root;
|
2008-06-15 17:30:21 +02:00
|
|
|
|
|
|
|
query_ptr_c = xcb_query_pointer_unchecked(globalconf.connection, root);
|
|
|
|
query_ptr_r = xcb_query_pointer_reply(globalconf.connection, query_ptr_c, NULL);
|
|
|
|
|
|
|
|
if(query_ptr_r)
|
|
|
|
{
|
|
|
|
c = client_getbywin(query_ptr_r->child);
|
|
|
|
p_delete(&query_ptr_r);
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Move the focused window with the mouse.
|
2008-06-15 17:32:03 +02:00
|
|
|
* \param c The client.
|
|
|
|
* \param snap The maximum distance in pixels to trigger a "snap".
|
|
|
|
* \param infobox Enable or disable the infobox.
|
2007-12-19 04:39:59 +01:00
|
|
|
*/
|
2008-05-26 16:17:57 +02:00
|
|
|
static void
|
2008-06-12 13:41:53 +02:00
|
|
|
mouse_client_move(client_t *c, int snap, bool infobox)
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
2008-06-15 17:32:03 +02:00
|
|
|
/* current mouse postion */
|
|
|
|
int mouse_x, mouse_y;
|
|
|
|
/* last mouse position */
|
2008-06-19 23:00:02 +02:00
|
|
|
int last_x = 0, last_y = 0;
|
2008-06-15 17:32:03 +02:00
|
|
|
/* current layout */
|
2008-06-09 21:43:09 +02:00
|
|
|
layout_t *layout;
|
2008-06-15 17:32:03 +02:00
|
|
|
/* the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
simple_window_t sw;
|
2008-06-15 17:32:03 +02:00
|
|
|
/* the root window */
|
|
|
|
xcb_window_t root;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
layout = layout_get_current(c->screen);
|
2008-06-17 16:55:24 +02:00
|
|
|
root = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-15 17:32:03 +02:00
|
|
|
/* get current pointer position */
|
2008-06-19 16:51:33 +02:00
|
|
|
mouse_query_pointer(root, &last_x, &last_y, NULL);
|
2008-03-28 13:00:12 +01:00
|
|
|
|
2008-06-15 17:32:03 +02:00
|
|
|
/* grab pointer */
|
2008-09-03 14:59:18 +02:00
|
|
|
if(c->isfullscreen
|
|
|
|
|| c->type == WINDOW_TYPE_DESKTOP
|
|
|
|
|| c->type == WINDOW_TYPE_SPLASH
|
|
|
|
|| c->type == WINDOW_TYPE_DOCK
|
|
|
|
|| !mouse_grab_pointer(root, CurMove))
|
2008-06-21 23:22:29 +02:00
|
|
|
return;
|
2008-04-09 15:32:55 +02:00
|
|
|
|
2008-09-03 14:59:18 +02:00
|
|
|
if(infobox && (client_isfloating(c) || layout == layout_floating))
|
2008-09-20 21:24:16 +02:00
|
|
|
mouse_infobox_new(&sw, c->phys_screen, c->border, c->geometry);
|
|
|
|
else
|
|
|
|
infobox = false;
|
2008-03-25 16:10:12 +01:00
|
|
|
|
2008-06-15 17:32:03 +02:00
|
|
|
/* for each motion event */
|
|
|
|
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
2008-09-03 14:59:18 +02:00
|
|
|
if(client_isfloating(c) || layout == layout_floating)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2008-06-15 17:32:03 +02:00
|
|
|
area_t geometry;
|
|
|
|
|
|
|
|
/* calc new geometry */
|
|
|
|
geometry = c->geometry;
|
|
|
|
geometry.x += (mouse_x - last_x);
|
|
|
|
geometry.y += (mouse_y - last_y);
|
|
|
|
|
|
|
|
/* snap and move */
|
|
|
|
geometry = mouse_snapclient(c, geometry, snap);
|
|
|
|
c->ismoving = true;
|
|
|
|
client_resize(c, geometry, false);
|
2008-09-03 14:59:18 +02:00
|
|
|
xcb_flush(globalconf.connection);
|
2008-06-15 17:32:03 +02:00
|
|
|
c->ismoving = false;
|
|
|
|
|
|
|
|
/* draw the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(infobox)
|
|
|
|
mouse_infobox_draw(&sw, c->geometry, c->border);
|
2008-06-15 17:32:03 +02:00
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
/* refresh live */
|
|
|
|
wibox_refresh();
|
|
|
|
xcb_flush(globalconf.connection);
|
2008-09-05 02:09:06 +02:00
|
|
|
|
2008-06-15 17:32:03 +02:00
|
|
|
/* keep track */
|
|
|
|
last_x = mouse_x;
|
|
|
|
last_y = mouse_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int newscreen;
|
|
|
|
client_t *target;
|
|
|
|
|
|
|
|
/* client moved to another screen? */
|
2008-09-03 22:37:43 +02:00
|
|
|
newscreen = screen_getbycoord(c->screen, mouse_x, mouse_y);
|
2008-06-15 17:32:03 +02:00
|
|
|
if(newscreen != c->screen)
|
|
|
|
{
|
2008-09-05 02:05:30 +02:00
|
|
|
screen_client_moveto(c, newscreen, true, true);
|
2008-06-15 17:32:03 +02:00
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
globalconf.screens[newscreen].need_arrange = true;
|
|
|
|
layout_refresh();
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_refresh();
|
|
|
|
xcb_flush(globalconf.connection);
|
2008-06-15 17:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find client to swap with */
|
2008-08-14 22:16:13 +02:00
|
|
|
target = mouse_get_client_under_pointer(c->phys_screen);
|
2008-06-15 17:32:03 +02:00
|
|
|
|
|
|
|
/* swap position */
|
|
|
|
if(target && target != c && !target->isfloating)
|
|
|
|
{
|
|
|
|
client_list_swap(&globalconf.clients, c, target);
|
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
2008-10-20 15:01:16 +02:00
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
|
2008-06-15 17:32:03 +02:00
|
|
|
layout_refresh();
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_refresh();
|
|
|
|
xcb_flush(globalconf.connection);
|
2008-01-28 11:32:55 +01:00
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
}
|
2008-06-15 17:32:03 +02:00
|
|
|
|
|
|
|
/* ungrab pointer */
|
|
|
|
xcb_ungrab_pointer(globalconf.connection, XCB_CURRENT_TIME);
|
|
|
|
|
|
|
|
/* free the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(infobox)
|
|
|
|
simplewindow_wipe(&sw);
|
2007-11-13 22:57:57 +01:00
|
|
|
}
|
|
|
|
|
2008-06-04 19:09:43 +02:00
|
|
|
|
|
|
|
/** Resize a floating client with the mouse.
|
|
|
|
* \param c The client to resize.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param corner The corner to resize with.
|
2008-06-12 13:41:53 +02:00
|
|
|
* \param infobox Enable or disable the infobox.
|
2008-06-04 19:09:43 +02:00
|
|
|
*/
|
|
|
|
static void
|
2008-06-12 13:41:53 +02:00
|
|
|
mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
|
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;
|
2008-06-15 20:30:19 +02:00
|
|
|
/* the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
simple_window_t sw;
|
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
|
|
|
|
2008-06-17 16:55:24 +02:00
|
|
|
screen = xutil_screen_get(globalconf.connection, c->phys_screen);
|
2008-06-04 19:09:43 +02:00
|
|
|
|
2008-06-08 18:15:53 +02:00
|
|
|
/* get current mouse position */
|
2008-06-19 16:51:33 +02:00
|
|
|
mouse_query_pointer(screen->root, &mouse_x, &mouse_y, NULL);
|
2008-06-04 19:09:43 +02:00
|
|
|
|
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-15 18:51:47 +02:00
|
|
|
corner = mouse_snap_to_corner(c->geometry, &mouse_x, &mouse_y, corner);
|
|
|
|
|
|
|
|
/* the opposite corner is fixed */
|
|
|
|
fixed_x = (mouse_x == left) ? right : left;
|
|
|
|
fixed_y = (mouse_y == top) ? bottom : top;
|
2008-06-04 19:09:43 +02:00
|
|
|
|
2008-06-15 18:51:47 +02:00
|
|
|
/* select cursor */
|
2008-06-08 18:15:53 +02:00
|
|
|
switch(corner)
|
|
|
|
{
|
|
|
|
default:
|
2008-06-15 18:51:47 +02:00
|
|
|
cursor = CurTopLeft;
|
2008-06-08 18:15:53 +02:00
|
|
|
break;
|
|
|
|
case TopRightCorner:
|
|
|
|
cursor = CurTopRight;
|
|
|
|
break;
|
|
|
|
case BottomLeftCorner:
|
|
|
|
cursor = CurBotLeft;
|
|
|
|
break;
|
|
|
|
case BottomRightCorner:
|
|
|
|
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-12 13:41:53 +02:00
|
|
|
/* create the infobox */
|
|
|
|
if(infobox)
|
2008-09-20 21:24:16 +02:00
|
|
|
mouse_infobox_new(&sw, c->phys_screen, c->border, c->geometry);
|
2008-06-04 19:09:43 +02:00
|
|
|
|
|
|
|
/* 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)) };
|
2008-06-18 15:38:09 +02:00
|
|
|
/* new moveable corner */
|
|
|
|
corner_t new_corner;
|
|
|
|
|
|
|
|
if(mouse_x == AREA_LEFT(geo))
|
|
|
|
new_corner = (mouse_y == AREA_TOP(geo)) ? TopLeftCorner : BottomLeftCorner;
|
|
|
|
else
|
|
|
|
new_corner = (mouse_y == AREA_TOP(geo)) ? TopRightCorner : BottomRightCorner;
|
|
|
|
|
|
|
|
/* update cursor */
|
|
|
|
if(corner != new_corner)
|
|
|
|
{
|
|
|
|
corner = new_corner;
|
|
|
|
|
|
|
|
switch(corner)
|
|
|
|
{
|
|
|
|
default: cursor = CurTopLeft; break;
|
|
|
|
case TopRightCorner: cursor = CurTopRight; break;
|
|
|
|
case BottomLeftCorner: cursor = CurBotLeft; break;
|
|
|
|
case BottomRightCorner: cursor = CurBotRight; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_change_active_pointer_grab(globalconf.connection, globalconf.cursor[cursor],
|
|
|
|
XCB_CURRENT_TIME, MOUSEMASK);
|
|
|
|
}
|
2008-06-04 19:09:43 +02:00
|
|
|
|
2008-06-25 15:42:07 +02:00
|
|
|
if(c->hassizehints && c->honorsizehints)
|
2008-06-18 15:53:08 +02:00
|
|
|
{
|
|
|
|
int dx, dy;
|
|
|
|
|
|
|
|
/* apply size hints */
|
|
|
|
geo = client_geometry_hints(c, geo);
|
|
|
|
|
|
|
|
/* get the nonmoveable corner back onto fixed_x,fixed_y */
|
|
|
|
switch(corner)
|
|
|
|
{
|
|
|
|
default /* TopLeftCorner */:
|
|
|
|
dx = fixed_x - AREA_RIGHT(geo);
|
|
|
|
dy = fixed_y - AREA_BOTTOM(geo);
|
|
|
|
break;
|
|
|
|
case TopRightCorner:
|
|
|
|
dx = fixed_x - AREA_LEFT(geo);
|
|
|
|
dy = fixed_y - AREA_BOTTOM(geo);
|
|
|
|
break;
|
|
|
|
case BottomRightCorner:
|
|
|
|
dx = fixed_x - AREA_LEFT(geo);
|
|
|
|
dy = fixed_y - AREA_TOP(geo);
|
|
|
|
break;
|
|
|
|
case BottomLeftCorner:
|
|
|
|
dx = fixed_x - AREA_RIGHT(geo);
|
|
|
|
dy = fixed_y - AREA_TOP(geo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
geo.x += dx;
|
|
|
|
geo.y += dy;
|
|
|
|
}
|
|
|
|
|
2008-06-04 19:09:43 +02:00
|
|
|
/* resize the client */
|
2008-06-18 15:53:08 +02:00
|
|
|
client_resize(c, geo, false);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
|
|
|
/* refresh live */
|
|
|
|
wibox_refresh();
|
|
|
|
xcb_flush(globalconf.connection);
|
2008-06-04 19:09:43 +02:00
|
|
|
|
2008-06-12 13:41:53 +02:00
|
|
|
/* draw the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(infobox)
|
|
|
|
mouse_infobox_draw(&sw, c->geometry, c->border);
|
2008-06-04 19:09:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* relase pointer */
|
|
|
|
mouse_ungrab_pointer();
|
|
|
|
|
2008-06-15 20:30:19 +02:00
|
|
|
/* free the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(infobox)
|
|
|
|
simplewindow_wipe(&sw);
|
2008-06-04 19:09:43 +02:00
|
|
|
}
|
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
/** Resize the master column/row of a tiled layout
|
2008-06-09 21:43:09 +02:00
|
|
|
* \param c A client on the tag/layout to resize.
|
2008-06-07 22:44:16 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mouse_client_resize_tiled(client_t *c)
|
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
xcb_screen_t *screen;
|
2008-09-24 12:13:21 +02:00
|
|
|
/* screen area modulo wibox */
|
2008-06-07 22:44:16 +02:00
|
|
|
area_t area;
|
2008-06-09 21:43:09 +02:00
|
|
|
/* current tag */
|
|
|
|
tag_t *tag;
|
|
|
|
/* current layout */
|
|
|
|
layout_t *layout;
|
|
|
|
|
2008-06-19 23:00:02 +02:00
|
|
|
int mouse_x = 0, mouse_y = 0;
|
2008-06-07 23:37:24 +02:00
|
|
|
size_t cursor = CurResize;
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-06-17 16:55:24 +02:00
|
|
|
screen = xutil_screen_get(globalconf.connection, c->phys_screen);
|
2008-06-09 21:43:09 +02:00
|
|
|
tag = tags_get_current(c->screen)[0];
|
|
|
|
layout = tag->layout;
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-09-03 22:15:14 +02:00
|
|
|
area = screen_area_get(tag->screen,
|
2008-09-24 12:13:21 +02:00
|
|
|
&globalconf.screens[tag->screen].wiboxes,
|
2008-09-03 22:15:14 +02:00
|
|
|
&globalconf.screens[tag->screen].padding,
|
|
|
|
true);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-06-19 16:51:33 +02:00
|
|
|
mouse_query_pointer(screen->root, &mouse_x, &mouse_y, NULL);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
|
|
|
/* select initial pointer position */
|
2008-06-09 21:43:09 +02:00
|
|
|
if(layout == layout_tile)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
mouse_x = area.x + area.width * tag->mwfact;
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeH;
|
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
else if(layout == layout_tileleft)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
mouse_x = area.x + area.width * (1. - tag->mwfact);
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeH;
|
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
else if(layout == layout_tilebottom)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
mouse_y = area.y + area.height * tag->mwfact;
|
2008-06-07 23:37:24 +02:00
|
|
|
cursor = CurResizeV;
|
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
else if(layout == layout_tiletop)
|
2008-06-07 23:37:24 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
mouse_y = area.y + area.height * (1. - tag->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 21:43:09 +02:00
|
|
|
if(!mouse_grab_pointer(screen->root, cursor))
|
2008-06-07 22:44:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* set pointer to the moveable border */
|
2008-06-09 21:43:09 +02:00
|
|
|
mouse_warp_pointer(screen->root, mouse_x, mouse_y);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
2008-08-26 19:35:37 +02:00
|
|
|
xcb_flush(globalconf.connection);
|
2008-06-07 22:44:16 +02:00
|
|
|
|
|
|
|
/* for each motion event */
|
|
|
|
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
|
|
|
{
|
2008-06-23 13:20:01 +02:00
|
|
|
double mwfact = 0, fact_x, fact_y;
|
2008-06-07 22:44:16 +02:00
|
|
|
|
|
|
|
/* 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 21:43:09 +02:00
|
|
|
if(layout == layout_tile)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = fact_x;
|
2008-06-09 21:43:09 +02:00
|
|
|
else if(layout == layout_tileleft)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = 1. - fact_x;
|
2008-06-09 21:43:09 +02:00
|
|
|
else if(layout == layout_tilebottom)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = fact_y;
|
2008-06-09 21:43:09 +02:00
|
|
|
else if(layout == layout_tiletop)
|
2008-06-07 22:44:16 +02:00
|
|
|
mwfact = 1. - fact_y;
|
|
|
|
|
2008-06-15 20:30:19 +02:00
|
|
|
/* keep mwfact within reasonable bounds */
|
2008-06-23 13:20:01 +02:00
|
|
|
mwfact = MIN(MAX( 0.01, mwfact), 0.99);
|
2008-06-14 23:37:48 +02:00
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
/* refresh layout */
|
2008-06-09 21:43:09 +02:00
|
|
|
if(fabs(tag->mwfact - mwfact) >= 0.01)
|
2008-06-07 22:44:16 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
tag->mwfact = mwfact;
|
|
|
|
globalconf.screens[tag->screen].need_arrange = true;
|
2008-06-07 22:44:16 +02:00
|
|
|
layout_refresh();
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_refresh();
|
|
|
|
xcb_flush(globalconf.connection);
|
2008-06-07 22:44:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* relase pointer */
|
|
|
|
mouse_ungrab_pointer();
|
|
|
|
}
|
|
|
|
|
2008-06-15 20:29:25 +02:00
|
|
|
/** Resize the master client in mangifier layout
|
|
|
|
* \param c The client to resize.
|
|
|
|
* \param infobox Enable or disable the infobox.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mouse_client_resize_magnified(client_t *c, bool infobox)
|
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
/* screen area modulo wibox */
|
2008-06-15 20:29:25 +02:00
|
|
|
area_t area;
|
|
|
|
/* center of area */
|
|
|
|
int center_x, center_y;
|
|
|
|
/* max. distance from the center */
|
|
|
|
double maxdist;
|
|
|
|
/* mouse position */
|
2008-06-19 23:00:02 +02:00
|
|
|
int mouse_x = 0, mouse_y = 0;
|
2008-06-15 20:29:25 +02:00
|
|
|
/* cursor while grabbing */
|
|
|
|
size_t cursor = CurResize;
|
|
|
|
corner_t corner = AutoCorner;
|
|
|
|
/* current tag */
|
|
|
|
tag_t *tag;
|
|
|
|
/* the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
simple_window_t sw;
|
2008-06-15 20:29:25 +02:00
|
|
|
xcb_window_t root;
|
|
|
|
|
|
|
|
tag = tags_get_current(c->screen)[0];
|
|
|
|
|
2008-06-17 16:55:24 +02:00
|
|
|
root = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
|
2008-06-15 20:29:25 +02:00
|
|
|
|
2008-09-03 22:15:14 +02:00
|
|
|
area = screen_area_get(tag->screen,
|
2008-09-24 12:13:21 +02:00
|
|
|
&globalconf.screens[tag->screen].wiboxes,
|
2008-09-03 22:15:14 +02:00
|
|
|
&globalconf.screens[tag->screen].padding,
|
|
|
|
true);
|
2008-06-15 20:29:25 +02:00
|
|
|
|
|
|
|
center_x = area.x + (round(area.width / 2.));
|
|
|
|
center_y = area.y + (round(area.height / 2.));
|
|
|
|
|
|
|
|
maxdist = round(sqrt((area.width*area.width) + (area.height*area.height)) / 2.);
|
|
|
|
|
2008-08-14 22:16:13 +02:00
|
|
|
root = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
|
|
|
|
|
|
|
|
if(!mouse_query_pointer(root, &mouse_x, &mouse_y, NULL))
|
|
|
|
return;
|
2008-06-15 20:29:25 +02:00
|
|
|
|
|
|
|
/* select corner */
|
|
|
|
corner = mouse_snap_to_corner(c->geometry, &mouse_x, &mouse_y, corner);
|
|
|
|
|
|
|
|
/* select cursor */
|
|
|
|
switch(corner)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
cursor = CurTopLeft;
|
|
|
|
break;
|
|
|
|
case TopRightCorner:
|
|
|
|
cursor = CurTopRight;
|
|
|
|
break;
|
|
|
|
case BottomLeftCorner:
|
|
|
|
cursor = CurBotLeft;
|
|
|
|
break;
|
|
|
|
case BottomRightCorner:
|
|
|
|
cursor = CurBotRight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* grab pointer */
|
2008-06-21 23:22:29 +02:00
|
|
|
if(!mouse_grab_pointer(root, cursor))
|
|
|
|
return;
|
2008-06-15 20:29:25 +02:00
|
|
|
|
|
|
|
/* move pointer to corner */
|
|
|
|
mouse_warp_pointer(root, mouse_x, mouse_y);
|
|
|
|
|
|
|
|
/* create the infobox */
|
|
|
|
if(infobox)
|
2008-09-20 21:24:16 +02:00
|
|
|
mouse_infobox_new(&sw, c->phys_screen, c->border, c->geometry);
|
2008-06-15 20:29:25 +02:00
|
|
|
|
|
|
|
/* for each motion event */
|
|
|
|
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
|
|
|
{
|
|
|
|
/* \todo keep pointer on screen diagonals */
|
|
|
|
double mwfact, dist, dx, dy;
|
|
|
|
|
|
|
|
/* calc distance from the center */
|
|
|
|
dx = center_x - mouse_x;
|
|
|
|
dy = center_y - mouse_y;
|
2008-08-23 08:40:07 +02:00
|
|
|
dist = sqrt((dx * dx) + (dy * dy));
|
2008-06-15 20:29:25 +02:00
|
|
|
|
|
|
|
/* new master/rest ratio */
|
2008-08-22 22:09:51 +02:00
|
|
|
mwfact = (dist * dist) / (maxdist * maxdist);
|
2008-06-15 20:29:25 +02:00
|
|
|
|
2008-06-15 21:20:36 +02:00
|
|
|
/* keep mwfact within reasonable bounds */
|
|
|
|
mwfact = MIN(MAX( 0.01, mwfact), 0.99);
|
|
|
|
|
2008-06-15 20:29:25 +02:00
|
|
|
/* refresh the layout */
|
|
|
|
if(fabs(tag->mwfact - mwfact) >= 0.01)
|
|
|
|
{
|
|
|
|
tag->mwfact = mwfact;
|
|
|
|
globalconf.screens[tag->screen].need_arrange = true;
|
|
|
|
layout_refresh();
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_refresh();
|
|
|
|
xcb_flush(globalconf.connection);
|
2008-06-15 20:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(infobox)
|
|
|
|
mouse_infobox_draw(&sw, c->geometry, c->border);
|
2008-06-15 20:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ungrab pointer */
|
|
|
|
mouse_ungrab_pointer();
|
|
|
|
|
2008-06-15 20:30:19 +02:00
|
|
|
/* free the infobox */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(infobox)
|
|
|
|
simplewindow_wipe(&sw);
|
2008-06-15 20:29:25 +02:00
|
|
|
}
|
2008-06-07 22:44:16 +02:00
|
|
|
|
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.
|
2008-06-12 13:41:53 +02:00
|
|
|
* \param infobox Enable or disable the info box.
|
2007-12-19 04:39:59 +01:00
|
|
|
*/
|
2008-05-26 16:17:57 +02:00
|
|
|
static void
|
2008-06-12 13:41:53 +02:00
|
|
|
mouse_client_resize(client_t *c, corner_t corner, bool infobox)
|
2007-11-13 22:57:57 +01:00
|
|
|
{
|
2008-06-04 19:09:43 +02:00
|
|
|
int n, screen;
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_t **curtags;
|
|
|
|
layout_t *layout;
|
2008-05-20 15:39:47 +02:00
|
|
|
xcb_screen_t *s;
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2008-09-03 14:59:18 +02:00
|
|
|
if(c->isfullscreen
|
|
|
|
|| c->type == WINDOW_TYPE_DESKTOP
|
|
|
|
|| c->type == WINDOW_TYPE_SPLASH
|
|
|
|
|| c->type == WINDOW_TYPE_DOCK)
|
2008-08-21 17:52:44 +02:00
|
|
|
return;
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
curtags = tags_get_current(c->screen);
|
|
|
|
layout = curtags[0]->layout;
|
2008-06-17 16:55:24 +02:00
|
|
|
s = xutil_screen_get(globalconf.connection, c->phys_screen);
|
2008-03-28 13:22:26 +01:00
|
|
|
|
2008-06-15 20:29:25 +02:00
|
|
|
/* only handle floating, tiled and magnifier layouts */
|
2008-09-03 14:59:18 +02:00
|
|
|
if(layout == layout_floating || client_isfloating(c))
|
2008-06-12 13:41:53 +02:00
|
|
|
mouse_client_resize_floating(c, corner, infobox);
|
2008-06-15 20:29:25 +02:00
|
|
|
else if(layout == layout_tile || layout == layout_tileleft
|
|
|
|
|| layout == layout_tilebottom || layout == layout_tiletop)
|
2008-03-28 13:22:26 +01:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
screen = c->screen;
|
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-08-06 16:22:48 +02:00
|
|
|
if(n <= curtags[0]->nmaster)
|
|
|
|
goto bailout;
|
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-08-06 16:22:48 +02:00
|
|
|
if(!c)
|
|
|
|
goto bailout;
|
2008-03-28 13:22:26 +01:00
|
|
|
|
2008-06-07 22:44:16 +02:00
|
|
|
mouse_client_resize_tiled(c);
|
2007-11-13 22:57:57 +01:00
|
|
|
}
|
2008-06-15 20:29:25 +02:00
|
|
|
else if(layout == layout_magnifier)
|
|
|
|
mouse_client_resize_magnified(c, infobox);
|
2008-08-06 16:22:48 +02:00
|
|
|
|
|
|
|
bailout:
|
|
|
|
p_delete(&curtags);
|
2007-11-13 22:57:57 +01:00
|
|
|
}
|
|
|
|
|
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
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A client.
|
2008-06-12 13:41:53 +02:00
|
|
|
* \lparam An optional table with keys: `corner', such as bottomleft,
|
|
|
|
* topright, etc, to specify which corner to grab (default to auto) and
|
|
|
|
* `infobox' to enable or disable the coordinates and dimensions box (default to
|
|
|
|
* enabled).
|
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;
|
2008-06-12 13:41:53 +02:00
|
|
|
bool infobox = true;
|
2008-06-23 14:01:33 +02:00
|
|
|
size_t len;
|
2008-06-25 17:33:05 +02:00
|
|
|
const char *buf;
|
2008-06-08 18:15:53 +02:00
|
|
|
|
2008-06-12 13:41:53 +02:00
|
|
|
if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 2);
|
2008-06-25 17:33:05 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 2, "corner", "auto", &len);
|
|
|
|
corner = a_strtocorner(buf, len);
|
2008-06-12 13:41:53 +02:00
|
|
|
infobox = luaA_getopt_boolean(L, 2, "infobox", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
mouse_client_resize(*c, corner, infobox);
|
2008-06-08 18:15:53 +02:00
|
|
|
|
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
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A client.
|
2008-06-12 13:41:53 +02:00
|
|
|
* \lparam An optional table with keys: `snap' for pixel to snap (default to 8), and
|
|
|
|
* `infobox' to enable or disable the coordinates and dimensions box (default to
|
|
|
|
* enabled).
|
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-06-12 13:41:53 +02:00
|
|
|
int snap = 8;
|
|
|
|
bool infobox = true;
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
snap = luaA_getopt_number(L, 2, "snap", 8);
|
|
|
|
infobox = luaA_getopt_boolean(L, 2, "infobox", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
mouse_client_move(*c, snap, infobox);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
/** Create a new mouse button bindings.
|
|
|
|
* \param L The Lua VM state.
|
2008-07-02 09:00:59 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-13 15:35:47 +02:00
|
|
|
* \luastack
|
2008-10-19 18:42:51 +02:00
|
|
|
* \lparam A table with modifiers keys, or a button to clone.
|
2008-06-13 15:35:47 +02:00
|
|
|
* \lparam A mouse button number.
|
|
|
|
* \lparam A function to execute on click events.
|
2008-08-12 13:23:10 +02:00
|
|
|
* \lparam A function to execute on release events.
|
2008-06-13 15:35:47 +02:00
|
|
|
* \lreturn A mouse button binding.
|
|
|
|
*/
|
|
|
|
static int
|
2008-08-12 13:23:10 +02:00
|
|
|
luaA_button_new(lua_State *L)
|
2008-06-13 15:35:47 +02:00
|
|
|
{
|
|
|
|
int i, len;
|
2008-10-19 18:42:51 +02:00
|
|
|
button_t *button, **orig;
|
|
|
|
|
|
|
|
if((orig = luaA_toudata(L, 2, "button")))
|
|
|
|
{
|
|
|
|
button_t *copy = p_new(button_t, 1);
|
|
|
|
copy->mod = (*orig)->mod;
|
|
|
|
copy->button = (*orig)->button;
|
|
|
|
if((*orig)->press != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, (*orig)->press);
|
|
|
|
luaA_registerfct(L, -1, ©->press);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
copy->press = LUA_REFNIL;
|
|
|
|
if((*orig)->release != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, (*orig)->release);
|
|
|
|
luaA_registerfct(L, -1, ©->release);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
copy->release = LUA_REFNIL;
|
|
|
|
return luaA_button_userdata_new(L, copy);
|
|
|
|
}
|
2008-06-13 15:35:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
luaA_checktable(L, 2);
|
2008-06-13 15:35:47 +02:00
|
|
|
/* arg 3 is mouse button */
|
2008-06-30 14:01:55 +02:00
|
|
|
i = luaL_checknumber(L, 3);
|
2008-08-12 13:23:10 +02:00
|
|
|
/* arg 4 and 5 are callback functions */
|
|
|
|
if(!lua_isnil(L, 4))
|
|
|
|
luaA_checkfunction(L, 4);
|
|
|
|
if(lua_gettop(L) == 5 && !lua_isnil(L, 5))
|
|
|
|
luaA_checkfunction(L, 5);
|
2008-06-13 15:35:47 +02:00
|
|
|
|
|
|
|
button = p_new(button_t, 1);
|
|
|
|
button->button = xutil_button_fromint(i);
|
2008-08-12 13:23:10 +02:00
|
|
|
|
|
|
|
if(lua_isnil(L, 4))
|
|
|
|
button->press = LUA_REFNIL;
|
|
|
|
else
|
|
|
|
luaA_registerfct(L, 4, &button->press);
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 5 && !lua_isnil(L, 5))
|
|
|
|
luaA_registerfct(L, 5, &button->release);
|
|
|
|
else
|
|
|
|
button->release = LUA_REFNIL;
|
2008-06-13 15:35:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
len = lua_objlen(L, 2);
|
2008-06-13 15:35:47 +02:00
|
|
|
for(i = 1; i <= len; i++)
|
|
|
|
{
|
2008-10-01 11:09:57 +02:00
|
|
|
size_t blen;
|
|
|
|
const char *buf;
|
2008-06-30 14:01:55 +02:00
|
|
|
lua_rawgeti(L, 2, i);
|
2008-10-01 11:09:57 +02:00
|
|
|
buf = luaL_checklstring(L, -1, &blen);
|
|
|
|
button->mod |= xutil_key_mask_fromstr(buf, blen);
|
2008-06-13 15:35:47 +02:00
|
|
|
}
|
|
|
|
|
2008-08-12 13:23:10 +02:00
|
|
|
return luaA_button_userdata_new(L, button);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set a button array with a Lua table.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param idx The index of the Lua table.
|
|
|
|
* \param buttons The array button to fill.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
luaA_button_array_set(lua_State *L, int idx, button_array_t *buttons)
|
|
|
|
{
|
|
|
|
button_t **b;
|
|
|
|
|
|
|
|
luaA_checktable(L, idx);
|
|
|
|
button_array_wipe(buttons);
|
|
|
|
button_array_init(buttons);
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, idx))
|
|
|
|
{
|
|
|
|
b = luaA_checkudata(L, -1, "button");
|
|
|
|
button_array_append(buttons, *b);
|
|
|
|
button_ref(b);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Push an array of button as an Lua table onto the stack.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param buttons The button array to push.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_button_array_get(lua_State *L, button_array_t *buttons)
|
|
|
|
{
|
|
|
|
luaA_otable_new(L);
|
|
|
|
for(int i = 0; i < buttons->len; i++)
|
|
|
|
{
|
|
|
|
luaA_button_userdata_new(L, buttons->tab[i]);
|
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
return 1;
|
2008-06-13 15:35:47 +02:00
|
|
|
}
|
|
|
|
|
2008-10-19 18:42:51 +02:00
|
|
|
/** Button object.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lfield press The function called when button press event is received.
|
|
|
|
* \lfield release The function called when button release event is received.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_button_index(lua_State *L)
|
|
|
|
{
|
|
|
|
if(luaA_usemetatable(L, 1, 2))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
button_t **button = luaA_checkudata(L, 1, "button");
|
|
|
|
const char *attr = luaL_checklstring(L, 2, &len);
|
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
|
|
|
case A_TK_PRESS:
|
2008-10-21 10:35:23 +02:00
|
|
|
if((*button)->press != LUA_REFNIL)
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, (*button)->press);
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
2008-10-19 18:42:51 +02:00
|
|
|
break;
|
|
|
|
case A_TK_RELEASE:
|
2008-10-21 10:35:23 +02:00
|
|
|
if((*button)->release != LUA_REFNIL)
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, (*button)->release);
|
|
|
|
else
|
|
|
|
lua_pushnil(L);
|
2008-10-19 18:42:51 +02:00
|
|
|
break;
|
|
|
|
case A_TK_BUTTON:
|
|
|
|
/* works fine, but not *really* neat */
|
|
|
|
lua_pushnumber(L, (*button)->button);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Button object.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_button_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
if(luaA_usemetatable(L, 1, 2))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
button_t **button = luaA_checkudata(L, 1, "button");
|
|
|
|
const char *attr = luaL_checklstring(L, 2, &len);
|
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
|
|
|
case A_TK_PRESS:
|
|
|
|
luaA_registerfct(L, 3, &(*button)->press);
|
|
|
|
break;
|
|
|
|
case A_TK_RELEASE:
|
|
|
|
luaA_registerfct(L, 3, &(*button)->release);
|
|
|
|
break;
|
|
|
|
case A_TK_BUTTON:
|
|
|
|
(*button)->button = xutil_button_fromint(luaL_checknumber(L, 3));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-12 13:23:10 +02:00
|
|
|
const struct luaL_reg awesome_button_methods[] =
|
|
|
|
{
|
|
|
|
{ "__call", luaA_button_new },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_button_meta[] =
|
|
|
|
{
|
2008-10-19 18:42:51 +02:00
|
|
|
{ "__index", luaA_button_index },
|
|
|
|
{ "__newindex", luaA_button_newindex },
|
2008-08-12 13:23:10 +02:00
|
|
|
{ "__gc", luaA_button_gc },
|
|
|
|
{ "__eq", luaA_button_eq },
|
|
|
|
{ "__tostring", luaA_button_tostring },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Mouse library.
|
2008-07-02 09:00:59 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \luastack
|
|
|
|
* \lfield coords Mouse coordinates.
|
|
|
|
* \lfield screen Mouse screen number.
|
2008-07-02 09:00:59 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_mouse_index(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
2008-07-02 09:05:21 +02:00
|
|
|
const char *attr = luaL_checklstring(L, 2, &len);
|
2008-08-20 12:10:22 +02:00
|
|
|
int mouse_x, mouse_y, i;
|
2008-08-14 22:16:13 +02:00
|
|
|
int screen;
|
2008-07-02 09:00:59 +02:00
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
2008-07-02 09:14:17 +02:00
|
|
|
case A_TK_SCREEN:
|
2008-08-14 22:16:13 +02:00
|
|
|
if(!mouse_query_pointer_root(&screen, &mouse_x, &mouse_y, NULL))
|
2008-07-02 09:14:17 +02:00
|
|
|
return 0;
|
|
|
|
|
2008-09-03 22:37:43 +02:00
|
|
|
i = screen_getbycoord(screen, mouse_x, mouse_y);
|
2008-07-02 09:14:17 +02:00
|
|
|
|
|
|
|
lua_pushnumber(L, i + 1);
|
|
|
|
break;
|
2008-07-02 09:00:59 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-02 09:05:21 +02:00
|
|
|
/** Newindex for mouse.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_mouse_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char *attr = luaL_checklstring(L, 2, &len);
|
2008-08-20 12:10:22 +02:00
|
|
|
int x, y = 0;
|
2008-07-02 09:05:21 +02:00
|
|
|
xcb_window_t root;
|
2008-08-14 22:16:13 +02:00
|
|
|
int screen, phys_screen;
|
2008-07-02 09:05:21 +02:00
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
2008-08-14 22:16:13 +02:00
|
|
|
case A_TK_SCREEN:
|
|
|
|
screen = luaL_checknumber(L, 3) - 1;
|
|
|
|
luaA_checkscreen(screen);
|
|
|
|
|
|
|
|
/* we need the physical one to get the root window */
|
|
|
|
phys_screen = screen_virttophys(screen);
|
|
|
|
root = xutil_screen_get(globalconf.connection, phys_screen)->root;
|
|
|
|
|
2008-09-18 16:03:05 +02:00
|
|
|
x = globalconf.screens[screen].geometry.x;
|
|
|
|
y = globalconf.screens[screen].geometry.y;
|
2008-08-14 22:16:13 +02:00
|
|
|
|
2008-07-02 09:05:21 +02:00
|
|
|
mouse_warp_pointer(root, x, y);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-20 12:10:22 +02:00
|
|
|
/** Get or set the mouse coords.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam None or a table with x and y keys as mouse coordinates.
|
|
|
|
* \lreturn A table with mouse coordinates.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_mouse_coords(lua_State *L)
|
|
|
|
{
|
2008-08-25 17:19:53 +02:00
|
|
|
uint16_t mask, maski;
|
|
|
|
int screen, x, y, mouse_x, mouse_y, i = 1;
|
2008-08-20 12:10:22 +02:00
|
|
|
|
2008-08-20 16:25:45 +02:00
|
|
|
if(lua_gettop(L) == 1)
|
2008-08-20 12:10:22 +02:00
|
|
|
{
|
|
|
|
xcb_window_t root;
|
|
|
|
|
2008-08-20 16:25:45 +02:00
|
|
|
luaA_checktable(L, 1);
|
2008-08-20 12:10:22 +02:00
|
|
|
|
|
|
|
if(!mouse_query_pointer_root(&screen, &mouse_x, &mouse_y, &mask))
|
|
|
|
return 0;
|
|
|
|
|
2008-08-20 16:25:45 +02:00
|
|
|
x = luaA_getopt_number(L, 1, "x", mouse_x);
|
|
|
|
y = luaA_getopt_number(L, 1, "y", mouse_y);
|
2008-08-20 12:10:22 +02:00
|
|
|
|
|
|
|
root = xutil_screen_get(globalconf.connection, screen)->root;
|
|
|
|
mouse_warp_pointer(root, x, y);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mouse_query_pointer_root(&screen, &mouse_x, &mouse_y, &mask))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L, mouse_x);
|
|
|
|
lua_setfield(L, -2, "x");
|
|
|
|
lua_pushnumber(L, mouse_y);
|
|
|
|
lua_setfield(L, -2, "y");
|
|
|
|
lua_newtable(L);
|
2008-08-25 17:19:53 +02:00
|
|
|
for(maski = XCB_BUTTON_MASK_1; i <= XCB_BUTTON_MASK_5; maski <<= 1, i++)
|
|
|
|
if(mask & maski)
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, true);
|
|
|
|
lua_rawseti(L, -2, i);
|
|
|
|
}
|
2008-08-20 12:10:22 +02:00
|
|
|
lua_setfield(L, -2, "buttons");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
const struct luaL_reg awesome_mouse_methods[] =
|
|
|
|
{
|
2008-07-02 09:00:59 +02:00
|
|
|
{ "__index", luaA_mouse_index },
|
2008-07-02 09:05:21 +02:00
|
|
|
{ "__newindex", luaA_mouse_newindex },
|
2008-08-20 12:10:22 +02:00
|
|
|
{ "coords", luaA_mouse_coords },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2008-06-13 15:35:47 +02:00
|
|
|
const struct luaL_reg awesome_mouse_meta[] =
|
|
|
|
{
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|