2026-03-12 04:09:08 +03:00
|
|
|
{ pkgs, lib, config, osConfig, inputs, ... }: {
|
2024-10-02 22:10:08 +03:00
|
|
|
wayland.windowManager.hyprland = let
|
|
|
|
|
colors = config.lib.stylix.colors;
|
2026-06-08 03:24:54 +03:00
|
|
|
accent = colors.${config.stylix.accent};
|
2026-09-05 19:45:18 +03:00
|
|
|
hyprLua = import ../../../modules/user/hyprland/lua.nix { inherit lib; };
|
2025-11-27 15:33:23 +03:00
|
|
|
|
|
|
|
|
wallpaper_changer = pkgs.writers.writePython3Bin "wallpaper_changer" {
|
|
|
|
|
libraries = [ pkgs.python3Packages.requests ];
|
2026-06-08 03:47:46 +03:00
|
|
|
flakeIgnore = [ "E111" "E121" "E241" "E501" "E701" "E731" ];
|
2025-11-27 15:33:23 +03:00
|
|
|
} /*py*/ ''
|
|
|
|
|
import requests as requests
|
|
|
|
|
from random import choice
|
2026-06-08 03:47:46 +03:00
|
|
|
from os import listdir, makedirs, remove, replace, system
|
2025-11-27 15:33:23 +03:00
|
|
|
from os.path import exists
|
2026-06-08 03:47:46 +03:00
|
|
|
from subprocess import run
|
|
|
|
|
|
|
|
|
|
notify_id = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def notify(text, progress=None, expire_time=5000):
|
|
|
|
|
global notify_id
|
|
|
|
|
|
|
|
|
|
command = [
|
|
|
|
|
"${pkgs.libnotify}/bin/notify-send",
|
|
|
|
|
"--app-name", "wallpaper_changer",
|
|
|
|
|
"--print-id",
|
|
|
|
|
"--expire-time", str(expire_time),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if notify_id:
|
|
|
|
|
command.extend(["--replace-id", str(notify_id)])
|
|
|
|
|
|
|
|
|
|
if progress is not None:
|
|
|
|
|
command.extend(["--hint", f"int:value:{progress}"])
|
|
|
|
|
|
|
|
|
|
command.extend(["Wallpaper", text])
|
|
|
|
|
|
|
|
|
|
result = run(command, capture_output=True, text=True, check=False)
|
|
|
|
|
output = result.stdout.strip()
|
|
|
|
|
if output.isdigit():
|
|
|
|
|
notify_id = output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def download_with_progress(link, destination):
|
|
|
|
|
temporary = f"{destination}.part"
|
|
|
|
|
downloaded = 0
|
|
|
|
|
last_progress = -1
|
|
|
|
|
|
|
|
|
|
response = None
|
|
|
|
|
try:
|
|
|
|
|
response = requests.get(link, stream=True)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
total = int(response.headers.get("content-length", 0))
|
|
|
|
|
|
|
|
|
|
with open(temporary, "wb") as file:
|
|
|
|
|
for chunk in response.iter_content(chunk_size=256 * 1024):
|
|
|
|
|
if not chunk:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
file.write(chunk)
|
|
|
|
|
downloaded += len(chunk)
|
|
|
|
|
|
|
|
|
|
if total <= 0:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
progress = min(100, downloaded * 100 // total)
|
|
|
|
|
if progress == 100 or progress >= last_progress + 2:
|
|
|
|
|
notify(f"Downloading... {progress}%", progress, 0)
|
|
|
|
|
last_progress = progress
|
|
|
|
|
|
|
|
|
|
replace(temporary, destination)
|
|
|
|
|
except Exception:
|
|
|
|
|
if exists(temporary):
|
|
|
|
|
remove(temporary)
|
|
|
|
|
raise
|
|
|
|
|
finally:
|
|
|
|
|
if response is not None:
|
|
|
|
|
response.close()
|
|
|
|
|
|
2025-11-27 15:33:23 +03:00
|
|
|
|
|
|
|
|
folder = "${config.home.homeDirectory}/Wallpapers"
|
2026-03-12 04:09:08 +03:00
|
|
|
url = "https://wallhaven.cc/api/v1/collections/sweetbread/${
|
|
|
|
|
if osConfig.networking.hostName == "Rias" then "1764377"
|
|
|
|
|
else "2108577"
|
|
|
|
|
}"
|
2025-11-27 15:33:23 +03:00
|
|
|
with open("${config.sops.secrets."tokens/apis/wallhaven".path}") as f:
|
|
|
|
|
token = f.read()
|
|
|
|
|
|
2026-06-08 03:47:46 +03:00
|
|
|
filename = None
|
|
|
|
|
notify("Updating wallpaper...", 0)
|
2025-11-27 15:33:23 +03:00
|
|
|
|
|
|
|
|
try:
|
2026-06-08 03:47:46 +03:00
|
|
|
response = requests.get(url, params={'apikey': token})
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
json = response.json()
|
2025-11-27 15:33:23 +03:00
|
|
|
|
|
|
|
|
wallpaper = choice(json['data'])
|
|
|
|
|
link = wallpaper['path']
|
|
|
|
|
format = wallpaper['file_type']
|
|
|
|
|
id = wallpaper['id']
|
|
|
|
|
|
|
|
|
|
if format == "image/jpeg": ext = "jpg"
|
|
|
|
|
else: ext = "png"
|
|
|
|
|
|
|
|
|
|
filename = f"{id}.{ext}"
|
2026-06-08 03:47:46 +03:00
|
|
|
destination = f"{folder}/{filename}"
|
2025-11-27 15:33:23 +03:00
|
|
|
|
2026-06-08 03:47:46 +03:00
|
|
|
if not exists(destination):
|
|
|
|
|
makedirs(folder, exist_ok=True)
|
|
|
|
|
notify("Downloading... 0%", 0, 0)
|
|
|
|
|
download_with_progress(link, destination)
|
|
|
|
|
notify("Downloaded", 100)
|
|
|
|
|
else:
|
|
|
|
|
notify("Using cached wallpaper", 100)
|
2025-11-27 15:33:23 +03:00
|
|
|
|
2026-06-08 03:47:46 +03:00
|
|
|
except requests.exceptions.RequestException:
|
2025-11-27 15:33:23 +03:00
|
|
|
notify("Offline mode")
|
2026-06-08 03:47:46 +03:00
|
|
|
try:
|
|
|
|
|
filename = choice(listdir(folder))
|
|
|
|
|
except (FileNotFoundError, IndexError):
|
|
|
|
|
notify("Offline mode and wallpaper cache is empty")
|
2025-11-27 15:33:23 +03:00
|
|
|
|
|
|
|
|
finally:
|
2026-06-08 03:47:46 +03:00
|
|
|
if filename is not None:
|
|
|
|
|
notify("Applying wallpaper", 100)
|
|
|
|
|
system(f"awww img {folder}/{filename} --transition-type center")
|
2025-11-27 15:33:23 +03:00
|
|
|
'';
|
2024-10-02 22:10:08 +03:00
|
|
|
in {
|
|
|
|
|
settings = {
|
2026-09-05 19:45:18 +03:00
|
|
|
config = {
|
|
|
|
|
general = {
|
|
|
|
|
gaps_in = 2;
|
|
|
|
|
gaps_out = 10;
|
|
|
|
|
border_size = 3;
|
|
|
|
|
"col.active_border" = lib.mkForce {
|
|
|
|
|
colors = [
|
|
|
|
|
"rgba(${colors.base0C}aa)"
|
|
|
|
|
"rgba(${accent}aa)"
|
|
|
|
|
];
|
|
|
|
|
angle = 45;
|
|
|
|
|
};
|
|
|
|
|
layout = "dwindle";
|
2024-10-02 22:10:08 +03:00
|
|
|
};
|
|
|
|
|
|
2026-09-05 19:45:18 +03:00
|
|
|
decoration = {
|
|
|
|
|
rounding = 10;
|
|
|
|
|
|
|
|
|
|
blur = {
|
|
|
|
|
enabled = true;
|
|
|
|
|
size = 16;
|
|
|
|
|
passes = 2;
|
|
|
|
|
new_optimizations = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
shadow.enabled = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
animations.enabled = true;
|
|
|
|
|
dwindle.smart_split = true;
|
|
|
|
|
master.new_status = "master";
|
|
|
|
|
|
|
|
|
|
misc = {
|
|
|
|
|
animate_manual_resizes = true;
|
|
|
|
|
animate_mouse_windowdragging = true;
|
|
|
|
|
enable_swallow = true;
|
|
|
|
|
};
|
2024-10-02 22:10:08 +03:00
|
|
|
};
|
|
|
|
|
|
2026-09-05 19:45:18 +03:00
|
|
|
curve = {
|
|
|
|
|
_args = [
|
|
|
|
|
"myBezier"
|
|
|
|
|
{
|
|
|
|
|
type = "bezier";
|
|
|
|
|
points = [
|
|
|
|
|
[ 0.05 0.9 ]
|
|
|
|
|
[ 0.1 1.05 ]
|
|
|
|
|
];
|
|
|
|
|
}
|
2024-10-02 22:10:08 +03:00
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2026-09-05 19:45:18 +03:00
|
|
|
animation = [
|
|
|
|
|
{ leaf = "windows"; enabled = true; speed = 7; bezier = "myBezier"; }
|
|
|
|
|
{ leaf = "windowsOut"; enabled = true; speed = 7; bezier = "default"; style = "popin 80%"; }
|
|
|
|
|
{ leaf = "border"; enabled = true; speed = 10; bezier = "default"; }
|
|
|
|
|
{ leaf = "borderangle"; enabled = true; speed = 8; bezier = "default"; }
|
|
|
|
|
{ leaf = "fade"; enabled = true; speed = 7; bezier = "default"; }
|
|
|
|
|
{ leaf = "workspaces"; enabled = true; speed = 6; bezier = "default"; }
|
2025-11-27 15:33:23 +03:00
|
|
|
];
|
|
|
|
|
|
2026-09-05 19:45:18 +03:00
|
|
|
on = [
|
|
|
|
|
(hyprLua.onStart [ "${lib.getExe wallpaper_changer}" ])
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
workspace_rule = [
|
|
|
|
|
{
|
|
|
|
|
workspace = "2";
|
|
|
|
|
layout = "scrolling";
|
|
|
|
|
}
|
2026-04-02 17:51:27 +03:00
|
|
|
];
|
|
|
|
|
|
2024-10-02 22:10:08 +03:00
|
|
|
bind = [
|
2026-09-05 19:45:18 +03:00
|
|
|
(hyprLua.bind "Print" (hyprLua.exec "${lib.getExe pkgs.hyprshot} -z -o ~/Screenshots -m active -m output"))
|
|
|
|
|
(hyprLua.bind "CTRL + Print" (hyprLua.exec "${lib.getExe pkgs.hyprshot} -z -o ~/Screenshots -m region"))
|
|
|
|
|
(hyprLua.bind "ALT + Print" (hyprLua.exec "${lib.getExe pkgs.hyprshot} -z -o ~/Screenshots -m active -m window"))
|
|
|
|
|
(hyprLua.bind "SUPER + W" (hyprLua.exec "${lib.getExe wallpaper_changer}"))
|
2024-10-02 22:10:08 +03:00
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|