aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-19 15:16:40 -0400
committerGitHub <noreply@github.com>2017-06-19 15:16:40 -0400
commitfa4a04da223aadcc1feba7fe133b0f44ac01e95a (patch)
treec5b5a57ddf085993a16a5c9f29076b90f3baccf1 /backend
parent325a331425c1771d16fa90d099fa33f3ab8772f3 (diff)
parent632a04f1b7dea35f46a2fa478bf53869854a1b5e (diff)
Merge pull request #11 from SirCmpwn/libinput
[WIP] libinput backend
Diffstat (limited to 'backend')
-rw-r--r--backend/CMakeLists.txt15
-rw-r--r--backend/backend.c42
-rw-r--r--backend/drm/drm.c96
-rw-r--r--backend/libinput/backend.c121
-rw-r--r--backend/libinput/events.c188
-rw-r--r--backend/libinput/keyboard.c65
-rw-r--r--backend/libinput/pointer.c129
-rw-r--r--backend/libinput/tablet_pad.c95
-rw-r--r--backend/libinput/tablet_tool.c150
-rw-r--r--backend/libinput/touch.c93
-rw-r--r--backend/multi/backend.c107
11 files changed, 1082 insertions, 19 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index 91f0f06e..9594c318 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -2,6 +2,7 @@ include_directories(
${PROTOCOLS_INCLUDE_DIRS}
${WAYLAND_INCLUDE_DIR}
${DRM_INCLUDE_DIRS}
+ ${LIBINPUT_INCLUDE_DIRS}
)
add_library(wlr-backend
@@ -9,11 +10,22 @@ add_library(wlr-backend
#wayland/registry.c
#wayland/wl_seat.c
#wayland/wl_output.c
+
drm/backend.c
drm/drm.c
- udev.c
+
+ libinput/backend.c
+ libinput/events.c
+ libinput/keyboard.c
+ libinput/pointer.c
+ libinput/touch.c
+ libinput/tablet_tool.c
+ libinput/tablet_pad.c
+
+ multi/backend.c
backend.c
egl.c
+ udev.c
)
target_link_libraries(wlr-backend
@@ -26,5 +38,6 @@ target_link_libraries(wlr-backend
${EGL_LIBRARIES}
${SYSTEMD_LIBRARIES}
${UDEV_LIBRARIES}
+ ${LIBINPUT_LIBRARIES}
${GBM_LIBRARIES}
)
diff --git a/backend/backend.c b/backend/backend.c
index 38b65dca..02fd7479 100644
--- a/backend/backend.c
+++ b/backend/backend.c
@@ -3,10 +3,15 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <libinput.h>
#include <wlr/session.h>
#include <wlr/backend/interface.h>
+#include <wlr/backend/drm.h>
+#include <wlr/backend/libinput.h>
+#include <wlr/backend/multi.h>
+#include "backend/libinput.h"
+#include "backend/udev.h"
#include "common/log.h"
-#include "backend/drm.h"
struct wlr_backend *wlr_backend_create(const struct wlr_backend_impl *impl,
struct wlr_backend_state *state) {
@@ -17,14 +22,10 @@ struct wlr_backend *wlr_backend_create(const struct wlr_backend_impl *impl,
}
backend->state = state;
backend->impl = impl;
+ wl_signal_init(&backend->events.input_add);
+ wl_signal_init(&backend->events.input_remove);
wl_signal_init(&backend->events.output_add);
wl_signal_init(&backend->events.output_remove);
- wl_signal_init(&backend->events.keyboard_add);
- wl_signal_init(&backend->events.keyboard_remove);
- wl_signal_init(&backend->events.pointer_add);
- wl_signal_init(&backend->events.pointer_remove);
- wl_signal_init(&backend->events.touch_add);
- wl_signal_init(&backend->events.touch_remove);
return backend;
}
@@ -51,12 +52,27 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
wlr_log(L_ERROR, "Failed to open DRM device");
goto error_udev;
}
- struct wlr_backend *wlr;
- wlr = wlr_drm_backend_create(display, session, udev, gpu);
- if (!wlr) {
+ struct wlr_backend *multi = wlr_multi_backend_create();
+ if (!multi) {
goto error_gpu;
}
- return wlr;
+ struct wlr_backend *libinput =
+ wlr_libinput_backend_create(display, session, udev);
+ if (!libinput) {
+ goto error_multi;
+ }
+ struct wlr_backend *drm =
+ wlr_drm_backend_create(display, session, udev, gpu);
+ if (!drm) {
+ goto error_libinput;
+ }
+ wlr_multi_backend_add(multi, libinput);
+ wlr_multi_backend_add(multi, drm);
+ return multi;
+error_libinput:
+ wlr_backend_destroy(libinput);
+error_multi:
+ wlr_backend_destroy(multi);
error_gpu:
close(gpu);
error_udev:
@@ -64,3 +80,7 @@ error_udev:
error:
return NULL;
}
+
+struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *dev) {
+ return dev->state->handle;
+}
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index d6a3f8a2..befbfb94 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -112,8 +112,8 @@ static void wlr_drm_output_end(struct wlr_output_state *output) {
drmModePageFlip(renderer->fd, output->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output);
output->pageflip_pending = true;
- output->bo_last = output->bo_current;
- output->bo_current = bo;
+ output->bo[1] = output->bo[0];
+ output->bo[0] = bo;
}
void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
@@ -141,8 +141,8 @@ void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
drmModePageFlip(renderer->fd, output->crtc, fb_id,
DRM_MODE_PAGE_FLIP_EVENT, output);
- output->bo_last = NULL;
- output->bo_current = bo;
+ output->bo[1] = NULL;
+ output->bo[0] = bo;
}
static bool display_init_renderer(struct wlr_drm_renderer *renderer,
@@ -280,6 +280,63 @@ static void wlr_drm_output_transform(struct wlr_output_state *output,
output->wlr_output->transform = transform;
}
+static void wlr_drm_cursor_bo_update(struct wlr_output_state *output,
+ uint32_t width, uint32_t height) {
+ if (output->cursor_width == width && output->cursor_height == height) {
+ return;
+ }
+ wlr_log(L_DEBUG, "Allocating new cursor bos");
+ struct wlr_backend_state *state =
+ wl_container_of(output->renderer, state, renderer);
+ for (size_t i = 0; i < 2; ++i) {
+ output->cursor_bo[i] = gbm_bo_create(state->renderer.gbm,
+ width, height, GBM_FORMAT_ARGB8888,
+ GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
+ if (!output->cursor_bo[i]) {
+ wlr_log(L_ERROR, "Failed to create cursor bo");
+ return;
+ }
+ if (!get_fb_for_bo(state->fd, output->cursor_bo[i])) {
+ wlr_log(L_ERROR, "Failed to create cursor fb");
+ return;
+ }
+ }
+}
+
+static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
+ const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) {
+ struct wlr_backend_state *state =
+ wl_container_of(output->renderer, state, renderer);
+ if (!buf) {
+ drmModeSetCursor(state->fd, output->crtc, 0, 0, 0);
+ return true;
+ }
+ wlr_drm_cursor_bo_update(output, width, height);
+ struct gbm_bo *bo;
+ output->current_cursor ^= 1;
+ bo = output->cursor_bo[output->current_cursor];
+ uint32_t _buf[width * height];
+ memset(_buf, 0, sizeof(_buf));
+ for (size_t i = 0; i < height; ++i) {
+ memcpy(_buf + i * width,
+ buf + i * stride,
+ width * 4);
+ }
+ if (gbm_bo_write(bo, _buf, sizeof(_buf)) < 0) {
+ wlr_log(L_ERROR, "Failed to write cursor to bo");
+ return false;
+ }
+ return !drmModeSetCursor(state->fd, output->crtc,
+ gbm_bo_get_handle(bo).s32, width, height);
+}
+
+static bool wlr_drm_output_move_cursor(struct wlr_output_state *output,
+ int x, int y) {
+ struct wlr_backend_state *state =
+ wl_container_of(output->renderer, state, renderer);
+ return !drmModeMoveCursor(state->fd, output->crtc, x, y);
+}
+
static void wlr_drm_output_destroy(struct wlr_output_state *output) {
wlr_drm_output_cleanup(output, true);
free(output);
@@ -289,6 +346,8 @@ static struct wlr_output_impl output_impl = {
.enable = wlr_drm_output_enable,
.set_mode = wlr_drm_output_set_mode,
.transform = wlr_drm_output_transform,
+ .set_cursor = wlr_drm_output_set_cursor,
+ .move_cursor = wlr_drm_output_move_cursor,
.destroy = wlr_drm_output_destroy,
};
@@ -457,6 +516,29 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *state) {
snprintf(wlr_output->name, sizeof(wlr_output->name), "%s-%"PRIu32,
conn_name[conn->connector_type],
conn->connector_type_id);
+ wlr_output->phys_width = conn->mmWidth;
+ wlr_output->phys_height = conn->mmHeight;
+ switch (conn->subpixel) {
+ case DRM_MODE_SUBPIXEL_UNKNOWN:
+ wlr_output->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
+ break;
+ case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
+ wlr_output->subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
+ break;
+ case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
+ wlr_output->subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
+ break;
+ case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
+ wlr_output->subpixel = WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
+ break;
+ case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
+ wlr_output->subpixel = WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
+ break;
+ case DRM_MODE_SUBPIXEL_NONE:
+ default:
+ wlr_output->subpixel = WL_OUTPUT_SUBPIXEL_NONE;
+ break;
+ }
drmModeEncoder *curr_enc = drmModeGetEncoder(state->fd, conn->encoder_id);
if (curr_enc) {
@@ -519,9 +601,9 @@ static void page_flip_handler(int fd, unsigned seq,
struct wlr_backend_state *state =
wl_container_of(output->renderer, state, renderer);
- if (output->bo_last) {
- gbm_surface_release_buffer(output->gbm, output->bo_last);
- output->bo_last = NULL;
+ if (output->bo[1]) {
+ gbm_surface_release_buffer(output->gbm, output->bo[1]);
+ output->bo[1] = NULL;
}
output->pageflip_pending = false;
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c
new file mode 100644
index 00000000..82ba44a6
--- /dev/null
+++ b/backend/libinput/backend.c
@@ -0,0 +1,121 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/backend/interface.h>
+#include "backend/udev.h"
+#include "backend/libinput.h"
+#include "common/log.h"
+
+static int wlr_libinput_open_restricted(const char *path,
+ int flags, void *_state) {
+ struct wlr_backend_state *state = _state;
+ return wlr_session_open_file(state->session, path);
+}
+
+static void wlr_libinput_close_restricted(int fd, void *_state) {
+ struct wlr_backend_state *state = _state;
+ wlr_session_close_file(state->session, fd);
+}
+
+static const struct libinput_interface libinput_impl = {
+ .open_restricted = wlr_libinput_open_restricted,
+ .close_restricted = wlr_libinput_close_restricted
+};
+
+static int wlr_libinput_readable(int fd, uint32_t mask, void *_state) {
+ struct wlr_backend_state *state = _state;
+ if (libinput_dispatch(state->libinput) != 0) {
+ wlr_log(L_ERROR, "Failed to dispatch libinput");
+ // TODO: some kind of abort?
+ return 0;
+ }
+ struct libinput_event *event;
+ while ((event = libinput_get_event(state->libinput))) {
+ wlr_libinput_event(state, event);
+ }
+ return 0;
+}
+
+static void wlr_libinput_log(struct libinput *libinput,
+ enum libinput_log_priority priority, const char *fmt, va_list args) {
+ _wlr_vlog(L_ERROR, fmt, args);
+}
+
+static bool wlr_libinput_backend_init(struct wlr_backend_state *state) {
+ wlr_log(L_DEBUG, "Initializing libinput");
+ state->libinput = libinput_udev_create_context(&libinput_impl, state,
+ state->udev->udev);
+ if (!state->libinput) {
+ wlr_log(L_ERROR, "Failed to create libinput context");
+ return false;
+ }
+
+ // TODO: Let user customize seat used
+ if (libinput_udev_assign_seat(state->libinput, "seat0") != 0) {
+ wlr_log(L_ERROR, "Failed to assign libinput seat");
+ return false;
+ }
+
+ // TODO: More sophisticated logging
+ libinput_log_set_handler(state->libinput, wlr_libinput_log);
+ libinput_log_set_priority(state->libinput, LIBINPUT_LOG_PRIORITY_ERROR);
+
+ struct wl_event_loop *event_loop =
+ wl_display_get_event_loop(state->display);
+ if (state->input_event) {
+ wl_event_source_remove(state->input_event);
+ }
+ state->input_event = wl_event_loop_add_fd(event_loop,
+ libinput_get_fd(state->libinput), WL_EVENT_READABLE,
+ wlr_libinput_readable, state);
+ if (!state->input_event) {
+ wlr_log(L_ERROR, "Failed to create input event on event loop");
+ return false;
+ }
+ wlr_log(L_DEBUG, "libinput sucessfully initialized");
+ return true;
+}
+
+static void wlr_libinput_backend_destroy(struct wlr_backend_state *state) {
+ // TODO
+}
+
+static struct wlr_backend_impl backend_impl = {
+ .init = wlr_libinput_backend_init,
+ .destroy = wlr_libinput_backend_destroy
+};
+
+struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
+ struct wlr_session *session, struct wlr_udev *udev) {
+ assert(display && session && udev);
+
+ struct wlr_backend_state *state = calloc(1, sizeof(struct wlr_backend_state));
+ if (!state) {
+ wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
+ return NULL;
+ }
+
+ struct wlr_backend *backend = wlr_backend_create(&backend_impl, state);
+ if (!backend) {
+ wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
+ goto error_state;
+ }
+
+ if (!(state->devices = list_create())) {
+ wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
+ goto error_backend;
+ }
+
+ state->backend = backend;
+ state->session = session;
+ state->udev = udev;
+ state->display = display;
+
+ return backend;
+error_state:
+ free(state);
+error_backend:
+ wlr_backend_destroy(backend);
+ return NULL;
+}
diff --git a/backend/libinput/events.c b/backend/libinput/events.c
new file mode 100644
index 00000000..2e7cc541
--- /dev/null
+++ b/backend/libinput/events.c
@@ -0,0 +1,188 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_input_device *get_appropriate_device(
+ enum wlr_input_device_type desired_type,
+ struct libinput_device *device) {
+ list_t *devices = libinput_device_get_user_data(device);
+ if (!devices) {
+ return NULL;
+ }
+ for (size_t i = 0; i < devices->length; ++i) {
+ struct wlr_input_device *dev = devices->items[i];
+ if (dev->type == desired_type) {
+ return dev;
+ }
+ }
+ return NULL;
+}
+
+static void wlr_libinput_device_destroy(struct wlr_input_device_state *state) {
+ libinput_device_unref(state->handle);
+ free(state);
+}
+
+static struct wlr_input_device_impl input_device_impl = {
+ .destroy = wlr_libinput_device_destroy
+};
+
+static struct wlr_input_device *allocate_device(
+ struct wlr_backend_state *state, struct libinput_device *device,
+ list_t *devices, enum wlr_input_device_type type) {
+ int vendor = libinput_device_get_id_vendor(device);
+ int product = libinput_device_get_id_product(device);
+ const char *name = libinput_device_get_name(device);
+ struct wlr_input_device_state *devstate =
+ calloc(1, sizeof(struct wlr_input_device_state));
+ devstate->handle = device;
+ libinput_device_ref(device);
+ struct wlr_input_device *wlr_device = wlr_input_device_create(
+ type, &input_device_impl, devstate,
+ name, vendor, product);
+ list_add(devices, wlr_device);
+ list_add(state->devices, wlr_device);
+ return wlr_device;
+}
+
+static void handle_device_added(struct wlr_backend_state *state,
+ struct libinput_device *device) {
+ assert(state && device);
+ /*
+ * Note: the wlr API exposes only devices with a single capability, because
+ * that meshes better with how Wayland does things and is a bit simpler.
+ * However, libinput devices often have multiple capabilities - in such
+ * cases we have to create several devices.
+ */
+ int vendor = libinput_device_get_id_vendor(device);
+ int product = libinput_device_get_id_product(device);
+ const char *name = libinput_device_get_name(device);
+ list_t *devices = list_create();
+ wlr_log(L_DEBUG, "Added %s [%d:%d]", name, vendor, product);
+
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
+ struct wlr_input_device *wlr_device = allocate_device(state,
+ device, devices, WLR_INPUT_DEVICE_KEYBOARD);
+ wlr_device->keyboard = wlr_libinput_keyboard_create(device);
+ wl_signal_emit(&state->backend->events.input_add, wlr_device);
+ }
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) {
+ struct wlr_input_device *wlr_device = allocate_device(state,
+ device, devices, WLR_INPUT_DEVICE_POINTER);
+ wlr_device->pointer = wlr_libinput_pointer_create(device);
+ wl_signal_emit(&state->backend->events.input_add, wlr_device);
+ }
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)) {
+ struct wlr_input_device *wlr_device = allocate_device(state,
+ device, devices, WLR_INPUT_DEVICE_TOUCH);
+ wlr_device->touch = wlr_libinput_touch_create(device);
+ wl_signal_emit(&state->backend->events.input_add, wlr_device);
+ }
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) {
+ struct wlr_input_device *wlr_device = allocate_device(state,
+ device, devices, WLR_INPUT_DEVICE_TABLET_TOOL);
+ wlr_device->tablet_tool = wlr_libinput_tablet_tool_create(device);
+ wl_signal_emit(&state->backend->events.input_add, wlr_device);
+ }
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_PAD)) {
+ struct wlr_input_device *wlr_device = allocate_device(state,
+ device, devices, WLR_INPUT_DEVICE_TABLET_PAD);
+ wlr_device->tablet_pad = wlr_libinput_tablet_pad_create(device);
+ wl_signal_emit(&state->backend->events.input_add, wlr_device);
+ }
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) {
+ // TODO
+ }
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_SWITCH)) {
+ // TODO
+ }
+
+ if (devices->length > 0) {
+ libinput_device_set_user_data(device, devices);
+ } else {
+ list_free(devices);
+ }
+}
+
+static void handle_device_removed(struct wlr_backend_state *state,
+ struct libinput_device *device) {
+ wlr_log(L_DEBUG, "libinput device removed");
+ // TODO
+}
+
+void wlr_libinput_event(struct wlr_backend_state *state,
+ struct libinput_event *event) {
+ assert(state && event);
+ struct libinput *context = libinput_event_get_context(event);
+ struct libinput_device *device = libinput_event_get_device(event);
+ enum libinput_event_type event_type = libinput_event_get_type(event);
+ (void)context;
+ switch (event_type) {
+ case LIBINPUT_EVENT_DEVICE_ADDED:
+ handle_device_added(state, device);
+ break;
+ case LIBINPUT_EVENT_DEVICE_REMOVED:
+ handle_device_removed(state, device);
+ break;
+ case LIBINPUT_EVENT_KEYBOARD_KEY:
+ handle_keyboard_key(event, device);
+ break;
+ case LIBINPUT_EVENT_POINTER_MOTION:
+ handle_pointer_motion(event, device);
+ break;
+ case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
+ handle_pointer_motion_abs(event, device);
+ break;
+ case LIBINPUT_EVENT_POINTER_BUTTON:
+ handle_pointer_button(event, device);
+ break;
+ case LIBINPUT_EVENT_POINTER_AXIS:
+ handle_pointer_axis(event, device);
+ break;
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ handle_touch_down(event, device);
+ break;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ handle_touch_up(event, device);
+ break;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ handle_touch_motion(event, device);
+ break;
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
+ handle_touch_cancel(event, device);
+ break;
+ case LIBINPUT_EVENT_TOUCH_FRAME:
+ // no-op (at least for now)
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
+ handle_tablet_tool_axis(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
+ handle_tablet_tool_proximity(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_TIP:
+ handle_tablet_tool_tip(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
+ handle_tablet_tool_button(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
+ handle_tablet_pad_button(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_PAD_RING:
+ handle_tablet_pad_ring(event, device);
+ break;
+ case LIBINPUT_EVENT_TABLET_PAD_STRIP:
+ handle_tablet_pad_strip(event, device);
+ break;
+ default:
+ wlr_log(L_DEBUG, "Unknown libinput event %d", event_type);
+ break;
+ }
+}
diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c
new file mode 100644
index 00000000..f94f0103
--- /dev/null
+++ b/backend/libinput/keyboard.c
@@ -0,0 +1,65 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_keyboard_state {
+ struct libinput_device *device;
+};
+
+static void wlr_libinput_keyboard_set_leds(struct wlr_keyboard_state *kbstate, uint32_t leds) {
+ libinput_device_led_update(kbstate->device, leds);
+}
+
+static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *kbstate) {
+ libinput_device_unref(kbstate->device);
+ free(kbstate);
+}
+
+struct wlr_keyboard_impl impl = {
+ .destroy = wlr_libinput_keyboard_destroy,
+ .led_update = wlr_libinput_keyboard_set_leds
+};
+
+struct wlr_keyboard *wlr_libinput_keyboard_create(
+ struct libinput_device *device) {
+ assert(device);
+ struct wlr_keyboard_state *kbstate = calloc(1, sizeof(struct wlr_keyboard_state));
+ kbstate->device = device;
+ libinput_device_ref(device);
+ libinput_device_led_update(device, 0);
+ return wlr_keyboard_create(&impl, kbstate);
+}
+
+void handle_keyboard_key(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a keyboard event for a device with no keyboards?");
+ return;
+ }
+ struct libinput_event_keyboard *kbevent =
+ libinput_event_get_keyboard_event(event);
+ struct wlr_keyboard_key *wlr_event =
+ calloc(1, sizeof(struct wlr_keyboard_key));
+ wlr_event->time_sec = libinput_event_keyboard_get_time(kbevent);
+ wlr_event->time_usec = libinput_event_keyboard_get_time_usec(kbevent);
+ wlr_event->keycode = libinput_event_keyboard_get_key(kbevent);
+ enum libinput_key_state state =
+ libinput_event_keyboard_get_key_state(kbevent);
+ switch (state) {
+ case LIBINPUT_KEY_STATE_RELEASED:
+ wlr_event->state = WLR_KEY_RELEASED;
+ break;
+ case LIBINPUT_KEY_STATE_PRESSED:
+ wlr_event->state = WLR_KEY_PRESSED;
+ break;
+ }
+ wl_signal_emit(&dev->keyboard->events.key, wlr_event);
+}
diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c
new file mode 100644
index 00000000..0139fd60
--- /dev/null
+++ b/backend/libinput/pointer.c
@@ -0,0 +1,129 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_pointer *wlr_libinput_pointer_create(
+ struct libinput_device *device) {
+ assert(device);
+ return wlr_pointer_create(NULL, NULL);
+}
+
+void handle_pointer_motion(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_POINTER, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
+ return;
+ }
+ struct libinput_event_pointer *pevent =
+ libinput_event_get_pointer_event(event);
+ struct wlr_pointer_motion *wlr_event =
+ calloc(1, sizeof(struct wlr_pointer_motion));
+ wlr_event->time_sec = libinput_event_pointer_get_time(pevent);
+ wlr_event->time_usec = libinput_event_pointer_get_time_usec(pevent);
+ wlr_event->delta_x = libinput_event_pointer_get_dx(pevent);
+ wlr_event->delta_y = libinput_event_pointer_get_dy(pevent);
+ wl_signal_emit(&dev->pointer->events.motion, wlr_event);
+}
+
+void handle_pointer_motion_abs(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_POINTER, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
+ return;
+ }
+ struct libinput_event_pointer *pevent =
+ libinput_event_get_pointer_event(event);
+ struct wlr_pointer_motion_absolute *wlr_event =
+ calloc(1, sizeof(struct wlr_pointer_motion_absolute));
+ wlr_event->time_sec = libinput_event_pointer_get_time(pevent);
+ wlr_event->time_usec = libinput_event_pointer_get_time_usec(pevent);
+ wlr_event->x_mm = libinput_event_pointer_get_absolute_x(pevent);
+ wlr_event->y_mm = libinput_event_pointer_get_absolute_y(pevent);
+ libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm);
+ wl_signal_emit(&dev->pointer->events.motion_absolute, wlr_event);
+}
+
+void handle_pointer_button(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_POINTER, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
+ return;
+ }
+ struct libinput_event_pointer *pevent =
+ libinput_event_get_pointer_event(event);
+ struct wlr_pointer_button *wlr_event =
+ calloc(1, sizeof(struct wlr_pointer_button));
+ wlr_event->time_sec = libinput_event_pointer_get_time(pevent);
+ wlr_event->time_usec = libinput_event_pointer_get_time_usec(pevent);
+ wlr_event->button = libinput_event_pointer_get_button(pevent);
+ switch (libinput_event_pointer_get_button_state(pevent)) {
+ case LIBINPUT_BUTTON_STATE_PRESSED:
+ wlr_event->state = WLR_BUTTON_PRESSED;
+ break;
+ case LIBINPUT_BUTTON_STATE_RELEASED:
+ wlr_event->state = WLR_BUTTON_RELEASED;
+ break;
+ }
+ wl_signal_emit(&dev->pointer->events.button, wlr_event);
+}
+
+void handle_pointer_axis(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_POINTER, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a pointer event for a device with no pointers?");
+ return;
+ }
+ struct libinput_event_pointer *pevent =
+ libinput_event_get_pointer_event(event);
+ struct wlr_pointer_axis *wlr_event =
+ calloc(1, sizeof(struct wlr_pointer_axis));
+ wlr_event->time_sec = libinput_event_pointer_get_time(pevent);
+ wlr_event->time_usec = libinput_event_pointer_get_time_usec(pevent);
+ switch (libinput_event_pointer_get_axis_source(pevent)) {
+ case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
+ wlr_event->source = WLR_AXIS_SOURCE_WHEEL;
+ break;
+ case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
+ wlr_event->source = WLR_AXIS_SOURCE_FINGER;
+ break;
+ case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
+ wlr_event->source = WLR_AXIS_SOURCE_CONTINUOUS;
+ break;
+ case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT:
+ wlr_event->source = WLR_AXIS_SOURCE_WHEEL_TILT;
+ break;
+ }
+ enum libinput_pointer_axis axies[] = {
+ LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
+ LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+ };
+ for (size_t i = 0; i < sizeof(axies) / sizeof(axies[0]); ++i) {
+ if (libinput_event_pointer_has_axis(pevent, axies[i])) {
+ switch (axies[i]) {
+ case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
+ wlr_event->orientation = WLR_AXIS_ORIENTATION_VERTICAL;
+ break;
+ case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
+ wlr_event->orientation = WLR_AXIS_ORIENTATION_HORIZONTAL;
+ break;
+ }
+ wlr_event->delta = libinput_event_pointer_get_axis_value(
+ pevent, axies[i]);
+ }
+ wl_signal_emit(&dev->pointer->events.axis, wlr_event);
+ }
+}
diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c
new file mode 100644
index 00000000..ee7c82f8
--- /dev/null
+++ b/backend/libinput/tablet_pad.c
@@ -0,0 +1,95 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_tablet_pad *wlr_libinput_tablet_pad_create(
+ struct libinput_device *device) {
+ assert(device);
+ return wlr_tablet_pad_create(NULL, NULL);
+}
+
+void handle_tablet_pad_button(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet pad event for a device with no tablet pad?");
+ return;
+ }
+ struct libinput_event_tablet_pad *pevent =
+ libinput_event_get_tablet_pad_event(event);
+ struct wlr_tablet_pad_button *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_pad_button));
+ wlr_event->time_sec = libinput_event_tablet_pad_get_time(pevent);
+ wlr_event->time_usec = libinput_event_tablet_pad_get_time_usec(pevent);
+ wlr_event->button = libinput_event_tablet_pad_get_button_number(pevent);
+ switch (libinput_event_tablet_pad_get_button_state(pevent)) {
+ case LIBINPUT_BUTTON_STATE_PRESSED:
+ wlr_event->state = WLR_BUTTON_PRESSED;
+ break;
+ case LIBINPUT_BUTTON_STATE_RELEASED:
+ wlr_event->state = WLR_BUTTON_RELEASED;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_pad->events.button, wlr_event);
+}
+
+void handle_tablet_pad_ring(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet pad event for a device with no tablet pad?");
+ return;
+ }
+ struct libinput_event_tablet_pad *pevent =
+ libinput_event_get_tablet_pad_event(event);
+ struct wlr_tablet_pad_ring *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_pad_ring));
+ wlr_event->time_sec = libinput_event_tablet_pad_get_time(pevent);
+ wlr_event->time_usec = libinput_event_tablet_pad_get_time_usec(pevent);
+ wlr_event->ring = libinput_event_tablet_pad_get_ring_number(pevent);
+ wlr_event->position = libinput_event_tablet_pad_get_ring_position(pevent);
+ switch (libinput_event_tablet_pad_get_ring_source(pevent)) {
+ case LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN:
+ wlr_event->source = WLR_TABLET_PAD_RING_SOURCE_UNKNOWN;
+ break;
+ case LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER:
+ wlr_event->source = WLR_TABLET_PAD_RING_SOURCE_FINGER;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_pad->events.ring, wlr_event);
+}
+
+void handle_tablet_pad_strip(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet pad event for a device with no tablet pad?");
+ return;
+ }
+ struct libinput_event_tablet_pad *pevent =
+ libinput_event_get_tablet_pad_event(event);
+ struct wlr_tablet_pad_strip *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_pad_strip));
+ wlr_event->time_sec = libinput_event_tablet_pad_get_time(pevent);
+ wlr_event->time_usec = libinput_event_tablet_pad_get_time_usec(pevent);
+ wlr_event->strip = libinput_event_tablet_pad_get_strip_number(pevent);
+ wlr_event->position = libinput_event_tablet_pad_get_strip_position(pevent);
+ switch (libinput_event_tablet_pad_get_strip_source(pevent)) {
+ case LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN:
+ wlr_event->source = WLR_TABLET_PAD_STRIP_SOURCE_UNKNOWN;
+ break;
+ case LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER:
+ wlr_event->source = WLR_TABLET_PAD_STRIP_SOURCE_FINGER;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_pad->events.strip, wlr_event);
+}
diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c
new file mode 100644
index 00000000..e8a3bc7d
--- /dev/null
+++ b/backend/libinput/tablet_tool.c
@@ -0,0 +1,150 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_tablet_tool *wlr_libinput_tablet_tool_create(
+ struct libinput_device *device) {
+ assert(device);
+ return wlr_tablet_tool_create(NULL, NULL);
+}
+
+void handle_tablet_tool_axis(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_axis *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_axis));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm);
+ if (libinput_event_tablet_tool_x_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_X;
+ wlr_event->x_mm = libinput_event_tablet_tool_get_x(tevent);
+ }
+ if (libinput_event_tablet_tool_y_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_Y;
+ wlr_event->y_mm = libinput_event_tablet_tool_get_y(tevent);
+ }
+ if (libinput_event_tablet_tool_pressure_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE;
+ wlr_event->pressure = libinput_event_tablet_tool_get_pressure(tevent);
+ }
+ if (libinput_event_tablet_tool_distance_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_DISTANCE;
+ wlr_event->distance = libinput_event_tablet_tool_get_distance(tevent);
+ }
+ if (libinput_event_tablet_tool_tilt_x_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_TILT_X;
+ wlr_event->tilt_x = libinput_event_tablet_tool_get_tilt_x(tevent);
+ }
+ if (libinput_event_tablet_tool_tilt_y_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_TILT_Y;
+ wlr_event->tilt_y = libinput_event_tablet_tool_get_tilt_y(tevent);
+ }
+ if (libinput_event_tablet_tool_rotation_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_ROTATION;
+ wlr_event->rotation = libinput_event_tablet_tool_get_rotation(tevent);
+ }
+ if (libinput_event_tablet_tool_slider_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_SLIDER;
+ wlr_event->slider = libinput_event_tablet_tool_get_slider_position(tevent);
+ }
+ if (libinput_event_tablet_tool_wheel_has_changed(tevent)) {
+ wlr_event->updated_axes |= WLR_TABLET_TOOL_AXIS_WHEEL;
+ wlr_event->wheel_delta = libinput_event_tablet_tool_get_wheel_delta(tevent);
+ }
+ wl_signal_emit(&dev->tablet_tool->events.axis, wlr_event);
+}
+
+void handle_tablet_tool_proximity(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_proximity *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_proximity));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ switch (libinput_event_tablet_tool_get_proximity_state(tevent)) {
+ case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT:
+ wlr_event->state = WLR_TABLET_TOOL_PROXIMITY_OUT;
+ break;
+ case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN:
+ wlr_event->state = WLR_TABLET_TOOL_PROXIMITY_IN;
+ handle_tablet_tool_axis(event, device);
+ break;
+ }
+ wl_signal_emit(&dev->tablet_tool->events.proximity, wlr_event);
+}
+
+void handle_tablet_tool_tip(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ handle_tablet_tool_axis(event, device);
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_tip *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_tip));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ switch (libinput_event_tablet_tool_get_tip_state(tevent)) {
+ case LIBINPUT_TABLET_TOOL_TIP_UP:
+ wlr_event->state = WLR_TABLET_TOOL_TIP_UP;
+ break;
+ case LIBINPUT_TABLET_TOOL_TIP_DOWN:
+ wlr_event->state = WLR_TABLET_TOOL_TIP_DOWN;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_tool->events.tip, wlr_event);
+}
+
+void handle_tablet_tool_button(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a tablet tool event for a device with no tablet tools?");
+ return;
+ }
+ // Tip events contain axis information. We update this information
+ // before we send the proximity event
+ handle_tablet_tool_axis(event, device);
+ struct libinput_event_tablet_tool *tevent =
+ libinput_event_get_tablet_tool_event(event);
+ struct wlr_tablet_tool_button *wlr_event =
+ calloc(1, sizeof(struct wlr_tablet_tool_button));
+ wlr_event->time_sec = libinput_event_tablet_tool_get_time(tevent);
+ wlr_event->time_usec = libinput_event_tablet_tool_get_time_usec(tevent);
+ wlr_event->button = libinput_event_tablet_tool_get_button(tevent);
+ switch (libinput_event_tablet_tool_get_button_state(tevent)) {
+ case LIBINPUT_BUTTON_STATE_RELEASED:
+ wlr_event->state = WLR_BUTTON_RELEASED;
+ break;
+ case LIBINPUT_BUTTON_STATE_PRESSED:
+ wlr_event->state = WLR_BUTTON_PRESSED;
+ break;
+ }
+ wl_signal_emit(&dev->tablet_tool->events.button, wlr_event);
+}
diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c
new file mode 100644
index 00000000..02c9cfef
--- /dev/null
+++ b/backend/libinput/touch.c
@@ -0,0 +1,93 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <libinput.h>
+#include <wlr/session.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "backend/libinput.h"
+#include "common/log.h"
+#include "types.h"
+
+struct wlr_touch *wlr_libinput_touch_create(
+ struct libinput_device *device) {
+ assert(device);
+ return wlr_touch_create(NULL, NULL);
+}
+
+void handle_touch_down(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a touch event for a device with no touch?");
+ return;
+ }
+ struct libinput_event_touch *tevent =
+ libinput_event_get_touch_event(event);
+ struct wlr_touch_down *wlr_event =
+ calloc(1, sizeof(struct wlr_touch_down));
+ wlr_event->time_sec = libinput_event_touch_get_time(tevent);
+ wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent);
+ wlr_event->slot = libinput_event_touch_get_slot(tevent);
+ wlr_event->x_mm = libinput_event_touch_get_x(tevent);
+ wlr_event->y_mm = libinput_event_touch_get_y(tevent);
+ libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm);
+ wl_signal_emit(&dev->touch->events.down, wlr_event);
+}
+
+void handle_touch_up(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a touch event for a device with no touch?");
+ return;
+ }
+ struct libinput_event_touch *tevent =
+ libinput_event_get_touch_event(event);
+ struct wlr_touch_up *wlr_event =
+ calloc(1, sizeof(struct wlr_touch_up));
+ wlr_event->time_sec = libinput_event_touch_get_time(tevent);
+ wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent);
+ wlr_event->slot = libinput_event_touch_get_slot(tevent);
+ wl_signal_emit(&dev->touch->events.up, wlr_event);
+}
+
+void handle_touch_motion(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a touch event for a device with no touch?");
+ return;
+ }
+ struct libinput_event_touch *tevent =
+ libinput_event_get_touch_event(event);
+ struct wlr_touch_motion *wlr_event =
+ calloc(1, sizeof(struct wlr_touch_motion));
+ wlr_event->time_sec = libinput_event_touch_get_time(tevent);
+ wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent);
+ wlr_event->slot = libinput_event_touch_get_slot(tevent);
+ wlr_event->x_mm = libinput_event_touch_get_x(tevent);
+ wlr_event->y_mm = libinput_event_touch_get_y(tevent);
+ libinput_device_get_size(device, &wlr_event->width_mm, &wlr_event->height_mm);
+ wl_signal_emit(&dev->touch->events.motion, wlr_event);
+}
+
+void handle_touch_cancel(struct libinput_event *event,
+ struct libinput_device *device) {
+ struct wlr_input_device *dev =
+ get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, device);
+ if (!dev) {
+ wlr_log(L_DEBUG, "Got a touch event for a device with no touch?");
+ return;
+ }
+ struct libinput_event_touch *tevent =
+ libinput_event_get_touch_event(event);
+ struct wlr_touch_cancel *wlr_event =
+ calloc(1, sizeof(struct wlr_touch_cancel));
+ wlr_event->time_sec = libinput_event_touch_get_time(tevent);
+ wlr_event->time_usec = libinput_event_touch_get_time_usec(tevent);
+ wlr_event->slot = libinput_event_touch_get_slot(tevent);
+ wl_signal_emit(&dev->touch->events.cancel, wlr_event);
+}
diff --git a/backend/multi/backend.c b/backend/multi/backend.c
new file mode 100644
index 00000000..e3d87ccc
--- /dev/null
+++ b/backend/multi/backend.c
@@ -0,0 +1,107 @@
+#include <stdbool.h>
+#include <stdlib.h>
+#include <wlr/backend/interface.h>
+#include <wlr/common/log.h>
+#include "backend/multi.h"
+#include "common/log.h"
+
+struct subbackend_state {
+ struct wlr_backend *backend;
+ struct wlr_backend *container;
+ struct wl_listener input_add;
+ struct wl_listener input_remove;
+ struct wl_listener output_add;
+ struct wl_listener output_remove;
+};
+
+static bool multi_backend_init(struct wlr_backend_state *state) {
+ for (size_t i = 0; i < state->backends->length; ++i) {
+ struct subbackend_state *sub = state->backends->items[i];
+ if (!wlr_backend_init(sub->backend)) {
+ wlr_log(L_ERROR, "Failed to initialize backend %zd", i);
+ return false;
+ }
+ }
+ return true;
+}
+
+static void multi_backend_destroy(struct wlr_backend_state *state) {
+ for (size_t i = 0; i < state->backends->length; ++i) {
+ struct subbackend_state *sub = state->backends->items[i];
+ wlr_backend_destroy(sub->backend);
+ free(sub);
+ }
+ list_free(state->backends);
+ free(state);
+}
+
+struct wlr_backend_impl backend_impl = {
+ .init = multi_backend_init,
+ .destroy = multi_backend_destroy
+};
+
+struct wlr_backend *wlr_multi_backend_create() {
+ struct wlr_backend_state *state =
+ calloc(1, sizeof(struct wlr_backend_state));
+ if (!state) {
+ wlr_log(L_ERROR, "Backend allocation failed");
+ return NULL;
+ }
+ state->backends = list_create();
+ if (!state->backends) {
+ free(state);
+ wlr_log(L_ERROR, "Backend allocation failed");
+ return NULL;
+ }
+ struct wlr_backend *backend = wlr_backend_create(&backend_impl, state);
+ state->backend = backend;
+ return backend;
+}
+
+static void input_add_reemit(struct wl_listener *listener, void *data) {
+ struct subbackend_state *state = wl_container_of(listener,
+ state, input_add);
+ wl_signal_emit(&state->container->events.input_add, data);
+}
+
+static void input_remove_reemit(struct wl_listener *listener, void *data) {
+ struct subbackend_state *state = wl_container_of(listener,
+ state, input_remove);
+ wl_signal_emit(&state->container->events.input_remove, data);
+}
+
+static void output_add_reemit(struct wl_listener *listener, void *data) {
+ struct subbackend_state *state = wl_container_of(listener,
+ state, output_add);
+ wl_signal_emit(&state->container->events.output_add, data);
+}
+
+static void output_remove_reemit(struct wl_listener *listener, void *data) {
+ struct subbackend_state *state = wl_container_of(listener,
+ state, output_remove);
+ wl_signal_emit(&state->container->events.output_remove, data);
+}
+
+void wlr_multi_backend_add(struct wlr_backend *multi,
+ struct wlr_backend *backend) {
+ struct subbackend_state *sub = calloc(1, sizeof(struct subbackend_state));
+ sub->backend = backend;
+ sub->container = multi;
+
+ sub->input_add.notify = input_add_reemit;
+ sub->input_remove.notify = input_remove_reemit;
+ sub->output_add.notify = output_add_reemit;
+ sub->output_remove.notify = output_remove_reemit;
+
+ wl_list_init(&sub->input_add.link);
+ wl_list_init(&sub->input_remove.link);
+ wl_list_init(&sub->output_add.link);
+ wl_list_init(&sub->output_remove.link);
+
+ wl_signal_add(&backend->events.input_add, &sub->input_add);
+ wl_signal_add(&backend->events.input_remove, &sub->input_remove);
+ wl_signal_add(&backend->events.output_add, &sub->output_add);
+ wl_signal_add(&backend->events.output_remove, &sub->output_remove);
+
+ list_add(multi->state->backends, sub);
+}