mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-04-23 09:18:35 +02:00
feat: wallpaper_random
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
{pkgs, ...}: {
|
||||
imports = [
|
||||
./wallpaper
|
||||
|
||||
./creative.nix
|
||||
./immutable-file.nix
|
||||
./media.nix
|
||||
|
||||
9
home/linux/desktop/wallpaper/default.nix
Normal file
9
home/linux/desktop/wallpaper/default.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
{ wallpapers, ... }:
|
||||
|
||||
{
|
||||
home.file.".config/wallpapers".source = wallpapers;
|
||||
home.file.".local/bin/wallpaper_random" = {
|
||||
source = ./wallpaper_random.py;
|
||||
executable = true;
|
||||
};
|
||||
}
|
||||
90
home/linux/desktop/wallpaper/wallpaper_random.py
Normal file
90
home/linux/desktop/wallpaper/wallpaper_random.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
WALLPAPERS_DIR = "~/.config/wallpapers"
|
||||
LAST_WALLPAPER_FILE = "/tmp/my_last_wallpaper"
|
||||
IMAGE_EXTENSIONS = (
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".png",
|
||||
# ".gif",
|
||||
# ".webp"
|
||||
)
|
||||
|
||||
|
||||
def get_random_wallpaper():
|
||||
wallpapers_dir = Path(WALLPAPERS_DIR).expanduser()
|
||||
last_wallpaper_file = Path(LAST_WALLPAPER_FILE)
|
||||
if last_wallpaper_file.exists():
|
||||
last_wallpaper = Path(last_wallpaper_file.read_text().strip())
|
||||
print("Last wallpaper:", last_wallpaper)
|
||||
else:
|
||||
last_wallpaper = None
|
||||
|
||||
wallpapers = [
|
||||
p for p in Path(wallpapers_dir).glob("*") if p.suffix in IMAGE_EXTENSIONS
|
||||
]
|
||||
print("Found wallpaper:")
|
||||
for p in wallpapers:
|
||||
if p == last_wallpaper:
|
||||
print(" ", p, "(skipped)")
|
||||
wallpapers.remove(p)
|
||||
else:
|
||||
print(" ", p)
|
||||
if not wallpapers:
|
||||
raise RuntimeError("No wallpapers found!")
|
||||
|
||||
w = random.choice(wallpapers)
|
||||
print("Selected wallpaper:", w)
|
||||
last_wallpaper_file.write_text(str(w))
|
||||
return w
|
||||
|
||||
|
||||
def set_wallpaper_x11(path):
|
||||
subprocess.run(["feh", "--bg-fill", path])
|
||||
|
||||
|
||||
def set_wallpaper_wayland(path):
|
||||
# find all swaybg processes
|
||||
swaybg_pids = subprocess.run(
|
||||
["pgrep", "-f", "swaybg"], stdout=subprocess.PIPE
|
||||
).stdout.decode("utf-8")
|
||||
|
||||
# run swaybg in the background, and make it running even after the parent process exits
|
||||
subprocess.Popen(
|
||||
["swaybg", "--output", "*", "--mode", "fill", "--image", path],
|
||||
start_new_session=True,
|
||||
)
|
||||
time.sleep(1)
|
||||
|
||||
# kill all old swaybg processes
|
||||
for pid in swaybg_pids.splitlines():
|
||||
try:
|
||||
os.kill(int(pid), 9)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
|
||||
|
||||
def set_wallpaper(path):
|
||||
# check if we are running under x11 or wayland
|
||||
if (
|
||||
"WAYLAND_DISPLAY" in os.environ
|
||||
or os.environ.get("XDG_SESSION_TYPE") == "wayland"
|
||||
):
|
||||
set_wallpaper_wayland(path)
|
||||
else:
|
||||
set_wallpaper_x11(path)
|
||||
|
||||
|
||||
def main():
|
||||
wallpaper = get_random_wallpaper()
|
||||
set_wallpaper(wallpaper)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,4 +1,4 @@
|
||||
{pkgs, catppuccin-hyprland, wallpaper, ...}: {
|
||||
{pkgs, catppuccin-hyprland, ...}: {
|
||||
imports = [
|
||||
./wayland-apps.nix
|
||||
];
|
||||
@@ -14,9 +14,7 @@
|
||||
# copy the scripts directory recursively
|
||||
recursive = true;
|
||||
};
|
||||
home.file.".config/hypr-themes".source = "${catppuccin-hyprland}/themes";
|
||||
|
||||
home.file.".config/hypr/wallpapers/wallpaper".source = wallpaper;
|
||||
home.file.".config/hypr/themes".source = "${catppuccin-hyprland}/themes";
|
||||
|
||||
# gtk's theme settings, generate files:
|
||||
# 1. ~/.gtkrc-2.0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Hyprland configuration file
|
||||
|
||||
# color-scheme: cappuccin-mocha
|
||||
source=~/.config/hypr-themes/mocha.conf
|
||||
source=~/.config/hypr/themes/mocha.conf
|
||||
|
||||
#-- Output ----------------------------------------------------
|
||||
# Configure your Display resolution, offset, scale and Monitors here, use `hyprctl monitors` to get the info.
|
||||
|
||||
@@ -11,7 +11,7 @@ for _prs in "${_ps[@]}"; do
|
||||
done
|
||||
|
||||
# Set wallpaper
|
||||
swaybg --output '*' --mode fill --image ~/.config/hypr/wallpapers/wallpaper &
|
||||
swaybg --output '*' --mode fill --image ~/.config/wallpapers/default_wallpaper &
|
||||
|
||||
# Lauch notification daemon (mako)
|
||||
~/.config/hypr/scripts/notifications &
|
||||
|
||||
@@ -262,7 +262,7 @@ exec --no-startup-id ~/.screenlayout/monitor.sh
|
||||
|
||||
# set wallpaper
|
||||
# exec --no-startup-id sleep 2 && nitrogen --restore
|
||||
exec --no-startup-id sleep 1 && feh --bg-fill ~/.config/i3/wallpaper
|
||||
exec --no-startup-id sleep 1 && feh --bg-fill ~/.config/wallpapers/default_wallpaper
|
||||
|
||||
# set powersavings for display:
|
||||
exec --no-startup-id xset s 480 dpms 600 600 600
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ pkgs, wallpaper, ...}: {
|
||||
{ pkgs, ...}: {
|
||||
# i3 window manager's config, based on https://github.com/endeavouros-team/endeavouros-i3wm-setup
|
||||
|
||||
imports = [
|
||||
@@ -6,8 +6,6 @@
|
||||
];
|
||||
|
||||
home.file = {
|
||||
# wallpaper, binary file
|
||||
".config/i3/wallpaper".source = wallpaper;
|
||||
".config/i3/config".source = ./config;
|
||||
".config/i3/i3blocks.conf".source = ./i3blocks.conf;
|
||||
".config/i3/scripts" = {
|
||||
|
||||
Reference in New Issue
Block a user