gnustep / libs-back

The GNUstep gui library is a library of graphical user interface classes written completely in the Objective-C language; the classes are based upon Apple's Cocoa framework (which came from the OpenStep specification). *** Larger patches require copyright assignment to FSF. please file bugs here. ***
http://www.gnustep.org
GNU General Public License v3.0
50 stars 34 forks source link

try to fix extended char handling in NSEvent #50

Closed rmottola closed 2 months ago

rmottola commented 2 months ago

Issue described in https://github.com/gnustep/libs-back/issues/49

I found out that sometimes XLookupString returns more than one char for a single key, which does not make much sense for Latin1. So I suspect I am getting back UTF-8 in that case and indeed, interpreting that string as such works!

Looks like X11 got "extended" here beyond the Spec that says Latin1 only. The question remains why it is happening for characters contained in Latin1? Last found is that €, not contained in Latin1 gets not back.

However I think this "hack" is pretty safe, since if only one char is returned, Latin1 is used as per-spec.

rmottola commented 2 months ago

Addendum. Actually also € works! It is returned as 3 chars and is interpreted correctly. What confused me is that its value for ukeys (that is without modifiers) is 'e', while for è keys and ukeys are both 'è'

rmottola commented 2 months ago

Tried on Linux where I had no issues and continue having no issues with Italian keyboard.

Would you mind testing e.g. with German keyboard?

rmottola commented 2 months ago

@fredkiefer if you want somehow create a TODO and work with this on the next hacking session together or if I should test a patch for you, I'm available! In the meanwhile we see if this change creates issues.

rfm commented 2 months ago

I think the change is good. If the data is utf-8 a single byte is guaranteed to be correct latin1. If the data is latin1, it's either got the top bit set (and would be invalid utf-8) or it hasn't (and it's the correct ASCII value). So it seems very safe to me.

rmottola commented 2 months ago

@rfm thanks for you opinion, I was a bit wary about this because it is somehow against documentation of X11 and I saw 2 or 3 bytes and was attempted at trial-and-error, but it is safe for 1byte.