diff --git a/protocol/wayland.xml b/protocol/wayland.xml index 9e95d343..bd3c8686 100644 --- a/protocol/wayland.xml +++ b/protocol/wayland.xml @@ -109,7 +109,7 @@ - + @@ -239,7 +239,7 @@ NULL for not accepted. Use for feedback during drag and drop. - + @@ -311,7 +311,7 @@ data source that provides the data for the eventual data transfer. The origin surface is the surface where the drag originates and the client must have an active implicit grab - that matches the timestamp. The icon surface is an optional + that matches the serial. The icon surface is an optional (can be nil) surface that provides an icon to be moved around with the cursor. Initially, the top-left corner of the icon surface is placed at the cursor hotspot, but subsequent @@ -320,12 +320,12 @@ - + - + @@ -343,7 +343,7 @@ - + @@ -405,7 +405,7 @@ - + @@ -422,7 +422,7 @@ - + @@ -517,7 +517,7 @@ - + @@ -547,7 +547,6 @@ received. - @@ -663,7 +662,7 @@ clients surfaces. - + @@ -686,6 +685,7 @@ of the click is given by the last motion or pointer_focus event. + @@ -712,6 +712,7 @@ A key was pressed or released. + @@ -725,7 +726,7 @@ event by setting an appropriate pointer image. - + @@ -734,22 +735,23 @@ - + - + - + + @@ -758,6 +760,7 @@ + diff --git a/src/data-device.c b/src/data-device.c index 03997f19..1d22a848 100644 --- a/src/data-device.c +++ b/src/data-device.c @@ -29,7 +29,7 @@ static void data_offer_accept(struct wl_client *client, struct wl_resource *resource, - uint32_t time, const char *mime_type) + uint32_t serial, const char *mime_type) { struct wl_data_offer *offer = resource->data; @@ -58,7 +58,7 @@ data_offer_receive(struct wl_client *client, struct wl_resource *resource, static void data_offer_destroy(struct wl_client *client, struct wl_resource *resource) { - wl_resource_destroy(resource, 0); + wl_resource_destroy(resource); } static void @@ -78,7 +78,7 @@ static const struct wl_data_offer_interface data_offer_interface = { static void destroy_offer_data_source(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_data_offer *offer; @@ -146,7 +146,7 @@ data_source_offer(struct wl_client *client, static void data_source_destroy(struct wl_client *client, struct wl_resource *resource) { - wl_resource_destroy(resource, 0); + wl_resource_destroy(resource); } static struct wl_data_source_interface data_source_interface = { @@ -169,7 +169,7 @@ find_resource(struct wl_list *list, struct wl_client *client) static void destroy_drag_focus(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_input_device *device = container_of(listener, struct wl_input_device, @@ -179,12 +179,14 @@ destroy_drag_focus(struct wl_listener *listener, } static void -drag_grab_focus(struct wl_pointer_grab *grab, uint32_t time, +drag_grab_focus(struct wl_pointer_grab *grab, struct wl_surface *surface, int32_t x, int32_t y) { struct wl_input_device *device = container_of(grab, struct wl_input_device, drag_grab); struct wl_resource *resource, *offer; + struct wl_display *display; + uint32_t serial; if (device->drag_focus_resource) { wl_data_device_send_leave(device->drag_focus_resource); @@ -197,10 +199,13 @@ drag_grab_focus(struct wl_pointer_grab *grab, uint32_t time, resource = find_resource(&device->drag_resource_list, surface->resource.client); if (surface && resource) { + display = wl_client_get_display(resource->client); + serial = wl_display_next_serial(display); + offer = wl_data_source_send_offer(device->drag_data_source, resource); - wl_data_device_send_enter(resource, time, &surface->resource, + wl_data_device_send_enter(resource, serial, &surface->resource, x, y, offer); device->drag_focus = surface; @@ -225,7 +230,7 @@ drag_grab_motion(struct wl_pointer_grab *grab, } static void -data_device_end_drag_grab(struct wl_input_device *device, uint32_t time) +data_device_end_drag_grab(struct wl_input_device *device) { struct wl_resource *surface_resource; struct wl_surface_interface *implementation; @@ -240,7 +245,7 @@ data_device_end_drag_grab(struct wl_input_device *device, uint32_t time) wl_list_remove(&device->drag_icon_listener.link); } - wl_input_device_end_pointer_grab(device, time); + wl_input_device_end_pointer_grab(device); device->drag_data_source = NULL; device->drag_surface = NULL; @@ -258,7 +263,7 @@ drag_grab_button(struct wl_pointer_grab *grab, wl_data_device_send_drop(device->drag_focus_resource); if (device->button_count == 0 && state == 0) { - data_device_end_drag_grab(device, time); + data_device_end_drag_grab(device); wl_list_remove(&device->drag_data_source_listener.link); } } @@ -271,19 +276,19 @@ static const struct wl_pointer_grab_interface drag_grab_interface = { static void destroy_data_device_source(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_input_device *device; device = container_of(listener, struct wl_input_device, drag_data_source_listener); - data_device_end_drag_grab(device, time); + data_device_end_drag_grab(device); } static void destroy_data_device_icon(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_input_device *device; @@ -297,7 +302,7 @@ static void data_device_start_drag(struct wl_client *client, struct wl_resource *resource, struct wl_resource *source_resource, struct wl_resource *origin_resource, - struct wl_resource *icon_resource, uint32_t time) + struct wl_resource *icon_resource, uint32_t serial) { struct wl_input_device *device = resource->data; struct wl_listener *listener, *tmp; @@ -322,15 +327,15 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource, wl_list_for_each_safe(listener, tmp, &device->drag_icon_listener_list, link) - listener->func(listener, icon_resource, time); + listener->func(listener, icon_resource); } - wl_input_device_start_pointer_grab(device, &device->drag_grab, time); + wl_input_device_start_pointer_grab(device, &device->drag_grab); } static void destroy_selection_data_source(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_input_device *device = container_of(listener, struct wl_input_device, @@ -349,7 +354,7 @@ destroy_selection_data_source(struct wl_listener *listener, WL_EXPORT void wl_input_device_set_selection(struct wl_input_device *device, - struct wl_data_source *source, uint32_t time) + struct wl_data_source *source) { struct wl_resource *data_device, *focus, *offer; struct wl_selection_listener *listener, *next; @@ -386,13 +391,13 @@ wl_input_device_set_selection(struct wl_input_device *device, static void data_device_set_selection(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *source_resource, uint32_t time) + struct wl_resource *source_resource, uint32_t serial) { if (!source_resource) return; - wl_input_device_set_selection(resource->data, - source_resource->data, time); + /* FIXME: Store serial and check against incoming serial here. */ + wl_input_device_set_selection(resource->data, source_resource->data); } static const struct wl_data_device_interface data_device_interface = { diff --git a/src/wayland-client.c b/src/wayland-client.c index 9057b4f7..713c8945 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -433,7 +433,7 @@ wl_display_get_fd(struct wl_display *display, } static void -sync_callback(void *data, struct wl_callback *callback, uint32_t time) +sync_callback(void *data, struct wl_callback *callback, uint32_t serial) { int *done = data; diff --git a/src/wayland-server.c b/src/wayland-server.c index a649d66a..e6eccd69 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -72,6 +72,7 @@ struct wl_display { int run; uint32_t id; + uint32_t serial; struct wl_list global_list; struct wl_list socket_list; @@ -382,23 +383,22 @@ destroy_resource(void *element, void *data) { struct wl_resource *resource = element; struct wl_listener *l, *next; - uint32_t *time = data; wl_list_for_each_safe(l, next, &resource->destroy_listener_list, link) - l->func(l, resource, *time); + l->func(l, resource); if (resource->destroy) resource->destroy(resource); } WL_EXPORT void -wl_resource_destroy(struct wl_resource *resource, uint32_t time) +wl_resource_destroy(struct wl_resource *resource) { struct wl_client *client = resource->client; uint32_t id; id = resource->object.id; - destroy_resource(resource, &time); + destroy_resource(resource, NULL); if (id < WL_SERVER_ID_START) { if (client->display_resource) { @@ -414,12 +414,12 @@ wl_resource_destroy(struct wl_resource *resource, uint32_t time) WL_EXPORT void wl_client_destroy(struct wl_client *client) { - uint32_t time = 0; + uint32_t serial = 0; printf("disconnect from client %p\n", client); wl_client_flush(client); - wl_map_for_each(&client->objects, destroy_resource, &time); + wl_map_for_each(&client->objects, destroy_resource, &serial); wl_map_release(&client->objects); wl_event_source_remove(client->source); wl_connection_destroy(client->connection); @@ -429,7 +429,7 @@ wl_client_destroy(struct wl_client *client) static void lose_pointer_focus(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_input_device *device = container_of(listener, struct wl_input_device, @@ -440,7 +440,7 @@ lose_pointer_focus(struct wl_listener *listener, static void lose_keyboard_focus(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time) + struct wl_resource *resource) { struct wl_input_device *device = container_of(listener, struct wl_input_device, @@ -450,7 +450,7 @@ lose_keyboard_focus(struct wl_listener *listener, } static void -default_grab_focus(struct wl_pointer_grab *grab, uint32_t time, +default_grab_focus(struct wl_pointer_grab *grab, struct wl_surface *surface, int32_t x, int32_t y) { struct wl_input_device *device = grab->input_device; @@ -458,7 +458,7 @@ default_grab_focus(struct wl_pointer_grab *grab, uint32_t time, if (device->button_count > 0) return; - wl_input_device_set_pointer_focus(device, surface, time, x, y); + wl_input_device_set_pointer_focus(device, surface, x, y); } static void @@ -478,14 +478,18 @@ default_grab_button(struct wl_pointer_grab *grab, { struct wl_input_device *device = grab->input_device; struct wl_resource *resource; + uint32_t serial; resource = device->pointer_focus_resource; - if (resource) - wl_input_device_send_button(resource, time, button, state); + if (resource) { + serial = wl_display_next_serial(resource->client->display); + wl_input_device_send_button(resource, serial, time, + button, state); + } if (device->button_count == 0 && state == 0) wl_input_device_set_pointer_focus(device, - device->current, time, + device->current, device->current_x, device->current_y); } @@ -499,14 +503,17 @@ static const struct wl_pointer_grab_interface static void default_grab_key(struct wl_keyboard_grab *grab, - uint32_t time, uint32_t key, int32_t state) + uint32_t time, uint32_t key, int32_t state) { struct wl_input_device *device = grab->input_device; struct wl_resource *resource; + uint32_t serial; resource = device->keyboard_focus_resource; - if (resource) - wl_input_device_send_key(resource, time, key, state); + if (resource) { + serial = wl_display_next_serial(resource->client->display); + wl_input_device_send_key(resource, serial, time, key, state); + } } static const struct wl_keyboard_grab_interface @@ -574,70 +581,75 @@ find_resource_for_surface(struct wl_list *list, struct wl_surface *surface) WL_EXPORT void wl_input_device_set_pointer_focus(struct wl_input_device *device, struct wl_surface *surface, - uint32_t time, int32_t sx, int32_t sy) { struct wl_resource *resource; + uint32_t serial; if (device->pointer_focus == surface) return; - if (device->pointer_focus_resource) { - wl_input_device_send_pointer_leave( - device->pointer_focus_resource, - time, &device->pointer_focus->resource); + resource = device->pointer_focus_resource; + if (resource) { + serial = wl_display_next_serial(resource->client->display); + wl_input_device_send_pointer_leave(resource, serial, + &device->pointer_focus->resource); wl_list_remove(&device->pointer_focus_listener.link); } + resource = find_resource_for_surface(&device->resource_list, surface); if (resource) { - wl_input_device_send_pointer_enter(resource, time, + serial = wl_display_next_serial(resource->client->display); + wl_input_device_send_pointer_enter(resource, serial, &surface->resource, sx, sy); wl_list_insert(resource->destroy_listener_list.prev, &device->pointer_focus_listener.link); + device->pointer_focus_serial = serial; } device->pointer_focus_resource = resource; device->pointer_focus = surface; - device->pointer_focus_time = time; device->default_pointer_grab.focus = surface; } WL_EXPORT void wl_input_device_set_keyboard_focus(struct wl_input_device *device, - struct wl_surface *surface, - uint32_t time) + struct wl_surface *surface) { struct wl_resource *resource; + uint32_t serial; if (device->keyboard_focus == surface) return; if (device->keyboard_focus_resource) { - wl_input_device_send_keyboard_leave( - device->keyboard_focus_resource, - time, &device->keyboard_focus->resource); + resource = device->keyboard_focus_resource; + serial = wl_display_next_serial(resource->client->display); + wl_input_device_send_keyboard_leave(resource, serial, + &device->keyboard_focus->resource); wl_list_remove(&device->keyboard_focus_listener.link); } resource = find_resource_for_surface(&device->resource_list, surface); if (resource) { - wl_input_device_send_keyboard_enter(resource, time, + serial = wl_display_next_serial(resource->client->display); + wl_input_device_send_keyboard_enter(resource, serial, &surface->resource, &device->keys); wl_list_insert(resource->destroy_listener_list.prev, &device->keyboard_focus_listener.link); + device->keyboard_focus_serial = serial; } device->keyboard_focus_resource = resource; device->keyboard_focus = surface; - device->keyboard_focus_time = time; } WL_EXPORT void wl_input_device_start_keyboard_grab(struct wl_input_device *device, - struct wl_keyboard_grab *grab, uint32_t time) + struct wl_keyboard_grab *grab) { device->keyboard_grab = grab; grab->input_device = device; @@ -645,14 +657,14 @@ wl_input_device_start_keyboard_grab(struct wl_input_device *device, } WL_EXPORT void -wl_input_device_end_keyboard_grab(struct wl_input_device *device, uint32_t time) +wl_input_device_end_keyboard_grab(struct wl_input_device *device) { device->keyboard_grab = &device->default_keyboard_grab; } WL_EXPORT void wl_input_device_start_pointer_grab(struct wl_input_device *device, - struct wl_pointer_grab *grab, uint32_t time) + struct wl_pointer_grab *grab) { const struct wl_pointer_grab_interface *interface; @@ -661,18 +673,18 @@ wl_input_device_start_pointer_grab(struct wl_input_device *device, grab->input_device = device; if (device->current) - interface->focus(device->pointer_grab, time, device->current, + interface->focus(device->pointer_grab, device->current, device->current_x, device->current_y); } WL_EXPORT void -wl_input_device_end_pointer_grab(struct wl_input_device *device, uint32_t time) +wl_input_device_end_pointer_grab(struct wl_input_device *device) { const struct wl_pointer_grab_interface *interface; device->pointer_grab = &device->default_pointer_grab; interface = device->pointer_grab->interface; - interface->focus(device->pointer_grab, time, device->current, + interface->focus(device->pointer_grab, device->current, device->current_x, device->current_y); } @@ -701,11 +713,13 @@ display_sync(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wl_resource *callback; + uint32_t serial; callback = wl_client_add_object(client, &wl_callback_interface, NULL, id, NULL); - wl_callback_send_done(callback, 0); - wl_resource_destroy(callback, 0); + serial = wl_display_get_serial(client->display); + wl_callback_send_done(callback, serial); + wl_resource_destroy(callback); } struct wl_display_interface display_interface = { @@ -830,6 +844,20 @@ wl_display_remove_global(struct wl_display *display, struct wl_global *global) free(global); } +WL_EXPORT uint32_t +wl_display_get_serial(struct wl_display *display) +{ + return display->serial; +} + +WL_EXPORT uint32_t +wl_display_next_serial(struct wl_display *display) +{ + display->serial++; + + return display->serial; +} + WL_EXPORT struct wl_event_loop * wl_display_get_event_loop(struct wl_display *display) { diff --git a/src/wayland-server.h b/src/wayland-server.h index 6d2ab7cb..4b345471 100644 --- a/src/wayland-server.h +++ b/src/wayland-server.h @@ -96,6 +96,9 @@ struct wl_global *wl_display_add_global(struct wl_display *display, void wl_display_remove_global(struct wl_display *display, struct wl_global *global); +uint32_t wl_display_get_serial(struct wl_display *display); +uint32_t wl_display_next_serial(struct wl_display *display); + struct wl_client *wl_client_create(struct wl_display *display, int fd); void wl_client_destroy(struct wl_client *client); void wl_client_flush(struct wl_client *client); @@ -129,7 +132,7 @@ struct wl_buffer { struct wl_listener { struct wl_list link; void (*func)(struct wl_listener *listener, - struct wl_resource *resource, uint32_t time); + struct wl_resource *resource); }; struct wl_surface { @@ -138,7 +141,7 @@ struct wl_surface { struct wl_pointer_grab; struct wl_pointer_grab_interface { - void (*focus)(struct wl_pointer_grab *grab, uint32_t time, + void (*focus)(struct wl_pointer_grab *grab, struct wl_surface *surface, int32_t x, int32_t y); void (*motion)(struct wl_pointer_grab *grab, uint32_t time, int32_t x, int32_t y); @@ -155,8 +158,8 @@ struct wl_pointer_grab { struct wl_keyboard_grab; struct wl_keyboard_grab_interface { - void (*key)(struct wl_keyboard_grab *grab, - uint32_t time, uint32_t key, int32_t state); + void (*key)(struct wl_keyboard_grab *grab, uint32_t time, + uint32_t key, int32_t state); }; struct wl_keyboard_grab { @@ -193,8 +196,8 @@ struct wl_input_device { struct wl_resource *keyboard_focus_resource; struct wl_surface *keyboard_focus; struct wl_array keys; - uint32_t pointer_focus_time; - uint32_t keyboard_focus_time; + uint32_t pointer_focus_serial; + uint32_t keyboard_focus_serial; struct wl_listener pointer_focus_listener; struct wl_listener keyboard_focus_listener; @@ -208,6 +211,7 @@ struct wl_input_device { struct wl_keyboard_grab default_keyboard_grab; uint32_t button_count; uint32_t grab_time; + uint32_t grab_serial; int32_t grab_x, grab_y; uint32_t grab_button; uint32_t grab_key; @@ -266,7 +270,7 @@ struct wl_display * wl_client_get_display(struct wl_client *client); void -wl_resource_destroy(struct wl_resource *resource, uint32_t time); +wl_resource_destroy(struct wl_resource *resource); void wl_input_device_init(struct wl_input_device *device); @@ -277,13 +281,11 @@ wl_input_device_release(struct wl_input_device *device); void wl_input_device_set_pointer_focus(struct wl_input_device *device, struct wl_surface *surface, - uint32_t time, int32_t sx, int32_t sy); void wl_input_device_set_keyboard_focus(struct wl_input_device *device, - struct wl_surface *surface, - uint32_t time); + struct wl_surface *surface); void wl_data_device_set_keyboard_focus(struct wl_input_device *device); int @@ -291,20 +293,19 @@ wl_data_device_manager_init(struct wl_display *display); void wl_input_device_start_keyboard_grab(struct wl_input_device *device, - struct wl_keyboard_grab *grab, uint32_t time); + struct wl_keyboard_grab *grab); void -wl_input_device_end_keyboard_grab(struct wl_input_device *device, uint32_t time); +wl_input_device_end_keyboard_grab(struct wl_input_device *device); void wl_input_device_start_pointer_grab(struct wl_input_device *device, - struct wl_pointer_grab *grab, uint32_t time); + struct wl_pointer_grab *grab); void -wl_input_device_end_pointer_grab(struct wl_input_device *device, uint32_t time); +wl_input_device_end_pointer_grab(struct wl_input_device *device); void wl_input_device_set_selection(struct wl_input_device *device, - struct wl_data_source *source, - uint32_t time); + struct wl_data_source *source); void * diff --git a/src/wayland-shm.c b/src/wayland-shm.c index 8f026d5c..7900ba19 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -73,7 +73,7 @@ destroy_buffer(struct wl_resource *resource) static void shm_buffer_destroy(struct wl_client *client, struct wl_resource *resource) { - wl_resource_destroy(resource, 0); + wl_resource_destroy(resource); } static const struct wl_buffer_interface shm_buffer_interface = { @@ -147,7 +147,7 @@ destroy_pool(struct wl_resource *resource) static void shm_pool_destroy(struct wl_client *client, struct wl_resource *resource) { - wl_resource_destroy(resource, 0); + wl_resource_destroy(resource); } struct wl_shm_pool_interface shm_pool_interface = {