66 lines
2.0 KiB
Python
Executable File
66 lines
2.0 KiB
Python
Executable File
#!/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) |