[PATCH weston 13/17] evdev: log input devices

Pekka Paalanen ppaalanen at gmail.com
Thu Jul 5 03:33:10 PDT 2012


Write information about found input devices into the log. Also fetch and
record the device name.

Print a note, when a device is removed via udev.

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 src/evdev.c      |   26 ++++++++++++++++++++++----
 src/evdev.h      |    1 +
 src/udev-evdev.c |    4 ++++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index 3379227..bbdbf6a 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -461,16 +461,29 @@ evdev_configure_device(struct evdev_input_device *device)
 	/* This rule tries to catch accelerometer devices and opt out. We may
 	 * want to adjust the protocol later adding a proper event for dealing
 	 * with accelerometers and implement here accordingly */
-	if (has_abs && !has_key && !device->is_mt)
+	if (has_abs && !has_key && !device->is_mt) {
+		weston_log("input device %s, %s "
+			   "ignored: unsupported device type\n",
+			   device->devname, device->devnode);
 		return -1;
+	}
 
 	if ((device->caps &
-	     (EVDEV_MOTION_ABS | EVDEV_MOTION_REL | EVDEV_BUTTON)))
+	     (EVDEV_MOTION_ABS | EVDEV_MOTION_REL | EVDEV_BUTTON))) {
 		weston_seat_init_pointer(&device->master->base);
-	if ((device->caps & EVDEV_KEYBOARD))
+		weston_log("input device %s, %s is a pointer\n",
+			   device->devname, device->devnode);
+	}
+	if ((device->caps & EVDEV_KEYBOARD)) {
 		weston_seat_init_keyboard(&device->master->base, NULL);
-	if ((device->caps & EVDEV_TOUCH))
+		weston_log("input device %s, %s is a keyboard\n",
+			   device->devname, device->devnode);
+	}
+	if ((device->caps & EVDEV_TOUCH)) {
 		weston_seat_init_touch(&device->master->base);
+		weston_log("input device %s, %s is a touch device\n",
+			   device->devname, device->devnode);
+	}
 
 	return 0;
 }
@@ -481,6 +494,7 @@ evdev_input_device_create(struct evdev_seat *master,
 {
 	struct evdev_input_device *device;
 	struct weston_compositor *ec;
+	char devname[256] = "unknown";
 
 	device = malloc(sizeof *device);
 	if (device == NULL)
@@ -500,6 +514,9 @@ evdev_input_device_create(struct evdev_seat *master,
 	device->dispatch = NULL;
 	device->fd = device_fd;
 
+	ioctl(device->fd, EVIOCGNAME(sizeof(devname)), devname);
+	device->devname = strdup(devname);
+
 	if (evdev_configure_device(device) == -1)
 		goto err1;
 
@@ -529,6 +546,7 @@ evdev_input_device_create(struct evdev_seat *master,
 err2:
 	device->dispatch->interface->destroy(device->dispatch);
 err1:
+	free(device->devname);
 	free(device->devnode);
 	free(device);
 	return NULL;
diff --git a/src/evdev.h b/src/evdev.h
index 8fe3eb8..b82ea36 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -57,6 +57,7 @@ struct evdev_input_device {
 	struct weston_output *output;
 	struct evdev_dispatch *dispatch;
 	char *devnode;
+	char *devname;
 	int fd;
 	struct {
 		int min_x, max_x, min_y, max_y;
diff --git a/src/udev-evdev.c b/src/udev-evdev.c
index 01b2509..7fa4885 100644
--- a/src/udev-evdev.c
+++ b/src/udev-evdev.c
@@ -91,6 +91,7 @@ device_removed(struct evdev_input_device *device)
 	if (device->mtdev)
 		mtdev_close_delete(device->mtdev);
 	close(device->fd);
+	free(device->devname);
 	free(device->devnode);
 	free(device);
 }
@@ -163,6 +164,9 @@ evdev_udev_handler(int fd, uint32_t mask, void *data)
 					      &master->evdev.devices_list,
 					      link)
 				if (!strcmp(device->devnode, devnode)) {
+					weston_log("input device %s, %s removed\n",
+						   device->devname,
+						   device->devnode);
 					device_removed(device);
 					break;
 				}
-- 
1.7.8.6



More information about the wayland-devel mailing list