diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-04-25 15:06:58 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-04-25 15:06:58 -0400 |
commit | de01e654cef2c72dce3adb580e20fe2cbc8aeb16 (patch) | |
tree | 11dbed7b9a15b1f0bb43320243c74e780e791c99 /backend | |
parent | 52e6ed54cbaf05cd1829099e04427d1706ca0da4 (diff) |
Flesh out wayland backend somewhat, add example
Diffstat (limited to 'backend')
-rw-r--r-- | backend/CMakeLists.txt | 15 | ||||
-rw-r--r-- | backend/wayland/CMakeLists.txt | 13 | ||||
-rw-r--r-- | backend/wayland/backend.c | 46 | ||||
-rw-r--r-- | backend/wayland/registry.c | 29 |
4 files changed, 84 insertions, 19 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index d69efdd5..01ac5e4e 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -1 +1,14 @@ -add_subdirectory(wayland) +include_directories( + ${PROTOCOLS_INCLUDE_DIRS} + ${WAYLAND_INCLUDE_DIR} +) + +add_library(wlr-backend + wayland/backend.c + wayland/registry.c +) + +target_link_libraries(wlr-backend + wlr-common + ${WAYLAND_LIBRARIES} +) diff --git a/backend/wayland/CMakeLists.txt b/backend/wayland/CMakeLists.txt deleted file mode 100644 index f185245c..00000000 --- a/backend/wayland/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -include_directories( - ${PROTOCOLS_INCLUDE_DIRS} - ${WAYLAND_INCLUDE_DIR} - . -) - -add_library(wlr-backend-wayland - backend.c -) - -target_link_libraries(wlr-backend-wayland - ${WAYLAND_LIBRARIES} -) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 3564fc12..8ea54058 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -1,13 +1,49 @@ #include <stdlib.h> #include <stdint.h> #include <wayland-server.h> +#include <assert.h> #include "backend/wayland.h" +#include "common/log.h" -struct wlr_wayland_backend *wayland_backend_init(struct wl_display *display, - size_t outputs) { - struct wlr_wayland_backend *backend = calloc( - sizeof(struct wlr_wayland_backend), 1); +void wlr_wl_backend_free(struct wlr_wl_backend *backend) { + if (!backend) { + return; + } + // TODO: free more shit + free(backend); +} + +/* + * Initializes the wayland backend. Opens a connection to a remote wayland + * compositor and creates surfaces for each output, then registers globals on + * the specified display. + */ +struct wlr_wl_backend *wlr_wl_backend_init( + struct wl_display *display, size_t outputs) { + assert(display); + struct wlr_wl_backend *backend; + if (!(backend = calloc(sizeof(struct wlr_wl_backend), 1))) { + wlr_log(L_ERROR, "Could not allocate backend"); + goto error; + } + if (!(backend->outputs = list_create())) { + wlr_log(L_ERROR, "Could not allocate output list"); + goto error; + } backend->local_display = display; - // TODO: obtain reference to remote display + backend->remote_display = wl_display_connect(getenv("_WAYLAND_DISPLAY")); + if (!backend->remote_display) { + wlr_log(L_ERROR, "Could not connect to remote display"); + goto error; + } + if (!(backend->remote_registry = wl_display_get_registry( + backend->remote_display))) { + wlr_log(L_ERROR, "Could not obtain reference to remote registry"); + goto error; + } + wlr_wlb_registry_poll(backend); return backend; +error: + wlr_wl_backend_free(backend); + return NULL; } diff --git a/backend/wayland/registry.c b/backend/wayland/registry.c new file mode 100644 index 00000000..35d386d3 --- /dev/null +++ b/backend/wayland/registry.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdint.h> +#include <wayland-client.h> +#include "backend/wayland.h" +#include "common/log.h" + +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(L_DEBUG, "Remote wayland global: %s v%d", interface, version); + // TODO +} + +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 wlr_wlb_registry_poll(struct wlr_wl_backend *backend) { + wl_registry_add_listener(backend->remote_registry, + ®istry_listener, backend->remote_registry); + wl_display_dispatch(backend->remote_display); + wl_display_roundtrip(backend->remote_display); +} |