Skip to content

Add determining keyboard layout from Wayland#1807

Merged
mkrnr merged 5 commits intoopensteno:mainfrom
iansw246:wayland-keymap
Feb 1, 2026
Merged

Add determining keyboard layout from Wayland#1807
mkrnr merged 5 commits intoopensteno:mainfrom
iansw246:wayland-keymap

Conversation

@iansw246
Copy link
Contributor

@iansw246 iansw246 commented Jan 7, 2026

Summary of changes

Adds a Linux keyboard layout option "wayland-auto" that retrieves the current keyboard layout from the running Wayland compositor. Uses the xkbcommon package to parse the keymap, as well as to generate the other keyboard layout options.

Solves #1726 but only for Wayland users.

Another limitation is that keyboard capture isn't using the retrieved layout. This means keyboard modifiers other than the standard QWERTY keys (for example mapping CapsLock to Ctrl) won't be handled properly when passing through keyboard shortcuts. This issue exists currently so new issues shouldn't be added and this PR should be ready to merge.

Pull Request Checklist

  • Changes have tests Linux specific changes
  • News fragment added in news.d. See documentation for details

@iansw246 iansw246 marked this pull request as draft January 7, 2026 01:52
@iansw246 iansw246 force-pushed the wayland-keymap branch 3 times, most recently from aaf3a75 to 97d2312 Compare January 7, 2026 02:21
@iansw246 iansw246 marked this pull request as ready for review January 7, 2026 02:28
@mkrnr
Copy link
Contributor

mkrnr commented Jan 10, 2026

Thank you so much @iansw246 for this important contribution!

I tested it on my Ubuntu 24.04 machine having a German and English layout. For me, Plover always uses the German layout when selecting wayland-auto. I'm not deep into this but maybe its because I always get "0" here:

martin@martin-ubuntu-X230:~$ gsettings get org.gnome.desktop.input-sources sources
[('xkb', 'de'), ('xkb', 'us')]
martin@martin-ubuntu-X230:~$ gsettings get org.gnome.desktop.input-sources current
uint32 0

Even when setting my keyboard to en in the Ubuntu taskbar, I still get that 0. Maybe because of that, Wayland also doesn't get the info that I switched to en?

Apart from that problem, the detected German layout does work.

One question: Have you tested how Plover reacts when the libxkbcommon package is missing? I'm thinking of people with very minimal Linux installations that don't use Wayland.

Given my limited knowledge in this area, I'm not able to a thorough review. @LilleAila do you possibly have time to look into this approach?

@LilleAila
Copy link
Contributor

LGTM from a glance at the code. I think it is olah that this only applies to wayland as that is what the uinput output was primaily intended from. I have switched to MacOS since initially writing the output layer, but i can see if i can get it working on my secondary computer. Other than that it looks good (apart from the issue @mkrnr mentioned) and it seems like it is ready to merge. Although i haven’t tested it personally, i didn’t see anything specific in the code that i disagree with.

@mkrnr
Copy link
Contributor

mkrnr commented Jan 27, 2026

Thanks a lot @LilleAila!

@iansw246 there's now some minor conflicts since #1812 also modified the apt_get_install in the CI files. Once those are resolved, I'm happy to approve and merge.

@mkrnr
Copy link
Contributor

mkrnr commented Jan 28, 2026

@iansw246 let me know when the PR is ready to be merged

@iansw246
Copy link
Contributor Author

iansw246 commented Jan 29, 2026

@mkrnr About the multiple layouts, there's not a way to detect which layout is active over Wayland without receiving the key events themselves. Plover always assumes the first layout is active. I'll add a warning in the UI before merging. Is there somewhere else this be documented too?

Plover will crash without libxkcommon if it tries to use Uinput. I'll work on fixing that later. If you think supporting that use case is important, we can wait until that's fixed as well.

@mkrnr
Copy link
Contributor

mkrnr commented Jan 29, 2026

@iansw246 thanks! Maybe you find a place in the docs regarding selecting the first layout but a note in the UI is already very good. I'd suggest not relying on tooltips though since not everyone reads them.

You can decide if you want to fix the crash when libxkcommon is missing now or later. I can't really judge how common that situation would be.

mkrnr
mkrnr previously approved these changes Jan 29, 2026
@iansw246 iansw246 force-pushed the wayland-keymap branch 2 times, most recently from da0cbee to 94d49df Compare February 1, 2026 01:35
@iansw246
Copy link
Contributor Author

iansw246 commented Feb 1, 2026

Added text below the keyboard layout selection. Should be good to merge now.

I will fix the libxkbcommon crash another time.

Copy link
Contributor

@mkrnr mkrnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the info text! Tested it on Ubuntu and it works as expected.

@mkrnr mkrnr merged commit ffaa0c9 into opensteno:main Feb 1, 2026
18 checks passed
@iansw246 iansw246 mentioned this pull request Feb 1, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants