154 lines
4.9 KiB
Nix
154 lines
4.9 KiB
Nix
{ lib, config, inputs, system, pkgs, ... }:
|
|
|
|
with lib;
|
|
let
|
|
cfg = config.modules.desktop.awww;
|
|
in {
|
|
options.modules.desktop.awww = {
|
|
enable = mkEnableOption "Enable awww, an Answer to your Wayland Wallpaper Woes";
|
|
backdrop = mkEnableOption "Enable a second, blurred, awww daemon with a `-backdrop` suffix. Primarily for use in niri";
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.awww;
|
|
example = "pkgs.awww";
|
|
};
|
|
wallpapersFolder = mkOption {
|
|
type = types.str;
|
|
default = "${pkgs.my.wallpapers}/share/backgrounds";
|
|
example = "$XDG_PICTURES_DIR/wallpapers";
|
|
};
|
|
wallpaperEffectsCacheFolder = mkOption {
|
|
type = types.str;
|
|
default = "$XDG_CACHE_HOME/wallpaper-blurcache";
|
|
example = "$XDG_CACHE_HOME/wallpaper-blurcache";
|
|
};
|
|
lastWallpaper = mkOption {
|
|
type = types.str;
|
|
default = "$XDG_DATA_HOME/awww-last-wallpaper";
|
|
example = "$XDG_DATA_HOME/awww-last-wallpaper";
|
|
};
|
|
lastWallpaperSym = mkOption {
|
|
type = types.str;
|
|
default = "$XDG_DATA_HOME/awww-last-wallpaper-sym";
|
|
example = "$XDG_DATA_HOME/awww-last-wallpaper-sym";
|
|
};
|
|
# TODO: somehow make this match up with the theme blur radius when i add that?
|
|
blurScript = mkOption {
|
|
type = types.package;
|
|
default = pkgs.writeShellScript "awww-blur" ''
|
|
set -euo pipefail
|
|
|
|
: "''${1:?missing argument}"
|
|
|
|
mkdir -p "${cfg.wallpaperEffectsCacheFolder}"
|
|
blurred="${cfg.wallpaperEffectsCacheFolder}/$(basename "$1")"
|
|
|
|
if [ ! -f "$blurred" ]; then
|
|
${lib.getExe pkgs.imagemagick} "$1" \
|
|
-blur 0x8 \
|
|
-fill black \
|
|
-colorize 40% \
|
|
"$blurred"
|
|
fi
|
|
|
|
echo "$blurred"
|
|
'';
|
|
};
|
|
setScript = mkOption {
|
|
type = types.package;
|
|
default = pkgs.writeShellScript "awww-set" ''
|
|
set -euo pipefail
|
|
|
|
if [ ! -f "${cfg.lastWallpaper}" ]; then
|
|
echo "$(ls ${cfg.wallpapersFolder} | shuf -n 1)" > "${cfg.lastWallpaper}"
|
|
fi
|
|
|
|
wallpaper="${cfg.wallpapersFolder}/$(cat ${cfg.lastWallpaper})"
|
|
|
|
ln -sf "$wallpaper" "${cfg.lastWallpaperSym}"
|
|
|
|
${lib.getExe cfg.package} img "$wallpaper" --transition-type none
|
|
${lib.optionalString cfg.backdrop ''${lib.getExe cfg.package} img $(${cfg.blurScript} "$wallpaper") --namespace backdrop --transition-type none''}
|
|
'';
|
|
};
|
|
swapScript = mkOption {
|
|
type = types.package;
|
|
default = pkgs.writeShellScript "awww-swap" ''
|
|
set -euo pipefail
|
|
|
|
file=$(ls ${cfg.wallpapersFolder} | dmenu -p "select a wallpaper")
|
|
wallpaper="${cfg.wallpapersFolder}/$file"
|
|
|
|
[ ! -f "$wallpaper" ] && exit 1
|
|
|
|
${lib.getExe cfg.package} img "$wallpaper" --transition-type grow --transition-fps 60 --transition-pos 1.0,1.0 --transition-duration 1.5
|
|
${lib.optionalString cfg.backdrop ''${lib.getExe cfg.package} img $(${cfg.blurScript} "$wallpaper") --namespace backdrop --transition-type grow --transition-fps 60 --transition-pos 1.0,1.0 --transition-duration 1.5''}
|
|
|
|
ln -sf "$wallpaper" "${cfg.lastWallpaperSym}"
|
|
echo "$file" > "${cfg.lastWallpaper}"
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = mkMerge [
|
|
(mkIf cfg.enable {
|
|
hm.home.packages = [ cfg.package ];
|
|
hm.systemd.user.services.awww = {
|
|
Unit = {
|
|
Description = "awww, an Answer to your Wayland Wallpaper Woes";
|
|
After = [ "graphical-session-pre.target" ];
|
|
PartOf = [ "graphical-session.target" ];
|
|
};
|
|
|
|
Install = {
|
|
WantedBy = [ "graphical-session.target" ];
|
|
};
|
|
|
|
Service = {
|
|
Type = "simple";
|
|
ExecStart = "${cfg.package}/bin/awww-daemon";
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
};
|
|
};
|
|
hm.systemd.user.services.awww-set = {
|
|
Unit = {
|
|
Description = "awww, an Answer to your Wayland Wallpaper Woes (startup script)";
|
|
After = [ "awww.service" ] ++ optional cfg.backdrop "awww-backdrop.service";
|
|
PartOf = [ "awww.service" ] ++ optional cfg.backdrop "awww-backdrop.service";
|
|
};
|
|
|
|
Install = {
|
|
WantedBy = [ "graphical-session.target" ];
|
|
};
|
|
|
|
Service = {
|
|
Type = "oneshot";
|
|
ExecStart = "${cfg.setScript}";
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
};
|
|
};
|
|
})
|
|
(mkIf cfg.backdrop {
|
|
hm.systemd.user.services.awww-backdrop = {
|
|
Unit = {
|
|
Description = "awww, an Answer to your Wayland Wallpaper Woes";
|
|
After = [ "graphical-session-pre.target" ];
|
|
PartOf = [ "graphical-session.target" ];
|
|
};
|
|
|
|
Install = {
|
|
WantedBy = [ "graphical-session.target" ];
|
|
};
|
|
|
|
Service = {
|
|
Type = "simple";
|
|
ExecStart = "${cfg.package}/bin/awww-daemon --namespace backdrop";
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
};
|
|
};
|
|
})
|
|
];
|
|
}
|