[PATCH weston] Assign any output to a seat if it doesn't have one

Neil Roberts neil at linux.intel.com
Wed Apr 23 07:32:15 PDT 2014


Commit 4ade0e4a29 changed the order of initialising the seats and outputs so
that the seats would be done before the outputs. However the device_added
function in libinput-seat and udev-seat which gets called during initialisation
was trying to use the output list to assign an output to the device. If the
device doesn't have an output name associated with it then it would just use
the first output in the list. At this point during the initialisation the
output list is empty so it would actually end up with a garbage pointer and it
would later crash when a touch event tries to access the details of the output.

This patch changes it to only assign an output to the device if the output list
is not empty. That way the device's output will remain NULL during the
initialisation. It now also assigns the first output that is created to the
device during notify_output_create if it does not already have an output. If a
later output is created which matches the device's output name then that will
replace the selected output as before.
---
 src/libinput-seat.c | 10 ++++++----
 src/udev-seat.c     | 10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/libinput-seat.c b/src/libinput-seat.c
index 8bf538c..bea8f6e 100644
--- a/src/libinput-seat.c
+++ b/src/libinput-seat.c
@@ -86,7 +86,7 @@ device_added(struct udev_input *input, struct libinput_device *libinput_device)
 				evdev_device_set_output(device, output);
 	}
 
-	if (device->output == NULL) {
+	if (device->output == NULL && !wl_list_empty(&c->output_list)) {
 		output = container_of(c->output_list.next,
 				      struct weston_output, link);
 		evdev_device_set_output(device, output);
@@ -316,11 +316,13 @@ notify_output_create(struct wl_listener *listener, void *data)
 	struct evdev_device *device;
 	struct weston_output *output = data;
 
-	wl_list_for_each(device, &seat->devices_list, link)
-		if (device->output_name &&
-		    strcmp(output->name, device->output_name) == 0) {
+	wl_list_for_each(device, &seat->devices_list, link) {
+		if (device->output == NULL ||
+		    (device->output_name &&
+		     strcmp(output->name, device->output_name) == 0)) {
 			evdev_device_set_output(device, output);
 		}
+	}
 }
 
 static struct udev_seat *
diff --git a/src/udev-seat.c b/src/udev-seat.c
index 5e018de..853a15c 100644
--- a/src/udev-seat.c
+++ b/src/udev-seat.c
@@ -127,7 +127,7 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
 				evdev_device_set_output(device, output);
 	}
 
-	if (device->output == NULL) {
+	if (device->output == NULL && !wl_list_empty(&c->output_list)) {
 		output = container_of(c->output_list.next,
 				      struct weston_output, link);
 		evdev_device_set_output(device, output);
@@ -359,11 +359,13 @@ notify_output_create(struct wl_listener *listener, void *data)
 	struct evdev_device *device;
 	struct weston_output *output = data;
 
-	wl_list_for_each(device, &seat->devices_list, link)
-		if (device->output_name &&
-		    strcmp(output->name, device->output_name) == 0) {
+	wl_list_for_each(device, &seat->devices_list, link) {
+		if (device->output == NULL ||
+		    (device->output_name &&
+		     strcmp(output->name, device->output_name) == 0)) {
 			evdev_device_set_output(device, output);
 		}
+	}
 }
 
 static struct udev_seat *
-- 
1.9.0



More information about the wayland-devel mailing list