diff options
author | nyorain <nyorain@gmail.com> | 2017-06-19 19:05:10 +0200 |
---|---|---|
committer | nyorain <nyorain@gmail.com> | 2017-06-19 19:05:10 +0200 |
commit | 8fbf1ca3ff060c54ce0855e10a96ce968b89cd5e (patch) | |
tree | a8ed01de2b8ce364ee516f91325bf2f432f028ac /backend | |
parent | 41a477375cf5fc2cfafc97fb6d98e4e3457dfa62 (diff) |
Continue wayland backend update
Update wayland backend to new api.
Start to use the input interfaces.
Compiling now, not tested.
Diffstat (limited to 'backend')
-rw-r--r-- | backend/wayland/backend.c | 9 | ||||
-rw-r--r-- | backend/wayland/registry.c | 110 | ||||
-rw-r--r-- | backend/wayland/wl_output.c | 33 | ||||
-rw-r--r-- | backend/wayland/wl_seat.c | 76 |
4 files changed, 145 insertions, 83 deletions
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index dec559f3..53a96696 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -3,6 +3,7 @@ #include <wayland-server.h> #include <assert.h> #include <wlr/backend/interface.h> +#include <wlr/types.h> #include "backend/wayland.h" #include "common/log.h" @@ -34,12 +35,12 @@ static void wlr_wl_backend_destroy(struct wlr_backend_state *state) { // TODO: Free surfaces for (size_t i = 0; state->outputs && i < state->outputs->length; ++i) { - struct wlr_wl_output *output = state->outputs->items[i]; - wlr_wl_output_free(output); + struct wlr_output *output = state->outputs->items[i]; + wlr_output_destroy(output); } list_free(state->outputs); - if (state->seat) wlr_wl_seat_free(state->seat); + if (state->seat) wl_seat_destroy(state->seat); if (state->shm) wl_shm_destroy(state->shm); if (state->shell) wl_shell_destroy(state->shell); if (state->compositor) wl_compositor_destroy(state->compositor); @@ -74,7 +75,9 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, wlr_log(L_ERROR, "Could not allocate output list"); goto error; } + state->local_display = display; + state->backend = backend; return backend; diff --git a/backend/wayland/registry.c b/backend/wayland/registry.c index 4a639f62..66ea4b72 100644 --- a/backend/wayland/registry.c +++ b/backend/wayland/registry.c @@ -2,77 +2,91 @@ #include <stdlib.h> #include <string.h> #include <wayland-client.h> +#include <wlr/types.h> +#include "types.h" #include "backend/wayland.h" #include "common/log.h" -static void registry_wl_seat(struct wlr_wl_backend *backend, - struct wl_seat *wl_seat, struct wl_registry *registry, uint32_t version) { - struct wlr_wl_seat *seat; - if (!(seat = calloc(sizeof(struct wlr_wl_seat), 1))) { - wlr_log(L_ERROR, "Failed to allocate wlr_wl_seat"); - goto error; - } - if (!(seat->keyboards = list_create())) { - wlr_log(L_ERROR, "Failed to allocate wlr_wl_seat"); - goto error; - } - if (!(seat->pointers = list_create())) { - wlr_log(L_ERROR, "Failed to allocate wlr_wl_pointer"); - goto error; - } - seat->wl_seat = wl_seat; - wl_seat_set_user_data(wl_seat, backend); - wl_seat_add_listener(wl_seat, &seat_listener, seat); - return; -error: - wlr_wl_seat_free(seat); - return; +// TODO +static void wlr_wl_output_enable(struct wlr_output_state *output, bool enable) { +} + +static bool wlr_wl_output_set_mode(struct wlr_output_state *output, + struct wlr_output_mode *mode) { + return false; +} + +static void wlr_wl_output_transform(struct wlr_output_state *output, + enum wl_output_transform transform) { +} + +static bool wlr_wl_output_set_cursor(struct wlr_output_state *output, + const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) { + return false; } -static void registry_wl_output(struct wlr_wl_backend *backend, - struct wl_output *wl_output, struct wl_registry *registry, uint32_t version) { - struct wlr_wl_output *output; - if (!(output = calloc(sizeof(struct wlr_wl_output), 1))) { +static bool wlr_wl_output_move_cursor(struct wlr_output_state *output, + int x, int y) { + return false; +} + +static void wlr_wl_output_destroy(struct wlr_output_state *output) { + free(output); +} + +static struct wlr_output_impl output_impl = { + .enable = wlr_wl_output_enable, + .set_mode = wlr_wl_output_set_mode, + .transform = wlr_wl_output_transform, + .set_cursor = wlr_wl_output_set_cursor, + .move_cursor = wlr_wl_output_move_cursor, + .destroy = wlr_wl_output_destroy, +}; + +static void registry_wl_output(struct wlr_backend_state *state, + struct wl_output *wl_output, struct wl_registry *registry, uint32_t version) { + struct wlr_output_state *output; + if (!(output = calloc(sizeof(struct wlr_output_state), 1))) { wlr_log(L_ERROR, "Failed to allocate wlr_wl_output"); - goto error; + return; } - if (!(output->modes = list_create())) { - wlr_log(L_ERROR, "Failed to allocate wlr_wl_output"); - goto error; + + struct wlr_output *wlr_output = wlr_output_create(&output_impl, output); + if (!wlr_output) { + free(state); + wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); + return; } - output->wl_output = wl_output; - output->scale = 1; - list_add(backend->outputs, output); - wl_output_set_user_data(wl_output, backend); + + output->output = wl_output; + list_add(state->outputs, output); wl_output_add_listener(wl_output, &output_listener, output); - return; -error: - wlr_wl_output_free(output); + wl_signal_emit(&state->backend->events.output_add, wlr_output); return; } 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; + struct wlr_backend_state *state = data; wlr_log(L_DEBUG, "Remote wayland global: %s v%d", interface, version); if (strcmp(interface, wl_compositor_interface.name) == 0) { - backend->compositor = wl_registry_bind(registry, name, + state->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, version); } else if (strcmp(interface, wl_shell_interface.name) == 0) { - backend->shell = wl_registry_bind(registry, name, + state->shell = wl_registry_bind(registry, name, &wl_shell_interface, version); } else if (strcmp(interface, wl_shm_interface.name) == 0) { - backend->shm = wl_registry_bind(registry, name, + state->shm = wl_registry_bind(registry, name, &wl_shm_interface, version); } else if (strcmp(interface, wl_seat_interface.name) == 0) { - struct wl_seat *wl_seat = wl_registry_bind(registry, name, + state->seat = wl_registry_bind(registry, name, &wl_seat_interface, version); - registry_wl_seat(backend, wl_seat, registry, version); + wl_seat_add_listener(state->seat, &seat_listener, state); } else if (strcmp(interface, wl_output_interface.name) == 0) { struct wl_output *wl_output = wl_registry_bind(registry, name, &wl_output_interface, version); - registry_wl_output(backend, wl_output, registry, version); + registry_wl_output(state, wl_output, registry, version); } } @@ -86,8 +100,8 @@ static const struct wl_registry_listener registry_listener = { .global_remove = registry_global_remove }; -void wlr_wlb_registry_poll(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); +void wlr_wlb_registry_poll(struct wlr_backend_state *state) { + wl_registry_add_listener(state->registry, ®istry_listener, state); + wl_display_dispatch(state->remote_display); + wl_display_roundtrip(state->remote_display); } diff --git a/backend/wayland/wl_output.c b/backend/wayland/wl_output.c index cc4e9cce..b3ad575a 100644 --- a/backend/wayland/wl_output.c +++ b/backend/wayland/wl_output.c @@ -4,23 +4,27 @@ #include <stdlib.h> #include <stdint.h> #include <wayland-client.h> +#include <wlr/types.h> +#include "types.h" #include "backend/wayland.h" #include "common/log.h" static void wl_output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) { - struct wlr_wl_output *output = data; - assert(output->wl_output == wl_output); - struct wlr_wl_output_mode *mode; - if (!(mode = calloc(sizeof(struct wlr_wl_output_mode), 1))) { - wlr_log(L_ERROR, "Failed to allocate wlr_wl_output_mode"); + struct wlr_output *output = data; + assert(output->state->output == wl_output); + struct wlr_output_mode *mode; + if (!(mode = calloc(sizeof(struct wlr_output_mode), 1))) { + wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); return; } + mode->flags = flags; mode->width = width; mode->height = height; mode->refresh = refresh; list_add(output->modes, mode); + wlr_log(L_DEBUG, "Got mode for output %p: %dx%d @ %.2fHz%s%s", wl_output, width, height, refresh / 1000.0, (flags & WL_OUTPUT_MODE_PREFERRED) ? " (preferred)" : "", @@ -30,15 +34,18 @@ static void wl_output_handle_mode(void *data, struct wl_output *wl_output, static void wl_output_handle_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform) { - struct wlr_wl_output *output = data; - assert(output->wl_output == wl_output); - output->x = x; - output->y = y; + struct wlr_output *output = data; + assert(output->state->output == wl_output); + + // TODO + // output->x = x; + // output->y = y; + output->phys_width = physical_width; output->phys_height = physical_height; output->subpixel = subpixel; - output->make = strdup(make); - output->model = strdup(model); + strncpy(output->make, make, sizeof(output->make)); + strncpy(output->model, model, sizeof(output->model)); output->transform = transform; wlr_log(L_DEBUG, "Got info for output %p %dx%d (%dmm x %dmm) %s %s", wl_output, (int)x, (int)y, (int)physical_width, (int)physical_height, @@ -46,8 +53,8 @@ static void wl_output_handle_geometry(void *data, struct wl_output *wl_output, } static void wl_output_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) { - struct wlr_wl_output *output = data; - assert(output->wl_output == wl_output); + struct wlr_output *output = data; + assert(output->state->output == wl_output); output->scale = factor; wlr_log(L_DEBUG, "Got scale factor for output %p: %d", wl_output, factor); } diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index bc2b21a8..d56f7d74 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -4,49 +4,87 @@ #include <stdint.h> #include <string.h> #include <wayland-client.h> +#include <wlr/types.h> +#include "types.h" #include "backend/wayland.h" #include "common/log.h" +static void wlr_wl_device_destroy(struct wlr_input_device_state *state) { + free(state); +} + +static struct wlr_input_device_impl input_device_impl = { + .destroy = wlr_wl_device_destroy +}; + +static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, + enum wlr_input_device_type type) { + struct wlr_input_device_state *devstate = + calloc(1, sizeof(struct wlr_input_device_state)); + if(!devstate) { + wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); + return NULL; + } + + // TODO: any way to retrieve those information? + int vendor = 0; + int product = 0; + const char *name = "unknown;wayland"; + struct wlr_input_device *wlr_device = wlr_input_device_create( + type, &input_device_impl, devstate, + name, vendor, product); + if(!wlr_device) { + free(devstate); + return NULL; + } + + list_add(state->devices, wlr_device); + return wlr_device; +} + static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum wl_seat_capability caps) { - struct wlr_wl_seat *seat = data; - assert(seat->wl_seat == wl_seat); - struct wlr_wl_backend *backend = wl_seat_get_user_data(wl_seat); - assert(backend); + struct wlr_backend_state *state = data; + assert(state->seat == wl_seat); + // TODO: add listeners and receive input if ((caps & WL_SEAT_CAPABILITY_POINTER)) { wlr_log(L_DEBUG, "seat %p offered pointer", wl_seat); struct wl_pointer *wl_pointer = wl_seat_get_pointer(wl_seat); - struct wlr_wl_pointer *pointer; - if (!(pointer = calloc(sizeof(struct wlr_wl_pointer), 1))) { + + struct wlr_input_device *wlr_device = allocate_device(state, + WLR_INPUT_DEVICE_POINTER); + if(!wlr_device) { wl_pointer_destroy(wl_pointer); - wlr_log(L_ERROR, "Unable to allocate wlr_wl_pointer"); + wlr_log(L_ERROR, "Unable to allocate wl_pointer device"); return; } - pointer->wl_pointer = wl_pointer; - //wl_pointer_add_listener(wl_pointer, &pointer_listener, backend->registry); TODO - } + wlr_device->pointer = wlr_pointer_create(NULL, NULL); + wl_signal_emit(&state->backend->events.input_add, wlr_device); + } if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { wlr_log(L_DEBUG, "seat %p offered keyboard", wl_seat); struct wl_keyboard *wl_keyboard = wl_seat_get_keyboard(wl_seat); - struct wlr_wl_keyboard *keyboard; - if (!(keyboard = calloc(sizeof(struct wlr_wl_pointer), 1))) { - wl_keyboard_destroy(wl_keyboard); - wlr_log(L_ERROR, "Unable to allocate wlr_wl_keyboard"); + struct wlr_input_device *wlr_device = allocate_device(state, + WLR_INPUT_DEVICE_KEYBOARD); + if(!wlr_device) { + wl_keyboard_release(wl_keyboard); + wlr_log(L_ERROR, "Unable to allocate wl_pointer device"); return; } - keyboard->wl_keyboard = wl_keyboard; - //wl_keyboard_add_listener(wl_keyboard, &keyboard_listener, backend->registry); TODO + + wlr_device->keyboard = wlr_keyboard_create(NULL, NULL); + wl_signal_emit(&state->backend->events.input_add, wlr_device); } // TODO: touch } static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) { - struct wlr_wl_seat *seat = data; - assert(seat->wl_seat == wl_seat); - seat->name = strdup(name); + struct wlr_backend_state *state = data; + assert(state->seat == wl_seat); + state->seatName = strdup(name); } const struct wl_seat_listener seat_listener = { |