From bf4ba5c5c662e17a30ed08261d8dc882e21226f9 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Wed, 16 Oct 2024 01:00:10 -0400 Subject: [PATCH] lavaridge: add support for dynamic resolution based on charging status --- hosts/lavaridge/default.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hosts/lavaridge/default.nix b/hosts/lavaridge/default.nix index b2057759..19e16256 100644 --- a/hosts/lavaridge/default.nix +++ b/hosts/lavaridge/default.nix @@ -2,6 +2,7 @@ { config, lib, + pkgs, self, ... }: { @@ -38,6 +39,31 @@ environment.variables.GDK_SCALE = "2"; networking.hostName = "lavaridge"; + + services.udev.extraRules = let + hyprlandDynamicRes = pkgs.writeShellScript "hyprland-dynamic-resolution" '' + MON="eDP-1" + RES="2880x1920" + + for dir in /run/user/*; do + for hypr_dir in "$dir/hypr/"*/; do + socket="''${hypr_dir}.socket.sock" + if [[ -S $socket ]]; then + monitor_info=$(echo -e "monitors" | ${lib.getExe pkgs.socat} - UNIX-CONNECT:"$socket") + + if echo "$monitor_info" | grep -q "$MON"; then + echo -e "keyword monitor $MON, $RES@$1, 0x0, 2, vrr, $2" | ${lib.getExe pkgs.socat} - UNIX-CONNECT:"$socket" + fi + + fi + done + done + ''; + in '' + SUBSYSTEM=="power_supply", ATTR{online}=="1", ACTION=="change", RUN+="${hyprlandDynamicRes} 120 1" + SUBSYSTEM=="power_supply", ATTR{online}=="0", ACTION=="change", RUN+="${hyprlandDynamicRes} 60 0" + ''; + system.stateVersion = "24.05"; ar = {