We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3102

Summary: Compose key with TextInput returns double utf8 encoded string
Product: SDL Reporter: Dennis Felsing <dennis>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: alex
Version: HG 2.1   
Hardware: x86_64   
OS: Linux   

Description Dennis Felsing 2015-08-25 00:24:07 UTC
I'm on Linux, X server 1.17.2 and trying to enter a smiley (☺) in an SDL2 program.

With a compose key this works fine in xev:

KeyPress event, serial 32, synthetic NO, window 0xe00001,
    root 0x4a1, subw 0x0, time 14483802, (479,264), root:(1440,283),
    state 0x1, keycode 0 (keysym 0x100263a, U263A), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 3 bytes: (e2 98 ba) "☺"
    XFilterEvent returns: False

With SDL2' checkkeys I get a wrong output instead:

INFO: INPUT Text (\xc3\xa2\xc2\x98\xc2\xba): "âº"

After looking at it closely, I noticed that the SDL2 string utf8 encodes each utf8 encoded byte. Instead it should just be utf8 encoded once of course.

Is there any way to fix this or work around it? I haven't noticed this problem in anything other than SDL2 programs. SDL1.2 worked fine.
Comment 1 Alex Baines 2015-09-29 18:12:34 UTC
If you add a call to setlocale(LC_ALL, "") at the start of checkkeys.c (and include locale.h in it) is this problem still present?

For me, checkkeys does not work with my compose key at all unless I add a setlocale call, and once I do that I get properly encoded strings.
Comment 2 Dennis Felsing 2015-09-29 18:19:12 UTC
Yes, that works, thanks a lot! So is it recommended to simply use setlocale(LC_ALL, "") at the start of my program or is this something that can be fixed in SDL?
Comment 3 Alex Baines 2015-09-29 18:42:05 UTC
SDL1.2 used to call setlocale internally before calling XOpenIM, but this was changed for some reason in SDL2. 

It could be changed back, but this might have been done to fix some other bug, I'm not sure.

It's probably best to call it yourself for the moment.
Comment 4 Sam Lantinga 2016-10-01 21:10:31 UTC
Fixed by Alex's patch in bug 3136
https://hg.libsdl.org/SDL/rev/2f18ea79bc03