seat: Move set_cursor_surface and all that tracking to MetaWaylandPointer

This commit is contained in:
Jasper St. Pierre 2014-04-17 17:00:59 -04:00
parent ae0853ed86
commit 4510b82361
3 changed files with 44 additions and 29 deletions

View File

@ -56,6 +56,32 @@
static void meta_wayland_pointer_end_popup_grab (MetaWaylandPointer *pointer); static void meta_wayland_pointer_end_popup_grab (MetaWaylandPointer *pointer);
static void
set_cursor_surface (MetaWaylandPointer *pointer,
MetaWaylandSurface *surface)
{
if (pointer->cursor_surface == surface)
return;
if (pointer->cursor_surface)
wl_list_remove (&pointer->cursor_surface_destroy_listener.link);
pointer->cursor_surface = surface;
if (pointer->cursor_surface)
wl_resource_add_destroy_listener (pointer->cursor_surface->resource,
&pointer->cursor_surface_destroy_listener);
}
static void
pointer_handle_cursor_surface_destroy (struct wl_listener *listener, void *data)
{
MetaWaylandPointer *pointer = wl_container_of (listener, pointer, cursor_surface_destroy_listener);
set_cursor_surface (pointer, NULL);
meta_wayland_pointer_update_cursor_surface (pointer);
}
static void static void
pointer_handle_focus_surface_destroy (struct wl_listener *listener, void *data) pointer_handle_focus_surface_destroy (struct wl_listener *listener, void *data)
{ {
@ -284,12 +310,17 @@ meta_wayland_pointer_init (MetaWaylandPointer *pointer)
clutter_input_device_get_coords (device, NULL, &current); clutter_input_device_get_coords (device, NULL, &current);
pointer->x = wl_fixed_from_double (current.x); pointer->x = wl_fixed_from_double (current.x);
pointer->y = wl_fixed_from_double (current.y); pointer->y = wl_fixed_from_double (current.y);
pointer->cursor_surface = NULL;
pointer->cursor_surface_destroy_listener.notify = pointer_handle_cursor_surface_destroy;
pointer->hotspot_x = 16;
pointer->hotspot_y = 16;
} }
void void
meta_wayland_pointer_release (MetaWaylandPointer *pointer) meta_wayland_pointer_release (MetaWaylandPointer *pointer)
{ {
/* Do nothing. */ set_cursor_surface (pointer, NULL);
} }
static void static void
@ -626,3 +657,10 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
if (cursor) if (cursor)
meta_cursor_reference_unref (cursor); meta_cursor_reference_unref (cursor);
} }
void
meta_wayland_pointer_set_cursor_surface (MetaWaylandPointer *pointer,
MetaWaylandSurface *surface)
{
set_cursor_surface (pointer, surface);
}

View File

@ -107,4 +107,8 @@ meta_wayland_pointer_update_current_focus (MetaWaylandPointer *pointer,
void void
meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer); meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer);
void
meta_wayland_pointer_set_cursor_surface (MetaWaylandPointer *pointer,
MetaWaylandSurface *surface);
#endif /* __META_WAYLAND_POINTER_H__ */ #endif /* __META_WAYLAND_POINTER_H__ */

View File

@ -52,17 +52,7 @@ static void
set_cursor_surface (MetaWaylandSeat *seat, set_cursor_surface (MetaWaylandSeat *seat,
MetaWaylandSurface *surface) MetaWaylandSurface *surface)
{ {
if (seat->pointer.cursor_surface == surface) meta_wayland_pointer_set_cursor_surface (&seat->pointer, surface);
return;
if (seat->pointer.cursor_surface)
wl_list_remove (&seat->pointer.cursor_surface_destroy_listener.link);
seat->pointer.cursor_surface = surface;
if (seat->pointer.cursor_surface)
wl_resource_add_destroy_listener (seat->pointer.cursor_surface->resource,
&seat->pointer.cursor_surface_destroy_listener);
} }
void void
@ -199,16 +189,6 @@ bind_seat (struct wl_client *client,
wl_seat_send_name (resource, "seat0"); wl_seat_send_name (resource, "seat0");
} }
static void
pointer_handle_cursor_surface_destroy (struct wl_listener *listener, void *data)
{
MetaWaylandPointer *pointer = wl_container_of (listener, pointer, cursor_surface_destroy_listener);
MetaWaylandSeat *seat = wl_container_of (pointer, seat, pointer);
set_cursor_surface (seat, NULL);
meta_wayland_seat_update_cursor_surface (seat);
}
MetaWaylandSeat * MetaWaylandSeat *
meta_wayland_seat_new (struct wl_display *display) meta_wayland_seat_new (struct wl_display *display)
{ {
@ -225,11 +205,6 @@ meta_wayland_seat_new (struct wl_display *display)
seat->current_stage = 0; seat->current_stage = 0;
seat->pointer.cursor_surface = NULL;
seat->pointer.cursor_surface_destroy_listener.notify = pointer_handle_cursor_surface_destroy;
seat->pointer.hotspot_x = 16;
seat->pointer.hotspot_y = 16;
wl_global_create (display, &wl_seat_interface, META_WL_SEAT_VERSION, seat, bind_seat); wl_global_create (display, &wl_seat_interface, META_WL_SEAT_VERSION, seat, bind_seat);
return seat; return seat;
@ -238,8 +213,6 @@ meta_wayland_seat_new (struct wl_display *display)
void void
meta_wayland_seat_free (MetaWaylandSeat *seat) meta_wayland_seat_free (MetaWaylandSeat *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);