Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using keyboard layout in Language widget #91

Merged
merged 6 commits into from
Dec 31, 2024

Conversation

Osyx
Copy link
Contributor

@Osyx Osyx commented Dec 27, 2024

Implements a layout_name variable accessible via {lang[layout_name]} in the Language widget.

Closes #90.

This config:

widgets:
  language:
    type: 'yasb.language.LanguageWidget'
    options:
      label: "<span>\uf11c</span>{lang[language_code]}-{lang[country_code]}  {lang[layout_name]}"

will give this:
image

@Osyx
Copy link
Contributor Author

Osyx commented Dec 27, 2024

It seems to work somewhat, but when I'm running it locally it only updates the layout on start, and then never updates it again, even though the rest of the returned object is updated.

Open to suggestions on how to fix! Haven't really written python in ages, and never used Win APIs really, so I'm very rusty.

@amnweb
Copy link
Owner

amnweb commented Dec 27, 2024

Open to suggestions on how to fix! Haven't really written python in ages, and never used Win APIs really, so I'm very rusty.

Welcome to the Windows API jungle xD

@amnweb
Copy link
Owner

amnweb commented Dec 28, 2024

I have tried to play with that but I have no idea why layout_name is not updating, maybe it is that API limitation or something else not sure :(

@Osyx
Copy link
Contributor Author

Osyx commented Dec 30, 2024

@amnweb Hmm that's sad, idk how we should go forward then, I didn't manage to find another way either :/

I saw in the docs that they recommended using Windows.Globalization.Language.CurrentInputMethodLanguageTag instead. Tried implementing that, but it yielded the same result as GetKeyboardLayout(thread_id), though it also only updated on startup. Also saw this comment:

This property returns a value for the currently active input method on the thread with keyboard input focus. Calling this on a background thread may not return the expected results.

which is basically the only way to use CurrentInputMethodLanguageTag it seems, so that seems like a dead end.

We could rename it to initial_layout_name but might not be worth due to people expecting more of it.
I think my use case is quite uncommon as well. So maybe we should just close this PR, idk.

@Osyx Osyx marked this pull request as ready for review December 31, 2024 00:59
@Osyx
Copy link
Contributor Author

Osyx commented Dec 31, 2024

It should now work as expected!

Showcase:
test-yasb-layout.webm

@amnweb amnweb merged commit 006fd3b into amnweb:main Dec 31, 2024
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.

Keyboard layout in the Language widget
2 participants