diff options
author | Markus Ongyerth <ongy@ongy.net> | 2018-04-24 08:10:45 +0200 |
---|---|---|
committer | Markus Ongyerth <ongy@ongy.net> | 2018-07-14 09:40:39 +0200 |
commit | e235f7d33621b5879a5f9a8a1d89d4a8515857c3 (patch) | |
tree | e1c8a9d3d6966753fdccf3940197929f5681bedf /backend | |
parent | 77bac448ccac9827abfa2ab10e798295f07f3980 (diff) |
Basic tablet_v2 object lifetime
Diffstat (limited to 'backend')
-rw-r--r-- | backend/libinput/tablet_pad.c | 28 | ||||
-rw-r--r-- | backend/libinput/tablet_tool.c | 12 |
2 files changed, 31 insertions, 9 deletions
diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index ed5374c6..2558d09c 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -1,4 +1,8 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif #include <assert.h> +#include <string.h> #include <libinput.h> #include <stdlib.h> #include <wlr/backend/session.h> @@ -8,12 +12,26 @@ #include "backend/libinput.h" #include "util/signal.h" +//TODO: Move out +static void add_tablet_path(struct wl_list *list, const char *path) { + struct wlr_tablet_path *tablet_path = calloc(1, sizeof(struct wlr_tablet_path)); + + if (!tablet_path) { + return; + } + + tablet_path->path = strdup(path); + assert(tablet_path->path); + wl_list_insert(list, &tablet_path->link); +} + +// FIXME: Decide on how to alloc/count here static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad, struct libinput_device *device, unsigned int index) { struct libinput_tablet_pad_mode_group *li_group = libinput_device_tablet_pad_get_mode_group(device, index); - struct wlr_tablet_pad_group_v2 *group = - calloc(1, sizeof(struct wlr_tablet_pad_group_v2)); + struct wlr_tablet_pad_group *group = + calloc(1, sizeof(struct wlr_tablet_pad_group)); if (!group) { return; } @@ -77,9 +95,11 @@ struct wlr_tablet_pad *libinput_tablet_pad_create( wlr_tablet_pad->strip_count = libinput_device_tablet_pad_get_num_strips(libinput_dev); - //struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); - //add_tablet_path(&pad->paths, udev_device_get_syspath(udev)); + wl_list_init(&wlr_tablet_pad->paths); + struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); + add_tablet_path(&wlr_tablet_pad->paths, udev_device_get_syspath(udev)); + wl_list_init(&wlr_tablet_pad->groups); int groups = libinput_device_tablet_pad_get_num_mode_groups(libinput_dev); for (int i = 0; i < groups; ++i) { add_pad_group_from_libinput(wlr_tablet_pad, libinput_dev, i); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 6c48dcf0..f69e41f8 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -64,30 +64,32 @@ void wlr_libinput_tablet_tool_destroy(struct wlr_input_device *wlr_dev) { struct tablet_tool_list_elem *pos; struct tablet_tool_list_elem *tmp; wl_list_for_each_safe(pos, tmp, &tablet->tools, link) { - wl_list_remove(&pos->link); struct wlr_libinput_tablet_tool *tool = pos->tool; + wl_list_remove(&pos->link); + free(pos); if (--tool->pad_refs == 0) { destroy_tool_tool(tool); } - - free(pos); } } struct wlr_tablet_tool *libinput_tablet_tool_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - struct wlr_tablet_tool *wlr_tablet_tool = calloc(1, sizeof(struct wlr_tablet_tool)); + struct wlr_libinput_tablet *libinput_tablet_tool = + calloc(1, sizeof(struct wlr_libinput_tablet)); + struct wlr_tablet_tool *wlr_tablet_tool = &libinput_tablet_tool->wlr_tool; if (!wlr_tablet_tool) { wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_tool"); return NULL; } + wl_list_init(&wlr_tablet_tool->paths); struct udev_device *udev = libinput_device_get_udev_device(libinput_dev); add_tablet_path(&wlr_tablet_tool->paths, udev_device_get_syspath(udev)); wlr_tablet_tool->name = strdup(libinput_device_get_name(libinput_dev)); - + wl_list_init(&libinput_tablet_tool->tools); wlr_tablet_tool_init(wlr_tablet_tool, NULL); return wlr_tablet_tool; |