aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-10 12:24:35 -0400
committerDrew DeVault <sir@cmpwn.com>2017-06-13 08:10:36 -0400
commit508d135de78a483feb947ee4cc5e979743bd7317 (patch)
tree91bdfcd73f693ea10bb6251bd14c2bcca317dee4 /backend
parent7a5f35b5bb2a30e46defe9ea1bd610cb06df95e8 (diff)
Only allocate device state when it will be used
This design also avoids double frees in the future when we're creating several wlr_input_devices from one libinput_device.
Diffstat (limited to 'backend')
-rw-r--r--backend/libinput/events.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/backend/libinput/events.c b/backend/libinput/events.c
index 60a2fd5e..2ce368e3 100644
--- a/backend/libinput/events.c
+++ b/backend/libinput/events.c
@@ -47,10 +47,12 @@ 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_state *devstate =
+ calloc(1, sizeof(struct wlr_input_device_state));
+ devstate->handle = device;
+ libinput_device_ref(device);
struct wlr_input_device *wlr_device = wlr_input_device_create(
WLR_INPUT_DEVICE_KEYBOARD, &input_device_impl, devstate,
name, vendor, product);
@@ -80,7 +82,6 @@ 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);
}
}