Replace list_t with wl_list for wlr_input_device

Signed-off-by: Heghedus Razvan <heghedus.razvan@gmail.com>
This commit is contained in:
Heghedus Razvan 2017-10-14 19:17:43 +03:00
parent 1d716241af
commit e1f196a3e9
5 changed files with 25 additions and 21 deletions

View File

@ -153,7 +153,6 @@ error_event:
wl_event_source_remove(drm->drm_event); wl_event_source_remove(drm->drm_event);
error_fd: error_fd:
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(drm->session, drm->fd);
error_backend:
free(drm); free(drm);
return NULL; return NULL;
} }

View File

@ -3,19 +3,19 @@
#include <libinput.h> #include <libinput.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/util/list.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wayland-util.h>
#include "backend/libinput.h" #include "backend/libinput.h"
struct wlr_input_device *get_appropriate_device( struct wlr_input_device *get_appropriate_device(
enum wlr_input_device_type desired_type, enum wlr_input_device_type desired_type,
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
list_t *wlr_devices = libinput_device_get_user_data(libinput_dev); struct wl_list *wlr_devices = libinput_device_get_user_data(libinput_dev);
if (!wlr_devices) { if (!wlr_devices) {
return NULL; return NULL;
} }
for (size_t i = 0; i < wlr_devices->length; ++i) { struct wlr_input_device *dev;
struct wlr_input_device *dev = wlr_devices->items[i]; wl_list_for_each(dev, wlr_devices, link) {
if (dev->type == desired_type) { if (dev->type == desired_type) {
return dev; return dev;
} }
@ -35,7 +35,7 @@ static struct wlr_input_device_impl input_device_impl = {
static struct wlr_input_device *allocate_device( static struct wlr_input_device *allocate_device(
struct wlr_libinput_backend *backend, struct libinput_device *libinput_dev, struct wlr_libinput_backend *backend, struct libinput_device *libinput_dev,
list_t *wlr_devices, enum wlr_input_device_type type) { struct wl_list *wlr_devices, enum wlr_input_device_type type) {
int vendor = libinput_device_get_id_vendor(libinput_dev); int vendor = libinput_device_get_id_vendor(libinput_dev);
int product = libinput_device_get_id_product(libinput_dev); int product = libinput_device_get_id_product(libinput_dev);
const char *name = libinput_device_get_name(libinput_dev); const char *name = libinput_device_get_name(libinput_dev);
@ -44,10 +44,7 @@ static struct wlr_input_device *allocate_device(
return NULL; return NULL;
} }
struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device; struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device;
if (list_add(wlr_devices, wlr_dev) == -1) { wl_list_insert(wlr_devices, &wlr_dev->link);
free(wlr_libinput_dev);
return NULL;
}
wlr_libinput_dev->handle = libinput_dev; wlr_libinput_dev->handle = libinput_dev;
libinput_device_ref(libinput_dev); libinput_device_ref(libinput_dev);
wlr_input_device_init(wlr_dev, type, &input_device_impl, wlr_input_device_init(wlr_dev, type, &input_device_impl,
@ -67,7 +64,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
int vendor = libinput_device_get_id_vendor(libinput_dev); int vendor = libinput_device_get_id_vendor(libinput_dev);
int product = libinput_device_get_id_product(libinput_dev); int product = libinput_device_get_id_product(libinput_dev);
const char *name = libinput_device_get_name(libinput_dev); const char *name = libinput_device_get_name(libinput_dev);
list_t *wlr_devices = list_create(); struct wl_list *wlr_devices = calloc(1, sizeof(struct wl_list));
wl_list_init(wlr_devices);
if (!wlr_devices) { if (!wlr_devices) {
goto fail; goto fail;
} }
@ -145,23 +143,26 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
// TODO // TODO
} }
if (wlr_devices->length > 0) { if (wl_list_length(wlr_devices) > 0) {
libinput_device_set_user_data(libinput_dev, wlr_devices); libinput_device_set_user_data(libinput_dev, wlr_devices);
list_add(backend->wlr_device_lists, wlr_devices); list_add(backend->wlr_device_lists, wlr_devices);
} else { } else {
list_free(wlr_devices); free(wlr_devices);
} }
return; return;
fail: fail:
wlr_log(L_ERROR, "Could not allocate new device"); wlr_log(L_ERROR, "Could not allocate new device");
list_foreach(wlr_devices, free); struct wlr_input_device *dev, *tmp_dev;
list_free(wlr_devices); wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) {
free(dev);
}
free(wlr_devices);
} }
static void handle_device_removed(struct wlr_libinput_backend *backend, static void handle_device_removed(struct wlr_libinput_backend *backend,
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
list_t *wlr_devices = libinput_device_get_user_data(libinput_dev); struct wl_list *wlr_devices = libinput_device_get_user_data(libinput_dev);
int vendor = libinput_device_get_id_vendor(libinput_dev); int vendor = libinput_device_get_id_vendor(libinput_dev);
int product = libinput_device_get_id_product(libinput_dev); int product = libinput_device_get_id_product(libinput_dev);
const char *name = libinput_device_get_name(libinput_dev); const char *name = libinput_device_get_name(libinput_dev);
@ -169,10 +170,10 @@ static void handle_device_removed(struct wlr_libinput_backend *backend,
if (!wlr_devices) { if (!wlr_devices) {
return; return;
} }
for (size_t i = 0; i < wlr_devices->length; i++) { struct wlr_input_device *dev, *tmp_dev;
struct wlr_input_device *wlr_dev = wlr_devices->items[i]; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) {
wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wl_signal_emit(&backend->backend.events.input_remove, dev);
wlr_input_device_destroy(wlr_dev); wlr_input_device_destroy(dev);
} }
for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { for (size_t i = 0; i < backend->wlr_device_lists->length; i++) {
if (backend->wlr_device_lists->items[i] == wlr_devices) { if (backend->wlr_device_lists->items[i] == wlr_devices) {
@ -180,7 +181,7 @@ static void handle_device_removed(struct wlr_libinput_backend *backend,
break; break;
} }
} }
list_free(wlr_devices); free(wlr_devices);
} }
void wlr_libinput_event(struct wlr_libinput_backend *backend, void wlr_libinput_event(struct wlr_libinput_backend *backend,

View File

@ -21,6 +21,7 @@
#include <wlr/xcursor.h> #include <wlr/xcursor.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/list.h>
#include "shared.h" #include "shared.h"
#include "config.h" #include "config.h"
#include "cat.h" #include "cat.h"

View File

@ -45,6 +45,8 @@ struct wlr_input_device {
} events; } events;
void *data; void *data;
struct wl_list link;
}; };
#endif #endif

View File

@ -5,6 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <wlr/util/list.h>
#ifdef HAS_XCB_ICCCM #ifdef HAS_XCB_ICCCM
#include <xcb/xcb_icccm.h> #include <xcb/xcb_icccm.h>