Are the SDL_TEXTINPUT events suppressed?

4 posts / 0 new
Last post
walkero
walkero's picture
Offline
Last seen: 4 months 3 days ago
Joined: 2009-05-03 16:54
Are the SDL_TEXTINPUT events suppressed?

Hello guys,
I am trying to make an SDL app of mine working when typing texts in other encodings than the English ones. For example, I want to type in Greek, but when I switch my locale the SDL_TEXTINPUT event is not triggered at all.

I have a small demo that shows the problem

  1. #include <SDL.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char* argv[]) {
  5. if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  6. printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
  7. return 1;
  8. }
  9.  
  10. SDL_Window* window = SDL_CreateWindow("SDL Unicode Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
  11. if (window == NULL) {
  12. printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
  13. return 1;
  14. }
  15.  
  16. SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
  17.  
  18. SDL_Event e;
  19. int quit = 0;
  20.  
  21. while (!quit) {
  22. while (SDL_PollEvent(&e) != 0) {
  23. if (e.type == SDL_QUIT) {
  24. quit = 1;
  25. } else if (e.type == SDL_TEXTINPUT) {
  26. // Handle Unicode characters
  27. printf("Text input: %s\n", e.text.text);
  28. }
  29. }
  30. }
  31.  
  32. SDL_DestroyRenderer(renderer);
  33. SDL_DestroyWindow(window);
  34. SDL_Quit();
  35.  
  36. return 0;
  37. }

You can compile it with something like:
gcc -o sdl_textinput sdl_textinput.c -I/sdk/local/newlib/include/SDL2 -lSDL2

Does anyone know if that's the case and if there is a workaround? Is this something that is happening in our SDL port, or is it a problem of the keymap?

jabirulo
jabirulo's picture
Offline
Last seen: 9 hours 45 min ago
Joined: 2013-05-30 00:53
Re: Are the SDL_TEXTINPUT events suppressed?

compiled here and in my spanish keyboard the Ñ (n with tilde) doesn't work ¿:-/, maybe it only "acts" on "ASCII" keystrokes.

#SDL_TextInput
Text input: u
Text input: u
Text input: i
Text input: i
<here y press Ñ (n with tilde ñ) but don't get any output>
Text input: .
Text input: .
Text input: .
Text input: ,
Text input: ,
Text input: ,
Text input: -
Text input: -
Text input: l
Text input: l
Text input: l

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

walkero
walkero's picture
Offline
Last seen: 4 months 3 days ago
Joined: 2009-05-03 16:54
Re: Are the SDL_TEXTINPUT events suppressed?

@jabirulo
Thank you for testing it. I opened an issue at https://github.com/AmigaPorts/SDL-2.0/issues/73

jabirulo
jabirulo's picture
Offline
Last seen: 9 hours 45 min ago
Joined: 2013-05-30 00:53
Re: Are the SDL_TEXTINPUT events suppressed?

BTW no idea if useful, but I have a string to file as utf-8 using codeset_lib:

  1. void ConvertXML2UTF(char *fn)
  2. {
  3. STRPTR destbuf, buf = AllocVecTags(BUF_MAX_LEN, AVT_ClearWithValue,0, TAG_END); // see awn_io.h for value
  4. ULONG destlen;
  5. struct codeset *srcCodeset = CodesetsFind("ISO-8859-1", CSA_FallbackToDefault,FALSE, TAG_DONE);
  6. struct codeset *destCodeset = CodesetsFind("UTF-8", CSA_FallbackToDefault,FALSE, TAG_DONE);
  7. DBUG(" Converting '%s' ISO-8859-1 to UTF-8\n",fn);
  8. BPTR f = FOpen(fn, MODE_OLDFILE, 0);
  9.  
  10. FRead(f, buf, 1, BUF_MAX_LEN); // see awn_io.h for value
  11. FClose(f);
  12.  
  13. destbuf = CodesetsConvertStr(CSA_SourceCodeset, srcCodeset,
  14. CSA_DestCodeset, destCodeset,
  15. CSA_Source, buf,
  16. CSA_DestLenPtr, &destlen,
  17. TAG_DONE);
  18. if(destbuf)
  19. {
  20. f = FOpen(fn, MODE_NEWFILE, 0); // we overwrite downloaded xml
  21. FWrite(f, destbuf, destlen, 1);
  22. FClose(f);
  23.  
  24. CodesetsFreeA(destbuf, NULL);
  25. }
  26.  
  27. FreeVec(buf);
  28. }

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

Log in or register to post comments