Skip to content

Commit ffaa0c9

Browse files
authored
Add determining keyboard layout from Wayland (#1807)
1 parent 7806499 commit ffaa0c9

File tree

10 files changed

+879
-348
lines changed

10 files changed

+879
-348
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ jobs:
273273
path: .cache
274274
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/dist.txt', 'reqs/test.txt') }}
275275

276+
# Required to install xkbcommon Python package.
277+
- name: Install system dependencies
278+
run: apt_get_install libxkbcommon-dev
279+
276280
- name: Setup Python environment
277281
run: setup_python_env -c reqs/constraints.txt -r reqs/dist.txt -r reqs/test.txt
278282

@@ -439,6 +443,10 @@ jobs:
439443
path: .cache
440444
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/dist.txt', 'reqs/test.txt') }}
441445

446+
# Required to install xkbcommon Python package.
447+
- name: Install system dependencies
448+
run: apt_get_install libxkbcommon-dev
449+
442450
- name: Setup Python environment
443451
run: setup_python_env -c reqs/constraints.txt -r reqs/dist.txt -r reqs/test.txt
444452

@@ -493,6 +501,10 @@ jobs:
493501
path: .cache
494502
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/dist.txt', 'reqs/test.txt') }}
495503

504+
# Required to install xkbcommon Python package.
505+
- name: Install system dependencies
506+
run: apt_get_install libxkbcommon-dev
507+
496508
- name: Setup Python environment
497509
run: setup_python_env -c reqs/constraints.txt -r reqs/dist.txt -r reqs/test.txt
498510

@@ -547,6 +559,10 @@ jobs:
547559
path: .cache
548560
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/dist.txt', 'reqs/test.txt') }}
549561

562+
# Required to install xkbcommon Python package.
563+
- name: Install system dependencies
564+
run: apt_get_install libxkbcommon-dev
565+
550566
- name: Setup Python environment
551567
run: setup_python_env -c reqs/constraints.txt -r reqs/dist.txt -r reqs/test.txt
552568

@@ -601,6 +617,10 @@ jobs:
601617
path: .cache
602618
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/dist.txt', 'reqs/test.txt') }}
603619

620+
# Required to install xkbcommon Python package.
621+
- name: Install system dependencies
622+
run: apt_get_install libxkbcommon-dev
623+
604624
- name: Setup Python environment
605625
run: setup_python_env -c reqs/constraints.txt -r reqs/dist.txt -r reqs/test.txt
606626

@@ -656,7 +676,7 @@ jobs:
656676
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/dist.txt', 'reqs/dist_extra_gui_qt.txt', 'reqs/test.txt') }}
657677

658678
- name: Install system dependencies
659-
run: apt_get_install libdbus-1-dev libdbus-glib-1-dev libudev-dev libegl-dev libxkbcommon-x11-0
679+
run: apt_get_install libdbus-1-dev libdbus-glib-1-dev libudev-dev libegl-dev libxkbcommon-x11-0 libxkbcommon-dev
660680

661681
- name: Setup Python environment
662682
run: setup_python_env -c reqs/constraints.txt -r reqs/dist.txt -r reqs/dist_extra_gui_qt.txt -r reqs/test.txt
@@ -718,6 +738,10 @@ jobs:
718738
path: .cache
719739
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/packaging.txt', 'reqs/setup.txt') }}
720740

741+
# Required to install xkbcommon Python package.
742+
- name: Install system dependencies
743+
run: apt_get_install libxkbcommon-dev
744+
721745
- name: Setup Python environment
722746
run: setup_python_env -c reqs/constraints.txt -r reqs/packaging.txt -r reqs/setup.txt
723747

@@ -805,6 +829,10 @@ jobs:
805829
path: .cache
806830
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/code_quality.txt') }}
807831

832+
# Required to install xkbcommon Python package.
833+
- name: Install system dependencies
834+
run: apt_get_install libxkbcommon-dev
835+
808836
- name: Setup Python environment
809837
run: setup_python_env -c reqs/constraints.txt -r reqs/code_quality.txt
810838

@@ -862,7 +890,7 @@ jobs:
862890
key: 0_${{ steps.set_cache.outputs.cache_name }}_${{ hashFiles('reqs/constraints.txt', 'reqs/build.txt', 'reqs/setup.txt', 'reqs/dist_*.txt', 'linux/appimage/deps.sh') }}
863891

864892
- name: Install system dependencies
865-
run: apt_get_install libdbus-1-dev libdbus-glib-1-dev libudev-dev libegl-dev libxkbcommon-x11-0
893+
run: apt_get_install libdbus-1-dev libdbus-glib-1-dev libudev-dev libegl-dev libxkbcommon-x11-0 libxkbcommon-dev
866894

867895
- name: Setup Python environment
868896
run: setup_python_env -c reqs/constraints.txt -r reqs/build.txt -r reqs/setup.txt

.github/workflows/ci/workflow_template.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ jobs:
144144
run: setup_osx_python '<@ j.python @>'
145145

146146
<% endif %>
147-
<% if j.type in ['build', 'test_gui_qt'] and j.os == 'Linux' %>
147+
<% if j.os == 'Linux' %>
148+
<% if j.type in ['build', 'test_gui_qt'] %>
149+
- name: Install system dependencies
150+
run: apt_get_install libdbus-1-dev libdbus-glib-1-dev libudev-dev libegl-dev libxkbcommon-x11-0 libxkbcommon-dev
151+
152+
<% else %>
153+
# Required to install xkbcommon Python package.
148154
- name: Install system dependencies
149-
run: apt_get_install libdbus-1-dev libdbus-glib-1-dev libudev-dev libegl-dev libxkbcommon-x11-0
155+
run: apt_get_install libxkbcommon-dev
150156

157+
<% endif %>
151158
<% endif %>
152159
<% if j.type != 'notarize' %>
153160
- name: Setup Python environment

linux/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ To be able to setup a complete development environment, you'll need to manually
66
install some system libraries (including the development version of your
77
distribution corresponding packages):
88
- log / notifications support: `libdbus` is needed.
9+
- Uinput support: `libxkbcommon` is needed by the [`xkbcommon` package](https://pypi.org/project/xkbcommon)
910

1011
For the rest of the steps, follow the [developer guide](../doc/developer_guide.md).

news.d/feature/1807.linux.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support determining keyboard layout from Wayland with the `wayland-auto` layout.

plover/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _set(self, section, option, value):
456456
),
457457
choice_option(
458458
"keyboard_layout",
459-
("qwerty", "qwertz", "colemak", "colemak-dh", "dvorak"),
459+
("qwerty", "qwertz", "colemak", "colemak-dh", "dvorak", "wayland-auto"),
460460
OUTPUT_CONFIG_SECTION,
461461
),
462462
# Logging.

plover/gui_qt/config_window.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,23 @@ def __init__(self, choice_false, choice_true):
306306
super().__init__(choices)
307307

308308

309+
class TextWrapQLabel(QLabel):
310+
"""Simple QLabel wrapper that enables wordWrap"""
311+
312+
def __init__(self, *args):
313+
super().__init__(*args)
314+
self.setWordWrap(True)
315+
316+
309317
class ConfigOption:
310318
def __init__(
311-
self, display_name, option_name, widget_class, help_text="", dependents=()
319+
self,
320+
display_name,
321+
option_name,
322+
widget_class,
323+
help_text="",
324+
dependents=(),
325+
additional_widget_classes=[],
312326
):
313327
self.display_name = display_name
314328
self.option_name = option_name
@@ -318,6 +332,9 @@ def __init__(
318332
self.layout = None
319333
self.widget = None
320334
self.label = None
335+
# Other widgets to be added immediately after the main widget_class
336+
# Does not work in dependents
337+
self.additional_widget_classes = additional_widget_classes
321338

322339

323340
class ConfigWindow(QDialog, Ui_ConfigWindow, WindowStateMixin):
@@ -521,12 +538,26 @@ def __init__(self, engine):
521538
"colemak": "colemak",
522539
"colemak-dh": "colemak-dh",
523540
"dvorak": "dvorak",
541+
"wayland-auto": "wayland-auto",
524542
},
525543
),
526544
_(
527-
"Set the keyboard layout configurad in your system.\n"
528-
"This only applies when using Linux/BSD and not using X11."
545+
"Set the keyboard layout configured in your system.\n"
546+
"This only applies when using Linux/BSD and not using X11.\n\n"
547+
"When wayland-auto is selected,"
548+
"Plover is only able detect the first keyboard layout\n"
549+
"and can not detect to layout switches."
529550
),
551+
additional_widget_classes=[
552+
partial(
553+
TextWrapQLabel,
554+
_(
555+
"When wayland-auto is selected, "
556+
"Plover is only able detect the first keyboard layout "
557+
"and can not detect to layout switches."
558+
),
559+
)
560+
],
530561
),
531562
),
532563
),
@@ -592,6 +623,8 @@ def __init__(self, engine):
592623
option.label.setToolTip(option.help_text)
593624
option.label.setBuddy(option.widget)
594625
layout.addRow(option.label, option.widget)
626+
for additional_widget_class in option.additional_widget_classes:
627+
layout.addRow(None, additional_widget_class())
595628
frame = QFrame()
596629
frame.setLayout(layout)
597630
frame.setAccessibleName(section)

0 commit comments

Comments
 (0)