wlroots-hyprland/types/wlr_input_device.c

60 lines
1.6 KiB
C
Raw Normal View History

2017-06-09 23:31:21 +02:00
#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <string.h>
#include <wayland-server.h>
2017-06-21 16:27:45 +02: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 18:10:07 +02:00
#include <wlr/util/log.h>
2017-06-09 23:31:21 +02:00
struct wlr_input_device *wlr_input_device_create(
2017-06-10 18:21:54 +02:00
enum wlr_input_device_type type,
struct wlr_input_device_impl *impl,
struct wlr_input_device_state *state,
const char *name, int vendor, int product) {
2017-06-09 23:31:21 +02:00
struct wlr_input_device *dev = calloc(1, sizeof(struct wlr_input_device));
dev->type = type;
2017-06-10 18:21:54 +02:00
dev->impl = impl;
dev->state = state;
2017-06-09 23:31:21 +02:00
dev->name = strdup(name);
dev->vendor = vendor;
dev->product = product;
return dev;
}
void wlr_input_device_destroy(struct wlr_input_device *dev) {
if (!dev) return;
2017-06-10 18:21:54 +02:00
if (dev->impl && dev->impl->destroy && dev->state) {
dev->impl->destroy(dev->state);
}
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_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 18:21:54 +02:00
default:
wlr_log(L_DEBUG, "Warning: leaking memory %p %p %d",
dev->_device, dev, dev->type);
break;
}
}
2017-06-09 23:31:21 +02:00
free(dev->name);
free(dev);
}