diff options
Diffstat (limited to 'backend/session')
-rw-r--r-- | backend/session/direct-freebsd.c | 68 | ||||
-rw-r--r-- | backend/session/direct.c | 15 | ||||
-rw-r--r-- | backend/session/logind.c | 14 |
3 files changed, 69 insertions, 28 deletions
diff --git a/backend/session/direct-freebsd.c b/backend/session/direct-freebsd.c index cecfb0c1..342d0d4e 100644 --- a/backend/session/direct-freebsd.c +++ b/backend/session/direct-freebsd.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <dev/evdev/input.h> #include <errno.h> #include <fcntl.h> @@ -32,8 +33,14 @@ struct direct_session { struct wl_event_source *vt_source; }; +static struct direct_session *direct_session_from_session( + struct wlr_session *base) { + assert(base->impl == &session_direct); + return (struct direct_session *)base; +} + static int direct_session_open(struct wlr_session *base, const char *path) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); int fd = direct_ipc_open(session->sock, path); if (fd < 0) { @@ -46,7 +53,7 @@ static int direct_session_open(struct wlr_session *base, const char *path) { } static void direct_session_close(struct wlr_session *base, int fd) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); int ev; struct drm_version dv = {0}; @@ -60,33 +67,43 @@ static void direct_session_close(struct wlr_session *base, int fd) { } static bool direct_change_vt(struct wlr_session *base, unsigned vt) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); + + // Only seat0 has VTs associated with it + if (strcmp(session->base.seat, "seat0") != 0) { + return true; + } + return ioctl(session->tty_fd, VT_ACTIVATE, (int)vt) == 0; } static void direct_session_destroy(struct wlr_session *base) { - struct direct_session *session = wl_container_of(base, session, base); - struct vt_mode mode = { - .mode = VT_AUTO, - }; + struct direct_session *session = direct_session_from_session(base); - errno = 0; + if (strcmp(session->base.seat, "seat0") == 0) { + struct vt_mode mode = { + .mode = VT_AUTO, + }; - ioctl(session->tty_fd, KDSKBMODE, session->old_kbmode); - ioctl(session->tty_fd, KDSETMODE, KD_TEXT); - ioctl(session->tty_fd, VT_SETMODE, &mode); + errno = 0; - ioctl(session->tty_fd, VT_ACTIVATE, session->old_tty); + ioctl(session->tty_fd, KDSKBMODE, session->old_kbmode); + ioctl(session->tty_fd, KDSETMODE, KD_TEXT); + ioctl(session->tty_fd, VT_SETMODE, &mode); - if (errno) { - wlr_log(WLR_ERROR, "Failed to restore tty"); + ioctl(session->tty_fd, VT_ACTIVATE, session->old_tty); + + if (errno) { + wlr_log(WLR_ERROR, "Failed to restore tty"); + } + + wl_event_source_remove(session->vt_source); + close(session->tty_fd); } direct_ipc_finish(session->sock, session->child); close(session->sock); - wl_event_source_remove(session->vt_source); - close(session->tty_fd); free(session); } @@ -157,7 +174,8 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display } if (ioctl(fd, KDSKBMODE, K_CODE)) { - wlr_log_errno(WLR_ERROR, "Failed to set keyboard mode K_CODE on tty %d", tty); + wlr_log_errno(WLR_ERROR, + "Failed to set keyboard mode K_CODE on tty %d", tty); goto error; } @@ -213,13 +231,23 @@ static struct wlr_session *direct_session_create(struct wl_display *disp) { goto error_session; } - if (!setup_tty(session, disp)) { - goto error_ipc; + const char *seat = getenv("XDG_SEAT"); + if (!seat) { + seat = "seat0"; + } + + if (strcmp(seat, "seat0") == 0) { + if (!setup_tty(session, disp)) { + goto error_ipc; + } + } else { + session->base.vtnr = 0; + session->tty_fd = -1; } wlr_log(WLR_INFO, "Successfully loaded direct session"); - snprintf(session->base.seat, sizeof(session->base.seat), "seat0"); + snprintf(session->base.seat, sizeof(session->base.seat), "%s", seat); session->base.impl = &session_direct; return &session->base; diff --git a/backend/session/direct.c b/backend/session/direct.c index ed7a0c65..0912cd58 100644 --- a/backend/session/direct.c +++ b/backend/session/direct.c @@ -1,4 +1,5 @@ #define _POSIX_C_SOURCE 200809L +#include <assert.h> #include <errno.h> #include <fcntl.h> #include <linux/input.h> @@ -33,8 +34,14 @@ struct direct_session { struct wl_event_source *vt_source; }; +static struct direct_session *direct_session_from_session( + struct wlr_session *base) { + assert(base->impl == &session_direct); + return (struct direct_session *)base; +} + static int direct_session_open(struct wlr_session *base, const char *path) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); int fd = direct_ipc_open(session->sock, path); if (fd < 0) { @@ -57,7 +64,7 @@ static int direct_session_open(struct wlr_session *base, const char *path) { } static void direct_session_close(struct wlr_session *base, int fd) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); struct stat st; if (fstat(fd, &st) < 0) { @@ -76,7 +83,7 @@ static void direct_session_close(struct wlr_session *base, int fd) { } static bool direct_change_vt(struct wlr_session *base, unsigned vt) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); // Only seat0 has VTs associated with it if (strcmp(session->base.seat, "seat0") != 0) { @@ -87,7 +94,7 @@ static bool direct_change_vt(struct wlr_session *base, unsigned vt) { } static void direct_session_destroy(struct wlr_session *base) { - struct direct_session *session = wl_container_of(base, session, base); + struct direct_session *session = direct_session_from_session(base); if (strcmp(session->base.seat, "seat0") == 0) { struct vt_mode mode = { diff --git a/backend/session/logind.c b/backend/session/logind.c index 2f816b95..39143a2f 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -37,8 +37,14 @@ struct logind_session { char *path; }; +static struct logind_session *logind_session_from_session( + struct wlr_session *base) { + assert(base->impl == &session_logind); + return (struct logind_session *)base; +} + static int logind_take_device(struct wlr_session *base, const char *path) { - struct logind_session *session = wl_container_of(base, session, base); + struct logind_session *session = logind_session_from_session(base); int ret; int fd = -1; @@ -83,7 +89,7 @@ error: } static void logind_release_device(struct wlr_session *base, int fd) { - struct logind_session *session = wl_container_of(base, session, base); + struct logind_session *session = logind_session_from_session(base); int ret; sd_bus_message *msg = NULL; @@ -108,7 +114,7 @@ static void logind_release_device(struct wlr_session *base, int fd) { } static bool logind_change_vt(struct wlr_session *base, unsigned vt) { - struct logind_session *session = wl_container_of(base, session, base); + struct logind_session *session = logind_session_from_session(base); // Only seat0 has VTs associated with it if (strcmp(session->base.seat, "seat0") != 0) { @@ -212,7 +218,7 @@ static void release_control(struct logind_session *session) { } static void logind_session_destroy(struct wlr_session *base) { - struct logind_session *session = wl_container_of(base, session, base); + struct logind_session *session = logind_session_from_session(base); release_control(session); |