wayland: don't try to use seat devices that aren't (yet) present

Before commit ac448bd42b the pointer,
keyboard, and touch objects were initialized when the seat was created.
Now they're initialized later, when the clutter device manager finds and
loads them.

This commit makes sure we don't try to access those objects if they
aren't initialized.

https://bugzilla.gnome.org/show_bug.cgi?id=744640
This commit is contained in:
Ray Strode 2015-02-18 10:43:42 -05:00
parent 469b85eb7c
commit 2aa6dcd9d8

View File

@ -44,7 +44,8 @@ seat_get_pointer (struct wl_client *client,
MetaWaylandSeat *seat = wl_resource_get_user_data (resource); MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
MetaWaylandPointer *pointer = &seat->pointer; MetaWaylandPointer *pointer = &seat->pointer;
meta_wayland_pointer_create_new_resource (pointer, client, resource, id); if ((seat->capabilities & WL_SEAT_CAPABILITY_POINTER) != 0)
meta_wayland_pointer_create_new_resource (pointer, client, resource, id);
} }
static void static void
@ -55,7 +56,8 @@ seat_get_keyboard (struct wl_client *client,
MetaWaylandSeat *seat = wl_resource_get_user_data (resource); MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
MetaWaylandKeyboard *keyboard = &seat->keyboard; MetaWaylandKeyboard *keyboard = &seat->keyboard;
meta_wayland_keyboard_create_new_resource (keyboard, client, resource, id); if ((seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD) != 0)
meta_wayland_keyboard_create_new_resource (keyboard, client, resource, id);
} }
static void static void
@ -66,7 +68,8 @@ seat_get_touch (struct wl_client *client,
MetaWaylandSeat *seat = wl_resource_get_user_data (resource); MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
MetaWaylandTouch *touch = &seat->touch; MetaWaylandTouch *touch = &seat->touch;
meta_wayland_touch_create_new_resource (touch, client, resource, id); if ((seat->capabilities & WL_SEAT_CAPABILITY_TOUCH) != 0)
meta_wayland_touch_create_new_resource (touch, client, resource, id);
} }
static const struct wl_seat_interface seat_interface = { static const struct wl_seat_interface seat_interface = {
@ -350,6 +353,9 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
void void
meta_wayland_seat_repick (MetaWaylandSeat *seat) meta_wayland_seat_repick (MetaWaylandSeat *seat)
{ {
if ((seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0)
return;
meta_wayland_pointer_repick (&seat->pointer); meta_wayland_pointer_repick (&seat->pointer);
} }
@ -357,6 +363,9 @@ void
meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat, meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
MetaWaylandSurface *surface) MetaWaylandSurface *surface)
{ {
if ((seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD) == 0)
return;
meta_wayland_keyboard_set_focus (&seat->keyboard, surface); meta_wayland_keyboard_set_focus (&seat->keyboard, surface);
meta_wayland_data_device_set_keyboard_focus (&seat->data_device); meta_wayland_data_device_set_keyboard_focus (&seat->data_device);
} }
@ -364,6 +373,9 @@ meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
void void
meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat) meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat)
{ {
if ((seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0)
return;
meta_wayland_pointer_update_cursor_surface (&seat->pointer); meta_wayland_pointer_update_cursor_surface (&seat->pointer);
} }
@ -374,21 +386,29 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat,
gfloat *x, gfloat *x,
gfloat *y) gfloat *y)
{ {
ClutterEventSequence *sequence; ClutterEventSequence *sequence = NULL;
gboolean can_grab_surface = FALSE;
sequence = meta_wayland_touch_find_grab_sequence (&seat->touch, surface, serial); if ((seat->capabilities & WL_SEAT_CAPABILITY_TOUCH) != 0)
sequence = meta_wayland_touch_find_grab_sequence (&seat->touch, surface, serial);
if (sequence) 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) meta_wayland_touch_get_press_coords (&seat->touch, sequence, x, y);
*x = seat->pointer.grab_x;
if (y)
*y = seat->pointer.grab_y;
} }
else else
return FALSE; {
if ((seat->capabilities & WL_SEAT_CAPABILITY_POINTER) != 0)
can_grab_surface = meta_wayland_pointer_can_grab_surface (&seat->pointer, surface, serial);
return TRUE; if (can_grab_surface)
{
if (x)
*x = seat->pointer.grab_x;
if (y)
*y = seat->pointer.grab_y;
}
}
return sequence || can_grab_surface;
} }