aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/meson.build1
-rw-r--r--backend/session/noop.c48
-rw-r--r--backend/session/session.c30
3 files changed, 66 insertions, 13 deletions
diff --git a/backend/meson.build b/backend/meson.build
index 39769ecd..67bc1874 100644
--- a/backend/meson.build
+++ b/backend/meson.build
@@ -23,6 +23,7 @@ backend_files = files(
'noop/backend.c',
'noop/output.c',
'session/direct-ipc.c',
+ 'session/noop.c',
'session/session.c',
'wayland/backend.c',
'wayland/output.c',
diff --git a/backend/session/noop.c b/backend/session/noop.c
new file mode 100644
index 00000000..87ec1207
--- /dev/null
+++ b/backend/session/noop.c
@@ -0,0 +1,48 @@
+#define _POSIX_C_SOURCE 200809L
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <wayland-server.h>
+#include <wlr/backend/session/interface.h>
+#include <wlr/util/log.h>
+#include "util/signal.h"
+
+const struct session_impl session_noop;
+
+static int noop_session_open(struct wlr_session *base, const char *path) {
+ return open(path, O_RDWR | O_CLOEXEC);
+}
+
+static void noop_session_close(struct wlr_session *base, int fd) {
+ close(fd);
+}
+
+static bool noop_change_vt(struct wlr_session *base, unsigned vt) {
+ return false;
+}
+
+static void noop_session_destroy(struct wlr_session *base) {
+ free(base);
+}
+
+static struct wlr_session *noop_session_create(struct wl_display *disp) {
+ struct wlr_session *session = calloc(1, sizeof(*session));
+ if (!session) {
+ wlr_log_errno(WLR_ERROR, "Allocation failed");
+ return NULL;
+ }
+
+ session->impl = &session_noop;
+
+ wlr_log(WLR_INFO, "Successfully initialized noop session");
+ return session;
+}
+
+const struct session_impl session_noop = {
+ .create = noop_session_create,
+ .destroy = noop_session_destroy,
+ .open = noop_session_open,
+ .close = noop_session_close,
+ .change_vt = noop_change_vt,
+};
diff --git a/backend/session/session.c b/backend/session/session.c
index 96cde65c..90fcfed6 100644
--- a/backend/session/session.c
+++ b/backend/session/session.c
@@ -17,6 +17,7 @@
extern const struct session_impl session_logind;
extern const struct session_impl session_direct;
+extern const struct session_impl session_noop;
static const struct session_impl *impls[] = {
#if WLR_HAS_SYSTEMD || WLR_HAS_ELOGIND
@@ -69,16 +70,20 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) {
const char *env_wlr_session = getenv("WLR_SESSION");
if (env_wlr_session) {
- if (!strcmp(env_wlr_session, "logind") || !strcmp(env_wlr_session, "systemd")) {
- #if WLR_HAS_SYSTEMD || WLR_HAS_ELOGIND
+ if (strcmp(env_wlr_session, "logind") == 0 ||
+ strcmp(env_wlr_session, "systemd") == 0) {
+#if WLR_HAS_SYSTEMD || WLR_HAS_ELOGIND
session = session_logind.create(disp);
- #else
+#else
wlr_log(WLR_ERROR, "wlroots is not compiled with logind support");
- #endif
- } else if (!strcmp(env_wlr_session, "direct")) {
+#endif
+ } else if (strcmp(env_wlr_session, "direct") == 0) {
session = session_direct.create(disp);
+ } else if (strcmp(env_wlr_session, "noop") == 0) {
+ session = session_noop.create(disp);
} else {
- wlr_log(WLR_ERROR, "WLR_SESSION has an invalid value: %s", env_wlr_session);
+ wlr_log(WLR_ERROR, "Unsupported WLR_SESSION: %s",
+ env_wlr_session);
}
} else {
const struct session_impl **iter;
@@ -220,24 +225,23 @@ bool wlr_session_change_vt(struct wlr_session *session, unsigned vt) {
/* Tests if 'path' is KMS compatible by trying to open it.
* It leaves the open device in *fd_out it it succeeds.
*/
-static int open_if_kms(struct wlr_session *restrict session, const char *restrict path) {
- int fd;
-
+static int open_if_kms(struct wlr_session *restrict session,
+ const char *restrict path) {
if (!path) {
return -1;
}
- fd = wlr_session_open_file(session, path);
+ int fd = wlr_session_open_file(session, path);
if (fd < 0) {
return -1;
}
- drmModeRes *res = drmModeGetResources(fd);
- if (!res) {
+ drmVersion *ver = drmGetVersion(fd);
+ if (!ver) {
goto out_fd;
}
- drmModeFreeResources(res);
+ drmFreeVersion(ver);
return fd;
out_fd: