diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-08-26 08:22:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-26 08:22:44 -0500 |
commit | 2f5ff450397714674aec9ffc09ba86989382fcfe (patch) | |
tree | e52174f40cec92e47546011d20300171424467a3 /backend/session/logind.c | |
parent | 48fa59c22e0b49bc347006738cc5dda9c6d13821 (diff) | |
parent | d16b2977f6b156e5b3a4ceb028cfbe70b9a350c1 (diff) |
Merge pull request #123 from ascent12/session-multi-gpu
Session Multi-GPU
Diffstat (limited to 'backend/session/logind.c')
-rw-r--r-- | backend/session/logind.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/backend/session/logind.c b/backend/session/logind.c index 20d9b5ed..3b237360 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -1,4 +1,5 @@ #define _POSIX_C_SOURCE 200809L +#include <assert.h> #include <stdio.h> #include <stdbool.h> #include <stdlib.h> @@ -67,10 +68,6 @@ static int logind_take_device(struct wlr_session *base, const char *path) { goto error; } - if (major(st.st_rdev) == DRM_MAJOR) { - session->base.drm_fd = fd; - } - error: sd_bus_error_free(&error); sd_bus_message_unref(msg); @@ -97,10 +94,6 @@ static void logind_release_device(struct wlr_session *base, int fd) { wlr_log(L_ERROR, "Failed to release device '%d'", fd); } - if (major(st.st_rdev) == DRM_MAJOR) { - session->base.drm_fd = -1; - } - sd_bus_error_free(&error); sd_bus_message_unref(msg); } @@ -204,7 +197,7 @@ static void release_control(struct logind_session *session) { sd_bus_message_unref(msg); } -static void logind_session_finish(struct wlr_session *base) { +static void logind_session_destroy(struct wlr_session *base) { struct logind_session *session = wl_container_of(base, session, base); release_control(session); @@ -221,6 +214,20 @@ static int session_removed(sd_bus_message *msg, void *userdata, sd_bus_error *re return 0; } +static struct wlr_device *find_device(struct wlr_session *session, dev_t devnum) { + struct wlr_device *dev; + + wl_list_for_each(dev, &session->devices, link) { + if (dev->dev == devnum) { + return dev; + } + } + + wlr_log(L_ERROR, "Tried to use dev_t %lu not opened by session", + (unsigned long)devnum); + assert(0); +} + static int pause_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) { struct logind_session *session = userdata; int ret; @@ -267,9 +274,13 @@ static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_ } if (major == DRM_MAJOR) { - dup2(fd, session->base.drm_fd); - session->base.active = true; - wl_signal_emit(&session->base.session_signal, session); + struct wlr_device *dev = find_device(&session->base, makedev(major, minor)); + dup2(fd, dev->fd); + + if (!session->base.active) { + session->base.active = true; + wl_signal_emit(&session->base.session_signal, session); + } } error: @@ -316,7 +327,7 @@ static int dbus_event(int fd, uint32_t mask, void *data) { return 1; } -static struct wlr_session *logind_session_start(struct wl_display *disp) { +static struct wlr_session *logind_session_create(struct wl_display *disp) { int ret; struct logind_session *session = calloc(1, sizeof(*session)); if (!session) { @@ -374,10 +385,7 @@ static struct wlr_session *logind_session_start(struct wl_display *disp) { wlr_log(L_INFO, "Successfully loaded logind session"); - session->base.drm_fd = -1; session->base.impl = &session_logind; - session->base.active = true; - wl_signal_init(&session->base.session_signal); return &session->base; error_bus: @@ -390,8 +398,8 @@ error: } const struct session_impl session_logind = { - .start = logind_session_start, - .finish = logind_session_finish, + .create = logind_session_create, + .destroy = logind_session_destroy, .open = logind_take_device, .close = logind_release_device, .change_vt = logind_change_vt, |