From 577d2f6fcd8f69b78c2cd84190f060c60b7b9a2a Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 16 Aug 2017 19:19:31 +0200 Subject: wayland backend: switch to xdg shell Closes #72 and #96. --- backend/meson.build | 2 +- backend/wayland/backend.c | 4 +++- backend/wayland/output.c | 59 +++++++++++++++++++++++++++++----------------- backend/wayland/registry.c | 17 +++++++++++-- 4 files changed, 57 insertions(+), 25 deletions(-) (limited to 'backend') diff --git a/backend/meson.build b/backend/meson.build index cea3076c..6a6a5f9f 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -31,4 +31,4 @@ endif lib_wlr_backend = static_library('wlr_backend', backend_files, include_directories: wlr_inc, - dependencies: [wayland_server, egl, gbm, libinput, systemd]) + dependencies: [wayland_server, egl, gbm, libinput, systemd, wlr_protos]) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 467d137b..7bb0d0e9 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -10,6 +10,8 @@ #include #include #include "backend/wayland.h" +#include "xdg-shell-unstable-v6-client-protocol.h" + static int dispatch_events(int fd, uint32_t mask, void *data) { struct wlr_wl_backend *backend = data; @@ -89,7 +91,7 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) { wlr_egl_free(&backend->egl); if (backend->seat) wl_seat_destroy(backend->seat); if (backend->shm) wl_shm_destroy(backend->shm); - if (backend->shell) wl_shell_destroy(backend->shell); + if (backend->shell) zxdg_shell_v6_destroy(backend->shell); if (backend->compositor) wl_compositor_destroy(backend->compositor); if (backend->registry) wl_registry_destroy(backend->registry); if (backend->remote_display) wl_display_disconnect(backend->remote_display); diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 786dc46e..a5c16c7b 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -11,6 +11,7 @@ #include #include #include "backend/wayland.h" +#include "xdg-shell-unstable-v6-client-protocol.h" int os_create_anonymous_file(off_t size); @@ -136,7 +137,7 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) { } eglDestroySurface(output->backend->egl.display, output->surface); wl_egl_window_destroy(output->egl_window); - wl_shell_surface_destroy(output->shell_surface); + // xdg_surface/toplevel destroy wl_surface_destroy(output->surface); free(output); } @@ -162,16 +163,27 @@ static struct wlr_output_impl output_impl = { .move_cursor = wlr_wl_output_move_cursor }; -void handle_ping(void *data, struct wl_shell_surface *ssurface, uint32_t serial) { +static void xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *xdg_surface, + uint32_t serial) { struct wlr_wl_backend_output *output = data; - assert(output && output->shell_surface == ssurface); - wl_shell_surface_pong(ssurface, serial); + assert(output && output->xdg_surface == xdg_surface); + + zxdg_surface_v6_ack_configure(xdg_surface, serial); + + // nothing else? } -void handle_configure(void *data, struct wl_shell_surface *wl_shell_surface, - uint32_t edges, int32_t width, int32_t height){ +static struct zxdg_surface_v6_listener xdg_surface_listener = { + .configure = xdg_surface_handle_configure, +}; + +static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *xdg_toplevel, + int32_t width, int32_t height, struct wl_array *states) { struct wlr_wl_backend_output *output = data; - assert(output && output->shell_surface == wl_shell_surface); + assert(output && output->xdg_toplevel == xdg_toplevel); + + // loop over states for maximized etc? + wl_egl_window_resize(output->egl_window, width, height, 0, 0); output->wlr_output.width = width; output->wlr_output.height = height; @@ -179,14 +191,16 @@ void handle_configure(void *data, struct wl_shell_surface *wl_shell_surface, wl_signal_emit(&output->wlr_output.events.resolution, output); } -void handle_popup_done(void *data, struct wl_shell_surface *wl_shell_surface) { - wlr_log(L_ERROR, "Unexpected wl_shell_surface.popup_done event"); +static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) { + struct wlr_wl_backend_output *output = data; + assert(output && output->xdg_toplevel == xdg_toplevel); + + wl_display_terminate(output->backend->local_display); } -static struct wl_shell_surface_listener shell_surface_listener = { - .ping = handle_ping, - .configure = handle_configure, - .popup_done = handle_popup_done +static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = { + .configure = xdg_toplevel_handle_configure, + .close = xdg_toplevel_handle_close, }; struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { @@ -218,14 +232,17 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { // TODO: error handling output->surface = wl_compositor_create_surface(backend->compositor); - output->shell_surface = - wl_shell_get_shell_surface(backend->shell, output->surface); - - wl_shell_surface_set_class(output->shell_surface, "sway"); - wl_shell_surface_set_title(output->shell_surface, "sway-wl"); - wl_shell_surface_add_listener(output->shell_surface, - &shell_surface_listener, output); - wl_shell_surface_set_toplevel(output->shell_surface); + output->xdg_surface = + zxdg_shell_v6_get_xdg_surface(backend->shell, output->surface); + output->xdg_toplevel = + zxdg_surface_v6_get_toplevel(output->xdg_surface); + + // class? app_id? + zxdg_toplevel_v6_set_title(output->xdg_toplevel, "sway-wl"); + zxdg_surface_v6_add_listener(output->xdg_surface, + &xdg_surface_listener, output); + zxdg_toplevel_v6_add_listener(output->xdg_toplevel, + &xdg_toplevel_listener, output); output->egl_window = wl_egl_window_create(output->surface, wlr_output->width, wlr_output->height); diff --git a/backend/wayland/registry.c b/backend/wayland/registry.c index 9564b1dd..d6f61aa7 100644 --- a/backend/wayland/registry.c +++ b/backend/wayland/registry.c @@ -4,6 +4,18 @@ #include #include #include "backend/wayland.h" +#include "xdg-shell-unstable-v6-client-protocol.h" + + +static void xdg_shell_handle_ping(void *data, struct zxdg_shell_v6 *shell, + uint32_t serial) { + zxdg_shell_v6_pong(shell, serial); +} + +static const struct zxdg_shell_v6_listener xdg_shell_listener = { + xdg_shell_handle_ping, +}; + static void registry_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { @@ -13,9 +25,10 @@ static void registry_global(void *data, struct wl_registry *registry, if (strcmp(interface, wl_compositor_interface.name) == 0) { backend->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, version); - } else if (strcmp(interface, wl_shell_interface.name) == 0) { + } else if (strcmp(interface, zxdg_shell_v6_interface.name) == 0) { backend->shell = wl_registry_bind(registry, name, - &wl_shell_interface, version); + &zxdg_shell_v6_interface, version); + zxdg_shell_v6_add_listener(backend->shell, &xdg_shell_listener, NULL); } else if (strcmp(interface, wl_shm_interface.name) == 0) { backend->shm = wl_registry_bind(registry, name, &wl_shm_interface, version); -- cgit v1.2.3 From 4f3d21c3ff17a55301deb2f0f1f53d2897d05e10 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 16 Aug 2017 19:33:16 +0200 Subject: wayland output: add error handling for xdg shell Note that this does not go on to the next backend, because attempt_wl_backend does not check if we have any output created. We cannot test simply because (right now) a run of our examples will go in this function twice, the first of which will (rightly?) return no display but needs to return backend creation success. --- backend/wayland/output.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'backend') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index a5c16c7b..9d9f1fc6 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -137,7 +137,8 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) { } eglDestroySurface(output->backend->egl.display, output->surface); wl_egl_window_destroy(output->egl_window); - // xdg_surface/toplevel destroy + zxdg_toplevel_v6_destroy(output->xdg_toplevel); + zxdg_surface_v6_destroy(output->xdg_surface); wl_surface_destroy(output->surface); free(output); } @@ -230,12 +231,23 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { output->backend = backend; - // TODO: error handling output->surface = wl_compositor_create_surface(backend->compositor); + if (!output->surface) { + wlr_log_errno(L_ERROR, "Could not create output surface"); + goto error; + } output->xdg_surface = zxdg_shell_v6_get_xdg_surface(backend->shell, output->surface); + if (!output->xdg_surface) { + wlr_log_errno(L_ERROR, "Could not get xdg surface"); + goto error; + } output->xdg_toplevel = zxdg_surface_v6_get_toplevel(output->xdg_surface); + if (!output->xdg_toplevel) { + wlr_log_errno(L_ERROR, "Could not get xdg toplevel"); + goto error; + } // class? app_id? zxdg_toplevel_v6_set_title(output->xdg_toplevel, "sway-wl"); @@ -253,8 +265,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { output->egl_surface, output->egl_surface, output->backend->egl.context)) { wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); - free(output); - return NULL; + goto error; } glViewport(0, 0, wlr_output->width, wlr_output->height); @@ -266,16 +277,18 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) { wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); - free(output); - return NULL; + goto error; } if (list_add(backend->outputs, wlr_output) == -1) { wlr_log(L_ERROR, "Allocation failed"); - free(output); - return NULL; + goto error; } wlr_output_create_global(wlr_output, backend->local_display); wl_signal_emit(&backend->backend.events.output_add, wlr_output); return wlr_output; + +error: + wlr_output_destroy(&output->wlr_output); + return NULL; } -- cgit v1.2.3 From fb05923eaab276626b49b99d7dc56c4053d34251 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 16 Aug 2017 21:01:39 +0200 Subject: wayland backend: Fix shell title/app_id to wlroots --- backend/wayland/output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 9d9f1fc6..d956122f 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -249,8 +249,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { goto error; } - // class? app_id? - zxdg_toplevel_v6_set_title(output->xdg_toplevel, "sway-wl"); + zxdg_toplevel_v6_set_app_id(output->xdg_toplevel, "wlroots"); + zxdg_toplevel_v6_set_title(output->xdg_toplevel, "wlroots"); zxdg_surface_v6_add_listener(output->xdg_surface, &xdg_surface_listener, output); zxdg_toplevel_v6_add_listener(output->xdg_toplevel, -- cgit v1.2.3 From 3377e5e4f27fb5954ce2c14388beb08681fd1d40 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 17 Aug 2017 00:52:01 +0200 Subject: wayland backend: fix xdg-shell for gnome Calling wl_surface_commit after setting up the xdg_toplevel is apparently good enough for them. Still missing something for weston. --- backend/wayland/output.c | 1 + 1 file changed, 1 insertion(+) (limited to 'backend') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index d956122f..5dfca82e 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -255,6 +255,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { &xdg_surface_listener, output); zxdg_toplevel_v6_add_listener(output->xdg_toplevel, &xdg_toplevel_listener, output); + wl_surface_commit(output->surface); output->egl_window = wl_egl_window_create(output->surface, wlr_output->width, wlr_output->height); -- cgit v1.2.3 From e2e149784b2659e43f0459e9d659d828687d7c04 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 17 Aug 2017 10:22:54 +0200 Subject: wayland backend: fix xdg-shell for weston - xdg toplevel configure can be called with 0 width/height, in that case we are free to do as we like (so do nothing) - need a display roundtrip after everything is setup but before we start attaching buffers to the surface --- backend/wayland/output.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'backend') diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 5dfca82e..16f9f017 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -183,8 +183,10 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x struct wlr_wl_backend_output *output = data; assert(output && output->xdg_toplevel == xdg_toplevel); + if (width == 0 && height == 0) { + return; + } // loop over states for maximized etc? - wl_egl_window_resize(output->egl_window, width, height, 0, 0); output->wlr_output.width = width; output->wlr_output.height = height; @@ -261,6 +263,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { wlr_output->width, wlr_output->height); output->egl_surface = wlr_egl_create_surface(&backend->egl, output->egl_window); + wl_display_roundtrip(output->backend->remote_display); + // start rendering loop per callbacks by rendering first frame if (!eglMakeCurrent(output->backend->egl.display, output->egl_surface, output->egl_surface, -- cgit v1.2.3