Add onMonitorChange hyprland hook script

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-02-14 19:29:42 +00:00
parent 3e67e2a299
commit b6635d01c2
4 changed files with 48 additions and 12 deletions

View File

@@ -39,5 +39,7 @@
]; ];
}; };
}; };
wayland.windowManager.hyprland.onMonitorChange.services = [ "ags.service" ];
}; };
} }

View File

@@ -0,0 +1,8 @@
handle() {
# shellcheck disable=SC2086
case $1 in
monitoradded*|monitorremoved*) systemctl --user restart $SERVICES ;;
esac
}
socat -U - "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do handle "$line"; done

View File

@@ -23,21 +23,45 @@ in
default = ""; default = "";
description = "Extra configuration lines to add to exec"; description = "Extra configuration lines to add to exec";
}; };
onMonitorChange.services = mkOption {
type = listOf str;
default = [ ];
description = "Services to restart when a monitor is connected or disconnected";
};
}; };
config = { config = {
wayland.windowManager.hyprland.settings.exec-once = lib.meta.getExe ( wayland.windowManager.hyprland.initExtraConfig =
pkgs.writeShellApplication { lib.mkIf (cfg.onMonitorChange.services != [ ])
name = "init-hyprland"; "${
text = cfg.initExtraConfig; lib.meta.getExe (
} pkgs.writeShellApplication {
); name = "hyprland-monitor-change-services";
runtimeInputs = with pkgs; [
socat
systemd
];
runtimeEnv.SERVICES = lib.strings.concatStringsSep " " cfg.onMonitorChange.services;
text = builtins.readFile ./monitors.sh;
}
)
} &";
wayland.windowManager.hyprland.settings.exec = lib.meta.getExe ( wayland.windowManager.hyprland.settings = {
pkgs.writeShellApplication { exec-once = lib.meta.getExe (
name = "reload-hyprland"; pkgs.writeShellApplication {
text = cfg.reloadExtraConfig; name = "init-hyprland";
} text = cfg.initExtraConfig;
); }
);
exec = lib.meta.getExe (
pkgs.writeShellApplication {
name = "reload-hyprland";
text = cfg.reloadExtraConfig;
}
);
};
}; };
} }

View File

@@ -64,5 +64,7 @@ in
}; };
theme.reloadExtraConfig = "${themeSwww} &"; theme.reloadExtraConfig = "${themeSwww} &";
wayland.windowManager.hyprland.onMonitorChange.services = [ "swww.service" ];
}; };
} }