From a89641769bdb7856d73f430985753f9b79cbcfac Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 15 Sep 2026 13:04:00 -0400 Subject: [PATCH] tvos - disable autosleep and wake on hdmi --- configs/fwbook/hypr/hyprland.lua | 1 - configs/hl-fws1/hypr/conf/apps.lua | 4 +++ configs/hl-fws1/hypr/conf/autostart.lua | 3 +++ configs/hl-fws1/hypr/conf/cec.lua | 24 +++++++++++++++++ configs/hl-fws1/hypr/hyprland.lua | 1 + hosts/hl-fws1.nix | 36 ++++++++++++++++++++++++- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 configs/hl-fws1/hypr/conf/cec.lua diff --git a/configs/fwbook/hypr/hyprland.lua b/configs/fwbook/hypr/hyprland.lua index 68adfae..e5af201 100644 --- a/configs/fwbook/hypr/hyprland.lua +++ b/configs/fwbook/hypr/hyprland.lua @@ -10,4 +10,3 @@ require("conf/inputs") require("conf/window-rules") require("conf/keybindings") require("conf/autostart") -require("/home/ari/nixos-setup/configs/hl-fws1/hypr/conf/apps.lua") diff --git a/configs/hl-fws1/hypr/conf/apps.lua b/configs/hl-fws1/hypr/conf/apps.lua index c8e5b0c..939dccc 100644 --- a/configs/hl-fws1/hypr/conf/apps.lua +++ b/configs/hl-fws1/hypr/conf/apps.lua @@ -1,3 +1,5 @@ +require("conf/cec") + ---@param s string ---@return string local function escape_pattern(s) @@ -36,6 +38,8 @@ end ---@return fun() local function make_commandable(tag, cmd, is_target_window) return function() + Cec.wake_and_switch() + local existing = attempt_to_switch_to_existing(tag) if existing ~= nil then hl.dispatch(hl.dsp.focus({ window = existing })) diff --git a/configs/hl-fws1/hypr/conf/autostart.lua b/configs/hl-fws1/hypr/conf/autostart.lua index 9e91743..5702d4c 100644 --- a/configs/hl-fws1/hypr/conf/autostart.lua +++ b/configs/hl-fws1/hypr/conf/autostart.lua @@ -1,6 +1,9 @@ +require("conf/cec") + -- ========================= -- Autostart -- ========================= hl.on("hyprland.start", function() hl.exec_cmd("setpriv --ambient-caps -all -- hypridle") + Cec.wake_and_switch() end) diff --git a/configs/hl-fws1/hypr/conf/cec.lua b/configs/hl-fws1/hypr/conf/cec.lua new file mode 100644 index 0000000..56ffd6b --- /dev/null +++ b/configs/hl-fws1/hypr/conf/cec.lua @@ -0,0 +1,24 @@ +-- ========================= +-- CEC (HDMI-CEC control, e.g. waking/switching the TV) +-- ========================= + +---@param cmd string raw cec-client command, e.g. "on" or "as" +---@param target integer CEC logical address (0 = TV) +local function cec_send(cmd, target) + hl.exec_cmd(string.format("bash -c \"echo '%s %d' | cec-client -s -d 1\"", cmd, target)) +end + +---Wake a CEC device and make this box its active source. +---@param target integer? CEC logical address, defaults to 0 (TV) +local function wake_and_switch(target) + target = target or 0 + cec_send("on", target) + cec_send("as", target) +end + +---@class Cec +---@field send fun(cmd: string, target: integer) +---@field wake_and_switch fun(target: integer?) +Cec = Cec or {} +Cec.send = cec_send +Cec.wake_and_switch = wake_and_switch diff --git a/configs/hl-fws1/hypr/hyprland.lua b/configs/hl-fws1/hypr/hyprland.lua index f28952f..ec65cf4 100644 --- a/configs/hl-fws1/hypr/hyprland.lua +++ b/configs/hl-fws1/hypr/hyprland.lua @@ -11,6 +11,7 @@ require("conf/animations") require("conf/monitors") require("conf/inputs") require("conf/window-rules") +require("conf/cec") require("conf/keybindings") require("conf/autostart") require("conf/apps") diff --git a/hosts/hl-fws1.nix b/hosts/hl-fws1.nix index ed97375..0ed86ab 100644 --- a/hosts/hl-fws1.nix +++ b/hosts/hl-fws1.nix @@ -84,15 +84,49 @@ { name = "libpipewire-module-raop-discover"; } ]; }; + wireplumber.extraConfig."51-hdmi-tv" = { + # Stop remembering the analog profile between boots — always prefer HDMI. + "wireplumber.settings" = { + "device.restore-profile" = false; + "device.restore-routes" = false; + }; + # ACP ranks analog-stereo (6565) above hdmi-stereo (5900) by default; + # override that so the LG TV (hdmi-output-0, confirmed via ELD) wins. + "device.profile.priority.rules" = [ + { + matches = [{ "device.name" = "alsa_card.pci-0000_00_1f.3"; }]; + actions.update-props.priorities = [ "output:hdmi-stereo" ]; + } + ]; + # Make the resulting HDMI sink win the default-sink vote too. + "monitor.alsa.rules" = [ + { + matches = [{ "node.name" = "~alsa_output.*hdmi.*"; }]; + actions.update-props."priority.session" = 2000; + } + ]; + }; }; security.rtkit.enable = true; + # Let the logged-in session (not just root) open the CEC device, so + # Hyprland can drive the TV without sudo. + services.udev.extraRules = '' + SUBSYSTEM=="cec", MODE="0664", TAG+="uaccess" + ''; + + # Disable auto-suspend/hibernate — always-on TV box + systemd.targets.sleep.enable = false; + systemd.targets.suspend.enable = false; + systemd.targets.hibernate.enable = false; + systemd.targets.hybrid-sleep.enable = false; + # Send audio to AirPlay speakers services.avahi.enable = true; # AirPlay receiver services.shairport-sync = { enable = true; - arguments = "-o pw"; + arguments = "-o pipewire"; }; }