[PATCH 2/6] evdev: use a separate function for adding devices

Tiago Vignatti vignatti at freedesktop.org
Mon Dec 19 02:30:24 PST 2011


From: Tiago Vignatti <tiago.vignatti at intel.com>

Adds new function evdev_add_devices for adding udev devices. No
functional changes.

Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 compositor/evdev.c |   46 +++++++++++++++++++++++++++-------------------
 1 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/compositor/evdev.c b/compositor/evdev.c
index 83812bf..43776c8 100644
--- a/compositor/evdev.c
+++ b/compositor/evdev.c
@@ -434,6 +434,32 @@ device_removed(struct udev_device *udev_device, struct evdev_input *master)
 	fprintf(stderr, "evdev input device: removed: %s\n", devnode);
 }
 
+static void
+evdev_add_devices(struct udev *udev, struct wlsc_input_device *input_base)
+{
+	struct evdev_input *input = (struct evdev_input *) input_base;
+	struct udev_enumerate *e;
+	struct udev_list_entry *entry;
+	struct udev_device *device;
+	const char *path;
+
+	e = udev_enumerate_new(udev);
+	udev_enumerate_add_match_subsystem(e, "input");
+	udev_enumerate_scan_devices(e);
+	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+		path = udev_list_entry_get_name(entry);
+		device = udev_device_new_from_syspath(udev, path);
+
+		if (strncmp("event", udev_device_get_sysname(device), 5) != 0)
+			continue;
+
+		device_added(device, input);
+
+		udev_device_unref(device);
+	}
+	udev_enumerate_unref(e);
+}
+
 static int
 evdev_udev_handler(int fd, uint32_t mask, void *data)
 {
@@ -491,10 +517,6 @@ evdev_input_add_devices(struct wlsc_compositor *c,
 			struct udev *udev, const char *seat)
 {
 	struct evdev_input *input;
-	struct udev_enumerate *e;
-	struct udev_list_entry *entry;
-	struct udev_device *device;
-	const char *path;
 
 	input = malloc(sizeof *input);
 	if (input == NULL)
@@ -511,21 +533,7 @@ evdev_input_add_devices(struct wlsc_compositor *c,
 		return;
 	}
 
-	e = udev_enumerate_new(udev);
-	udev_enumerate_add_match_subsystem(e, "input");
-	udev_enumerate_scan_devices(e);
-	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
-		path = udev_list_entry_get_name(entry);
-		device = udev_device_new_from_syspath(udev, path);
-
-		if (strncmp("event", udev_device_get_sysname(device), 5) != 0)
-			continue;
-
-		device_added(device, input);
-
-		udev_device_unref(device);
-	}
-	udev_enumerate_unref(e);
+	evdev_add_devices(udev, &input->base);
 
 	c->input_device = &input->base.input_device;
 }
-- 
1.7.5.4



More information about the wayland-devel mailing list