mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 06:35:58 +01:00
Changed session signal to only emit on DRM changes
This commit is contained in:
parent
d1493b2391
commit
091de12bf4
6 changed files with 60 additions and 69 deletions
|
@ -40,37 +40,23 @@ static struct wlr_backend_impl backend_impl = {
|
||||||
.destroy = wlr_drm_backend_destroy
|
.destroy = wlr_drm_backend_destroy
|
||||||
};
|
};
|
||||||
|
|
||||||
static void device_paused(struct wl_listener *listener, void *data) {
|
static void session_signal(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_backend_state *drm = wl_container_of(listener, drm, device_paused);
|
struct wlr_backend_state *drm = wl_container_of(listener, drm, session_signal);
|
||||||
struct device_arg *arg = data;
|
struct wlr_session *session = data;
|
||||||
|
|
||||||
// TODO: Actually pause the renderer or something.
|
|
||||||
// We currently just expect it to fail its next pageflip.
|
|
||||||
|
|
||||||
if (arg->dev == drm->dev) {
|
|
||||||
wlr_log(L_INFO, "DRM fd paused");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void device_resumed(struct wl_listener *listener, void *data) {
|
|
||||||
struct wlr_backend_state *drm = wl_container_of(listener, drm, device_resumed);
|
|
||||||
struct device_arg *arg = data;
|
|
||||||
|
|
||||||
if (arg->dev != drm->dev) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dup2(arg->fd, drm->fd) < 0) {
|
|
||||||
wlr_log(L_ERROR, "dup2 failed: %s", strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (session->active) {
|
||||||
wlr_log(L_INFO, "DRM fd resumed");
|
wlr_log(L_INFO, "DRM fd resumed");
|
||||||
|
|
||||||
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
||||||
struct wlr_output_state *output = drm->outputs->items[i];
|
struct wlr_output_state *output = drm->outputs->items[i];
|
||||||
wlr_drm_output_start_renderer(output);
|
wlr_drm_output_start_renderer(output);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
wlr_log(L_INFO, "DRM fd paused");
|
||||||
|
|
||||||
|
// TODO: Actually pause the renderer or something.
|
||||||
|
// We currently just expect it to fail its next pageflip.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drm_invalidated(struct wl_listener *listener, void *data) {
|
static void drm_invalidated(struct wl_listener *listener, void *data) {
|
||||||
|
@ -139,14 +125,8 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
|
||||||
goto error_fd;
|
goto error_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_init(&state->device_paused.link);
|
state->session_signal.notify = session_signal;
|
||||||
wl_list_init(&state->device_paused.link);
|
wl_signal_add(&session->session_signal, &state->session_signal);
|
||||||
|
|
||||||
state->device_paused.notify = device_paused;
|
|
||||||
state->device_resumed.notify = device_resumed;
|
|
||||||
|
|
||||||
wl_signal_add(&session->device_paused, &state->device_paused);
|
|
||||||
wl_signal_add(&session->device_resumed, &state->device_resumed);
|
|
||||||
|
|
||||||
// TODO: what is the difference between the per-output renderer and this
|
// TODO: what is the difference between the per-output renderer and this
|
||||||
// one?
|
// one?
|
||||||
|
|
|
@ -42,6 +42,8 @@ static void handle_keyboard_key(struct keyboard_state *kbstate,
|
||||||
xkb_keysym_t sym, enum wlr_key_state key_state) {
|
xkb_keysym_t sym, enum wlr_key_state key_state) {
|
||||||
if (sym == XKB_KEY_Escape) {
|
if (sym == XKB_KEY_Escape) {
|
||||||
kbstate->compositor->exit = true;
|
kbstate->compositor->exit = true;
|
||||||
|
} else if (sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) {
|
||||||
|
wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,7 @@ struct wlr_backend_state {
|
||||||
struct wlr_backend *backend;
|
struct wlr_backend *backend;
|
||||||
struct wl_event_source *drm_event;
|
struct wl_event_source *drm_event;
|
||||||
|
|
||||||
struct wl_listener device_paused;
|
struct wl_listener session_signal;
|
||||||
struct wl_listener device_resumed;
|
|
||||||
struct wl_listener drm_invalidated;
|
struct wl_listener drm_invalidated;
|
||||||
|
|
||||||
uint32_t taken_crtcs;
|
uint32_t taken_crtcs;
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
#ifndef WLR_SESSION_H
|
#ifndef WLR_SESSION_H
|
||||||
#define WLR_SESSION_H
|
#define WLR_SESSION_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
struct session_impl;
|
struct session_impl;
|
||||||
|
|
||||||
// Passed to the listeners of device_paused/resumed
|
|
||||||
struct device_arg {
|
|
||||||
dev_t dev;
|
|
||||||
int fd; // Only for device_resumed
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wlr_session {
|
struct wlr_session {
|
||||||
const struct session_impl *impl;
|
const struct session_impl *impl;
|
||||||
|
|
||||||
struct wl_signal device_paused;
|
bool active;
|
||||||
struct wl_signal device_resumed;
|
struct wl_signal session_signal;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_session *wlr_session_start(struct wl_display *disp);
|
struct wlr_session *wlr_session_start(struct wl_display *disp);
|
||||||
|
|
|
@ -45,8 +45,8 @@ static struct wlr_session *direct_session_start(struct wl_display *disp) {
|
||||||
wlr_log(L_INFO, "Successfully loaded direct session");
|
wlr_log(L_INFO, "Successfully loaded direct session");
|
||||||
|
|
||||||
session->base.impl = &session_direct;
|
session->base.impl = &session_direct;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,12 +27,15 @@ 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,
|
||||||
const char *restrict path) {
|
const char *restrict path) {
|
||||||
struct logind_session *session = wl_container_of(base, session, base);
|
struct logind_session *session = wl_container_of(base, session, base);
|
||||||
|
|
||||||
|
wlr_log(L_DEBUG, "Taking '%s'", path);
|
||||||
int ret;
|
int ret;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
sd_bus_message *msg = NULL;
|
sd_bus_message *msg = NULL;
|
||||||
|
@ -58,7 +63,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 +72,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 +102,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 +198,32 @@ 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;
|
||||||
}
|
}
|
||||||
|
wlr_log(L_INFO, "PauseDevice signal received: (%lu) %s", makedev(major, minor), type);
|
||||||
|
|
||||||
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 +231,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;
|
||||||
|
|
||||||
|
@ -228,13 +242,13 @@ static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_
|
||||||
strerror(-ret));
|
strerror(-ret));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
wlr_log(L_INFO, "ResumeDevice signal received (%lu)", makedev(major, minor));
|
||||||
|
|
||||||
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 +348,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:
|
||||||
|
|
Loading…
Reference in a new issue