compositor: Track pointer image protocol change

The request pointer.attach was replaced with pointer.set_cursor that
lets a client set the cursor surface for a given pointer.
dev
Ander Conselvan de Oliveira 13 years ago committed by Kristian Høgsberg
parent 912f20b9b7
commit 37ffc3c14b
  1. 2
      clients/simple-egl.c
  2. 13
      clients/window.c
  3. 2
      src/compositor-wayland.c
  4. 110
      src/compositor.c
  5. 1
      src/compositor.h

@ -360,7 +360,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
struct display *display = data; struct display *display = data;
if (display->window->fullscreen) if (display->window->fullscreen)
wl_pointer_attach(pointer, serial, NULL, 0, 0); wl_pointer_set_cursor(pointer, serial, NULL, 0, 0);
} }
static void static void

@ -189,6 +189,7 @@ struct input {
struct window *pointer_focus; struct window *pointer_focus;
struct window *keyboard_focus; struct window *keyboard_focus;
int current_cursor; int current_cursor;
struct wl_surface *pointer_surface;
uint32_t modifiers; uint32_t modifiers;
uint32_t pointer_enter_serial; uint32_t pointer_enter_serial;
float sx, sy; float sx, sy;
@ -2295,8 +2296,12 @@ input_set_pointer_image_index(struct input *input, int pointer, int index)
return; return;
input->current_cursor = pointer; input->current_cursor = pointer;
wl_pointer_attach(input->pointer, input->pointer_enter_serial, wl_pointer_set_cursor(input->pointer, input->display->serial,
buffer, image->hotspot_x, image->hotspot_y); input->pointer_surface,
image->hotspot_x, image->hotspot_y);
wl_surface_attach(input->pointer_surface, buffer, 0, 0);
wl_surface_damage(input->pointer_surface, 0, 0,
image->width, image->height);
} }
void void
@ -3168,6 +3173,8 @@ display_add_input(struct display *d, uint32_t id)
input->seat); input->seat);
wl_data_device_add_listener(input->data_device, &data_device_listener, wl_data_device_add_listener(input->data_device, &data_device_listener,
input); input);
input->pointer_surface = wl_compositor_create_surface(d->compositor);
} }
static void static void
@ -3190,6 +3197,8 @@ input_destroy(struct input *input)
wl_data_device_destroy(input->data_device); wl_data_device_destroy(input->data_device);
fini_xkb(input); fini_xkb(input);
wl_surface_destroy(input->pointer_surface);
wl_list_remove(&input->link); wl_list_remove(&input->link);
wl_seat_destroy(input->seat); wl_seat_destroy(input->seat);
free(input); free(input);

@ -505,7 +505,7 @@ input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
output = wl_surface_get_user_data(surface); output = wl_surface_get_user_data(surface);
notify_pointer_focus(&c->base.seat->seat, &output->base, x, y); notify_pointer_focus(&c->base.seat->seat, &output->base, x, y);
wl_pointer_attach(input->pointer, serial, NULL, 0, 0); wl_pointer_set_cursor(input->pointer, serial, NULL, 0, 0);
} }
static void static void

@ -2064,13 +2064,59 @@ notify_touch(struct wl_seat *seat, uint32_t time, int touch_id,
} }
static void static void
pointer_attach(struct wl_client *client, struct wl_resource *resource, pointer_handle_sprite_destroy(struct wl_listener *listener, void *data)
uint32_t serial, struct wl_resource *buffer_resource, {
struct weston_seat *seat = container_of(listener, struct weston_seat,
sprite_destroy_listener);
seat->sprite = NULL;
}
static void
pointer_cursor_surface_configure(struct weston_surface *es,
int32_t dx, int32_t dy)
{
struct weston_seat *seat = es->private;
int x, y;
assert(es == seat->sprite);
seat->hotspot_x -= dx;
seat->hotspot_y -= dy;
x = wl_fixed_to_int(seat->seat.pointer->x) - seat->hotspot_x;
y = wl_fixed_to_int(seat->seat.pointer->y) - seat->hotspot_y;
weston_surface_configure(seat->sprite, x, y,
es->buffer->width, es->buffer->height);
if (!weston_surface_is_mapped(es)) {
wl_list_insert(&es->compositor->cursor_layer.surface_list,
&es->layer_link);
weston_surface_assign_output(es);
empty_region(&es->input);
}
}
static void
pointer_unmap_sprite(struct weston_seat *seat)
{
if (weston_surface_is_mapped(seat->sprite))
weston_surface_unmap(seat->sprite);
wl_list_remove(&seat->sprite_destroy_listener.link);
seat->sprite->configure = NULL;
seat->sprite->private = NULL;
seat->sprite = NULL;
}
static void
pointer_set_cursor(struct wl_client *client, struct wl_resource *resource,
uint32_t serial, struct wl_resource *surface_resource,
int32_t x, int32_t y) int32_t x, int32_t y)
{ {
struct weston_seat *seat = resource->data; struct weston_seat *seat = resource->data;
struct weston_compositor *compositor = seat->compositor; struct weston_surface *surface = NULL;
struct wl_buffer *buffer = NULL;
if (serial < seat->seat.pointer->focus_serial) if (serial < seat->seat.pointer->focus_serial)
return; return;
@ -2079,35 +2125,41 @@ pointer_attach(struct wl_client *client, struct wl_resource *resource,
if (seat->seat.pointer->focus->resource.client != client) if (seat->seat.pointer->focus->resource.client != client)
return; return;
if (buffer_resource) if (surface_resource)
buffer = buffer_resource->data; surface = container_of(surface_resource->data,
struct weston_surface, surface);
if (surface && surface != seat->sprite && surface->configure) {
wl_resource_post_error(&surface->surface.resource,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"surface->configure already set");
return;
}
weston_surface_attach(&seat->sprite->surface, buffer); if (seat->sprite)
empty_region(&seat->sprite->input); pointer_unmap_sprite(seat);
if (!buffer) if (!surface)
return; return;
if (!weston_surface_is_mapped(seat->sprite)) { wl_signal_add(&surface->surface.resource.destroy_signal,
wl_list_insert(&compositor->cursor_layer.surface_list, &seat->sprite_destroy_listener);
&seat->sprite->layer_link);
weston_surface_assign_output(seat->sprite);
}
surface->configure = pointer_cursor_surface_configure;
surface->private = seat;
empty_region(&surface->input);
seat->sprite = surface;
seat->hotspot_x = x; seat->hotspot_x = x;
seat->hotspot_y = y; seat->hotspot_y = y;
weston_surface_configure(seat->sprite,
wl_fixed_to_int(seat->seat.pointer->x) - x,
wl_fixed_to_int(seat->seat.pointer->y) - y,
buffer->width, buffer->height);
surface_damage(NULL, &seat->sprite->surface.resource, weston_surface_set_position(surface,
0, 0, buffer->width, buffer->height); wl_fixed_to_int(seat->seat.pointer->x) - x,
wl_fixed_to_int(seat->seat.pointer->y) - y);
} }
static const struct wl_pointer_interface pointer_interface = { static const struct wl_pointer_interface pointer_interface = {
pointer_attach, pointer_set_cursor
}; };
static void static void
@ -2428,8 +2480,8 @@ weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
wl_display_add_global(ec->wl_display, &wl_seat_interface, seat, wl_display_add_global(ec->wl_display, &wl_seat_interface, seat,
bind_seat); bind_seat);
seat->sprite = weston_surface_create(ec); seat->sprite = NULL;
seat->sprite->surface.resource.data = seat->sprite; seat->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
seat->compositor = ec; seat->compositor = ec;
seat->hotspot_x = 16; seat->hotspot_x = 16;
@ -2456,7 +2508,7 @@ weston_seat_release(struct weston_seat *seat)
/* The global object is destroyed at wl_display_destroy() time. */ /* The global object is destroyed at wl_display_destroy() time. */
if (seat->sprite) if (seat->sprite)
destroy_surface(&seat->sprite->surface.resource); pointer_unmap_sprite(seat);
if (seat->xkb_state.state != NULL) if (seat->xkb_state.state != NULL)
xkb_state_unref(seat->xkb_state.state); xkb_state_unref(seat->xkb_state.state);
@ -2512,12 +2564,18 @@ device_release_drag_surface(struct weston_seat *seat)
static void static void
device_map_drag_surface(struct weston_seat *seat) device_map_drag_surface(struct weston_seat *seat)
{ {
struct wl_list *list;
if (weston_surface_is_mapped(seat->drag_surface) || if (weston_surface_is_mapped(seat->drag_surface) ||
!seat->drag_surface->buffer) !seat->drag_surface->buffer)
return; return;
wl_list_insert(&seat->sprite->layer_link, if (seat->sprite && weston_surface_is_mapped(seat->sprite))
&seat->drag_surface->layer_link); list = &seat->sprite->layer_link;
else
list = &seat->compositor->cursor_layer.surface_list;
wl_list_insert(list, &seat->drag_surface->layer_link);
weston_surface_assign_output(seat->drag_surface); weston_surface_assign_output(seat->drag_surface);
empty_region(&seat->drag_surface->input); empty_region(&seat->drag_surface->input);
} }

@ -207,6 +207,7 @@ struct weston_seat {
struct weston_compositor *compositor; struct weston_compositor *compositor;
struct weston_surface *sprite; struct weston_surface *sprite;
struct wl_listener sprite_destroy_listener;
struct weston_surface *drag_surface; struct weston_surface *drag_surface;
struct wl_listener drag_surface_destroy_listener; struct wl_listener drag_surface_destroy_listener;
int32_t hotspot_x, hotspot_y; int32_t hotspot_x, hotspot_y;

Loading…
Cancel
Save