]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
SDL2: combine SDL_KEYDOWN events directly with following SDL_TEXTINPUT events when...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 10 Jul 2017 12:43:27 +0000 (12:43 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 10 Jul 2017 12:43:27 +0000 (12:43 +0000)
This solves ` keypresses that open/close the console also typing in a character
"once and for all". The ability to type the ` character into the console is not
impaired by this as con_closeontoggleconsole's logic to by default ignore the
toggleconsole key when in the console but not at the beginning of the line
still applies.

From: terencehill <piuntn@gmail.com>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12335 d7cf8633-e32d-0410-b094-e92efae38249

vid_sdl.c

index 9fbe57c655f1feed7985d276087eaa9634041323..98d6567ee19bee9ac97f9dcc6ce119727dcbc11a 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -1218,12 +1218,14 @@ void Sys_SendKeyEvents( void )
        static qboolean sound_active = true;
        int keycode;
        int i;
+       qboolean isdown;
        Uchar unicode;
        SDL_Event event;
 
        VID_EnableJoystick(true);
 
        while( SDL_PollEvent( &event ) )
+               loop_start:
                switch( event.type ) {
                        case SDL_QUIT:
 #ifdef DEBUGSDLEVENTS
@@ -1240,8 +1242,31 @@ void Sys_SendKeyEvents( void )
                                        Con_DPrintf("SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym);
 #endif
                                keycode = MapKey(event.key.keysym.sym);
+                               isdown = (event.key.state == SDL_PRESSED);
+                               unicode = 0;
+                               if(isdown)
+                               {
+                                       if(SDL_PollEvent(&event))
+                                       {
+                                               if(event.type == SDL_TEXTINPUT)
+                                               {
+                                                       // combine key code from SDL_KEYDOWN event and character
+                                                       // from SDL_TEXTINPUT event in a single Key_Event call
+#ifdef DEBUGSDLEVENTS
+                                                       Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text);
+#endif
+                                                       unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL);
+                                               }
+                                               else
+                                               {
+                                                       if (!VID_JoyBlockEmulatedKeys(keycode))
+                                                               Key_Event(keycode, 0, isdown);
+                                                       goto loop_start;
+                                               }
+                                       }
+                               }
                                if (!VID_JoyBlockEmulatedKeys(keycode))
-                                       Key_Event(keycode, 0, (event.key.state == SDL_PRESSED));
+                                       Key_Event(keycode, unicode, isdown);
                                break;
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP: