2

I wrote a test program for SDL2 text event handling, and the input method cannot be turned on when I'm focusing on the window created by SDL2.

I'm testing that on Linux with Xfce desktop and Fcitx input method engine.

The code is simple:

#include <SDL.h>

int main(int argc, char** argv)
{
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
    SDL_Window* window = SDL_CreateWindow("sdl text test", 50, 50, 400, 400, SDL_WINDOW_OPENGL);

    SDL_StartTextInput();

    while (1)
    {
        // process events
        SDL_Event event{};
        bool should_exit = false;

        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT:
                should_exit = true;
                break;
            case SDL_TEXTEDITING:
                printf("text edit: %s %d %d\n", event.edit.text, event.edit.start, event.edit.length);
                break;
            case SDL_TEXTINPUT:
                printf("text input: %s\n", event.text.text);
                break;
            }
        }

        if (should_exit) break;

        SDL_Delay(20);
    }

    SDL_StopTextInput();
}

I have a brief look on SDL2's documents, but failed to find anything related with keyboard grabbing.

jiandingzhe
  • 1,881
  • 15
  • 35
  • I'm also having this issue. Did you ever figure it out? – Caleb Aug 11 '18 at 15:51
  • There's a working example in https://stackoverflow.com/questions/41570751/how-to-correctly-handle-control-key-combinations-in-sdl2 – Zvika May 04 '20 at 10:10

3 Answers3

2

try delete

videodata->ime_uilesss = UILess_SetupSinks(videodata); in function IME_Init of SDL_windowskeyboard.c.

It's ugly, but works.

If videodata->ime_uiless == SDL_False,

then windows will show input method,

else the sdl2 will render and show input method.

xwang
  • 89
  • 5
1

I'm using Windows 10 + SDL and was looking at SDL support for the IME under Windows, and have no idea how it could possibly work considering the IME_Render/IME_Present function are never called in SDL codebase.

Compiling SDL with #define SDL_DISABLE_WINDOWS_IME in SDL_windowskeyboard.c fixed it for me (xwang's suggestion will lead to a similar result).

Omar
  • 627
  • 4
  • 6
1

I don't know why but it may do the trick: build SDL2 yourself.

I once use SDL2 comes with Ubuntu apt repo, libsdl2-dev/bionic-updates,now 2.0.8+dfsg1-1ubuntu1.18.04.1 amd64 . IME cannot be shown or switched.

After I replace with myself-built SDL2 lib(same version 2.0.8), IME works good.

neoedmund
  • 561
  • 7
  • 15