diff --git a/lib/hidapi/hidapi_impl.py b/lib/hidapi/hidapi_impl.py index d9fc3047..38ba3e4f 100644 --- a/lib/hidapi/hidapi_impl.py +++ b/lib/hidapi/hidapi_impl.py @@ -60,6 +60,8 @@ _library_paths = ( "libhidapi-hidraw.so.0", "libhidapi-libusb.so", "libhidapi-libusb.so.0", + "libhidapi.so", + "libhidapi.so.0", "libhidapi-iohidmanager.so", "libhidapi-iohidmanager.so.0", "libhidapi.dylib", diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index e933f5ad..026c7556 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -21,7 +21,6 @@ import logging import math import numbers import os -import platform import socket import struct import subprocess @@ -39,12 +38,13 @@ import yaml from keysyms import keysymdef -# There is no evdev on macOS or Windows. Diversion will not work without -# it but other Solaar functionality is available. -if platform.system() in ("Darwin", "Windows"): - evdev = None -else: +# evdev is not available on every platform, and is an optional dependency +# elsewhere. Diversion will not work without it but other Solaar +# functionality is available. +try: import evdev +except ImportError: + evdev = None from .common import NamedInt from .hidpp20 import SupportedFeature @@ -197,7 +197,7 @@ def gnome_dbus_interface_setup(): bus = dbus.SessionBus() remote_object = bus.get_object("org.gnome.Shell", "/io/github/pwr_solaar/solaar") _dbus_interface = dbus.Interface(remote_object, "io.github.pwr_solaar.solaar") - except dbus.exceptions.DBusException: + except Exception: logger.warning( "Solaar Gnome extension not installed - some rule capabilities inoperable", exc_info=sys.exc_info(), @@ -257,6 +257,8 @@ else: def setup_uinput(): global udevice + if evdev is None: + return False if udevice is not None: return udevice try: @@ -337,6 +339,8 @@ def simulate_key(code, event): # X11 keycode but Solaar event code def click_uinput(button, count): + if evdev is None: + return False if isinstance(count, int): for _ in range(count): if not simulate_uinput(evdev.ecodes.EV_KEY, button[1], 1): diff --git a/lib/solaar/dbus.py b/lib/solaar/dbus.py index 142b5904..b7145cba 100644 --- a/lib/solaar/dbus.py +++ b/lib/solaar/dbus.py @@ -61,7 +61,9 @@ def watch_suspend_resume( global _resume_callback, _suspend_callback _suspend_callback = on_suspend_callback _resume_callback = on_resume_callback - if bus is not None and on_resume_callback is not None or on_suspend_callback is not None: + if bus is None: + return + if on_resume_callback is not None or on_suspend_callback is not None: bus.add_signal_receiver( _suspend_or_resume, "PrepareForSleep", diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index e0680820..4bc3c624 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -157,7 +157,8 @@ def _handlesig(signl, stack): def main(): - if platform.system() not in ("Darwin", "Windows"): + # Only the Linux HID backend uses pyudev; other platforms use the hidapi backend. + if platform.system() == "Linux": _require("pyudev", "python3-pyudev") args = _parse_arguments() diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index f09a9f18..7d515dc9 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -19,6 +19,7 @@ from __future__ import annotations import errno import logging +import platform import subprocess import time import typing @@ -472,7 +473,9 @@ def _process_add(device_info: DeviceInfo, retry): except OSError as e: if e.errno == errno.EACCES: try: - output = subprocess.check_output(["getfacl", "-p", device_info.path], text=True) + # -p (don't strip leading '/') is a Linux getfacl extension + getfacl = ["getfacl", "-p"] if platform.system() == "Linux" else ["getfacl"] + output = subprocess.check_output([*getfacl, device_info.path], text=True) logger.warning("Missing permissions on %s\n%s.", device_info.path, output) except Exception: pass diff --git a/setup.py b/setup.py index 41506287..fbc2bf8b 100755 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +import platform import subprocess import textwrap @@ -35,7 +36,8 @@ def _data_files(): yield dirname(mo), [mo] yield "share/applications", ["share/applications/solaar.desktop"] - yield "lib/udev/rules.d", ["rules.d/42-logitech-unify-permissions.rules"] + if platform.system() == "Linux": # udev is Linux-only + yield "lib/udev/rules.d", ["rules.d/42-logitech-unify-permissions.rules"] yield "share/metainfo", ["share/solaar/io.github.pwr_solaar.solaar.metainfo.xml"] @@ -64,13 +66,14 @@ setup( "Natural Language :: English", "Programming Language :: Python :: 3 :: Only", "Operating System :: POSIX :: Linux", + "Operating System :: POSIX :: BSD :: FreeBSD", "Topic :: Utilities", ], - platforms=["linux"], + platforms=["linux", "freebsd"], python_requires=">=3.8", install_requires=[ 'evdev (>= 1.1.2) ; platform_system=="Linux"', - "pyudev (>= 0.13)", + 'pyudev (>= 0.13) ; platform_system=="Linux"', "PyYAML (>= 3.12)", "python-xlib (>= 0.27)", "psutil (>= 5.4.3)",