Compare commits

...

2 Commits

Author SHA1 Message Date
nikolaizombie1
ba36d3ff21
Merge 0a59622b88 into 4120bf97d4 2024-06-02 06:30:36 -04:00
nikolaizombie1
0a59622b88 Add All suport for hyprpaper and remove unnecessary assignment. #7. 2024-06-02 06:30:17 -04:00

View File

@ -4,7 +4,7 @@ import subprocess
import time import time
from waypaper.config import Config from waypaper.config import Config
from waypaper.translations import Chinese, English, French, German, Polish, Russian from waypaper.translations import Chinese, English, French, German, Polish, Russian
import sys import re
def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|English|French|German|Polish|Russian): def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|English|French|German|Polish|Russian):
@ -115,18 +115,29 @@ def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|Eng
time.sleep(1) time.sleep(1)
preload_command = ["hyprctl", "hyprpaper", "preload", image_path] preload_command = ["hyprctl", "hyprpaper", "preload", image_path]
if monitor == "All": if monitor == "All":
monitor = "" monitors: list = []
wallpaper_command = ["hyprctl", "hyprpaper", "wallpaper", f"{monitor},{image_path}"] # Check available motitors (using hyprpaper):
unload_command = ["hyprctl", "hyprpaper", "unload", "all"] query_output = str(subprocess.check_output(["hyprctl", "monitors"], encoding='utf-8'))
result: str = "" query_output = query_output.split('\n')
retry_counter: int = 0 # Use a regular expression to get the lines that contain the monitor names:
while result != "ok" and retry_counter < 10: query_output = list(filter(lambda line: re.match(r"Monitor [a-zA-Z-0-9]+ \(ID \d+\):", line),query_output))
try: for line in query_output:
result = subprocess.check_output(unload_command, encoding="utf-8").strip() monitors.append(line.split(' ')[1])
result = subprocess.check_output(preload_command, encoding="utf-8").strip() else:
result = subprocess.check_output(wallpaper_command, encoding="utf-8").strip() monitors: list = [monitor]
except Exception: for m in monitors:
retry_counter += 1 wallpaper_command = ["hyprctl", "hyprpaper", "wallpaper", f"{m},{image_path}"]
unload_command = ["hyprctl", "hyprpaper", "unload", "all"]
result: str = ""
retry_counter: int = 0
while result != "ok" and retry_counter < 10:
try:
subprocess.check_output(unload_command, encoding="utf-8").strip()
subprocess.check_output(preload_command, encoding="utf-8").strip()
result = subprocess.check_output(wallpaper_command, encoding="utf-8").strip()
time.sleep(0.1)
except Exception:
retry_counter += 1
elif cf.backend == "none": elif cf.backend == "none":
pass pass