diff options
author | Simon Ser <contact@emersion.fr> | 2020-11-06 10:56:13 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-11-19 22:47:49 +0100 |
commit | 76bcddf071454cd373bd09e2619c0cb03a377350 (patch) | |
tree | 6b56079cb518e660fbd25ecd102c10103cc83a90 | |
parent | 768fbaad54027f8dd027e7e015e8eeb93cb38c52 (diff) |
backend/session: introduce wlr_session.events.add_drm_card
This is triggered when a new DRM card is added.
An easy way to test this patch is `modprobe vkms`.
-rw-r--r-- | backend/session/session.c | 33 | ||||
-rw-r--r-- | include/wlr/backend/session.h | 5 |
2 files changed, 31 insertions, 7 deletions
diff --git a/backend/session/session.c b/backend/session/session.c index b96f4294..a94793c8 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -55,19 +55,37 @@ static int udev_event(int fd, uint32_t mask, void *data) { } const char *sysname = udev_device_get_sysname(udev_dev); + const char *devnode = udev_device_get_devnode(udev_dev); const char *action = udev_device_get_action(udev_dev); wlr_log(WLR_DEBUG, "udev event for %s (%s)", sysname, action); - if (!is_drm_card(sysname) || !action || strcmp(action, "change") != 0) { + if (!is_drm_card(sysname) || !action || !devnode) { goto out; } - dev_t devnum = udev_device_get_devnum(udev_dev); - struct wlr_device *dev; - wl_list_for_each(dev, &session->devices, link) { - if (dev->dev == devnum) { - wlr_signal_emit_safe(&dev->events.change, NULL); - break; + const char *seat = udev_device_get_property_value(udev_dev, "ID_SEAT"); + if (!seat) { + seat = "seat0"; + } + if (session->seat[0] != '\0' && strcmp(session->seat, seat) != 0) { + goto out; + } + + if (strcmp(action, "add") == 0) { + wlr_log(WLR_DEBUG, "DRM device %s added", sysname); + struct wlr_session_add_event event = { + .path = devnode, + }; + wlr_signal_emit_safe(&session->events.add_drm_card, &event); + } else if (strcmp(action, "change") == 0) { + dev_t devnum = udev_device_get_devnum(udev_dev); + struct wlr_device *dev; + wl_list_for_each(dev, &session->devices, link) { + if (dev->dev == devnum) { + wlr_log(WLR_DEBUG, "DRM device %s changed", sysname); + wlr_signal_emit_safe(&dev->events.change, NULL); + break; + } } } @@ -84,6 +102,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { void session_init(struct wlr_session *session) { wl_signal_init(&session->session_signal); + wl_signal_init(&session->events.add_drm_card); wl_signal_init(&session->events.destroy); wl_list_init(&session->devices); } diff --git a/include/wlr/backend/session.h b/include/wlr/backend/session.h index 82f22a3f..b63c356c 100644 --- a/include/wlr/backend/session.h +++ b/include/wlr/backend/session.h @@ -43,10 +43,15 @@ struct wlr_session { struct wl_listener display_destroy; struct { + struct wl_signal add_drm_card; // struct wlr_session_add_event struct wl_signal destroy; } events; }; +struct wlr_session_add_event { + const char *path; +}; + /* * Opens a session, taking control of the current virtual terminal. * This should not be called if another program is already in control |