Skip to content

Commit abcd919

Browse files
committed
added config option to set keyboard layout
1 parent a5a50a4 commit abcd919

File tree

7 files changed

+43
-16
lines changed

7 files changed

+43
-16
lines changed

See

Whitespace-only changes.

[36

Whitespace-only changes.

linux/appimage/apprun.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ APPDIR="$(dirname "$(readlink -e "$0")")"
109109

110110
appimage_setenv
111111

112-
113112
# Handle AppImage specific options.
114113
[ -n "$APPIMAGE" ] && case "$1" in
115114
--install|--uninstall)

plover/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ def validate(config, key, value):
122122
return value
123123
return ConfigOption(name, lambda c, k: default, getter, setter, validate, None)
124124

125+
def str_option(name, default, section, option=None):
126+
option = option or name
127+
def getter(config, key):
128+
return config._config[section][option]
129+
def setter(config, key, value):
130+
config._set(section, option, str(value))
131+
def validate(config, key, value):
132+
try:
133+
value = str(value)
134+
except ValueError as e:
135+
raise InvalidConfigOption(value, default) from e
136+
return value
137+
return ConfigOption(name, lambda c, k: default, getter, setter, validate, None)
138+
125139
def boolean_option(name, default, section, option=None):
126140
option = option or name
127141
def getter(config, key):
@@ -338,6 +352,7 @@ def _set(self, section, option, value):
338352
boolean_option('start_capitalized', False, OUTPUT_CONFIG_SECTION),
339353
int_option('undo_levels', DEFAULT_UNDO_LEVELS, MINIMUM_UNDO_LEVELS, None, OUTPUT_CONFIG_SECTION),
340354
int_option('time_between_key_presses', DEFAULT_TIME_BETWEEN_KEY_PRESSES, MINIMUM_TIME_BETWEEN_KEY_PRESSES, None, OUTPUT_CONFIG_SECTION),
355+
str_option('xkb_layout', "us", OUTPUT_CONFIG_SECTION),
341356
# Logging.
342357
path_option('log_file_name', expand_path('strokes.log'), LOGGING_CONFIG_SECTION, 'log_file'),
343358
boolean_option('enable_stroke_logging', False, LOGGING_CONFIG_SECTION),

plover/engine.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ def _update(self, config_update=None, full=False, reset_machine=False):
212212
self._formatter.start_capitalized = config['start_capitalized']
213213
self._translator.set_min_undo_length(config['undo_levels'])
214214
self._keyboard_emulation.set_key_press_delay(config['time_between_key_presses'])
215+
# This only applies to UInput, because it emulates a physical keyboard and follows the layout set in software. Because there is no standard of defining it, the user has to do so manually if not using an US keyboard if not using an US keyboard.
216+
if hasattr(self._keyboard_emulation, '_update_layout'):
217+
self._keyboard_emulation._update_layout(config['xkb_layout'])
215218
# Update system.
216219
system_name = config['system_name']
217220
if system.NAME != system_name:

plover/gui_qt/config_window.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
QLabel,
2121
QScrollArea,
2222
QSpinBox,
23+
QLineEdit,
2324
QStyledItemDelegate,
2425
QTableWidget,
2526
QTableWidgetItem,
@@ -71,6 +72,17 @@ def __init__(self, maximum=None, minimum=None):
7172
self.setMinimum(minimum)
7273

7374

75+
class StrOption(QLineEdit):
76+
77+
valueChanged = pyqtSignal(str)
78+
79+
def __init__(self):
80+
super().__init__()
81+
self.textChanged.connect(self.valueChanged.emit)
82+
83+
def setValue(self, value):
84+
self.setText(value)
85+
7486
class ChoiceOption(QComboBox):
7587

7688
valueChanged = pyqtSignal(str)
@@ -392,6 +404,16 @@ def __init__(self, engine):
392404
'programs time to process each key press.\n'
393405
'Setting the delay too high will negatively impact the\n'
394406
'performance of key stroke output.')),
407+
ConfigOption(_('Keyboard Layout:'), 'xkb_layout', StrOption,
408+
_('Set the keyboard layout configured in your system.\n'
409+
'Examples: "us", "gb", "fr", "no"\n'
410+
'\n'
411+
'This only applies when using Linux/BSD and not using X11.\n'
412+
'If you\'re unsure, you probably don\'t need to change it.\n'
413+
'If you need to configure more options about your layout,\n'
414+
'such as setting the variant to a different layout like colemak,\n'
415+
'you can set environment variables starting with XKB_DEFAULT_\n'
416+
'for the RULES, MODEL, VARIANT and OPTIONS')),
395417
)),
396418
# i18n: Widget: “ConfigWindow”.
397419
(_('Plugins'), (

plover/oslayer/linux/keyboardcontrol_uinput.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# TODO: get a stop() function to run when KeyboardEmulation stops, calling `self._ui.close()`
2-
# TODO: figure out a better way to do this:
3-
import os # To read the layout variable
4-
5-
# TODO: somehow get the requires udev rule installed
61
from evdev import UInput, ecodes as e, util, InputDevice, list_devices
72
import threading
83
from select import select
@@ -163,7 +158,7 @@
163158
"eject": e.KEY_EJECTCD,
164159
"audiopause": e.KEY_PAUSE,
165160
"audioplay": e.KEY_PLAY,
166-
"audionext": e.KEY_NEXT, # Maybe VIDEO_NEXT or NEXTSONG
161+
"audionext": e.KEY_NEXT,
167162
"audiorewind": e.KEY_REWIND,
168163
"kbdbrightnessup": e.KEY_KBDILLUMUP,
169164
"kbdbrightnessdown": e.KEY_KBDILLUMDOWN,
@@ -177,18 +172,11 @@ def __init__(self):
177172
# Initialize UInput with all keys available
178173
self._res = util.find_ecodes_by_regex(r"KEY_.*")
179174
self._ui = UInput(self._res)
180-
# Set the keyboard layout from an environment variable
181-
kb_env = "PLOVER_UINPUT_LAYOUT"
182-
kb_layout = os.environ[kb_env] if kb_env in os.environ else "us"
183-
self._set_layout(kb_layout)
184175

185-
def _set_layout(self, layout):
186-
# Get the system keyboard layout so that emulation works on different layouts
176+
def _update_layout(self, layout):
187177
log.info("Using keyboard layout " + layout + " for keyboard emulation.")
188178
symbols = generate_symbols(layout)
189-
# Remove unwanted symbols from the table
190-
# Includes symbols such as numpad-star - use unicode instead
191-
# There has to be a cleaner way to do this
179+
# Remove symbols not in KEY_TO_KEYCODE
192180
syms_to_remove = []
193181
for sym in symbols:
194182
(base, _) = symbols[sym]

0 commit comments

Comments
 (0)