|
|
@ -14,6 +14,8 @@
|
|
|
|
#include <wlr/session/interface.h>
|
|
|
|
#include <wlr/session/interface.h>
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum { DRM_MAJOR = 226 };
|
|
|
|
|
|
|
|
|
|
|
|
const struct session_impl session_logind;
|
|
|
|
const struct session_impl session_logind;
|
|
|
|
|
|
|
|
|
|
|
|
struct logind_session {
|
|
|
|
struct logind_session {
|
|
|
@ -25,6 +27,8 @@ struct logind_session {
|
|
|
|
char *id;
|
|
|
|
char *id;
|
|
|
|
char *path;
|
|
|
|
char *path;
|
|
|
|
char *seat;
|
|
|
|
char *seat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int drm_fd;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int logind_take_device(struct wlr_session *restrict base,
|
|
|
|
static int logind_take_device(struct wlr_session *restrict base,
|
|
|
@ -58,7 +62,7 @@ static int logind_take_device(struct wlr_session *restrict base,
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The original fd seem to be closed when the message is freed
|
|
|
|
// The original fd seems to be closed when the message is freed
|
|
|
|
// so we just clone it.
|
|
|
|
// so we just clone it.
|
|
|
|
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
|
|
|
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
|
|
|
if (fd == -1) {
|
|
|
|
if (fd == -1) {
|
|
|
@ -67,6 +71,10 @@ static int logind_take_device(struct wlr_session *restrict base,
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (major(st.st_rdev) == DRM_MAJOR) {
|
|
|
|
|
|
|
|
session->drm_fd = fd;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
error:
|
|
|
|
sd_bus_error_free(&error);
|
|
|
|
sd_bus_error_free(&error);
|
|
|
|
sd_bus_message_unref(msg);
|
|
|
|
sd_bus_message_unref(msg);
|
|
|
@ -93,6 +101,10 @@ static void logind_release_device(struct wlr_session *base, int fd) {
|
|
|
|
wlr_log(L_ERROR, "Failed to release device '%d'", fd);
|
|
|
|
wlr_log(L_ERROR, "Failed to release device '%d'", fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (major(st.st_rdev) == DRM_MAJOR) {
|
|
|
|
|
|
|
|
session->drm_fd = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sd_bus_error_free(&error);
|
|
|
|
sd_bus_error_free(&error);
|
|
|
|
sd_bus_message_unref(msg);
|
|
|
|
sd_bus_message_unref(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,30 +197,31 @@ static int session_removed(sd_bus_message *msg, void *userdata, sd_bus_error *re
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int pause_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
|
|
|
|
static int pause_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
|
|
|
|
wlr_log(L_INFO, "PauseDevice signal received");
|
|
|
|
|
|
|
|
struct logind_session *session = userdata;
|
|
|
|
struct logind_session *session = userdata;
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t major, minor;
|
|
|
|
uint32_t major, minor;
|
|
|
|
ret = sd_bus_message_read(msg, "uu", &major, &minor);
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
ret = sd_bus_message_read(msg, "uus", &major, &minor, &type);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (ret < 0) {
|
|
|
|
wlr_log(L_ERROR, "Failed to parse D-Bus response for PauseDevice: %s",
|
|
|
|
wlr_log(L_ERROR, "Failed to parse D-Bus response for PauseDevice: %s",
|
|
|
|
strerror(-ret));
|
|
|
|
strerror(-ret));
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct device_arg arg = {
|
|
|
|
if (major == DRM_MAJOR) {
|
|
|
|
.dev = makedev(major, minor),
|
|
|
|
session->base.active = false;
|
|
|
|
.fd = -1,
|
|
|
|
wl_signal_emit(&session->base.session_signal, session);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_emit(&session->base.device_paused, &arg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(type, "pause") == 0) {
|
|
|
|
ret = sd_bus_call_method(session->bus, "org.freedesktop.login1",
|
|
|
|
ret = sd_bus_call_method(session->bus, "org.freedesktop.login1",
|
|
|
|
session->path, "org.freedesktop.login1.Session", "PauseDeviceComplete",
|
|
|
|
session->path, "org.freedesktop.login1.Session", "PauseDeviceComplete",
|
|
|
|
ret_error, &msg, "uu", major, minor);
|
|
|
|
ret_error, &msg, "uu", major, minor);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (ret < 0) {
|
|
|
|
wlr_log(L_ERROR, "Failed to send PauseDeviceComplete signal");
|
|
|
|
wlr_log(L_ERROR, "Failed to send PauseDeviceComplete signal: %s",
|
|
|
|
|
|
|
|
strerror(-ret));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
error:
|
|
|
@ -216,7 +229,6 @@ error:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
|
|
|
|
static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
|
|
|
|
wlr_log(L_INFO, "ResumeDevice signal received");
|
|
|
|
|
|
|
|
struct logind_session *session = userdata;
|
|
|
|
struct logind_session *session = userdata;
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
@ -229,12 +241,11 @@ static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct device_arg arg = {
|
|
|
|
if (major == DRM_MAJOR) {
|
|
|
|
.dev = makedev(major, minor),
|
|
|
|
dup2(fd, session->drm_fd);
|
|
|
|
.fd = fd,
|
|
|
|
session->base.active = true;
|
|
|
|
};
|
|
|
|
wl_signal_emit(&session->base.session_signal, session);
|
|
|
|
|
|
|
|
}
|
|
|
|
wl_signal_emit(&session->base.device_resumed, &arg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
error:
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -334,9 +345,10 @@ static struct wlr_session *logind_session_start(struct wl_display *disp) {
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Successfully loaded logind session");
|
|
|
|
wlr_log(L_INFO, "Successfully loaded logind session");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session->drm_fd = -1;
|
|
|
|
session->base.impl = &session_logind;
|
|
|
|
session->base.impl = &session_logind;
|
|
|
|
wl_signal_init(&session->base.device_paused);
|
|
|
|
session->base.active = true;
|
|
|
|
wl_signal_init(&session->base.device_resumed);
|
|
|
|
wl_signal_init(&session->base.session_signal);
|
|
|
|
return &session->base;
|
|
|
|
return &session->base;
|
|
|
|
|
|
|
|
|
|
|
|
error_bus:
|
|
|
|
error_bus:
|
|
|
|