aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/drm/legacy.c5
-rw-r--r--backend/session/direct-freebsd.c50
-rw-r--r--backend/session/direct-ipc.c24
-rw-r--r--rootston/seat.c6
4 files changed, 66 insertions, 19 deletions
diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c
index d27cf137..c205e167 100644
--- a/backend/drm/legacy.c
+++ b/backend/drm/legacy.c
@@ -39,7 +39,10 @@ bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm,
}
if (!bo) {
- drmModeSetCursor(drm->fd, crtc->id, 0, 0, 0);
+ if (drmModeSetCursor(drm->fd, crtc->id, 0, 0, 0)) {
+ wlr_log_errno(WLR_DEBUG, "Failed to clear hardware cursor");
+ return false;
+ }
return true;
}
diff --git a/backend/session/direct-freebsd.c b/backend/session/direct-freebsd.c
index 63e1be01..cecfb0c1 100644
--- a/backend/session/direct-freebsd.c
+++ b/backend/session/direct-freebsd.c
@@ -15,6 +15,7 @@
#include <wayland-server.h>
#include <wlr/backend/session/interface.h>
#include <wlr/util/log.h>
+#include <xf86drm.h>
#include "backend/session/direct-ipc.h"
#include "util/signal.h"
@@ -23,6 +24,7 @@ const struct session_impl session_direct;
struct direct_session {
struct wlr_session base;
int tty_fd;
+ int old_tty;
int old_kbmode;
int sock;
pid_t child;
@@ -40,23 +42,18 @@ static int direct_session_open(struct wlr_session *base, const char *path) {
return fd;
}
- struct stat st;
- if (fstat(fd, &st) < 0) {
- close(fd);
- return -errno;
- }
-
return fd;
}
static void direct_session_close(struct wlr_session *base, int fd) {
struct direct_session *session = wl_container_of(base, session, base);
- struct stat st;
- if (fstat(fd, &st) < 0) {
- wlr_log_errno(WLR_ERROR, "Stat failed");
- close(fd);
- return;
+ int ev;
+ struct drm_version dv = {0};
+ if (ioctl(fd, DRM_IOCTL_VERSION, &dv) == 0) {
+ direct_ipc_dropmaster(session->sock, fd);
+ } else if (ioctl(fd, EVIOCGVERSION, &ev) == 0) {
+ ioctl(fd, EVIOCREVOKE, 0);
}
close(fd);
@@ -79,6 +76,8 @@ static void direct_session_destroy(struct wlr_session *base) {
ioctl(session->tty_fd, KDSETMODE, KD_TEXT);
ioctl(session->tty_fd, VT_SETMODE, &mode);
+ ioctl(session->tty_fd, VT_ACTIVATE, session->old_tty);
+
if (errno) {
wlr_log(WLR_ERROR, "Failed to restore tty");
}
@@ -93,13 +92,29 @@ static void direct_session_destroy(struct wlr_session *base) {
static int vt_handler(int signo, void *data) {
struct direct_session *session = data;
+ struct drm_version dv = {0};
+ struct wlr_device *dev;
if (session->base.active) {
session->base.active = false;
wlr_signal_emit_safe(&session->base.session_signal, session);
+
+ wl_list_for_each(dev, &session->base.devices, link) {
+ if (ioctl(dev->fd, DRM_IOCTL_VERSION, &dv) == 0) {
+ direct_ipc_dropmaster(session->sock, dev->fd);
+ }
+ }
+
ioctl(session->tty_fd, VT_RELDISP, 1);
} else {
ioctl(session->tty_fd, VT_RELDISP, VT_ACKACQ);
+
+ wl_list_for_each(dev, &session->base.devices, link) {
+ if (ioctl(dev->fd, DRM_IOCTL_VERSION, &dv) == 0) {
+ direct_ipc_setmaster(session->sock, dev->fd);
+ }
+ }
+
session->base.active = true;
wlr_signal_emit_safe(&session->base.session_signal, session);
}
@@ -108,11 +123,15 @@ static int vt_handler(int signo, void *data) {
}
static bool setup_tty(struct direct_session *session, struct wl_display *display) {
- int fd = -1, tty = -1, tty0_fd = -1;
+ int fd = -1, tty = -1, tty0_fd = -1, old_tty = 1;
if ((tty0_fd = open("/dev/ttyv0", O_RDWR | O_CLOEXEC)) < 0) {
wlr_log_errno(WLR_ERROR, "Could not open /dev/ttyv0 to find a free vt");
goto error;
}
+ if (ioctl(tty0_fd, VT_GETACTIVE, &old_tty) != 0) {
+ wlr_log_errno(WLR_ERROR, "Could not get active vt");
+ goto error;
+ }
if (ioctl(tty0_fd, VT_OPENQRY, &tty) != 0) {
wlr_log_errno(WLR_ERROR, "Could not find a free vt");
goto error;
@@ -168,13 +187,16 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
session->base.vtnr = tty;
session->tty_fd = fd;
+ session->old_tty = old_tty;
session->old_kbmode = old_kbmode;
return true;
error:
- // Drop back to tty 1, better than hanging in a useless blank console
- ioctl(fd, VT_ACTIVATE, 1);
+ // In case we could not get the last active one, drop back to tty 1,
+ // better than hanging in a useless blank console. Otherwise activate the
+ // last active.
+ ioctl(fd, VT_ACTIVATE, old_tty);
close(fd);
return false;
}
diff --git a/backend/session/direct-ipc.c b/backend/session/direct-ipc.c
index 5fdb95ac..3abce46a 100644
--- a/backend/session/direct-ipc.c
+++ b/backend/session/direct-ipc.c
@@ -1,7 +1,7 @@
#define _POSIX_C_SOURCE 200809L
#ifdef __FreeBSD__
#define __BSD_VISIBLE 1
-#define INPUT_MAJOR 0
+#include <dev/evdev/input.h>
#endif
#include <errno.h>
#include <fcntl.h>
@@ -142,6 +142,7 @@ static void communicate(int sock) {
goto error;
}
+#ifndef __FreeBSD__
struct stat st;
if (fstat(fd, &st) < 0) {
ret = errno;
@@ -157,6 +158,20 @@ static void communicate(int sock) {
if (maj == DRM_MAJOR && drmSetMaster(fd)) {
ret = errno;
}
+#else
+ int ev;
+ struct drm_version dv = {0};
+ if (ioctl(fd, EVIOCGVERSION, &ev) == -1 &&
+ ioctl(fd, DRM_IOCTL_VERSION, &dv) == -1) {
+ ret = ENOTSUP;
+ goto error;
+ }
+
+ if (dv.version_major != 0 && drmSetMaster(fd)) {
+ ret = errno;
+ }
+#endif
+
error:
send_msg(sock, ret ? -1 : fd, &ret, sizeof(ret));
if (fd >= 0) {
@@ -193,8 +208,11 @@ int direct_ipc_open(int sock, const char *path) {
send_msg(sock, -1, &msg, sizeof(msg));
- int fd, err;
- recv_msg(sock, &fd, &err, sizeof(err));
+ int fd, err, ret;
+ int retry = 0;
+ do {
+ ret = recv_msg(sock, &fd, &err, sizeof(err));
+ } while (ret == 0 && retry++ < 3);
return err ? -err : fd;
}
diff --git a/rootston/seat.c b/rootston/seat.c
index c11ff017..a8e418ca 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -745,6 +745,7 @@ static void attach_tablet_pad(struct roots_tablet_pad *pad,
pad->tablet = tool;
+ wl_list_remove(&pad->tablet_destroy.link);
pad->tablet_destroy.notify = handle_pad_tool_destroy;
wl_signal_add(&tool->device->events.destroy, &pad->tablet_destroy);
}
@@ -812,7 +813,8 @@ static void seat_add_tablet_pad(struct roots_seat *seat,
&tablet_pad->device_destroy);
tablet_pad->attach.notify = handle_tablet_pad_attach;
- wl_signal_add(&tablet_pad->device->tablet_pad->events.attach_tablet, &tablet_pad->attach);
+ wl_signal_add(&tablet_pad->device->tablet_pad->events.attach_tablet,
+ &tablet_pad->attach);
tablet_pad->button.notify = handle_tablet_pad_button;
wl_signal_add(&tablet_pad->device->tablet_pad->events.button, &tablet_pad->button);
@@ -823,6 +825,8 @@ static void seat_add_tablet_pad(struct roots_seat *seat,
tablet_pad->ring.notify = handle_tablet_pad_ring;
wl_signal_add(&tablet_pad->device->tablet_pad->events.ring, &tablet_pad->ring);
+ wl_list_init(&tablet_pad->tablet_destroy.link);
+
struct roots_desktop *desktop = seat->input->server->desktop;
tablet_pad->tablet_v2_pad =
wlr_tablet_pad_create(desktop->tablet_v2, seat->seat, device);