diff src/video/photon/SDL_ph_events.c @ 283:3d8b6b9f1e18

Date: Mon, 18 Feb 2002 16:46:59 +1200 From: Julian Kinraid <jkinraid@clear.net.nz> Subject: Patches for photon port of SDL Hi, A couple more patches for photon and the nto audio. Adds mouse grabbing support, fixed cursor images, unicode keyboard events (though no unicode data on kye release, is that a problem?), hopefully fixing some audio lag problems, and a few other fixes. Thanks, Julian Kinraid
author Sam Lantinga <slouken@libsdl.org>
date Wed, 20 Feb 2002 01:05:51 +0000
parents c6abdda2f666
children f6ffac90895c
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_events.c	Wed Feb 20 01:02:33 2002 +0000
+++ b/src/video/photon/SDL_ph_events.c	Wed Feb 20 01:05:51 2002 +0000
@@ -55,7 +55,7 @@
    (idea shamelessly lifted from GII -- thanks guys! :)
  */
 
-/*
+#if 0
 static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
 {
 //	PhEvent_t* peekevent;
@@ -89,78 +89,33 @@
 	}
 	return(repeated);
 }
-
-*/
+#endif
 
-/* Note:  The X server buffers and accumulates mouse motion events, so
-   the motion event generated by the warp may not appear exactly as we
-   expect it to.  We work around this (and improve performance) by only
-   warping the pointer when it reaches the edge, and then wait for it.
-*/
-/*
-#define MOUSE_FUDGE_FACTOR	8
+static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
+{
+	PhPointerEvent_t *pointer = PhGetData( winEvent );
+	PhRect_t *rect = PhGetRects( winEvent );
 
-static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
-{
-	int w, h, i;
-	int deltax, deltay;
+	int centre_x, centre_y;
+	int dx, dy, abs_x, abs_y;
 	int posted;
 
-	w = SDL_VideoSurface->w;
-	h = SDL_VideoSurface->h;
-	deltax = xevent->xmotion.x - mouse_last.x;
-	deltay = xevent->xmotion.y - mouse_last.y;
-#ifdef DEBUG_MOTION
-  printf("Warped mouse motion: %d,%d\n", deltax, deltay);
-#endif
-	mouse_last.x = xevent->xmotion.x;
-	mouse_last.y = xevent->xmotion.y;
-	posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
+	centre_x = SDL_VideoSurface->w / 2;
+	centre_y = SDL_VideoSurface->h / 2;
+
+	dx = rect->ul.x - centre_x;
+	dy = rect->ul.y - centre_y;
 
-	if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
-	     (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
-	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
-	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
-		// Get the events that have accumulated
-/*		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
-			deltax = xevent->xmotion.x - mouse_last.x;
-			deltay = xevent->xmotion.y - mouse_last.y;
-#ifdef DEBUG_MOTION
-  printf("Extra mouse motion: %d,%d\n", deltax, deltay);
-#endif
-			mouse_last.x = xevent->xmotion.x;
-			mouse_last.y = xevent->xmotion.y;
-			posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
-		}
-		mouse_last.x = w/2;
-		mouse_last.y = h/2;
-		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
-					mouse_last.x, mouse_last.y);
-		for ( i=0; i<10; ++i ) {
-        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
-			if ( (xevent->xmotion.x >
-			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
-			     (xevent->xmotion.x <
-			          (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
-			     (xevent->xmotion.y >
-			          (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
-			     (xevent->xmotion.y <
-			          (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
-				break;
-			}
-#ifdef DEBUG_XEVENTS
-  printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
-#endif
-		}
-#ifdef DEBUG_XEVENTS
-		if ( i == 10 ) {
-			printf("Warning: didn't detect mouse warp motion\n");
-		}
-#endif
-	}
+	posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
+
+	/* Move mouse cursor to middle of the window */
+	PtGetAbsPosition( window, &abs_x, &abs_y );
+	PhMoveCursorAbs( PhInputGroup(NULL),
+			abs_x + centre_x,
+			abs_y + centre_y );
+
 	return(posted);
 }
-*/
 
 /* Control which motion flags the window has set, a flags value of -1 sets
  * MOTION_BUTTON and MOTION_NOBUTTON */
@@ -226,8 +181,13 @@
 			if ( SDL_VideoSurface ) {
 				pointerEvent = PhGetData( event );
 				rect = PhGetRects( event );
-				posted = SDL_PrivateMouseMotion(0, 0,
-						rect->ul.x, rect->ul.y);		
+				if( mouse_relative )
+				{
+					posted = ph_WarpedMotion(this, event);
+				}
+				else
+					posted = SDL_PrivateMouseMotion(0, 0,
+							rect->ul.x, rect->ul.y);
 			}
 		}
 		break;
@@ -291,10 +251,11 @@
 			{
 				set_motion_sensitivity(this, -1);
 				posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
-
+#if 0
 				/* Queue entry into fullscreen mode */
 				switch_waiting = 0x01 | SDL_FULLSCREEN;
 				switch_time = SDL_GetTicks() + 1500;
+#endif
 			}
 
 			/* request to quit */
@@ -302,6 +263,13 @@
 			{
 				posted = SDL_PrivateQuit();
 			}
+			else if (winEvent->event_f==Ph_WM_RESIZE)
+			{
+				PhDim_t *size;
+
+				PtGetResource( window, Pt_ARG_DIM, &size, 0 );
+				SDL_PrivateResize(size->w,size->h);
+			}
 		}
 		break;
 		
@@ -445,6 +413,7 @@
 		Uint32 now;
 
 		now  = SDL_GetTicks();
+#if 0
 		if ( pending || !SDL_VideoSurface ) {
 			/* Try again later... */
 			if ( switch_waiting & SDL_FULLSCREEN ) {
@@ -473,6 +442,7 @@
 			}
 */
 		}
+#endif
 	}
 }
 
@@ -573,6 +543,7 @@
 	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
 	We will assume it is valid.
 */
+	/* FIXME: This needs to check whether the cap & scancode is valid */
 	cap = key->key_cap;
 	switch (cap>>8) {
             case 0x00:  /* Latin 1 */
@@ -599,10 +570,27 @@
                 keysym->sym = MISC_keymap[cap&0xFF];
                 break;
             default:
-                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap);
+/*                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
+		keysym->sym = SDLK_UNKNOWN;                
                 break;
 	}
 	keysym->scancode = key->key_scan;
+	keysym->unicode = 0;
+	if( SDL_TranslateUNICODE )
+	{
+		char utf8[MB_CUR_MAX];
+		int utf8len;
+		wchar_t unicode;
+
+		utf8len = PhKeyToMb( utf8, key );
+		if( utf8len > 0 )
+		{
+			utf8len = mbtowc( &unicode, utf8, utf8len );
+			if( utf8len > 0)
+				keysym->unicode = unicode;
+		}
+	}
+
 	return (keysym);
 }