From 4120bf97d4455dbc06445013dd41e99c7051ec89 Mon Sep 17 00:00:00 2001 From: Roman Date: Sat, 25 May 2024 09:28:45 +0900 Subject: [PATCH] Further improving interactions with swww-daemon Checking if daemon is running before starting it in app.py --- waypaper/app.py | 15 ++++++++++----- waypaper/changer.py | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/waypaper/app.py b/waypaper/app.py index 2755908..c8e884b 100644 --- a/waypaper/app.py +++ b/waypaper/app.py @@ -230,7 +230,14 @@ class App(Gtk.Window): if self.cf.backend == "swww": try: - subprocess.Popen(["swww-daemon"]) + # Check if swww-deamon is already running. If not, launch it: + try: + subprocess.check_output(["pgrep", "swww-daemon"], encoding='utf-8') + except subprocess.CalledProcessError: + subprocess.Popen(["swww-daemon"]) + print("The swww-daemon launched.") + + # Check available monitors (using swww): query_output = str(subprocess.check_output(["swww", "query"], encoding='utf-8')) monitors = query_output.split("\n") for monitor in monitors[:-1]: @@ -240,14 +247,12 @@ class App(Gtk.Window): elif self.cf.backend == "hyprpaper": try: - # Query hyprctl for motitors + # Check available motitors (using hyprpaper): query_output = str(subprocess.check_output(["hyprctl", "monitors"], encoding='utf-8')) - # Get lines from output query_output = query_output.split('\n') - # Use a regular expression to get the lines that contain the monitor names + # Use a regular expression to get the lines that contain the monitor names: query_output = list(filter(lambda line: re.match(r"Monitor [a-zA-Z-0-9]+ \(ID \d+\):", line),query_output)) for line in query_output: - # Append monitor names to monitor_names monitor_names.append(line.split(' ')[1]) except Exception as e: print(f"{self.txt.err_disp} {e}") diff --git a/waypaper/changer.py b/waypaper/changer.py index 64f5fcc..2678856 100644 --- a/waypaper/changer.py +++ b/waypaper/changer.py @@ -62,6 +62,7 @@ def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|Eng subprocess.check_output(["pgrep", "swww-daemon"], encoding='utf-8') except subprocess.CalledProcessError: subprocess.Popen(["swww-daemon"]) + print("The swww-daemon launched.") command = ["swww", "img", image_path] command.extend(["--resize", fill])