wayland-seat: Fix pointer issues

Moving the mouse over weston-terminal, we can see several issues:

 * it often updates late, or not at all
 * the attachment of the pointer sprite is wrong

These are because we willy-nilly call seat_update_sprite all over the
place, and often in wrong areas. Set up a set_pointer_surface helper
method that will do the right thing for us in all cases, and call it
on transitions.
This commit is contained in:
Jasper St. Pierre 2014-02-01 17:18:21 -05:00
parent 92e36e7076
commit fdeb72224c

View File

@ -48,16 +48,19 @@ unbind_resource (struct wl_resource *resource)
} }
static void static void
pointer_unmap_sprite (MetaWaylandSeat *seat) set_cursor_surface (MetaWaylandSeat *seat,
MetaWaylandSurface *surface)
{ {
if (seat->cursor_tracker) if (seat->sprite == surface)
meta_cursor_tracker_set_window_cursor (seat->cursor_tracker, NULL, 0, 0); return;
if (seat->sprite) if (seat->sprite)
{ wl_list_remove (&seat->sprite_destroy_listener.link);
wl_list_remove (&seat->sprite_destroy_listener.link);
seat->sprite = NULL; seat->sprite = surface;
}
if (seat->sprite)
wl_resource_add_destroy_listener (seat->sprite->resource, &seat->sprite_destroy_listener);
} }
void void
@ -68,7 +71,7 @@ meta_wayland_seat_update_sprite (MetaWaylandSeat *seat)
if (seat->cursor_tracker == NULL) if (seat->cursor_tracker == NULL)
return; return;
if (seat->sprite->buffer_ref.buffer) if (seat->sprite && seat->sprite->buffer_ref.buffer)
buffer = seat->sprite->buffer_ref.buffer->resource; buffer = seat->sprite->buffer_ref.buffer->resource;
else else
buffer = NULL; buffer = NULL;
@ -89,9 +92,7 @@ pointer_set_cursor (struct wl_client *client,
MetaWaylandSeat *seat = wl_resource_get_user_data (resource); MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
MetaWaylandSurface *surface; MetaWaylandSurface *surface;
surface = (surface_resource ? surface = (surface_resource ? wl_resource_get_user_data (surface_resource) : NULL);
wl_resource_get_user_data (surface_resource) :
NULL);
if (seat->pointer.focus == NULL) if (seat->pointer.focus == NULL)
return; return;
@ -102,29 +103,13 @@ pointer_set_cursor (struct wl_client *client,
seat->hotspot_x = x; seat->hotspot_x = x;
seat->hotspot_y = y; seat->hotspot_y = y;
set_cursor_surface (seat, surface);
if (seat->sprite != surface) meta_wayland_seat_update_sprite (seat);
{
pointer_unmap_sprite (seat);
if (!surface)
return;
wl_resource_add_destroy_listener (surface->resource,
&seat->sprite_destroy_listener);
seat->sprite = surface;
if (seat->sprite->buffer_ref.buffer)
meta_wayland_seat_update_sprite (seat);
}
} }
static const struct wl_pointer_interface static const struct wl_pointer_interface pointer_interface = {
pointer_interface = pointer_set_cursor
{ };
pointer_set_cursor
};
static void static void
seat_get_pointer (struct wl_client *client, seat_get_pointer (struct wl_client *client,
@ -211,10 +196,10 @@ bind_seat (struct wl_client *client,
static void static void
pointer_handle_sprite_destroy (struct wl_listener *listener, void *data) pointer_handle_sprite_destroy (struct wl_listener *listener, void *data)
{ {
MetaWaylandSeat *seat = MetaWaylandSeat *seat = wl_container_of (listener, seat, sprite_destroy_listener);
wl_container_of (listener, seat, sprite_destroy_listener);
pointer_unmap_sprite (seat); set_cursor_surface (seat, NULL);
meta_wayland_seat_update_sprite (seat);
} }
MetaWaylandSeat * MetaWaylandSeat *
@ -457,7 +442,7 @@ meta_wayland_seat_repick (MetaWaylandSeat *seat,
void void
meta_wayland_seat_free (MetaWaylandSeat *seat) meta_wayland_seat_free (MetaWaylandSeat *seat)
{ {
pointer_unmap_sprite (seat); set_cursor_surface (seat, NULL);
meta_wayland_pointer_release (&seat->pointer); meta_wayland_pointer_release (&seat->pointer);
meta_wayland_keyboard_release (&seat->keyboard); meta_wayland_keyboard_release (&seat->keyboard);