Further improving interactions with swww-daemon

Checking if daemon is running before starting it in app.py
This commit is contained in:
Roman 2024-05-25 09:28:45 +09:00
parent 0028234011
commit 4120bf97d4
2 changed files with 11 additions and 5 deletions

View File

@ -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}")

View File

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