From e4a1e7e9670b77d5b145520d60c4b7570fe3c6ea Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 29 Jul 2020 20:19:54 -0400 Subject: [PATCH] wayland: remove wl_shell, add xdg shell support --- include/waffle-1/waffle_wayland.h | 10 ++-- src/waffle/wayland/wayland_display.c | 24 +++++++--- src/waffle/wayland/wayland_display.h | 4 +- src/waffle/wayland/wayland_sym.h | 2 - src/waffle/wayland/wayland_window.c | 71 +++++++++++++--------------- src/waffle/wayland/wayland_window.h | 3 +- src/waffle/wayland/wayland_wrapper.h | 3 +- 7 files changed, 61 insertions(+), 56 deletions(-) diff --git a/include/waffle-1/waffle_wayland.h b/include/waffle-1/waffle_wayland.h index 1a2ec43..a8b904f 100644 --- a/include/waffle-1/waffle_wayland.h +++ b/include/waffle-1/waffle_wayland.h @@ -39,14 +39,15 @@ extern "C" { struct wl_compositor; struct wl_display; struct wl_egl_window; -struct wl_shell; -struct wl_shell_surface; struct wl_surface; +struct xdg_wm_base; +struct xdg_surface; +struct xdg_toplevel; struct waffle_wayland_display { struct wl_display *wl_display; struct wl_compositor *wl_compositor; - struct wl_shell *wl_shell; + struct xdg_wm_base *xdg_wm_base; EGLDisplay egl_display; }; @@ -62,8 +63,9 @@ struct waffle_wayland_context { struct waffle_wayland_window { struct waffle_wayland_display display; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; struct wl_surface *wl_surface; - struct wl_shell_surface *wl_shell_surface; struct wl_egl_window *wl_window; EGLSurface egl_surface; }; diff --git a/src/waffle/wayland/wayland_display.c b/src/waffle/wayland/wayland_display.c index 412c38a..eb241cc 100644 --- a/src/waffle/wayland/wayland_display.c +++ b/src/waffle/wayland/wayland_display.c @@ -58,6 +58,16 @@ wayland_display_destroy(struct wcore_display *wc_self) return ok; } +static void +xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial) +{ + xdg_wm_base_pong(xdg_wm_base, serial); +} + +const static struct xdg_wm_base_listener xdg_wm_base_listener = { + .ping = xdg_wm_base_ping, +}; + static void registry_listener_global(void *data, struct wl_registry *registry, @@ -71,9 +81,11 @@ registry_listener_global(void *data, self->wl_compositor = wl_registry_bind(self->wl_registry, name, &wl_compositor_interface, 1); } - else if (!strncmp(interface, "wl_shell", 9)) { - self->wl_shell = wl_registry_bind(self->wl_registry, name, - &wl_shell_interface, 1); + else if (!strncmp(interface, "xdg_wm_base", 12)) { + self->xdg_wm_base = wl_registry_bind(self->wl_registry, name, + &xdg_wm_base_interface, 1); + xdg_wm_base_add_listener(self->xdg_wm_base, &xdg_wm_base_listener, + NULL); } } @@ -135,9 +147,9 @@ wayland_display_connect(struct wcore_platform *wc_plat, goto error; } - if (!self->wl_shell) { + if (!self->xdg_wm_base) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, "failed to bind to the wayland " - "shell"); + "xdg shell"); goto error; } @@ -158,7 +170,7 @@ wayland_display_fill_native(struct wayland_display *self, { n_dpy->wl_display = self->wl_display; n_dpy->wl_compositor = self->wl_compositor; - n_dpy->wl_shell = self->wl_shell; + n_dpy->xdg_wm_base = self->xdg_wm_base; n_dpy->egl_display = self->wegl.egl; } diff --git a/src/waffle/wayland/wayland_display.h b/src/waffle/wayland/wayland_display.h index 722e379..ab1fd88 100644 --- a/src/waffle/wayland/wayland_display.h +++ b/src/waffle/wayland/wayland_display.h @@ -38,13 +38,13 @@ struct wcore_platform; struct wl_display; struct wl_compositor; -struct wl_shell; +struct xdg_wm_base; struct wayland_display { struct wl_display *wl_display; struct wl_registry *wl_registry; struct wl_compositor *wl_compositor; - struct wl_shell *wl_shell; + struct xdg_wm_base *xdg_wm_base; struct wegl_display wegl; }; diff --git a/src/waffle/wayland/wayland_sym.h b/src/waffle/wayland/wayland_sym.h index f9ae52e..ce02a4b 100644 --- a/src/waffle/wayland/wayland_sym.h +++ b/src/waffle/wayland/wayland_sym.h @@ -1,7 +1,5 @@ WAFFLE_WAYLAND_INTERFACE(wl_compositor_interface) WAFFLE_WAYLAND_INTERFACE(wl_registry_interface) -WAFFLE_WAYLAND_INTERFACE(wl_shell_interface) -WAFFLE_WAYLAND_INTERFACE(wl_shell_surface_interface) WAFFLE_WAYLAND_INTERFACE(wl_surface_interface) diff --git a/src/waffle/wayland/wayland_window.c b/src/waffle/wayland/wayland_window.c index 89f7342..0ba6402 100644 --- a/src/waffle/wayland/wayland_window.c +++ b/src/waffle/wayland/wayland_window.c @@ -60,8 +60,11 @@ wayland_window_destroy(struct wcore_window *wc_self) if (self->wl_window) plat->wl_egl_window_destroy(self->wl_window); - if (self->wl_shell_surface) - wl_shell_surface_destroy(self->wl_shell_surface); + if (self->xdg_toplevel) + xdg_toplevel_destroy(self->xdg_toplevel); + + if (self->xdg_surface) + xdg_surface_destroy(self->xdg_surface); if (self->wl_surface) wl_surface_destroy(self->wl_surface); @@ -71,32 +74,14 @@ wayland_window_destroy(struct wcore_window *wc_self) } static void -shell_surface_listener_ping(void *data, - struct wl_shell_surface *shell_surface, - uint32_t serial) -{ - wl_shell_surface_pong(shell_surface, serial); -} - -static void -shell_surface_listener_configure(void *data, - struct wl_shell_surface *shell_surface, - uint32_t edges, - int32_t width, - int32_t height) -{ -} - -static void -shell_surface_listener_popup_done(void *data, - struct wl_shell_surface *shell_surface) +xdg_surface_configure(void *data, + struct xdg_surface *xdg_surface, uint32_t serial) { + xdg_surface_ack_configure(xdg_surface, serial); } -static const struct wl_shell_surface_listener shell_surface_listener = { - .ping = shell_surface_listener_ping, - .configure = shell_surface_listener_configure, - .popup_done = shell_surface_listener_popup_done +static const struct xdg_surface_listener xdg_surface_listener = { + .configure = xdg_surface_configure, }; struct wcore_window* @@ -130,10 +115,6 @@ wayland_window_create(struct wcore_platform *wc_plat, wcore_errorf(WAFFLE_ERROR_UNKNOWN, "wayland compositor not found"); goto error; } - if (!dpy->wl_shell) { - wcore_errorf(WAFFLE_ERROR_UNKNOWN, "wayland shell not found"); - goto error; - } self->wl_surface = wl_compositor_create_surface(dpy->wl_compositor); if (!self->wl_surface) { @@ -142,18 +123,29 @@ wayland_window_create(struct wcore_platform *wc_plat, goto error; } - self->wl_shell_surface = wl_shell_get_shell_surface(dpy->wl_shell, + if (dpy->xdg_wm_base) { + self->xdg_surface = xdg_wm_base_get_xdg_surface(dpy->xdg_wm_base, self->wl_surface); - if (!self->wl_shell_surface) { - wcore_errorf(WAFFLE_ERROR_UNKNOWN, - "wl_shell_get_shell_surface failed"); + if (!self->xdg_surface) { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "xdg_wm_base_get_xdg_surface failed"); + goto error; + } + self->xdg_toplevel = xdg_surface_get_toplevel(self->xdg_surface); + if (!self->xdg_toplevel) { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "xdg_surface_get_toplevel failed"); + goto error; + } + + xdg_surface_add_listener(self->xdg_surface, &xdg_surface_listener, + NULL); + } + else { + wcore_errorf(WAFFLE_ERROR_UNKNOWN, "wayland shell not found"); goto error; } - wl_shell_surface_add_listener(self->wl_shell_surface, - &shell_surface_listener, - NULL); - self->wl_window = plat->wl_egl_window_create(self->wl_surface, width, height); if (!self->wl_window) { @@ -184,7 +176,7 @@ wayland_window_show(struct wcore_window *wc_self) struct wayland_display *dpy = wayland_display(wc_self->display); bool ok = true; - wl_shell_surface_set_toplevel(self->wl_shell_surface); + wl_surface_commit(self->wl_surface); ok = wayland_display_sync(dpy); if (!ok) @@ -243,7 +235,8 @@ wayland_window_get_native(struct wcore_window *wc_self) wayland_display_fill_native(dpy, &n_window->wayland->display); n_window->wayland->wl_surface = self->wl_surface; - n_window->wayland->wl_shell_surface = self->wl_shell_surface; + n_window->wayland->xdg_surface = self->xdg_surface; + n_window->wayland->xdg_toplevel = self->xdg_toplevel; n_window->wayland->wl_window = self->wl_window; n_window->wayland->egl_surface = self->wegl.egl; diff --git a/src/waffle/wayland/wayland_window.h b/src/waffle/wayland/wayland_window.h index d63ae69..a79f827 100644 --- a/src/waffle/wayland/wayland_window.h +++ b/src/waffle/wayland/wayland_window.h @@ -38,7 +38,8 @@ struct wcore_platform; struct wayland_window { struct wl_surface *wl_surface; - struct wl_shell_surface *wl_shell_surface; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; struct wl_egl_window *wl_window; struct wegl_surface wegl; diff --git a/src/waffle/wayland/wayland_wrapper.h b/src/waffle/wayland/wayland_wrapper.h index 4125b7d..cfd5105 100644 --- a/src/waffle/wayland/wayland_wrapper.h +++ b/src/waffle/wayland/wayland_wrapper.h @@ -61,8 +61,6 @@ struct wl_display; #define wl_compositor_interface (*wfl_wl_compositor_interface) #define wl_registry_interface (*wfl_wl_registry_interface) -#define wl_shell_interface (*wfl_wl_shell_interface) -#define wl_shell_surface_interface (*wfl_wl_shell_surface_interface) #define wl_surface_interface (*wfl_wl_surface_interface) #define wl_display_connect (*wfl_wl_display_connect) @@ -75,3 +73,4 @@ struct wl_display; #define wl_proxy_marshal_constructor_versioned (*wfl_wl_proxy_marshal_constructor_versioned) #include +#include "xdg-shell-client-protocol.h" -- GitLab