wayland: Store and retrieve implicit grab information for tablet tools

Window moving and resizing depends on the `meta_wayland_seat_get_grab_info`
function succeeding. At the moment, tablet tools do not generate implicit
grabs like the pointer and touch. This commit adds the necessary elements
to track implicit grabs and retrieve their information.

https://bugzilla.gnome.org/show_bug.cgi?id=777333
This commit is contained in:
Jason Gerecke 2017-06-23 08:02:21 -07:00 committed by Carlos Garnacho
parent e52408d259
commit 9f68507f0c
4 changed files with 86 additions and 19 deletions

View File

@ -411,36 +411,58 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat,
gfloat *x, gfloat *x,
gfloat *y) gfloat *y)
{ {
ClutterEventSequence *sequence = NULL; MetaWaylandCompositor *compositor;
gboolean can_grab_surface = FALSE; MetaWaylandTabletSeat *tablet_seat;
GList *tools, *l;
compositor = meta_wayland_compositor_get_default ();
tablet_seat = meta_wayland_tablet_manager_ensure_seat (compositor->tablet_manager, seat);
tools = g_hash_table_get_values (tablet_seat->tools);
if (meta_wayland_seat_has_touch (seat)) if (meta_wayland_seat_has_touch (seat))
{
ClutterEventSequence *sequence;
sequence = meta_wayland_touch_find_grab_sequence (seat->touch, sequence = meta_wayland_touch_find_grab_sequence (seat->touch,
surface, surface,
serial); serial);
if (sequence) if (sequence)
{ {
meta_wayland_touch_get_press_coords (seat->touch, sequence, x, y); meta_wayland_touch_get_press_coords (seat->touch, sequence, x, y);
return TRUE;
}
} }
else
{
if (meta_wayland_seat_has_pointer (seat) &&
(!require_pressed || seat->pointer->button_count > 0))
can_grab_surface = meta_wayland_pointer_can_grab_surface (seat->pointer,
surface,
serial);
if (can_grab_surface) if (meta_wayland_seat_has_pointer (seat))
{
if ((!require_pressed || seat->pointer->button_count > 0) &&
meta_wayland_pointer_can_grab_surface (seat->pointer, surface, serial))
{ {
if (x) if (x)
*x = seat->pointer->grab_x; *x = seat->pointer->grab_x;
if (y) if (y)
*y = seat->pointer->grab_y; *y = seat->pointer->grab_y;
return TRUE;
} }
} }
return sequence || can_grab_surface; for (l = tools; l; l = l->next)
{
MetaWaylandTabletTool *tool = l->data;
if ((!require_pressed || tool->button_count > 0) &&
meta_wayland_tablet_tool_can_grab_surface (tool, surface, serial))
{
if (x)
*x = tool->grab_x;
if (y)
*y = tool->grab_y;
return TRUE;
}
}
return FALSE;
} }
gboolean gboolean

View File

@ -31,6 +31,7 @@
#include "meta-wayland-keyboard.h" #include "meta-wayland-keyboard.h"
#include "meta-wayland-touch.h" #include "meta-wayland-touch.h"
#include "meta-wayland-data-device.h" #include "meta-wayland-data-device.h"
#include "meta-wayland-tablet-tool.h"
struct _MetaWaylandSeat struct _MetaWaylandSeat
{ {

View File

@ -572,9 +572,15 @@ meta_wayland_tablet_tool_account_button (MetaWaylandTabletTool *tool,
const ClutterEvent *event) const ClutterEvent *event)
{ {
if (event->type == CLUTTER_BUTTON_PRESS) if (event->type == CLUTTER_BUTTON_PRESS)
{
tool->pressed_buttons |= 1 << (event->button.button - 1); tool->pressed_buttons |= 1 << (event->button.button - 1);
tool->button_count++;
}
else if (event->type == CLUTTER_BUTTON_RELEASE) else if (event->type == CLUTTER_BUTTON_RELEASE)
{
tool->pressed_buttons &= ~(1 << (event->button.button - 1)); tool->pressed_buttons &= ~(1 << (event->button.button - 1));
tool->button_count--;
}
} }
static void static void
@ -840,6 +846,9 @@ handle_button_event (MetaWaylandTabletTool *tool,
if (!tool->focus_surface) if (!tool->focus_surface)
return; return;
if (event->type == CLUTTER_BUTTON_PRESS && tool->button_count == 1)
clutter_event_get_coords (event, &tool->grab_x, &tool->grab_y);
if (event->type == CLUTTER_BUTTON_PRESS && event->button.button == 1) if (event->type == CLUTTER_BUTTON_PRESS && event->button.button == 1)
broadcast_down (tool, event); broadcast_down (tool, event);
else if (event->type == CLUTTER_BUTTON_RELEASE && event->button.button == 1) else if (event->type == CLUTTER_BUTTON_RELEASE && event->button.button == 1)
@ -918,3 +927,32 @@ meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool *tool,
if (tool->cursor_renderer) if (tool->cursor_renderer)
meta_cursor_renderer_set_position (tool->cursor_renderer, new_x, new_y); meta_cursor_renderer_set_position (tool->cursor_renderer, new_x, new_y);
} }
static gboolean
tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
MetaWaylandSurface *surface)
{
GList *l;
if (tool->focus_surface == surface)
return TRUE;
for (l = surface->subsurfaces; l; l = l->next)
{
MetaWaylandSurface *subsurface = l->data;
if (tablet_tool_can_grab_surface (tool, subsurface))
return TRUE;
}
return FALSE;
}
gboolean
meta_wayland_tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
MetaWaylandSurface *surface,
uint32_t serial)
{
return ((tool->down_serial == serial || tool->button_serial == serial) &&
tablet_tool_can_grab_surface (tool, surface));
}

View File

@ -48,11 +48,14 @@ struct _MetaWaylandTabletTool
MetaWaylandSurface *current; MetaWaylandSurface *current;
guint32 pressed_buttons; guint32 pressed_buttons;
guint32 button_count;
guint32 proximity_serial; guint32 proximity_serial;
guint32 down_serial; guint32 down_serial;
guint32 button_serial; guint32 button_serial;
float grab_x, grab_y;
MetaWaylandTablet *current_tablet; MetaWaylandTablet *current_tablet;
}; };
@ -79,5 +82,8 @@ void meta_wayland_tablet_tool_set_cursor_position (MetaWaylandTabletTool *t
int new_x, int new_x,
int new_y); int new_y);
gboolean meta_wayland_tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
MetaWaylandSurface *surface,
uint32_t serial);
#endif /* META_WAYLAND_TABLET_TOOL_H */ #endif /* META_WAYLAND_TABLET_TOOL_H */