diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-08-14 10:33:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 10:33:46 -0400 |
commit | 53052b3f6e457f35d46fc3a71bd7eac96e55a484 (patch) | |
tree | c51bfcd472cf38df7528eab9330bb0e44981ffbb /backend/libinput | |
parent | 1e1e9887fba15291256a806aca6cc6f94a8f671e (diff) | |
parent | e922e62924314866620cce662756ff09c8092cc2 (diff) |
Merge pull request #85 from martinetd/refactor_states
Refactor states
Diffstat (limited to 'backend/libinput')
-rw-r--r-- | backend/libinput/backend.c | 5 | ||||
-rw-r--r-- | backend/libinput/events.c | 19 | ||||
-rw-r--r-- | backend/libinput/keyboard.c | 25 | ||||
-rw-r--r-- | backend/libinput/pointer.c | 8 | ||||
-rw-r--r-- | backend/libinput/tablet_pad.c | 8 | ||||
-rw-r--r-- | backend/libinput/tablet_tool.c | 8 | ||||
-rw-r--r-- | backend/libinput/touch.c | 8 |
7 files changed, 57 insertions, 24 deletions
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 18e4826c..a8f43fbc 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -151,6 +151,7 @@ error_backend: return NULL; } -struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *dev) { - return dev->state->handle; +struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *_dev) { + struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev; + return dev->handle; } diff --git a/backend/libinput/events.c b/backend/libinput/events.c index a7c781c2..0e434b7c 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -23,9 +23,10 @@ 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 void wlr_libinput_device_destroy(struct wlr_input_device *_dev) { + struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev; + libinput_device_unref(dev->handle); + free(dev); } static struct wlr_input_device_impl input_device_impl = { @@ -38,13 +39,13 @@ static struct wlr_input_device *allocate_device( int vendor = libinput_device_get_id_vendor(libinput_dev); int product = libinput_device_get_id_product(libinput_dev); const char *name = libinput_device_get_name(libinput_dev); - struct wlr_input_device_state *devstate = - calloc(1, sizeof(struct wlr_input_device_state)); - devstate->handle = libinput_dev; + struct wlr_libinput_input_device *wlr_libinput_dev = + calloc(1, sizeof(struct wlr_libinput_input_device)); + struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device; + wlr_libinput_dev->handle = libinput_dev; libinput_device_ref(libinput_dev); - struct wlr_input_device *wlr_dev = wlr_input_device_create( - type, &input_device_impl, devstate, - name, vendor, product); + wlr_input_device_init(wlr_dev, type, &input_device_impl, + name, vendor, product); list_add(wlr_devices, wlr_dev); return wlr_dev; } diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index b231828d..db4ac0ed 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -7,17 +7,21 @@ #include <wlr/util/log.h> #include "backend/libinput.h" -struct wlr_keyboard_state { +struct wlr_libinput_keyboard { + struct wlr_keyboard wlr_keyboard; struct libinput_device *libinput_dev; }; -static void wlr_libinput_keyboard_set_leds(struct wlr_keyboard_state *kbstate, uint32_t leds) { - libinput_device_led_update(kbstate->libinput_dev, leds); +static void wlr_libinput_keyboard_set_leds(struct wlr_keyboard *wlr_kb, uint32_t leds) { + struct wlr_libinput_keyboard *wlr_libinput_kb = (struct wlr_libinput_keyboard *)wlr_kb; + libinput_device_led_update(wlr_libinput_kb->libinput_dev, leds); } -static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *kbstate) { - libinput_device_unref(kbstate->libinput_dev); - free(kbstate); +static void wlr_libinput_keyboard_destroy(struct wlr_keyboard *wlr_kb) { + struct wlr_libinput_keyboard *wlr_libinput_kb = + (struct wlr_libinput_keyboard *)wlr_kb; + libinput_device_unref(wlr_libinput_kb->libinput_dev); + free(wlr_libinput_kb); } struct wlr_keyboard_impl impl = { @@ -28,11 +32,14 @@ struct wlr_keyboard_impl impl = { struct wlr_keyboard *wlr_libinput_keyboard_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - struct wlr_keyboard_state *kbstate = calloc(1, sizeof(struct wlr_keyboard_state)); - kbstate->libinput_dev = libinput_dev; + struct wlr_libinput_keyboard *wlr_libinput_kb = + calloc(1, sizeof(struct wlr_libinput_keyboard)); + wlr_libinput_kb->libinput_dev = libinput_dev; libinput_device_ref(libinput_dev); libinput_device_led_update(libinput_dev, 0); - return wlr_keyboard_create(&impl, kbstate); + struct wlr_keyboard *wlr_kb = &wlr_libinput_kb->wlr_keyboard; + wlr_keyboard_init(wlr_kb, &impl); + return wlr_kb; } void handle_keyboard_key(struct libinput_event *event, diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index c2c47592..8bda205d 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -10,7 +10,13 @@ struct wlr_pointer *wlr_libinput_pointer_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - return wlr_pointer_create(NULL, NULL); + struct wlr_pointer *wlr_pointer = calloc(1, sizeof(struct wlr_pointer)); + if (!wlr_pointer) { + wlr_log(L_ERROR, "Unable to allocate wlr_pointer"); + return NULL; + } + wlr_pointer_init(wlr_pointer, NULL); + return wlr_pointer; } void handle_pointer_motion(struct libinput_event *event, diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 9713bb1d..efad1068 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -10,7 +10,13 @@ struct wlr_tablet_pad *wlr_libinput_tablet_pad_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - return wlr_tablet_pad_create(NULL, NULL); + struct wlr_tablet_pad *wlr_tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad)); + if (!wlr_tablet_pad) { + wlr_log(L_ERROR, "Unable to allocate wlr_tablet_pad"); + return NULL; + } + wlr_tablet_pad_init(wlr_tablet_pad, NULL); + return wlr_tablet_pad; } void handle_tablet_pad_button(struct libinput_event *event, diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index efe77f0a..8b3d34ed 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -10,7 +10,13 @@ struct wlr_tablet_tool *wlr_libinput_tablet_tool_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - return wlr_tablet_tool_create(NULL, NULL); + struct wlr_tablet_tool *wlr_tablet_tool = calloc(1, sizeof(struct wlr_tablet_tool)); + if (!wlr_tablet_tool) { + wlr_log(L_ERROR, "Unable to allocate wlr_tablet_tool"); + return NULL; + } + wlr_tablet_tool_init(wlr_tablet_tool, NULL); + return wlr_tablet_tool; } void handle_tablet_tool_axis(struct libinput_event *event, diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 5d990d3c..9e08d028 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -10,7 +10,13 @@ struct wlr_touch *wlr_libinput_touch_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - return wlr_touch_create(NULL, NULL); + struct wlr_touch *wlr_touch = calloc(1, sizeof(struct wlr_touch)); + if (!wlr_touch) { + wlr_log(L_ERROR, "Unable to allocate wlr_touch"); + return NULL; + } + wlr_touch_init(wlr_touch, NULL); + return wlr_touch; } void handle_touch_down(struct libinput_event *event, |