This commit is contained in:
Benjamyn Love 2021-12-20 08:57:10 +11:00
commit 3fa150b475
3 changed files with 82 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vscode/
Pipfile
Pipfile.lock

13
wallpaperctl.ini Normal file
View File

@ -0,0 +1,13 @@
[General]
WALLHAVEN_API_KEY=asdfg
X_SERVER=:0
WALLPAPER_ENGINE=feh
ULTRA_WALL_DIR=~/Pictures/wallpaper-ultra
HOR_WALL_DIR=~/Pictures/wallpaper-hor
VERT_WALL_DIR=~/Pictures/wallpaper-vert
[Monitors]
1=ultrawide
2=vertical
3=horizontal

66
wallpaperctl.py Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/python3
import configparser
import os
import random
from pathlib import Path
import subprocess
def find_all_images(path):
IMAGE_TYPES = ['jpg', 'png', 'webp', 'jpeg']
images = []
for image_type in IMAGE_TYPES:
[images.append(image) for image in path.glob(f'**/*.{image_type}')]
return images
conf_file = f"{os.environ['HOME']}/.config/wallpaperctl/wallpaperctl.ini"
# Initialize config file
config = configparser.ConfigParser()
try:
config.read(conf_file)
X_DISPLAY = config['General']['X_SERVER']
WALLHAVEN_API_KEY = config['General']['WALLHAVEN_API_KEY']
WALLPAPER_ENGINE = config['General']['WALLPAPER_ENGINE']
ULTRA_WALL_DIR = Path(config['General']['ULTRA_WALL_DIR']).expanduser()
HOR_WALL_DIR = Path(config['General']['HOR_WALL_DIR']).expanduser()
VERT_WALL_DIR = Path(config['General']['VERT_WALL_DIR']).expanduser()
monitors = {}
for ID in config['Monitors'].keys():
monitors[ID] = config['Monitors'][ID]
except Exception as ex:
print('Please copy default config from /opt/wallpaperctl to $HOME/.config/wallpaperctl/wallpaperctl.ini')
# Load a list of the images (supports nested files using **)
ultra_images = [image for image in find_all_images(ULTRA_WALL_DIR)]
hor_images = [image for image in find_all_images(HOR_WALL_DIR)]
vert_images = [image for image in find_all_images(VERT_WALL_DIR)]
# Store selected wallpapers here
wallpapers = []
# Loop through defined monitors and allocate an approprate wallpaper
for mon in monitors:
match monitors[mon]:
case 'ultrawide':
wallpapers.append(random.choice(ultra_images))
case 'vertical':
wallpapers.append(random.choice(vert_images))
case 'horizontal':
wallpapers.append(random.choice(hor_images))
case _:
print(monitors[mon])
print(wallpapers)
cmd = "/usr/bin/feh --no-fehbg --bg-fill "
for wallpaper in wallpapers:
cmd += str(f"{wallpaper} ")
subprocess.call(cmd, shell=True)
# subprocess.call("ls -alh",shell=True)