Allocate wlr_touch devices
This commit is contained in:
parent
7dfc2c28f1
commit
d6905f86cb
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ add_library(wlr-types
|
|||
wlr_output.c
|
||||
wlr_keyboard.c
|
||||
wlr_pointer.c
|
||||
wlr_touch.c
|
||||
wlr_input_device.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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue