aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/CMakeLists.txt1
-rw-r--r--backend/libinput/backend.c2
-rw-r--r--backend/libinput/events.c17
-rw-r--r--backend/libinput/touch.c15
-rw-r--r--include/backend/libinput.h15
-rw-r--r--include/types.h8
-rw-r--r--include/wlr/types.h18
-rw-r--r--types/CMakeLists.txt1
-rw-r--r--types/wlr_keyboard.c4
-rw-r--r--types/wlr_pointer.c10
-rw-r--r--types/wlr_touch.c27
11 files changed, 104 insertions, 14 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index b8df9373..8272e039 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -18,6 +18,7 @@ add_library(wlr-backend
libinput/events.c
libinput/keyboard.c
libinput/pointer.c
+ libinput/touch.c
multi/backend.c
backend.c
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c
index 9b0a6d8c..82ba44a6 100644
--- a/backend/libinput/backend.c
+++ b/backend/libinput/backend.c
@@ -102,7 +102,7 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
goto error_state;
}
- if (!(state->keyboards = list_create())) {
+ if (!(state->devices = list_create())) {
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
goto error_backend;
}
diff --git a/backend/libinput/events.c b/backend/libinput/events.c
index 5ef58a3e..4af8082f 100644
--- a/backend/libinput/events.c
+++ b/backend/libinput/events.c
@@ -33,7 +33,8 @@ static struct wlr_input_device_impl input_device_impl = {
.destroy = wlr_libinput_device_destroy
};
-static struct wlr_input_device *allocate_device(struct libinput_device *device,
+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);
@@ -46,6 +47,7 @@ static struct wlr_input_device *allocate_device(struct libinput_device *device,
type, &input_device_impl, devstate,
name, vendor, product);
list_add(devices, wlr_device);
+ list_add(state->devices, wlr_device);
return wlr_device;
}
@@ -65,19 +67,22 @@ static void handle_device_added(struct wlr_backend_state *state,
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(device, devices,
- WLR_INPUT_DEVICE_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(device, devices,
- WLR_INPUT_DEVICE_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)) {
- // TODO
+ 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)) {
// TODO
diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c
new file mode 100644
index 00000000..55e8609a
--- /dev/null
+++ b/backend/libinput/touch.c
@@ -0,0 +1,15 @@
+#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);
+}
diff --git a/include/backend/libinput.h b/include/backend/libinput.h
index 7c318746..dd24fbb0 100644
--- a/include/backend/libinput.h
+++ b/include/backend/libinput.h
@@ -16,7 +16,7 @@ struct wlr_backend_state {
struct libinput *libinput;
struct wl_event_source *input_event;
- list_t *keyboards;
+ list_t *devices;
};
struct wlr_input_device_state {
@@ -46,4 +46,17 @@ void handle_pointer_button(struct libinput_event *event,
void handle_pointer_axis(struct libinput_event *event,
struct libinput_device *device);
+struct wlr_touch *wlr_libinput_touch_create(
+ struct libinput_device *device);
+void handle_touch_down(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_touch_up(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_touch_motion(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_touch_cancel(struct libinput_event *event,
+ struct libinput_device *device);
+void handle_touch_frame(struct libinput_event *event,
+ struct libinput_device *device);
+
#endif
diff --git a/include/types.h b/include/types.h
index 20f5ed13..5b20e2ed 100644
--- a/include/types.h
+++ b/include/types.h
@@ -34,6 +34,14 @@ struct wlr_pointer *wlr_pointer_create(struct wlr_pointer_impl *impl,
struct wlr_pointer_state *state);
void wlr_pointer_destroy(struct wlr_pointer *pointer);
+struct wlr_touch_impl {
+ void (*destroy)(struct wlr_touch_state *state);
+};
+
+struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl,
+ struct wlr_touch_state *state);
+void wlr_touch_destroy(struct wlr_touch *touch);
+
struct wlr_input_device_impl {
void (*destroy)(struct wlr_input_device_state *state);
};
diff --git a/include/wlr/types.h b/include/wlr/types.h
index af23152c..b4d69ccb 100644
--- a/include/wlr/types.h
+++ b/include/wlr/types.h
@@ -134,7 +134,22 @@ struct wlr_pointer_axis {
double delta;
};
-// TODO: touch
+struct wlr_touch_state;
+struct wlr_touch_impl;
+
+struct wlr_touch {
+ struct wlr_touch_state *state;
+ struct wlr_touch_impl *impl;
+
+ struct {
+ struct wl_signal down;
+ struct wl_signal up;
+ struct wl_signal motion;
+ struct wl_signal cancel;
+ struct wl_signal frame;
+ } events;
+};
+
// TODO: tablet & tablet tool
// TODO: gestures
// TODO: switch
@@ -164,6 +179,7 @@ struct wlr_input_device {
void *_device;
struct wlr_keyboard *keyboard;
struct wlr_pointer *pointer;
+ struct wlr_touch *touch;
};
};
diff --git a/types/CMakeLists.txt b/types/CMakeLists.txt
index 91ab9da0..b158db39 100644
--- a/types/CMakeLists.txt
+++ b/types/CMakeLists.txt
@@ -7,6 +7,7 @@ add_library(wlr-types
wlr_output.c
wlr_keyboard.c
wlr_pointer.c
+ wlr_touch.c
wlr_input_device.c
)
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c
index db4f7ca7..32728c78 100644
--- a/types/wlr_keyboard.c
+++ b/types/wlr_keyboard.c
@@ -16,6 +16,8 @@ struct wlr_keyboard *wlr_keyboard_create(struct wlr_keyboard_impl *impl,
void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
if (!kb) return;
- kb->impl->destroy(kb->state);
+ if (kb->impl) {
+ kb->impl->destroy(kb->state);
+ }
free(kb);
}
diff --git a/types/wlr_pointer.c b/types/wlr_pointer.c
index b1364c34..9c40fe2f 100644
--- a/types/wlr_pointer.c
+++ b/types/wlr_pointer.c
@@ -17,8 +17,10 @@ struct wlr_pointer *wlr_pointer_create(struct wlr_pointer_impl *impl,
return pointer;
}
-void wlr_pointer_destroy(struct wlr_pointer *kb) {
- if (!kb) return;
- kb->impl->destroy(kb->state);
- free(kb);
+void wlr_pointer_destroy(struct wlr_pointer *pointer) {
+ if (!pointer) return;
+ if (pointer->impl) {
+ pointer->impl->destroy(pointer->state);
+ }
+ free(pointer);
}
diff --git a/types/wlr_touch.c b/types/wlr_touch.c
new file mode 100644
index 00000000..9c8b4b94
--- /dev/null
+++ b/types/wlr_touch.c
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include <string.h>
+#include <wayland-server.h>
+#include <wlr/types.h>
+#include <wlr/common/list.h>
+#include "types.h"
+
+struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl,
+ struct wlr_touch_state *state) {
+ struct wlr_touch *touch = calloc(1, sizeof(struct wlr_touch));
+ touch->impl = impl;
+ touch->state = state;
+ wl_signal_init(&touch->events.down);
+ wl_signal_init(&touch->events.up);
+ wl_signal_init(&touch->events.motion);
+ wl_signal_init(&touch->events.frame);
+ wl_signal_init(&touch->events.cancel);
+ return touch;
+}
+
+void wlr_touch_destroy(struct wlr_touch *touch) {
+ if (!touch) return;
+ if (touch->impl) {
+ touch->impl->destroy(touch->state);
+ }
+ free(touch);
+}