From 4e03802057279f62e79a4aa152af70243a14b9e3 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 11 Nov 2018 16:47:30 +1300 Subject: backend/wayland: Move registry into backend Registry was a very small file, and is heavily related to the backend, so there is not point in keeping them separate. --- backend/meson.build | 1 - backend/wayland/backend.c | 46 +++++++++++++++++++++++++++++++++++++- backend/wayland/registry.c | 55 ---------------------------------------------- include/backend/wayland.h | 1 - 4 files changed, 45 insertions(+), 58 deletions(-) delete mode 100644 backend/wayland/registry.c diff --git a/backend/meson.build b/backend/meson.build index dd1f4df3..03f8ea7d 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -23,7 +23,6 @@ backend_files = files( 'session/session.c', 'wayland/backend.c', 'wayland/output.c', - 'wayland/registry.c', 'wayland/wl_seat.c', ) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 28f61863..366f5283 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -40,6 +40,47 @@ static int dispatch_events(int fd, uint32_t mask, void *data) { return count; } +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) { + struct wlr_wl_backend *backend = data; + wlr_log(WLR_DEBUG, "Remote wayland global: %s v%d", interface, version); + + if (strcmp(interface, wl_compositor_interface.name) == 0) { + backend->compositor = wl_registry_bind(registry, name, + &wl_compositor_interface, version); + } else if (strcmp(interface, zxdg_shell_v6_interface.name) == 0) { + backend->shell = wl_registry_bind(registry, name, + &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); + } else if (strcmp(interface, wl_seat_interface.name) == 0) { + backend->seat = wl_registry_bind(registry, name, + &wl_seat_interface, version); + wl_seat_add_listener(backend->seat, &seat_listener, backend); + } +} + +static void registry_global_remove(void *data, struct wl_registry *registry, + uint32_t name) { + // TODO +} + +static const struct wl_registry_listener registry_listener = { + .global = registry_global, + .global_remove = registry_global_remove +}; + /* * Initializes the wayland backend. Opens a connection to a remote wayland * compositor and creates surfaces for each output, then registers globals on @@ -49,7 +90,10 @@ static bool backend_start(struct wlr_backend *wlr_backend) { struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend); wlr_log(WLR_INFO, "Initializating wayland backend"); - poll_wl_registry(backend); + wl_registry_add_listener(backend->registry, ®istry_listener, backend); + wl_display_dispatch(backend->remote_display); + wl_display_roundtrip(backend->remote_display); + if (!backend->compositor || !backend->shell) { wlr_log_errno(WLR_ERROR, "Could not obtain retrieve required globals"); return false; diff --git a/backend/wayland/registry.c b/backend/wayland/registry.c deleted file mode 100644 index 8b154750..00000000 --- a/backend/wayland/registry.c +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#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) { - struct wlr_wl_backend *backend = data; - wlr_log(WLR_DEBUG, "Remote wayland global: %s v%d", interface, version); - - if (strcmp(interface, wl_compositor_interface.name) == 0) { - backend->compositor = wl_registry_bind(registry, name, - &wl_compositor_interface, version); - } else if (strcmp(interface, zxdg_shell_v6_interface.name) == 0) { - backend->shell = wl_registry_bind(registry, name, - &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); - } else if (strcmp(interface, wl_seat_interface.name) == 0) { - backend->seat = wl_registry_bind(registry, name, - &wl_seat_interface, version); - wl_seat_add_listener(backend->seat, &seat_listener, backend); - } -} - -static void registry_global_remove(void *data, struct wl_registry *registry, - uint32_t name) { - // TODO -} - -static const struct wl_registry_listener registry_listener = { - .global = registry_global, - .global_remove = registry_global_remove -}; - -void poll_wl_registry(struct wlr_wl_backend *backend) { - wl_registry_add_listener(backend->registry, ®istry_listener, backend); - wl_display_dispatch(backend->remote_display); - wl_display_roundtrip(backend->remote_display); -} diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 47585d9e..54b791b1 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -80,7 +80,6 @@ struct wlr_wl_pointer { struct wlr_wl_backend *get_wl_backend_from_backend( struct wlr_backend *wlr_backend); -void poll_wl_registry(struct wlr_wl_backend *backend); void update_wl_output_cursor(struct wlr_wl_output *output); struct wlr_wl_pointer *pointer_get_wl(struct wlr_pointer *wlr_pointer); void create_wl_pointer(struct wl_pointer *wl_pointer, -- cgit v1.2.3