backend-wayland: replace a nested wl_display_roundtrip call
The wl_display_roundtrip call was originally introduced to let the display_add_seat function wait until a wl_seat.name event was received. This change replaces the wl_display_roundtrip call with an asynchronous, nonrecursive equivalent. Now a wl_display.sync callback is used to delay the final steps of adding a seat until one protocol roundtrip has occured/the name has been received. Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
This commit is contained in:
parent
43ec334c77
commit
ac20d4a293
|
@ -223,6 +223,7 @@ struct wayland_input {
|
||||||
struct weston_pointer_axis_event vert, horiz;
|
struct weston_pointer_axis_event vert, horiz;
|
||||||
|
|
||||||
bool seat_initialized;
|
bool seat_initialized;
|
||||||
|
char *name;
|
||||||
enum wl_seat_capability caps;
|
enum wl_seat_capability caps;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2354,10 +2355,11 @@ input_handle_name(void *data, struct wl_seat *seat,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
struct wayland_input *input = data;
|
struct wayland_input *input = data;
|
||||||
struct wayland_backend *b = input->backend;
|
|
||||||
|
|
||||||
weston_seat_init(&input->base, b->compositor, name);
|
if (!input->seat_initialized) {
|
||||||
input->seat_initialized = true;
|
assert(!input->name);
|
||||||
|
input->name = strdup(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_seat_listener seat_listener = {
|
static const struct wl_seat_listener seat_listener = {
|
||||||
|
@ -2366,9 +2368,42 @@ static const struct wl_seat_listener seat_listener = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_version)
|
display_finish_add_seat(void *data, struct wl_callback *wl_callback,
|
||||||
|
uint32_t callback_data)
|
||||||
|
{
|
||||||
|
struct wayland_input *input = data;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
wl_callback_destroy(wl_callback);
|
||||||
|
input->seat_initialized = true;
|
||||||
|
|
||||||
|
wl_list_insert(input->backend->input_list.prev, &input->link);
|
||||||
|
|
||||||
|
name = input->name ? input->name : "default";
|
||||||
|
weston_seat_init(&input->base, input->backend->compositor, name);
|
||||||
|
free(input->name);
|
||||||
|
input->name = NULL;
|
||||||
|
|
||||||
|
input_update_capabilities(input, input->caps);
|
||||||
|
|
||||||
|
/* Because this happens one roundtrip after wl_seat is bound,
|
||||||
|
* wl_compositor will also have been bound by this time. */
|
||||||
|
input->parent.cursor.surface =
|
||||||
|
wl_compositor_create_surface(input->backend->parent.compositor);
|
||||||
|
|
||||||
|
input->vert.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
|
||||||
|
input->horiz.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_callback_listener seat_callback_listener = {
|
||||||
|
display_finish_add_seat
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
display_start_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_version)
|
||||||
{
|
{
|
||||||
struct wayland_input *input;
|
struct wayland_input *input;
|
||||||
|
struct wl_callback *callback;
|
||||||
uint32_t version = MIN(available_version, 4);
|
uint32_t version = MIN(available_version, 4);
|
||||||
|
|
||||||
input = zalloc(sizeof *input);
|
input = zalloc(sizeof *input);
|
||||||
|
@ -2379,23 +2414,14 @@ display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_vers
|
||||||
input->parent.seat = wl_registry_bind(b->parent.registry, id,
|
input->parent.seat = wl_registry_bind(b->parent.registry, id,
|
||||||
&wl_seat_interface, version);
|
&wl_seat_interface, version);
|
||||||
input->seat_version = version;
|
input->seat_version = version;
|
||||||
wl_list_insert(b->input_list.prev, &input->link);
|
|
||||||
|
|
||||||
wl_seat_add_listener(input->parent.seat, &seat_listener, input);
|
wl_seat_add_listener(input->parent.seat, &seat_listener, input);
|
||||||
wl_seat_set_user_data(input->parent.seat, input);
|
wl_seat_set_user_data(input->parent.seat, input);
|
||||||
|
|
||||||
wl_display_roundtrip(b->parent.wl_display);
|
/* Wait one roundtrip for the compositor to provide the seat name
|
||||||
if (!input->seat_initialized) {
|
* and initial capabilities */
|
||||||
weston_seat_init(&input->base, b->compositor, "default");
|
callback = wl_display_sync(b->parent.wl_display);
|
||||||
input->seat_initialized = true;
|
wl_callback_add_listener(callback, &seat_callback_listener, input);
|
||||||
}
|
|
||||||
input_update_capabilities(input, input->caps);
|
|
||||||
|
|
||||||
input->parent.cursor.surface =
|
|
||||||
wl_compositor_create_surface(b->parent.compositor);
|
|
||||||
|
|
||||||
input->vert.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
|
|
||||||
input->horiz.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2603,7 +2629,7 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||||
wl_registry_bind(registry, name,
|
wl_registry_bind(registry, name,
|
||||||
&zwp_fullscreen_shell_v1_interface, 1);
|
&zwp_fullscreen_shell_v1_interface, 1);
|
||||||
} else if (strcmp(interface, "wl_seat") == 0) {
|
} else if (strcmp(interface, "wl_seat") == 0) {
|
||||||
display_add_seat(b, name, version);
|
display_start_add_seat(b, name, version);
|
||||||
} else if (strcmp(interface, "wl_output") == 0) {
|
} else if (strcmp(interface, "wl_output") == 0) {
|
||||||
wayland_backend_register_output(b, name);
|
wayland_backend_register_output(b, name);
|
||||||
} else if (strcmp(interface, "wl_shm") == 0) {
|
} else if (strcmp(interface, "wl_shm") == 0) {
|
||||||
|
|
Loading…
Reference in New Issue