fix(hyprland): repair dpms control, blank idle screens on stream
`hyprctl dispatch dpms off` has been a no-op since 0.55: hyprctl compiles its args into Lua, so it evaluated `hl.dispatch(dpms off)` and died on a syntax error. hypridle's blanking and after_sleep_cmd never ran. Adds a `hypr-dpms` wrapper over the Lua API, which needs a table — a bare string arg parses as "toggle" and ignores the monitor selector. Uses it to DPMS-off the two outputs Sunshine does not capture for the life of a stream, restoring them on the existing re-lock hook. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
let
|
||||
cfg = config.custom.gaming;
|
||||
|
||||
blankOutputs = lib.concatMapStringsSep " " lib.escapeShellArg cfg.sunshineBlankOutputs;
|
||||
|
||||
sunshine-session-lock = pkgs.writeShellApplication {
|
||||
name = "sunshine-session-lock";
|
||||
runtimeInputs = [
|
||||
@@ -57,6 +59,26 @@ let
|
||||
# XDG_SESSION_ID, so bare `loginctl lock-session` has nothing to resolve.
|
||||
# Selected by property rather than column position, which shifts between
|
||||
# systemd releases.
|
||||
# Outputs Sunshine does not capture. Hyprland stops compositing a
|
||||
# DPMS-off output entirely, so for the life of the stream the GPU renders
|
||||
# one 4K screen instead of three.
|
||||
#
|
||||
# These do NOT come back on their own: misc.mouse_move_enables_dpms and
|
||||
# misc.key_press_enables_dpms are both false by default on 0.56, so the
|
||||
# `lock` path is the only thing that restores them. A blank-but-unfixable
|
||||
# desktop is the failure mode to watch for if that path ever stops running
|
||||
# — recover with `hypr-dpms on`.
|
||||
outputs=(${blankOutputs})
|
||||
|
||||
set_blanked() {
|
||||
local out
|
||||
for out in ''${outputs[@]+"''${outputs[@]}"}; do
|
||||
# Never fatal: losing the stream because one output name went stale
|
||||
# (cable moved, monitor off) would be a much worse trade.
|
||||
${config.custom.hyprland.dpmsCommand} "$1" "$out" || true
|
||||
done
|
||||
}
|
||||
|
||||
graphical_session() {
|
||||
local s
|
||||
while read -r s; do
|
||||
@@ -79,6 +101,8 @@ let
|
||||
touch "$streaming"
|
||||
systemctl --user stop hypridle || true
|
||||
|
||||
set_blanked off
|
||||
|
||||
# No hyprlock running means the session was already unlocked: do
|
||||
# nothing, and leave no stamp so `lock` won't lock it on the way out.
|
||||
if pkill -u "$(id -u)" -USR1 -x hyprlock; then
|
||||
@@ -87,10 +111,12 @@ let
|
||||
;;
|
||||
|
||||
lock)
|
||||
# Before the stamp check: idle timers must come back even when the
|
||||
# stream arrived at an already-unlocked session and left no stamp.
|
||||
# Before the stamp check: idle timers and the blanked outputs must
|
||||
# come back even when the stream arrived at an already-unlocked
|
||||
# session and left no stamp.
|
||||
rm -f "$streaming"
|
||||
systemctl --user start hypridle || true
|
||||
set_blanked on
|
||||
|
||||
[ -e "$stamp" ] || exit 0
|
||||
rm -f "$stamp"
|
||||
@@ -114,6 +140,21 @@ in
|
||||
that actually run Sunshine, and read the security note in this file first
|
||||
'';
|
||||
|
||||
options.custom.gaming.sunshineBlankOutputs = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"HDMI-A-1"
|
||||
"DP-2"
|
||||
];
|
||||
description = ''
|
||||
Outputs to DPMS-off for the duration of a Sunshine stream — every screen
|
||||
except the one Sunshine captures. Which one that is comes from the
|
||||
journal: `journalctl --user -u sunshine | grep "Selected monitor"`.
|
||||
Leave empty to keep all displays on.
|
||||
'';
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.sunshineSessionLock {
|
||||
home.packages = [ sunshine-session-lock ];
|
||||
|
||||
|
||||
@@ -59,9 +59,39 @@ let
|
||||
--title=webcam-overlay --border=no --ontop \
|
||||
"av://v4l2:$dev"
|
||||
'';
|
||||
|
||||
# `hyprctl dispatch dpms off` is DEAD on 0.55+: hyprctl now compiles its args
|
||||
# into a Lua call, so it evaluates `hl.dispatch(dpms off)` and dies with
|
||||
# "')' expected near 'off'". Silent — the caller sees exit 0 semantics from a
|
||||
# shell pipeline and the screens simply never blank.
|
||||
#
|
||||
# hl.dsp.dpms also takes a *table*. A bare string arg is not a table, so
|
||||
# tableToggleAction() falls through to TOGGLE and the `monitor` selector is
|
||||
# never read — `hl.dsp.dpms("off", "DP-1")` toggles every output instead.
|
||||
hyprDpms = pkgs.writeShellScriptBin "hypr-dpms" ''
|
||||
action="''${1:?usage: hypr-dpms on|off|toggle [monitor]}"
|
||||
monitor="''${2:-}"
|
||||
|
||||
if [ -n "$monitor" ]; then
|
||||
lua=$(printf 'return hl.dispatch(hl.dsp.dpms({ action = "%s", monitor = "%s" }))' "$action" "$monitor")
|
||||
else
|
||||
lua=$(printf 'return hl.dispatch(hl.dsp.dpms({ action = "%s" }))' "$action")
|
||||
fi
|
||||
|
||||
exec ${hyprPkgs.hyprland}/bin/hyprctl eval "$lua"
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.custom.hyprland = {
|
||||
dpmsCommand = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
default = "${hyprDpms}/bin/hypr-dpms";
|
||||
description = ''
|
||||
Absolute path to the `hypr-dpms on|off|toggle [monitor]` helper, for
|
||||
other modules that blank outputs (e.g. the Sunshine stream hooks).
|
||||
'';
|
||||
};
|
||||
yaziSize = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "1400 1400";
|
||||
@@ -145,6 +175,7 @@ in
|
||||
wf-recorder
|
||||
slurp
|
||||
webcam
|
||||
hyprDpms
|
||||
];
|
||||
|
||||
home.sessionVariables = {
|
||||
@@ -466,7 +497,7 @@ in
|
||||
enable = true;
|
||||
settings = {
|
||||
general = {
|
||||
after_sleep_cmd = "hyprctl dispatch dpms on";
|
||||
after_sleep_cmd = "${hyprDpms}/bin/hypr-dpms on";
|
||||
before_sleep_cmd = "loginctl lock-session";
|
||||
# Must be true on this streaming box. GameMode (via Sunshine/Moonlight)
|
||||
# raises a dbus ScreenSaver inhibitor; if one arrives *after* the dpms-off
|
||||
@@ -485,8 +516,8 @@ in
|
||||
}
|
||||
{
|
||||
timeout = 1200;
|
||||
on-timeout = "hyprctl dispatch dpms off";
|
||||
on-resume = "hyprctl dispatch dpms on";
|
||||
on-timeout = "${hyprDpms}/bin/hypr-dpms off";
|
||||
on-resume = "${hyprDpms}/bin/hypr-dpms on";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user