From 2aa6dcd9d8d2b15d2716afa6017180cdf1cb1a7d Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 18 Feb 2015 10:43:42 -0500 Subject: [PATCH] wayland: don't try to use seat devices that aren't (yet) present Before commit ac448bd42be8cf8e46cadd7e1a209491e33b1693 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 --- src/wayland/meta-wayland-seat.c | 46 +++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c index 87525acb9..f455ad8bc 100644 --- a/src/wayland/meta-wayland-seat.c +++ b/src/wayland/meta-wayland-seat.c @@ -44,7 +44,8 @@ seat_get_pointer (struct wl_client *client, MetaWaylandSeat *seat = wl_resource_get_user_data (resource); 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 @@ -55,7 +56,8 @@ seat_get_keyboard (struct wl_client *client, MetaWaylandSeat *seat = wl_resource_get_user_data (resource); 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 @@ -66,7 +68,8 @@ seat_get_touch (struct wl_client *client, MetaWaylandSeat *seat = wl_resource_get_user_data (resource); 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 = { @@ -350,6 +353,9 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat, void meta_wayland_seat_repick (MetaWaylandSeat *seat) { + if ((seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0) + return; + meta_wayland_pointer_repick (&seat->pointer); } @@ -357,6 +363,9 @@ void meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat, MetaWaylandSurface *surface) { + if ((seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD) == 0) + return; + meta_wayland_keyboard_set_focus (&seat->keyboard, surface); meta_wayland_data_device_set_keyboard_focus (&seat->data_device); } @@ -364,6 +373,9 @@ meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat, void 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); } @@ -374,21 +386,29 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat, gfloat *x, 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) - 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; + meta_wayland_touch_get_press_coords (&seat->touch, sequence, x, y); } 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; }