[PATCH v2 5/6] libweston: fbdev: Attempt to detect the first framebuffer device in the seat. instead of defaulting to /dev/fb0

nerdopolis bluescreen_avenger at verizon.net
Wed Oct 4 02:28:37 UTC 2017


This adds a function to detect the first framebuffer device in the
current seat. Instead of hardcoding /dev/fb0, use udev to find the
first framebuffer device in the seat.
---
 libweston/compositor-fbdev.c | 45 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor-fbdev.c b/libweston/compositor-fbdev.c
index da841b7c..3d57ce61 100644
--- a/libweston/compositor-fbdev.c
+++ b/libweston/compositor-fbdev.c
@@ -727,6 +727,42 @@ fbdev_restore(struct weston_compositor *compositor)
 	weston_launcher_restore(compositor->launcher);
 }
 
+static char *
+find_framebuffer_device(struct fbdev_backend *b, const char *seat)
+{
+	struct udev_enumerate *e;
+	struct udev_list_entry *entry;
+	const char *path, *device_seat;
+	char *fb_device;
+	struct udev_device *device;
+
+	e = udev_enumerate_new(b->udev);
+	udev_enumerate_add_match_subsystem(e, "graphics");
+	udev_enumerate_add_match_sysname(e, "fb[0-9]*");
+
+	udev_enumerate_scan_devices(e);
+	fb_device = NULL;
+	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+
+		path = udev_list_entry_get_name(entry);
+		device = udev_device_new_from_syspath(b->udev, path);
+		if (!device)
+			continue;
+		device_seat = udev_device_get_property_value(device, "ID_SEAT");
+		if (!device_seat)
+			device_seat = default_seat;
+		if (!strcmp(device_seat, seat)) {
+			fb_device = udev_device_get_devnode(device);
+			udev_enumerate_unref(e);
+			break;
+		}
+		udev_device_unref(device);
+	}
+
+	udev_enumerate_unref(e);
+	return fb_device;
+}
+
 static struct fbdev_backend *
 fbdev_backend_create(struct weston_compositor *compositor,
                      struct weston_fbdev_backend_config *param)
@@ -758,6 +794,11 @@ fbdev_backend_create(struct weston_compositor *compositor,
 		goto out_compositor;
 	}
 
+	if (!param->device)
+		find_framebuffer_device(backend, seat_id);
+	if (!param->device)
+		param->device=strdup("/dev/fb0");
+
 	/* Set up the TTY. */
 	backend->session_listener.notify = session_notify;
 	wl_signal_add(&compositor->session_signal,
@@ -805,10 +846,8 @@ out_compositor:
 static void
 config_init_to_defaults(struct weston_fbdev_backend_config *config)
 {
-	/* TODO: Ideally, available frame buffers should be enumerated using
-	 * udev, rather than passing a device node in as a parameter. */
 	config->tty = 0; /* default to current tty */
-	config->device = "/dev/fb0"; /* default frame buffer */
+	config->device = NULL;
 	config->seat_id = NULL;
 }
 
-- 
2.14.1



More information about the wayland-devel mailing list