mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
Reassign ownership of libinput handle
This commit is contained in:
parent
f479b7c8c7
commit
7a5f35b5bb
8 changed files with 64 additions and 23 deletions
|
|
@ -24,6 +24,15 @@ struct wlr_input_device *get_appropriate_device(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void wlr_libinput_device_destroy(struct wlr_input_device_state *state) {
|
||||
libinput_device_unref(state->handle);
|
||||
free(state);
|
||||
}
|
||||
|
||||
static struct wlr_input_device_impl input_device_impl = {
|
||||
.destroy = wlr_libinput_device_destroy
|
||||
};
|
||||
|
||||
static void handle_device_added(struct wlr_backend_state *state,
|
||||
struct libinput_device *device) {
|
||||
assert(state && device);
|
||||
|
|
@ -38,10 +47,13 @@ static void handle_device_added(struct wlr_backend_state *state,
|
|||
const char *name = libinput_device_get_name(device);
|
||||
list_t *devices = list_create();
|
||||
wlr_log(L_DEBUG, "Added %s [%d:%d]", name, vendor, product);
|
||||
struct wlr_input_device_state *devstate =
|
||||
calloc(1, sizeof(struct wlr_input_device_state));
|
||||
|
||||
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
|
||||
struct wlr_input_device *wlr_device = wlr_input_device_create(
|
||||
WLR_INPUT_DEVICE_KEYBOARD, name, vendor, product);
|
||||
WLR_INPUT_DEVICE_KEYBOARD, &input_device_impl, devstate,
|
||||
name, vendor, product);
|
||||
wlr_device->keyboard = wlr_libinput_keyboard_create(device);
|
||||
wl_signal_emit(&state->backend->events.input_add, wlr_device);
|
||||
list_add(devices, wlr_device);
|
||||
|
|
@ -68,6 +80,7 @@ static void handle_device_added(struct wlr_backend_state *state,
|
|||
if (devices->length > 0) {
|
||||
libinput_device_set_user_data(device, devices);
|
||||
} else {
|
||||
wlr_libinput_device_destroy(devstate);
|
||||
list_free(devices);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,23 +8,10 @@
|
|||
#include "common/log.h"
|
||||
#include "types.h"
|
||||
|
||||
static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *state) {
|
||||
libinput_device_unref(state->handle);
|
||||
free(state);
|
||||
}
|
||||
|
||||
static struct wlr_keyboard_impl keyboard_impl = {
|
||||
.destroy = wlr_libinput_keyboard_destroy
|
||||
};
|
||||
|
||||
struct wlr_keyboard *wlr_libinput_keyboard_create(
|
||||
struct libinput_device *device) {
|
||||
assert(device);
|
||||
struct wlr_keyboard_state *kbstate =
|
||||
calloc(1, sizeof(struct wlr_keyboard_state));
|
||||
kbstate->handle = device;
|
||||
libinput_device_ref(device);
|
||||
return wlr_keyboard_create(&keyboard_impl, kbstate);
|
||||
return wlr_keyboard_create(NULL, NULL);
|
||||
}
|
||||
|
||||
void handle_keyboard_key(struct libinput_event *event,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue