nix/pkgs/hyprland-system76-scheduler-integration.nix
2023-09-11 21:30:13 +10:00

52 lines
1.2 KiB
Nix
Executable file

{
lib,
pkgs,
stdenv,
hyprland,
ripgrep,
socat,
dbus,
...
}:
stdenv.mkDerivation rec {
pname = "hyprland-system76-scheduler-integration";
version = "0.1.0";
nativeBuildInputs = [
socat
dbus
hyprland
ripgrep
];
dontUnpack = "true";
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cat <<EOF > $out/bin/hyprland-system76-scheduler-hook.sh
#!${pkgs.bash}/bin/bash
echo "opening socket.."
${pkgs.socat}/bin/socat -u UNIX-CLIENT:/tmp/hypr/\''$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock STDOUT |
while read line; do
if [[ "\''$line" == activewindow* ]]; then
echo "got \''$line."
pid="\''$(${pkgs.hyprland}/bin/hyprctl activewindow | ${pkgs.ripgrep}/bin/rg pid | ${pkgs.coreutils}/bin/cut -d' ' -f2)"
if [[ -n \''$pid ]]; then
echo "sending \''$pid!"
${pkgs.dbus}/bin/dbus-send --system --dest=com.system76.Scheduler --type=method_call /com/system76/Scheduler com.system76.Scheduler.SetForegroundProcess uint32:\''$pid
fi
pid=""
fi
echo "continuing.."
done
echo "finished."
EOF
chmod +x $out/bin/hyprland-system76-scheduler-hook.sh
runHook postInstall
'';
}