Skip to content

Commit

Permalink
added ability to change layout of emulated keyboard, for example colemak
Browse files Browse the repository at this point in the history
  • Loading branch information
LilleAila committed Jul 28, 2024
1 parent abcd919 commit 9fbe6b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ distribution corresponding packages):
- Treal support: `libusb` (1.0) and `libudev` are needed by
the [`hidapi` package](https://pypi.org/project/hidapi/).
- log / notifications support: `libdbus` is needed.
- Uinput support: `libxkbcommon` are needed by the [`xkbcommon` package](https://pypi.org/project/xkbcommon)
- Uinput support: `libxkbcommon` is needed by the [`xkbcommon` package](https://pypi.org/project/xkbcommon)

For the rest of the steps, follow the [developer guide](../doc/developer_guide.md).
6 changes: 2 additions & 4 deletions plover/gui_qt/config_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,8 @@ def __init__(self, engine):
'\n'
'This only applies when using Linux/BSD and not using X11.\n'
'If you\'re unsure, you probably don\'t need to change it.\n'
'If you need to configure more options about your layout,\n'
'such as setting the variant to a different layout like colemak,\n'
'you can set environment variables starting with XKB_DEFAULT_\n'
'for the RULES, MODEL, VARIANT and OPTIONS')),
'If you use a different layout variant, format it as\n'
'"language:layout", for example "us:colemak"')),
)),
# i18n: Widget: “ConfigWindow”.
(_('Plugins'), (
Expand Down
10 changes: 7 additions & 3 deletions plover/oslayer/linux/keyboardcontrol_uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,13 @@ def __init__(self):
self._res = util.find_ecodes_by_regex(r"KEY_.*")
self._ui = UInput(self._res)

def _update_layout(self, layout):
log.info("Using keyboard layout " + layout + " for keyboard emulation.")
symbols = generate_symbols(layout)
def _update_layout(self, _layout):
log.info("Using keyboard layout " +
_layout + " for keyboard emulation.")
_layout_options = _layout.split(":")
layout = _layout_options[0]
variant = _layout_options[1] if len(_layout_options) > 1 else ""
symbols = generate_symbols(layout, variant)
# Remove symbols not in KEY_TO_KEYCODE
syms_to_remove = []
for sym in symbols:
Expand Down
4 changes: 2 additions & 2 deletions plover/oslayer/linux/xkb_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


# layout can be "no", "us", "gb", "fr" or any other xkb layout
def generate_symbols(layout="us"):
def generate_symbols(layout="us", variant = ""):
ctx = xkb.Context()
keymap = ctx.keymap_new_from_names(layout=layout)
keymap = ctx.keymap_new_from_names(layout=layout, variant=variant)
# The keymaps have to be "translated" to a US layout keyboard for evdev
keymap_us = ctx.keymap_new_from_names(layout="us")

Expand Down

0 comments on commit 9fbe6b2

Please sign in to comment.