Skip to content

Commit 6272f65

Browse files
committed
Pass XDG_SESSION_TYPE with tox.ini
This environment variable was not passed with tox, meaning that it wasn't exposed to the environment in Python. Now it is, and now you can use it to determine x11 from Wayland.
1 parent 9382224 commit 6272f65

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

plover/gui_qt/machine_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from plover import _
2424
from plover.oslayer.serial import patch_ports_info
2525
from plover.oslayer.config import PLATFORM
26+
from plover.oslayer.linux.display_server import DISPLAY_SERVER
2627

2728
from plover.gui_qt.config_keyboard_widget_ui import Ui_KeyboardWidget
2829
from plover.gui_qt.config_serial_widget_ui import Ui_SerialWidget
@@ -204,7 +205,7 @@ def __init__(self):
204205
)
205206
)
206207
self._value = {}
207-
if PLATFORM == "linux":
208+
if PLATFORM == "linux" and DISPLAY_SERVER == "wayland":
208209
self.setup_keyboard_selection()
209210

210211
def setValue(self, value):

plover/machine/keyboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from plover.misc import boolean
1010
from plover.oslayer.keyboardcontrol import KeyboardCapture
1111
from plover.oslayer.config import PLATFORM
12+
from plover.oslayer.linux.display_server import DISPLAY_SERVER
1213

1314

1415
# i18n: Machine name.
@@ -91,7 +92,7 @@ def start_capture(self):
9192
self._initializing()
9293
try:
9394
self._keyboard_capture = KeyboardCapture()
94-
if PLATFORM == "linux":
95+
if PLATFORM == "linux" and DISPLAY_SERVER == "wayland":
9596
self._keyboard_capture.set_keyboard_selection(self._keyboard_selection)
9697
self._keyboard_capture.key_down = self._key_down
9798
self._keyboard_capture.key_up = self._key_up

plover/oslayer/linux/display_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
- wayland
77
- tty
88
"""
9+
print(os.environ.items())
910
DISPLAY_SERVER = os.environ.get("XDG_SESSION_TYPE", None)

test/test_keyboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from plover.machine.keymap import Keymap
66
from plover.oslayer.keyboardcontrol import KeyboardCapture
77
from plover.oslayer.config import PLATFORM
8+
from plover.oslayer.linux.display_server import DISPLAY_SERVER
89

910
from unittest import mock
1011

@@ -66,7 +67,7 @@ def strokes(machine):
6667
def test_lifecycle(capture, machine, strokes):
6768
# Start machine.
6869
machine.start_capture()
69-
if PLATFORM == "linux":
70+
if PLATFORM == "linux" and DISPLAY_SERVER == "wayland":
7071
assert capture.mock_calls == [
7172
mock.call.set_keyboard_selection(""),
7273
mock.call.start(),

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ setenv =
6060
# Linux: add to library path so ctypes can find hidapi libraries
6161
LD_LIBRARY_PATH = {env:HIDAPI_DEV_LIB_LNX}{:}{env:LD_LIBRARY_PATH:}
6262

63+
# Linux: pass XDG_SESSION_TYPE to distinguish between X and Wayland
64+
XDG_SESSION_TYPE = {env:XDG_SESSION_TYPE}
65+
6366
# Windows: not done via path; see dev/write_hidapi_pth.py
6467

6568
# Lightweight tests only environments.

0 commit comments

Comments
 (0)