wlroots/backend/headless/input_device.c

107 lines
3.1 KiB
C
Raw Normal View History

2018-09-17 19:46:39 +00:00
#include <assert.h>
2017-12-17 17:49:20 +00:00
#include <stdlib.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
2018-02-12 20:29:23 +00:00
#include <wlr/interfaces/wlr_pointer.h>
2017-12-17 17:49:20 +00:00
#include <wlr/interfaces/wlr_tablet_pad.h>
2018-02-12 20:29:23 +00:00
#include <wlr/interfaces/wlr_tablet_tool.h>
#include <wlr/interfaces/wlr_touch.h>
#include <wlr/interfaces/wlr_switch.h>
2017-12-17 17:49:20 +00:00
#include <wlr/util/log.h>
#include "backend/headless.h"
2018-02-12 20:29:23 +00:00
#include "util/signal.h"
2017-12-17 17:49:20 +00:00
static void input_device_destroy(struct wlr_input_device *wlr_dev) {
wl_list_remove(&wlr_dev->link);
free(wlr_dev);
}
static const struct wlr_input_device_impl input_device_impl = {
.destroy = input_device_destroy,
};
2017-12-17 17:49:20 +00:00
bool wlr_input_device_is_headless(struct wlr_input_device *wlr_dev) {
return wlr_dev->impl == &input_device_impl;
}
2017-12-17 17:49:20 +00:00
struct wlr_input_device *wlr_headless_add_input_device(
struct wlr_backend *wlr_backend, enum wlr_input_device_type type) {
struct wlr_headless_backend *backend =
2018-09-17 19:46:39 +00:00
headless_backend_from_backend(wlr_backend);
2017-12-17 17:49:20 +00:00
struct wlr_headless_input_device *device =
calloc(1, sizeof(struct wlr_headless_input_device));
if (device == NULL) {
return NULL;
}
device->backend = backend;
int vendor = 0;
int product = 0;
const char *name = "headless";
struct wlr_input_device *wlr_device = &device->wlr_input_device;
wlr_input_device_init(wlr_device, type, &input_device_impl, name, vendor,
product);
switch (type) {
case WLR_INPUT_DEVICE_KEYBOARD:
wlr_device->keyboard = calloc(1, sizeof(struct wlr_keyboard));
if (wlr_device->keyboard == NULL) {
2018-07-09 21:49:54 +00:00
wlr_log(WLR_ERROR, "Unable to allocate wlr_keyboard");
goto error;
2017-12-17 17:49:20 +00:00
}
wlr_keyboard_init(wlr_device->keyboard, NULL);
break;
case WLR_INPUT_DEVICE_POINTER:
wlr_device->pointer = calloc(1, sizeof(struct wlr_pointer));
if (wlr_device->pointer == NULL) {
2018-07-09 21:49:54 +00:00
wlr_log(WLR_ERROR, "Unable to allocate wlr_pointer");
goto error;
2017-12-17 17:49:20 +00:00
}
wlr_pointer_init(wlr_device->pointer, NULL);
break;
case WLR_INPUT_DEVICE_TOUCH:
wlr_device->touch = calloc(1, sizeof(struct wlr_touch));
if (wlr_device->touch == NULL) {
2018-07-09 21:49:54 +00:00
wlr_log(WLR_ERROR, "Unable to allocate wlr_touch");
goto error;
2017-12-17 17:49:20 +00:00
}
wlr_touch_init(wlr_device->touch, NULL);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
wlr_device->tablet = calloc(1, sizeof(struct wlr_tablet));
if (wlr_device->tablet == NULL) {
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet");
goto error;
2017-12-17 17:49:20 +00:00
}
wlr_tablet_init(wlr_device->tablet, NULL);
2017-12-17 17:49:20 +00:00
break;
case WLR_INPUT_DEVICE_TABLET_PAD:
wlr_device->tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad));
if (wlr_device->tablet_pad == NULL) {
2018-07-09 21:49:54 +00:00
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad");
goto error;
2017-12-17 17:49:20 +00:00
}
wlr_tablet_pad_init(wlr_device->tablet_pad, NULL);
break;
case WLR_INPUT_DEVICE_SWITCH:
wlr_device->switch_device = calloc(1, sizeof(struct wlr_switch));
if (wlr_device->switch_device == NULL) {
wlr_log(WLR_ERROR, "Unable to allocate wlr_switch");
goto error;
}
wlr_switch_init(wlr_device->switch_device, NULL);
2017-12-17 17:49:20 +00:00
}
wl_list_insert(&backend->input_devices, &wlr_device->link);
if (backend->started) {
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_device);
2017-12-17 17:49:20 +00:00
}
return wlr_device;
error:
free(device);
return NULL;
2017-12-17 17:49:20 +00:00
}