rules: only use X11 code when X11 is available

This commit is contained in:
Peter F. Patel-Schneider 2020-11-28 09:28:30 -05:00
parent 0427e5607e
commit 7d0402a97f
3 changed files with 35 additions and 35 deletions

View File

@ -20,20 +20,17 @@ and `hid-logitech-hidpp` loaded. Also, the `udev` package must be installed
and its daemon running. If you have a recent Linux distribution, you are and its daemon running. If you have a recent Linux distribution, you are
most likely good to go. most likely good to go.
Solaar requires Python 3.6+ Solaar requires Python 3.6+ and the
and the `python3-pyudev` package. `python3-pyudev` package.
To run the GUI Solaar also requires Gtk3, its GObject The Solaar GUI requires the
introspection bindings. `python3-psutil`, `python3-xlib`, and `python3-pyyaml` packages.
To run the GUI Solaar also requires Gtk3 and its GObject introspection bindings.
The Debian/Ubuntu packages that need to be installed are The Debian/Ubuntu packages that need to be installed are
`python3-gi` and `gir1.2-gtk-3.0`; `python3-gi` and `gir1.2-gtk-3.0`;
in Fedora you need `gtk3` and `python3-gobject`; in Fedora you need `gtk3` and `python3-gobject`;
if you're using another if you're using another
distribution the required packages are most likely named something similar. distribution the required packages are most likely named something similar.
The Solaar GUI also requires Python packages You may have to install `gcc` and the Python development package (`python3-dev` or `python3-devel`,
`PyYAML` (>= 5.1), `python-xlib` (>= 0.27), and `psutil` (>= 5.7.3).
These are best installed using `pip` via `pip install --user <package>`
if they are not already available.
You may have to install the `gcc` and the Python development package (`python3-dev` or `python3-devel`,
depending on your distribution). depending on your distribution).
If desktop notifications bindings are also installed If desktop notifications bindings are also installed

View File

@ -53,13 +53,14 @@ except Exception:
XK_KEYS = {} XK_KEYS = {}
x11 = False x11 = False
# determine name of active process if x11:
# determine name of active process
disp_prog = Display()
NET_ACTIVE_WINDOW = disp_prog.intern_atom('_NET_ACTIVE_WINDOW')
NET_WM_PID = disp_prog.intern_atom('_NET_WM_PID')
root2 = disp_prog.screen().root
root2.change_attributes(event_mask=Xlib.X.PropertyChangeMask)
disp_prog = Display()
NET_ACTIVE_WINDOW = disp_prog.intern_atom('_NET_ACTIVE_WINDOW')
NET_WM_PID = disp_prog.intern_atom('_NET_WM_PID')
root2 = disp_prog.screen().root
root2.change_attributes(event_mask=Xlib.X.PropertyChangeMask)
active_process_name = None active_process_name = None
@ -82,28 +83,29 @@ def determine_active_program():
active_process_name = active_program() active_process_name = active_program()
_thread.start_new_thread(determine_active_program, ()) if x11:
_thread.start_new_thread(determine_active_program, ())
# determine current key modifiers # determine current key modifiers
# there must be a better way to do this # there must be a better way to do this
display = Display() if x11:
context = display.record_create_context( display = Display()
0, [record.AllClients], [{ context = display.record_create_context(
'core_requests': (0, 0), 0, [record.AllClients], [{
'core_replies': (0, 0), 'core_requests': (0, 0),
'ext_requests': (0, 0, 0, 0), 'core_replies': (0, 0),
'ext_replies': (0, 0, 0, 0), 'ext_requests': (0, 0, 0, 0),
'delivered_events': (0, 0), 'ext_replies': (0, 0, 0, 0),
'device_events': (X.KeyPress, X.KeyRelease), 'delivered_events': (0, 0),
'errors': (0, 0), 'device_events': (X.KeyPress, X.KeyRelease),
'client_started': False, 'errors': (0, 0),
'client_died': False, 'client_started': False,
}] 'client_died': False,
) }]
)
modifier_keycodes = display.get_modifier_mapping() modifier_keycodes = display.get_modifier_mapping()
current_key_modifiers = 0 current_key_modifiers = 0
def modifier_code(keycode): def modifier_code(keycode):
@ -162,7 +164,8 @@ TESTS = {
COMPONENTS = {} COMPONENTS = {}
displayt = Display() if x11:
displayt = Display()
class RuleComponent(object): class RuleComponent(object):

View File

@ -63,7 +63,7 @@ battery status, and show and modify some of the modifiable features of devices.
'pyudev (>= 0.13)', 'pyudev (>= 0.13)',
'PyYAML (>= 5.1)', 'PyYAML (>= 5.1)',
'python-xlib (>= 0.27)', 'python-xlib (>= 0.27)',
'psutil (>= 5.7.3)', 'psutil (>= 5.6.0)',
], ],
package_dir={'': 'lib'}, package_dir={'': 'lib'},
packages=['hidapi', 'logitech_receiver', 'solaar', 'solaar.ui', 'solaar.cli'], packages=['hidapi', 'logitech_receiver', 'solaar', 'solaar.ui', 'solaar.cli'],