wlroots-hyprland/types/wlr_input_device.c

74 lines
1.8 KiB
C
Raw Normal View History

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>
#include <wayland-server-core.h>
2017-06-21 16:27:45 +02:00
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_switch.h>
2017-06-21 16:27:45 +02:00
#include <wlr/interfaces/wlr_tablet_pad.h>
2018-02-12 21:29:23 +01:00
#include <wlr/interfaces/wlr_tablet_tool.h>
#include <wlr/interfaces/wlr_touch.h>
#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,
2017-06-10 18:21:54 +02:00
enum wlr_input_device_type type,
const struct wlr_input_device_impl *impl, const char *name) {
2017-06-09 23:31:21 +02:00
dev->type = type;
2017-06-10 18:21:54 +02:00
dev->impl = impl;
2017-06-09 23:31:21 +02:00
dev->name = strdup(name);
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
}
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:
wlr_keyboard_destroy(dev->keyboard);
break;
2017-06-21 16:27:45 +02:00
case WLR_INPUT_DEVICE_POINTER:
wlr_pointer_destroy(dev->pointer);
break;
case WLR_INPUT_DEVICE_SWITCH:
wlr_switch_destroy(dev->switch_device);
break;
2017-06-21 16:27:45 +02:00
case WLR_INPUT_DEVICE_TOUCH:
wlr_touch_destroy(dev->touch);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
wlr_tablet_destroy(dev->tablet);
2017-06-21 16:27:45 +02:00
break;
case WLR_INPUT_DEVICE_TABLET_PAD:
wlr_tablet_pad_destroy(dev->tablet_pad);
break;
2017-06-10 18:21:54 +02:00
}
2017-08-14 14:54:53 +02:00
} else {
wlr_input_device_finish(dev);
if (dev->impl && dev->impl->destroy) {
dev->impl->destroy(dev);
} else {
free(dev);
}
2017-08-14 14:54:53 +02:00
}
2017-06-09 23:31:21 +02:00
}