From: Duna Oh Date: Mon, 18 Apr 2016 13:56:59 +0000 (+0900) Subject: Add a device only when the device is not created by libinput_path X-Git-Tag: submit/tizen/20171107.103302~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19a8aa65d0bf0a452daf926d060d933a935cc39c;p=platform%2Fupstream%2Flibinput.git Add a device only when the device is not created by libinput_path Signed-off-by: Duna Oh Change-Id: Ic9d444cbf0d8ab95293e3770a91e31e83f405d60 --- diff --git a/src/libinput-private.h b/src/libinput-private.h index 7b1d385c..0fd0772e 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -398,6 +398,11 @@ struct libinput_event_listener { void *notify_func_data; }; +struct device_node { + struct list link; + char *devname; +}; + typedef void (*libinput_source_dispatch_t)(void *data); #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) @@ -806,4 +811,7 @@ device_float_get_direction(struct device_float_coords coords) { return xy_get_direction(coords.x, coords.y); } + +struct list * +libinput_path_get_devices(void); #endif /* LIBINPUT_PRIVATE_H */ diff --git a/src/path-seat.c b/src/path-seat.c index f5e1af9f..1a0235d7 100644 --- a/src/path-seat.c +++ b/src/path-seat.c @@ -34,6 +34,7 @@ static const char default_seat[] = "seat0"; static const char default_seat_name[] = "default"; +static struct list devices_list; static void path_disable_device(struct libinput *libinput, @@ -206,6 +207,7 @@ path_input_destroy(struct libinput *input) { struct path_input *path_input = (struct path_input*)input; struct path_device *dev, *tmp; + struct device_node *dev_node, *tmp_node; udev_unref(path_input->udev); @@ -214,6 +216,10 @@ path_input_destroy(struct libinput *input) free(dev); } + list_for_each_safe(dev_node, tmp_node, &devices_list, link) { + free(dev_node->devname); + free(dev_node); + } } static struct libinput_device * @@ -224,6 +230,8 @@ path_create_device(struct libinput *libinput, struct path_input *input = (struct path_input*)libinput; struct path_device *dev; struct libinput_device *device; + struct device_node *dev_node; + const char *name; dev = zalloc(sizeof *dev); if (!dev) @@ -233,6 +241,18 @@ path_create_device(struct libinput *libinput, list_insert(&input->path_list, &dev->link); + name = udev_device_get_devnode(udev_device); + if (name) + { + dev_node = zalloc(sizeof *dev_node); + if (dev_node) + { + dev_node->devname = strdup(name); + if (dev_node->devname) + list_insert(&devices_list, &dev_node->link); + } + } + device = path_device_enable(input, udev_device, seat_name); if (!device) { @@ -296,6 +316,8 @@ libinput_path_create_context(const struct libinput_interface *interface, input->udev = udev; list_init(&input->path_list); + list_init(&devices_list); + return &input->base; } @@ -368,6 +390,7 @@ libinput_path_remove_device(struct libinput_device *device) struct libinput_seat *seat; struct evdev_device *evdev = evdev_device(device); struct path_device *dev; + struct device_node *dev_node; if (libinput->interface_backend != &interface_backend) { log_bug_client(libinput, "Mismatching backends.\n"); @@ -383,8 +406,23 @@ libinput_path_remove_device(struct libinput_device *device) } } + list_for_each(dev_node, &devices_list, link) { + if (strcmp(dev_node->devname, udev_device_get_devnode(evdev->udev_device)) == 0) { + list_remove(&dev_node->link); + free(dev_node->devname); + free(dev_node); + break; + } + } + seat = device->seat; libinput_seat_ref(seat); path_disable_device(libinput, evdev); libinput_seat_unref(seat); } + +struct list * +libinput_path_get_devices(void) +{ + return &devices_list; +} diff --git a/src/udev-seat.c b/src/udev-seat.c index 685b4486..75cbb6b2 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -43,6 +43,26 @@ udev_seat_create(struct udev_input *input, static struct udev_seat * udev_seat_get_named(struct udev_input *input, const char *seat_name); +static bool +libinput_path_has_device(struct libinput *libinput, const char *devnode) +{ + struct device_node *dev; + struct list *dev_list; + + if (!devnode) return false; + dev_list = libinput_path_get_devices(); + if (dev_list->prev == NULL && dev_list->next == NULL) return false; + + list_for_each(dev, dev_list, link) { + const char *name = dev->devname; + if (!name) break; + if (strcmp(name, devnode) == 0) + return true; + } + + return false; +} + static int device_added(struct udev_device *udev_device, struct udev_input *input, @@ -82,6 +102,11 @@ device_added(struct udev_device *udev_device, return -1; } + if (libinput_path_has_device(&input->base, devnode)) + { + log_info(&input->base, "libinput_path already created input device '%s.\n", devnode); + return 0; + } device = evdev_device_create(&seat->base, udev_device); libinput_seat_unref(&seat->base); @@ -233,7 +258,16 @@ udev_input_enable(struct libinput *libinput) if (input->udev_monitor) return 0; - input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); + char *env; + + if ((env = getenv("UDEV_MONITOR_EVENT_SOURCE"))) + { + log_info(libinput, "udev: event source is %s.\n", env); + input->udev_monitor = udev_monitor_new_from_netlink(udev, env); + } + else + input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); + if (!input->udev_monitor) { log_info(libinput, "udev: failed to create the udev monitor\n");