This commit is contained in:
Nick Price 2026-08-01 12:08:45 -07:00 committed by GitHub
commit 0b5f381613
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 13 deletions

View File

@ -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",

View File

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

View File

@ -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",

View File

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

View File

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

View File

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