2018-11-05 22:51:23 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2017-06-09 23:31:21 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
2017-06-21 18:10:07 +02:00
|
|
|
#include <wlr/util/log.h>
|
2018-02-12 19:45:58 +01:00
|
|
|
#include "util/signal.h"
|
2017-06-09 23:31:21 +02:00
|
|
|
|
2017-08-14 14:54:53 +02:00
|
|
|
void wlr_input_device_init(struct wlr_input_device *dev,
|
2022-02-09 22:14:56 +01:00
|
|
|
enum wlr_input_device_type type, const char *name) {
|
2017-06-09 23:31:21 +02:00
|
|
|
dev->type = type;
|
|
|
|
dev->name = strdup(name);
|
2022-02-04 15:26:57 +01:00
|
|
|
dev->vendor = 0;
|
|
|
|
dev->product = 0;
|
2017-08-28 16:29:53 +02:00
|
|
|
|
|
|
|
wl_signal_init(&dev->events.destroy);
|
2017-06-09 23:31:21 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 17:20:44 +01:00
|
|
|
void wlr_input_device_finish(struct wlr_input_device *wlr_device) {
|
|
|
|
if (!wlr_device) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&wlr_device->events.destroy, wlr_device);
|
|
|
|
|
|
|
|
free(wlr_device->name);
|
|
|
|
free(wlr_device->output_name);
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:31:21 +02:00
|
|
|
void wlr_input_device_destroy(struct wlr_input_device *dev) {
|
2017-08-14 17:09:56 +02:00
|
|
|
if (!dev) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-28 16:29:53 +02:00
|
|
|
|
2017-06-10 18:21:54 +02:00
|
|
|
if (dev->_device) {
|
|
|
|
switch (dev->type) {
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
2022-03-01 20:49:30 +01:00
|
|
|
wlr_log(WLR_ERROR, "wlr_keyboard will not be destroyed");
|
2017-06-10 18:21:54 +02:00
|
|
|
break;
|
2017-06-21 16:27:45 +02:00
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2022-03-02 19:57:28 +01:00
|
|
|
wlr_log(WLR_ERROR, "wlr_pointer will not be destroyed");
|
2017-06-21 16:27:45 +02:00
|
|
|
break;
|
2018-11-15 00:24:55 +01:00
|
|
|
case WLR_INPUT_DEVICE_SWITCH:
|
2022-03-02 20:17:31 +01:00
|
|
|
wlr_log(WLR_ERROR, "wlr_switch will not be destroyed");
|
2018-11-15 00:24:55 +01:00
|
|
|
break;
|
2017-06-21 16:27:45 +02:00
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
2022-03-02 22:07:40 +01:00
|
|
|
wlr_log(WLR_ERROR, "wlr_touch will not be destroyed");
|
2017-06-21 16:27:45 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
2022-03-02 21:58:44 +01:00
|
|
|
wlr_log(WLR_ERROR, "wlr_tablet_tool will not be destroyed");
|
2017-06-21 16:27:45 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
2022-03-02 21:11:25 +01:00
|
|
|
wlr_log(WLR_ERROR, "wlr_tablet_pad will not be destroyed");
|
2017-06-21 16:27:45 +02:00
|
|
|
break;
|
2017-06-10 18:21:54 +02:00
|
|
|
}
|
2017-08-14 14:54:53 +02:00
|
|
|
} else {
|
2022-02-11 15:06:26 +01:00
|
|
|
wlr_input_device_finish(dev);
|
2022-02-09 22:14:56 +01:00
|
|
|
free(dev);
|
2017-08-14 14:54:53 +02:00
|
|
|
}
|
2017-06-09 23:31:21 +02:00
|
|
|
}
|