Fixed processing of non-ASCII symbols missing in CP_THREAD_ACP but present in current KB layout #910
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there, my name is Eugene Golushkov, I had problems with Barrier and being the programmer decided to contribute fix.
I'm Ukrainian, this language uses https://en.wikipedia.org/wiki/Cyrillic_script, Unicode range 0x400 - 0x4FF, Windows cp1251
My setup consists of
Problem description:
When current keyboard layout is ENG everything works like a charm. But if I move mouse cursor to clients (2),(3) having UKR keyboard layout selected on win server (1), then win client (3) ignores key strokes, and macos client (2) enters Latin characters with diacritics instead.
Expected result:
Solution:
I enabled Debug1 log level on macos client (2) and pressed 'A' key that is near CapsLock, in ENG KB layout. Got expected log:
DEBUG1: recv key down id=0x00000061, mask=0x2000, button=0x001e
then I switched to UKR layout on (1) and pressed the same physical key, that was expected to produce U+0444 CYRILLIC SMALL LETTER EF, but got such log:
DEBUG1: recv key down id=0x000000f4, mask=0x2000, button=0x001e
where 0xF4 is code for CYRILLIC SMALL LETTER EF in Windows ANSI codepage cp1251.
It became obvious that Barrier was not able to restore unicode char from ANSI, probably because CP_THREAD_ACP that it tried to use for this purpose is not in any way connected to current HKL. This was even as (1) had "Current language for non-Unicode programs" = Ukrainian. The fix was easy - keyboard driver already produces UTF16 chars that could be obtained by ToUnicode function. ToAscii is actually just simple wrapper around ToUnicode that further converts UTF16 chars to ANSI, and by avoiding this unnecessary step we will fix the problem. Barrier inter-machine protocol is Unicode based (KeyID).
Results:
I found the reason of ANSI codepages mismatch.
My Windows 10 was installed as English, and Ukrainian was set as "Current language for non-Unicode programs" later. And I don't bother to install Ukrainian Language Pack or somehow change the locale - just added the Ukrainian keyboard layout to otherwise English Windows.
So ToAscii translated UTF16 from KB layout to ANSI using RtlUnicodeToMultiByteN that uses CP_ACP codepage aka "Current language for non-Unicode programs", in my case cp1251 Cyrillic
And then CP_THREAD_ACP was used to translate ANSI to UTF16. CP_THREAD_ACP is set by SetThreadLocale, and while I'm not sure which one of LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT was used by Barrier - but on my system all "The settings for the current user, welcome screen (system accounts) and new user accounts" are "English (United States)", therefore CP_THREAD_ACP is cp1252 Western.
Anyway, proposed fix is the ultimate fix for the problem, as it eliminates any dependency on ANSI codepages, by keeping data in Unicode all the time.
This PR fixes #527. I tried it and all keys type correct Turkish characters on the MacOS.
My PC too is English but I use Turkish-Q keyboard.
@eugenegff could you share the release links so i can test it myself since the PR had no response in 13 days?
I did not build full release, as I have no QT, etc. The way I tested it - I configured in CMake build without GUI, installer and tests, and copied built binaries into installed Barrier instance. Here are release binaries built by MSVC 2019 for x64 https://1drv.ms/u/s!AnyscjGR32vZhPxtPPb2RbgB8lIEpw?e=UXYhAC
And probably Turkish as Language for non-Unicode programs, meaning CP_ACP = cp1254, while CP_THREAD_ACP = cp1252
This looks great, thank you! I'll still need to look into the PR in more depth, but during cursory review I haven't seen any problems.
Maybe I can help somehow with this pull request? This fix for Windows Barrier server is a prerequisite for further investigation of problem with non-ASCII characters in macOS Barrier client, that I deliberately do not start till the current fix is landed.
Is there a way to download a distribution from this branch?
I have the problem (Windows 10 client and server, no accented chars from FR and DE keyboards work on the client)
I did try replacing the 3 executables kindly provided by @eugenegff
Unfortunately the server does not start (failed to launch, error: process immediately stopped).