feat: wallpaper_random

This commit is contained in:
Ryan Yin
2023-07-29 23:08:13 +08:00
parent bc290e371b
commit a310ab4d4a
12 changed files with 153 additions and 47 deletions

60
flake.lock generated
View File

@@ -371,11 +371,11 @@
]
},
"locked": {
"lastModified": 1690368313,
"narHash": "sha256-1MG/pU2riawknpYaTfaynKJPaIKFnQiYTTCFJAjXM5Q=",
"lastModified": 1690431538,
"narHash": "sha256-Uml8ivMMOFPB9fNSDcw72imGHRdJpaK12sRm2DTLLe8=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "94212ebe32948471a1aa11baa5c576ce60d54589",
"rev": "16c07487ac9bc59f58b121d13160c67befa3342e",
"type": "github"
},
"original": {
@@ -391,11 +391,11 @@
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1689903701,
"narHash": "sha256-kW1Rke5wLqw8XHVyiWw7qIKZR911GCsbOg5SkgKH1Uc=",
"lastModified": 1690420922,
"narHash": "sha256-qnVkCp364/NqvGyA9tL6yVO0ZjNDaHcZWSEueNZ6CEE=",
"owner": "nix-community",
"repo": "nix-eval-jobs",
"rev": "fcaf7773e3a6713b78dacfd442339a96cfab405f",
"rev": "f360004d785937aa0a9ed19bbeec864dec37737b",
"type": "github"
},
"original": {
@@ -458,11 +458,11 @@
},
"nixpkgs-darwin": {
"locked": {
"lastModified": 1690298576,
"narHash": "sha256-RLgIGS04t4Rd0viqsx2e9dGViKB6nVsGmO11EagCWmM=",
"lastModified": 1690558459,
"narHash": "sha256-5W7y1l2cLYPkpJGNlAja7XW2X2o9rjf0O1mo9nxS9jQ=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "88f63d511092e95d28e9a7c98534595c53de1048",
"rev": "48e82fe1b1c863ee26a33ce9bd39621d2ada0a33",
"type": "github"
},
"original": {
@@ -489,11 +489,11 @@
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1690179384,
"narHash": "sha256-+arbgqFTAtoeKtepW9wCnA0njCOyoiDFyl0Q0SBSOtE=",
"lastModified": 1690548937,
"narHash": "sha256-x3ZOPGLvtC0/+iFAg9Kvqm/8hTAIkGjc634SqtgaXTA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b12803b6d90e2e583429bb79b859ca53c348b39a",
"rev": "2a9d660ff0f7ffde9d73be328ee6e6f10ef66b28",
"type": "github"
},
"original": {
@@ -511,11 +511,11 @@
"nixpkgs": "nixpkgs_5"
},
"locked": {
"lastModified": 1690384532,
"narHash": "sha256-Nc9d6GPajVdSj02aBDkAAq93fdLUtRXP9EIfwKn3Uq4=",
"lastModified": 1690608929,
"narHash": "sha256-GUpBZvuDH+Hn3Dp7bg9RKt8mgUp4+y4uSxa/HFjZvaY=",
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"rev": "729cabdcc73e84963751dd65163048e9ff1a1a75",
"rev": "90fb8a2b8fe1a2fe792e87825d3ec5c8b1e50de3",
"type": "github"
},
"original": {
@@ -542,11 +542,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1690271650,
"narHash": "sha256-qwdsW8DBY1qH+9luliIH7VzgwvL+ZGI3LZWC0LTiDMI=",
"lastModified": 1690558459,
"narHash": "sha256-5W7y1l2cLYPkpJGNlAja7XW2X2o9rjf0O1mo9nxS9jQ=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6dc93f0daec55ee2f441da385aaf143863e3d671",
"rev": "48e82fe1b1c863ee26a33ce9bd39621d2ada0a33",
"type": "github"
},
"original": {
@@ -558,11 +558,11 @@
},
"nixpkgs_4": {
"locked": {
"lastModified": 1688951312,
"narHash": "sha256-0oG4uv60m5+oOMqgYYQ3ao3OK3YP3n3t7nWFtuyR/uQ=",
"lastModified": 1690420098,
"narHash": "sha256-47kn22jGYlCeHQxdmqoZeR2jHhZpJjxYFgCXdClVadA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2a5f6cac357616d2596167d0631b4ca729e9a3ea",
"rev": "6d8c4bd21e6f9fb6c67bb599459f35cf9486e18b",
"type": "github"
},
"original": {
@@ -574,11 +574,11 @@
},
"nixpkgs_5": {
"locked": {
"lastModified": 1690179384,
"narHash": "sha256-+arbgqFTAtoeKtepW9wCnA0njCOyoiDFyl0Q0SBSOtE=",
"lastModified": 1690548937,
"narHash": "sha256-x3ZOPGLvtC0/+iFAg9Kvqm/8hTAIkGjc634SqtgaXTA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b12803b6d90e2e583429bb79b859ca53c348b39a",
"rev": "2a9d660ff0f7ffde9d73be328ee6e6f10ef66b28",
"type": "github"
},
"original": {
@@ -591,11 +591,11 @@
"nushell-scripts": {
"flake": false,
"locked": {
"lastModified": 1690554155,
"narHash": "sha256-gJAnMY1HtRhRyRKOi0ifbuDVaImMmQeo4yY3jxY6N6c=",
"lastModified": 1690635434,
"narHash": "sha256-luGIvcKOfhDorPfGfL449+eD+58MGo5jMCsNwIRJWt4=",
"owner": "nushell",
"repo": "nu_scripts",
"rev": "f4f765a9462a4d06a1e1a8eab0dc2ee4c7421fe5",
"rev": "3ee56c6ec31fcc8dbffee85e1c73eb6fe0bbba8d",
"type": "github"
},
"original": {
@@ -669,11 +669,11 @@
"wallpapers": {
"flake": false,
"locked": {
"lastModified": 1690627498,
"narHash": "sha256-diR4OElUOWbCmTWTCLN50a8P35UM5xfBKHZPDHGFuH0=",
"lastModified": 1690641644,
"narHash": "sha256-WDBM0F+dizHWPA9rNAggck+UOXwPxq0wNupin2cka+U=",
"owner": "ryan4yin",
"repo": "wallpapers",
"rev": "a5d3a181e1dc7fd120f9acf11adc85bebea610d6",
"rev": "01a8eeed2176793c9909b3fd8dc13f375ebe3a66",
"type": "github"
},
"original": {

View File

@@ -20,16 +20,12 @@
nix-darwin,
home-manager,
nixos-generators,
wallpapers,
...
}: let
username = "ryan";
userfullname = "Ryan Yin";
useremail = "xiaoyin_c@qq.com";
# https://github.com/ryan4yin/wallpapers
wallpaper = "${wallpapers}/anime-girls_seagulls_smoking_nature-occupation.jpg";
x64_system = "x86_64-linux";
x64_darwin = "x86_64-darwin";
allSystems = [x64_system x64_darwin];
@@ -81,7 +77,7 @@
system = x64_system;
specialArgs =
{
inherit username userfullname useremail wallpaper;
inherit username userfullname useremail;
# use unstable branch for some packages to get the latest updates
pkgs-unstable = import nixpkgs-unstable {
system = x64_system; # refer the `system` parameter form outer scope recursively

View File

@@ -1,8 +1,18 @@
{...}: {
{ config, ...}: {
programs.nushell = {
enable = true;
configFile.source = ./config.nu;
extraConfig = ''
let-env PATH = ([
"${config.home.homeDirectory}/bin"
"${config.home.homeDirectory}/.local/bin"
"${config.home.homeDirectory}/go/bin"
($env.PATH | split row (char esep))
] | flatten)
'';
# home-manager will merge the cotent in `environmentVariables` with the `envFile.source`
# but basically, I set all environment variables via the shell-independent way, so I don't need to use those two options
#

View File

@@ -1,5 +1,7 @@
{pkgs, ...}: {
imports = [
./wallpaper
./creative.nix
./immutable-file.nix
./media.nix

View File

@@ -0,0 +1,9 @@
{ wallpapers, ... }:
{
home.file.".config/wallpapers".source = wallpapers;
home.file.".local/bin/wallpaper_random" = {
source = ./wallpaper_random.py;
executable = true;
};
}

View 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()

View File

@@ -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

View File

@@ -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.

View File

@@ -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 &

View File

@@ -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

View File

@@ -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" = {

View File

@@ -5,5 +5,8 @@ builtins.map
(builtins.filter # find all overlay files in the current directory
(f: f != "default.nix")
(f:
f != "default.nix" # ignore default.nix
&& f != "README.md" # ignore README.md
)
(builtins.attrNames (builtins.readDir ./.)))