refactor(hm/price): separate swww into its own module

This commit is contained in:
Price Hiller 2024-07-17 01:27:13 -05:00
parent 13505d1201
commit a4bbcaa73e
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
10 changed files with 85 additions and 56 deletions

View File

@ -0,0 +1,84 @@
{ pkgs, ... }:
let
wallpapers = ./wallpapers;
in
{
home.packages = [ pkgs.swww ];
systemd.user = {
services = {
swww-daemon = {
Service =
let
cleanup-socket-script = pkgs.writeShellScript "swww-daemon-cleanup-socket" ''
# Remove the existing swww.socket if it exists, avoids some issues with swww-daemon
# startup where swww-daemon claims the address is already in use
if [[ -w "$XDG_RUNTIME_DIR/swww.socket" ]]; then
rm -f $XDG_RUNTIME_DIR/swww.socket || exit 1
fi
'';
in
{
RestartSec = 3;
PassEnvironment = [ "XDG_RUNTIME_DIR" ];
ExecStartPre = "${cleanup-socket-script}";
ExecStopPost = "${cleanup-socket-script}";
ExecStart = "${pkgs.swww}/bin/swww-daemon";
};
Install.WantedBy = [ "graphical-session.target" ];
Unit = {
Description = "Wayland Wallpaper Service";
PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ];
};
};
swww-watch-wallpapers = {
Service = {
RestartSec = 3;
Environment = [
"SWWW_TRANSITION_FPS=120"
"SWWW_TRANSITION_STEP=30"
"SWWW_TRANSITION_DURATION=0.75"
];
ExecStart = "${
pkgs.writeShellApplication {
name = "swww-watch-wallpapers";
runtimeInputs = with pkgs; [
swww
coreutils
];
text = ''
set -eEuo pipefail
main() {
local prev_mons_connected=0
local mons_connected=0
local cached_swww_query
while sleep 1; do
cached_swww_query="$(swww query)"
mons_connected="$(wc -l <<< "$cached_swww_query")"
if ((mons_connected != prev_mons_connected)); then
prev_mons_connected="$mons_connected"
swww img -t random ${wallpapers}/Nebula.jpg
if [[ "$cached_swww_query" =~ "eDP-1: "* ]]; then
swww img -t wipe --transition-angle 40 -o eDP-1 ${wallpapers}/Autumn-Leaves.jpg
fi
fi
done
}
main
'';
}
}/bin/swww-watch-wallpapers";
};
Install.WantedBy = [ "swww-daemon.service" ];
Unit = {
Description = "Wayland Wallpaper Service";
PartOf = [ "swww-daemon.service" ];
After = [ "swww-daemon.service" ];
};
};
};
};
}

View File

Before

Width:  |  Height:  |  Size: 3.9 MiB

After

Width:  |  Height:  |  Size: 3.9 MiB

View File

Before

Width:  |  Height:  |  Size: 8.3 MiB

After

Width:  |  Height:  |  Size: 8.3 MiB

View File

Before

Width:  |  Height:  |  Size: 474 KiB

After

Width:  |  Height:  |  Size: 474 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 MiB

After

Width:  |  Height:  |  Size: 4.3 MiB

View File

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

Before

Width:  |  Height:  |  Size: 8.0 MiB

After

Width:  |  Height:  |  Size: 8.0 MiB

View File

Before

Width:  |  Height:  |  Size: 344 KiB

After

Width:  |  Height:  |  Size: 344 KiB

View File

@ -152,12 +152,7 @@ in
] ]
++ [ rust-analyzer ]; ++ [ rust-analyzer ];
file = { file = softLinkDots ".config";
".local/share/wallpapers" = {
source = ./dots/.local/share/wallpapers;
force = true;
};
} // softLinkDots ".config";
sessionVariables = { sessionVariables = {
_ZL_DATA = "${config.xdg.cacheHome}/zlua"; _ZL_DATA = "${config.xdg.cacheHome}/zlua";
@ -483,56 +478,6 @@ in
}; };
}; };
services = { services = {
swww-daemon = {
Service =
let
cleanup-socket-script = pkgs.writeShellScript "swww-daemon-cleanup-socket" ''
# Remove the existing swww.socket if it exists, avoids some issues with swww-daemon
# startup where swww-daemon claims the address is already in use
if [[ -w "$XDG_RUNTIME_DIR/swww.socket" ]]; then
rm -f $XDG_RUNTIME_DIR/swww.socket || exit 1
fi
'';
in
{
RestartSec = 3;
PassEnvironment = [ "XDG_RUNTIME_DIR" ];
ExecStartPre = "${cleanup-socket-script}";
ExecStopPost = "${cleanup-socket-script}";
ExecStart = "${pkgs.swww}/bin/swww-daemon";
};
Install.WantedBy = [ "compositor.target" ];
Unit = {
Description = "Wayland Wallpaper Service";
PartOf = [ "compositor.target" ];
After = [ "compositor.target" ];
};
};
swww-wallpapers = {
Service = {
RestartSec = 3;
Type = "oneshot";
Environment = [
"SWWW_TRANSITION_FPS=120"
"SWWW_TRANSITION_STEP=30"
"SWWW_TRANSITION_DURATION=0.75"
];
ExecStart =
let
wallpaper-dir = "${dotsDir}/.local/share/wallpapers";
in
[
"${pkgs.swww}/bin/swww img -t random ${wallpaper-dir}/Nebula.jpg"
"${pkgs.swww}/bin/swww img -t wipe --transition-angle 40 -o eDP-1 ${wallpaper-dir}/Autumn-Leaves.jpg"
];
};
Install.WantedBy = [ "swww-daemon.service" ];
Unit = {
Description = "Wayland Wallpaper Service";
PartOf = [ "swww-daemon.service" ];
After = [ "swww-daemon.service" ];
};
};
keyd-application-mapper = { keyd-application-mapper = {
Unit = { Unit = {
Description = "Keyd - Linux Keyboard Remapper"; Description = "Keyd - Linux Keyboard Remapper";