wlroots/types/wlr_input_device.c

65 lines
1.6 KiB
C
Raw Normal View History

2017-06-09 21:31:21 +00:00
#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <string.h>
#include <wayland-server.h>
2017-06-21 14:27:45 +00:00
#include <wlr/types/wlr_input_device.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_touch.h>
#include <wlr/interfaces/wlr_tablet_tool.h>
#include <wlr/interfaces/wlr_tablet_pad.h>
2017-06-21 16:10:07 +00:00
#include <wlr/util/log.h>
2018-02-12 18:45:58 +00:00
#include "util/signal.h"
2017-06-09 21:31:21 +00:00
2017-08-14 12:54:53 +00:00
void wlr_input_device_init(struct wlr_input_device *dev,
2017-06-10 16:21:54 +00:00
enum wlr_input_device_type type,
struct wlr_input_device_impl *impl,
const char *name, int vendor, int product) {
2017-06-09 21:31:21 +00:00
dev->type = type;
2017-06-10 16:21:54 +00:00
dev->impl = impl;
2017-06-09 21:31:21 +00:00
dev->name = strdup(name);
dev->vendor = vendor;
dev->product = product;
2017-08-28 14:29:53 +00:00
wl_signal_init(&dev->events.destroy);
2017-06-09 21:31:21 +00:00
}
void wlr_input_device_destroy(struct wlr_input_device *dev) {
2017-08-14 15:09:56 +00:00
if (!dev) {
return;
}
2017-08-28 14:29:53 +00:00
2018-02-12 08:12:31 +00:00
wlr_signal_emit_safe(&dev->events.destroy, dev);
2017-06-10 16:21:54 +00:00
if (dev->_device) {
switch (dev->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
wlr_keyboard_destroy(dev->keyboard);
break;
2017-06-21 14:27:45 +00:00
case WLR_INPUT_DEVICE_POINTER:
wlr_pointer_destroy(dev->pointer);
break;
case WLR_INPUT_DEVICE_TOUCH:
wlr_touch_destroy(dev->touch);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
wlr_tablet_tool_destroy(dev->tablet_tool);
break;
case WLR_INPUT_DEVICE_TABLET_PAD:
wlr_tablet_pad_destroy(dev->tablet_pad);
break;
2017-06-10 16:21:54 +00:00
default:
wlr_log(L_DEBUG, "Warning: leaking memory %p %p %d",
dev->_device, dev, dev->type);
break;
}
}
2017-06-09 21:31:21 +00:00
free(dev->name);
2017-08-14 12:54:53 +00:00
if (dev->impl && dev->impl->destroy) {
dev->impl->destroy(dev);
} else {
free(dev);
}
2017-06-09 21:31:21 +00:00
}