support multibytes input from Input method on Linux (Xlib) #62
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.
I am a big fan of LWJGL in japan.
Currently, LWJGL seems to not support input of multibytes long sentense.
I modified org.lwjgl.input.Keyboard to recieve long sentense from Input method on Linux(XIM).
Mainly modification is the following.
To be able to specify any argument to Xlib's XSetLocaleModifiers().
It is fixed to "@im=none" so far,
but to use the Input method of local environment,
the argument must be empty string.
I enhanced org.lwjgl.input.Keyboard.setImLocaleModifiers(String)
and the argument is set to XSetLocaleModifiers().
After XNextEvent() is called, XFilterEvent() must be called to filter all events.
When event occured window and LWJGL created window are not matched, XFilterEvent() has not been called.
But, Input method creates some other window for transformation of mutlibytes inputs (That window has the other window id.)
and events caused at the window also should be filtered by XFilterEvent().
Quoted from: ftp://ftp.x.org/pub/X11R7.0/doc/XIMTransport.txt,
In addition to the above,
when focus in/out events are caused, XSetICFocus()/XUnsetICFocus() must be called.
These functions notify that the receiver of Input method changed.
I modified it on org.lwjgl.opengl.LinuxDisplay.processEvents(),
org.lwjgl.opengl.LinuxEvent.filterEvent(long, LinuxKeyboard).
I modified org.lwjgl.opengl.LinuxKeyboard.lookupStringUnicode(long, int[])
to translate lookuped string into multibyte characters.
Until now, lookupStringUnicode() make a multibytes character
to each single bytes on the multibytes character.
But, a multibytes character should be translated to single character.
I’m sorry that I couldn’t explain as English well.
Explain it in 2 lines,
Before: lookupStringUnicode() translates 'あ' into char[] {0x??, 0x??, 0x??}
After: lookupStringUnicode() translates 'あ' into char[] {'あ'}
To be able to allocate large keyboard buffer for Input method.
When Input method sends long text, the text is stored to org.lwjgl.opengl.LinuxKeyboard.temp_translation_buffer at one time.
For Japanease long text (e.g. 20 characters, it was 60 bytes), current temp_translation_buffer may be small.
So to specify any buffer size to org.lwjgl.input.Keyboard.setImKeyboardBufferSize().
These modification are confirmed by this code.
If multibytes characters are inputed,
Keyboard.getEventCharacter() returns each as multibytes characters.
Best regards,
momokan