r1459 - in trunk/code: qcommon sdl

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Aug 25 17:15:25 EDT 2008


Author: tma
Date: 2008-08-25 17:15:25 -0400 (Mon, 25 Aug 2008)
New Revision: 1459

Modified:
   trunk/code/qcommon/common.c
   trunk/code/sdl/sdl_input.c
Log:
* Handle dead keys more gracefully by taking a "best guess" rather than ignoring
  completely
* When activating or deactivating the mouse flush any pending motion events;
  this should stop the view moving unpredictably in these circumstances
* Add keyname completion to "unbind"


Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2008-08-23 22:45:30 UTC (rev 1458)
+++ trunk/code/qcommon/common.c	2008-08-25 21:15:25 UTC (rev 1459)
@@ -3333,6 +3333,14 @@
 						Field_CompleteCommand( p, qtrue, qtrue );
 				}
 			}
+			else if( !Q_stricmp( baseCmd, "unbind" ) && completionArgument == 2 )
+			{
+				// Skip "unbind "
+				p = Com_SkipTokens( cmd, 1, " " );
+
+				if( p > cmd )
+					Field_CompleteKeyname( );
+			}
 #endif
 		}
 	}

Modified: trunk/code/sdl/sdl_input.c
===================================================================
--- trunk/code/sdl/sdl_input.c	2008-08-23 22:45:30 UTC (rev 1458)
+++ trunk/code/sdl/sdl_input.c	2008-08-25 21:15:25 UTC (rev 1459)
@@ -218,26 +218,38 @@
 		}
 	}
 
-	if( down && !( keysym->unicode & 0xFF80 ) )
+	if( down )
 	{
-		char ch = (char)keysym->unicode & 0x7F;
-
-		switch( ch )
+		if( keysym->unicode && !( keysym->unicode & 0xFF80 ) )
 		{
-			// So the key marked ~ always drops the console
-			case '~': *key = '~'; break;
+			char ch = (char)keysym->unicode & 0x7F;
 
-			case 127: // ASCII delete
-				if( *key != K_DEL )
-				{
-					// ctrl-h
-					*buf = CTRL('h');
-					break;
-				}
-				// fallthrough
+			switch( ch )
+			{
+				// So the key marked ~ always drops the console
+				case '~': *key = '~'; break;
 
-			default: *buf = ch; break;
+				case 127: // ASCII delete
+					if( *key != K_DEL )
+					{
+						// ctrl-h
+						*buf = CTRL('h');
+						break;
+					}
+					// fallthrough
+
+				default: *buf = ch; break;
+			}
 		}
+		else
+		{
+			// Unicode character which isn't ASCII, possibly the character
+			// following a dead key. Fallback on what SDL calls the key
+
+			const char *keyString = SDL_GetKeyName( keysym->sym );
+			if( strlen( keyString ) == 1 )
+				*buf = *keyString;
+		}
 	}
 
 	// Never allow a '~' SE_CHAR event to be generated
@@ -280,6 +292,21 @@
 
 /*
 ===============
+IN_GobbleMotionEvents
+===============
+*/
+static void IN_GobbleMotionEvents( void )
+{
+	SDL_Event dummy[ 1 ];
+
+	// Gobble any mouse motion events
+	SDL_PumpEvents( );
+	while( SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
+		SDL_EVENTMASK( SDL_MOUSEMOTION ) ) ) { }
+}
+
+/*
+===============
 IN_ActivateMouse
 ===============
 */
@@ -333,6 +360,8 @@
 		SDL_ShowCursor( 0 );
 #endif
 		SDL_WM_GrabInput( SDL_GRAB_ON );
+
+		IN_GobbleMotionEvents( );
 	}
 
 	// in_nograb makes no sense in fullscreen mode
@@ -391,6 +420,8 @@
 
 	if( mouseActive )
 	{
+		IN_GobbleMotionEvents( );
+
 		SDL_WM_GrabInput( SDL_GRAB_OFF );
 
 		// Don't warp the mouse unless the cursor is within the window




More information about the quake3-commits mailing list