wayland: Handle window drags for touch events

The grabbing state is now checked for both pointer/touch devices
within the seat, and the grab start coordinates returned by
meta_wayland_seat_get_grab_info().

https://bugzilla.gnome.org/show_bug.cgi?id=733631
This commit is contained in:
Carlos Garnacho 2014-07-22 01:28:39 +02:00
parent baadb75a5e
commit 930361b988
5 changed files with 105 additions and 19 deletions

View File

@ -320,9 +320,27 @@ meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat)
}
gboolean
meta_wayland_seat_can_grab_surface (MetaWaylandSeat *seat,
MetaWaylandSurface *surface,
uint32_t serial)
meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat,
MetaWaylandSurface *surface,
uint32_t serial,
gfloat *x,
gfloat *y)
{
return meta_wayland_pointer_can_grab_surface (&seat->pointer, surface, serial);
ClutterEventSequence *sequence;
sequence = meta_wayland_touch_find_grab_sequence (&seat->touch, surface, serial);
if (sequence)
meta_wayland_touch_get_press_coords (&seat->touch, sequence, x, y);
else if (meta_wayland_pointer_can_grab_surface (&seat->pointer, surface, serial))
{
if (x)
*x = seat->pointer.grab_x;
if (y)
*y = seat->pointer.grab_y;
}
else
return FALSE;
return TRUE;
}

View File

@ -60,8 +60,10 @@ void meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
void meta_wayland_seat_repick (MetaWaylandSeat *seat);
void meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat);
gboolean meta_wayland_seat_can_grab_surface (MetaWaylandSeat *seat,
MetaWaylandSurface *surface,
uint32_t serial);
gboolean meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat,
MetaWaylandSurface *surface,
uint32_t serial,
gfloat *x,
gfloat *y);
#endif /* META_WAYLAND_SEAT_H */

View File

@ -811,7 +811,7 @@ xdg_surface_show_window_menu (struct wl_client *client,
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
if (!meta_wayland_seat_get_grab_info (seat, surface, serial, NULL, NULL))
return;
meta_window_show_menu (surface->window, META_WINDOW_MENU_WM, x, y);
@ -820,7 +820,9 @@ xdg_surface_show_window_menu (struct wl_client *client,
static gboolean
begin_grab_op_on_surface (MetaWaylandSurface *surface,
MetaWaylandSeat *seat,
MetaGrabOp grab_op)
MetaGrabOp grab_op,
gfloat x,
gfloat y)
{
MetaWindow *window = surface->window;
@ -836,8 +838,7 @@ begin_grab_op_on_surface (MetaWaylandSurface *surface,
1, /* button. XXX? */
0, /* modmask */
meta_display_get_current_time_roundtrip (window->display),
seat->pointer.grab_x,
seat->pointer.grab_y);
x, y);
}
static void
@ -848,11 +849,12 @@ xdg_surface_move (struct wl_client *client,
{
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
gfloat x, y;
if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
if (!meta_wayland_seat_get_grab_info (seat, surface, serial, &x, &y))
return;
begin_grab_op_on_surface (surface, seat, META_GRAB_OP_MOVING);
begin_grab_op_on_surface (surface, seat, META_GRAB_OP_MOVING, x, y);
}
static MetaGrabOp
@ -891,11 +893,12 @@ xdg_surface_resize (struct wl_client *client,
{
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
gfloat x, y;
if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
if (!meta_wayland_seat_get_grab_info (seat, surface, serial, &x, &y))
return;
begin_grab_op_on_surface (surface, seat, grab_op_for_xdg_surface_resize_edge (edges));
begin_grab_op_on_surface (surface, seat, grab_op_for_xdg_surface_resize_edge (edges), x, y);
}
static void
@ -1159,11 +1162,12 @@ wl_shell_surface_move (struct wl_client *client,
{
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
gfloat x, y;
if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
if (!meta_wayland_seat_get_grab_info (seat, surface, serial, &x, &y))
return;
begin_grab_op_on_surface (surface, seat, META_GRAB_OP_MOVING);
begin_grab_op_on_surface (surface, seat, META_GRAB_OP_MOVING, x, y);
}
static MetaGrabOp
@ -1202,11 +1206,12 @@ wl_shell_surface_resize (struct wl_client *client,
{
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
gfloat x, y;
if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
if (!meta_wayland_seat_get_grab_info (seat, surface, serial, &x, &y))
return;
begin_grab_op_on_surface (surface, seat, grab_op_for_wl_shell_surface_resize_edge (edges));
begin_grab_op_on_surface (surface, seat, grab_op_for_wl_shell_surface_resize_edge (edges), x, y);
}
typedef enum {

View File

@ -46,6 +46,8 @@ struct _MetaWaylandTouchInfo
MetaWaylandTouchSurface *touch_surface;
guint32 slot_serial;
gint32 slot;
gfloat start_x;
gfloat start_y;
gfloat x;
gfloat y;
guint updated : 1;
@ -231,6 +233,7 @@ meta_wayland_touch_update (MetaWaylandTouch *touch,
touch_info = touch_get_info (touch, sequence, TRUE);
touch_info->touch_surface = touch_surface_get (touch, surface);
clutter_event_get_coords (event, &touch_info->start_x, &touch_info->start_y);
}
else
touch_info = touch_get_info (touch, sequence, FALSE);
@ -545,3 +548,52 @@ meta_wayland_touch_create_new_resource (MetaWaylandTouch *touch,
wl_resource_set_implementation (cr, &touch_interface, touch, unbind_resource);
wl_list_insert (&touch->resource_list, wl_resource_get_link (cr));
}
ClutterEventSequence *
meta_wayland_touch_find_grab_sequence (MetaWaylandTouch *touch,
MetaWaylandSurface *surface,
uint32_t serial)
{
MetaWaylandTouchInfo *touch_info;
ClutterEventSequence *sequence;
GHashTableIter iter;
if (!touch->touches)
return NULL;
g_hash_table_iter_init (&iter, touch->touches);
while (g_hash_table_iter_next (&iter, (gpointer*) &sequence,
(gpointer*) &touch_info))
{
if (touch_info->slot_serial == serial &&
touch_info->touch_surface->surface == surface)
return sequence;
}
return NULL;
}
gboolean
meta_wayland_touch_get_press_coords (MetaWaylandTouch *touch,
ClutterEventSequence *sequence,
gfloat *x,
gfloat *y)
{
MetaWaylandTouchInfo *touch_info;
if (!touch->touches)
return FALSE;
touch_info = g_hash_table_lookup (touch->touches, sequence);
if (!touch_info)
return FALSE;
if (x)
*x = touch_info->start_x;
if (y)
*y = touch_info->start_y;
return TRUE;
}

View File

@ -61,4 +61,13 @@ void meta_wayland_touch_create_new_resource (MetaWaylandTouch *touch,
void meta_wayland_touch_cancel (MetaWaylandTouch *touch);
ClutterEventSequence * meta_wayland_touch_find_grab_sequence (MetaWaylandTouch *touch,
MetaWaylandSurface *surface,
uint32_t serial);
gboolean meta_wayland_touch_get_press_coords (MetaWaylandTouch *touch,
ClutterEventSequence *sequence,
gfloat *x,
gfloat *y);
#endif /* META_WAYLAND_TOUCH_H */