-
Notifications
You must be signed in to change notification settings - Fork 399
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 native Windows IME support #4941
Conversation
Some IME messages didn't get sent trough `SDL_SetWindowsMessageHook`, so this alternative is required.
Generally disappointed to see more platform-specific handling, especially that it seems that it's bundled with workarounds to disable some SDL behaviour. |
…e queue Also changes Marshal.PtrToStructure so the nullref check isn't needed.
The hack for getting the result is no longer needed since the events are now handled before being posted in the queue (early enough so that internal IME state is preserved). Tested to work as expected with the edge case mentioned in the (now removed) comment.
{ | ||
start = cursorPosition; | ||
if (handle.IsClosed || handle.IsInvalid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super sure about these checks... Can this ever realistically happen in a scenario other than "this object has been disposed"? If so, then the usual way to proceed is to throw ObjectDisposedException
or similar rather than just soft-fail like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding of SafeHandle, IsClosed
can only happen when it's disposed. Since this means improper use of the class, I'll change that to a throw.
IsInvalid
can happen if a bad hWnd
was provided, or when ImmGetContext
doesn't provide a valid handle for some reason. In this case, we shouldn't throw as the consumer-facing methods are TryGet...
. Returning false is fine. We already return false for other Imm errors, such as those in tryGetCompositionSize/String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad HWND sounds pretty fatal and I'd say it would be fine to throw on that too. Not sure about the imm function itself returning a zero/negative handle, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we can differentiate between the two, Imm only returns a handle, and the docs don't mention any error values.
Windows properly sends the IME messages, so we don't have to worry about it accidentally remaining active.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested, but looks sane on a code pass.
Tested this briefly today, seems to work okay as far as I can tell (although not a frequent IME user soooo...) |
SDL2 text input shows some problems, mainly the 10 character limit and selection not working properly.
Existing issues on SDL's side: libsdl-org/SDL#1879 and libsdl-org/SDL#3385.
So I decided to write my own implementation for Windows IME handling. This is completely transparent to
TextBox
and even toSDL2DesktopWindowTextInput
. The composition text is no longer arbitrarily limited, and selection works as expected.It's unfortunate that we can't use
SDL_SetWindowsMessageHook
as we do inWindowsMouseHandler
(reasoning: eb44a5c). Seems a bit strange that this was the case, but the alternative way of receiving window messages works just fine (albeit with a minor issue).Some native IMM/IME code adapted from chromium.
With this in, we're one step closer to providing an in-game candidate window for composition. I've already got the native part working, but adding a candidate window in-game is a bit daunting to me.