mirror of
https://github.com/anufrievroman/waypaper.git
synced 2024-11-21 23:17:12 +03:00
Reimplementing monitor detection
Now, all monitor detection happens with sceeninfo
This commit is contained in:
parent
8bf2ced1a9
commit
f4d268b905
2
setup.py
2
setup.py
@ -17,7 +17,7 @@ setuptools.setup(
|
||||
"waypaper = waypaper.__main__:run"
|
||||
]
|
||||
},
|
||||
install_requires=["PyGObject", "importlib_metadata", "platformdirs", "Pillow", "opencv-python-headless"],
|
||||
install_requires=["PyGObject", "importlib_metadata", "platformdirs", "Pillow", "opencv-python-headless", "screeninfo"],
|
||||
version='2.3',
|
||||
python_requires='>3.9',
|
||||
classifiers=[
|
||||
|
@ -10,7 +10,7 @@ from PIL import Image
|
||||
from waypaper.aboutdata import AboutData
|
||||
from waypaper.changer import change_wallpaper
|
||||
from waypaper.config import Config
|
||||
from waypaper.common import get_image_paths, get_random_file, get_monitor_names_hyprctl, get_monitor_names_swww
|
||||
from waypaper.common import get_image_paths, get_random_file, get_monitor_names, get_monitor_names_hyprctl, get_monitor_names_swww
|
||||
from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SORT_DISPLAYS, VIDEO_EXTENSIONS
|
||||
from waypaper.translations import Chinese, English, French, German, Polish, Russian, Belarusian, Spanish
|
||||
|
||||
@ -241,14 +241,7 @@ class App(Gtk.Window):
|
||||
self.options_box.remove(self.monitor_option_combo)
|
||||
# Check available monitors:
|
||||
monitor_names = ["All"]
|
||||
if self.cf.backend == "swww":
|
||||
connected_monitors = get_monitor_names_swww()
|
||||
monitor_names.extend(connected_monitors)
|
||||
elif self.cf.backend == "hyprpaper":
|
||||
connected_monitors = get_monitor_names_hyprctl()
|
||||
monitor_names.extend(connected_monitors)
|
||||
else:
|
||||
return
|
||||
monitor_names.extend(get_monitor_names())
|
||||
|
||||
# Create a monitor option dropdown menu:
|
||||
self.monitor_option_combo = Gtk.ComboBoxText()
|
||||
|
@ -5,9 +5,11 @@ import re
|
||||
import random
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
from screeninfo import get_monitors
|
||||
from pathlib import Path
|
||||
|
||||
from waypaper.options import IMAGE_EXTENSIONS, BACKEND_OPTIONS
|
||||
from typing import List
|
||||
|
||||
@ -120,43 +122,10 @@ def check_installed_backends() -> List[str]:
|
||||
return installed_backends
|
||||
|
||||
|
||||
def get_monitor_names_swww() -> List[str]:
|
||||
"""Obtain the list of plugged monitors using swww daemon"""
|
||||
connected_monitors: List[str] = []
|
||||
try:
|
||||
# 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:
|
||||
query_output = str(subprocess.check_output(["swww", "query"], encoding='utf-8'))
|
||||
monitors = query_output.split("\n")
|
||||
for monitor in monitors[:-1]:
|
||||
connected_monitors.append(monitor.split(':')[0])
|
||||
except Exception as e:
|
||||
print(f"Exception: {e}")
|
||||
|
||||
return connected_monitors
|
||||
|
||||
|
||||
def get_monitor_names_hyprctl() -> List[str]:
|
||||
"""Obtain the list of plugged monitors using hyprctl"""
|
||||
connected_monitors: List[str] = []
|
||||
|
||||
try:
|
||||
# Check available motitors:
|
||||
query_output = str(subprocess.check_output(["hyprctl", "monitors"], encoding='utf-8'))
|
||||
query_output = query_output.split('\n')
|
||||
|
||||
# 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:
|
||||
connected_monitors.append(line.split(' ')[1])
|
||||
except Exception as e:
|
||||
print(f"Exception: {e}")
|
||||
|
||||
def get_monitor_names() -> List[str]:
|
||||
"""Obtain the list of plugged monitors"""
|
||||
connected_monitors: List[str] = []
|
||||
for m in get_monitors():
|
||||
connected_monitors.append(m.name)
|
||||
return connected_monitors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user