src/video/photon/SDL_ph_events.c
changeset 283 3d8b6b9f1e18
parent 266 c6abdda2f666
child 297 f6ffac90895c
     1.1 --- a/src/video/photon/SDL_ph_events.c	Wed Feb 20 01:02:33 2002 +0000
     1.2 +++ b/src/video/photon/SDL_ph_events.c	Wed Feb 20 01:05:51 2002 +0000
     1.3 @@ -55,7 +55,7 @@
     1.4     (idea shamelessly lifted from GII -- thanks guys! :)
     1.5   */
     1.6  
     1.7 -/*
     1.8 +#if 0
     1.9  static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
    1.10  {
    1.11  //	PhEvent_t* peekevent;
    1.12 @@ -89,78 +89,33 @@
    1.13  	}
    1.14  	return(repeated);
    1.15  }
    1.16 +#endif
    1.17  
    1.18 -*/
    1.19 +static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
    1.20 +{
    1.21 +	PhPointerEvent_t *pointer = PhGetData( winEvent );
    1.22 +	PhRect_t *rect = PhGetRects( winEvent );
    1.23  
    1.24 -/* Note:  The X server buffers and accumulates mouse motion events, so
    1.25 -   the motion event generated by the warp may not appear exactly as we
    1.26 -   expect it to.  We work around this (and improve performance) by only
    1.27 -   warping the pointer when it reaches the edge, and then wait for it.
    1.28 -*/
    1.29 -/*
    1.30 -#define MOUSE_FUDGE_FACTOR	8
    1.31 -
    1.32 -static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
    1.33 -{
    1.34 -	int w, h, i;
    1.35 -	int deltax, deltay;
    1.36 +	int centre_x, centre_y;
    1.37 +	int dx, dy, abs_x, abs_y;
    1.38  	int posted;
    1.39  
    1.40 -	w = SDL_VideoSurface->w;
    1.41 -	h = SDL_VideoSurface->h;
    1.42 -	deltax = xevent->xmotion.x - mouse_last.x;
    1.43 -	deltay = xevent->xmotion.y - mouse_last.y;
    1.44 -#ifdef DEBUG_MOTION
    1.45 -  printf("Warped mouse motion: %d,%d\n", deltax, deltay);
    1.46 -#endif
    1.47 -	mouse_last.x = xevent->xmotion.x;
    1.48 -	mouse_last.y = xevent->xmotion.y;
    1.49 -	posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
    1.50 +	centre_x = SDL_VideoSurface->w / 2;
    1.51 +	centre_y = SDL_VideoSurface->h / 2;
    1.52  
    1.53 -	if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
    1.54 -	     (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
    1.55 -	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
    1.56 -	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
    1.57 -		// Get the events that have accumulated
    1.58 -/*		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
    1.59 -			deltax = xevent->xmotion.x - mouse_last.x;
    1.60 -			deltay = xevent->xmotion.y - mouse_last.y;
    1.61 -#ifdef DEBUG_MOTION
    1.62 -  printf("Extra mouse motion: %d,%d\n", deltax, deltay);
    1.63 -#endif
    1.64 -			mouse_last.x = xevent->xmotion.x;
    1.65 -			mouse_last.y = xevent->xmotion.y;
    1.66 -			posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
    1.67 -		}
    1.68 -		mouse_last.x = w/2;
    1.69 -		mouse_last.y = h/2;
    1.70 -		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
    1.71 -					mouse_last.x, mouse_last.y);
    1.72 -		for ( i=0; i<10; ++i ) {
    1.73 -        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
    1.74 -			if ( (xevent->xmotion.x >
    1.75 -			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
    1.76 -			     (xevent->xmotion.x <
    1.77 -			          (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
    1.78 -			     (xevent->xmotion.y >
    1.79 -			          (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
    1.80 -			     (xevent->xmotion.y <
    1.81 -			          (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
    1.82 -				break;
    1.83 -			}
    1.84 -#ifdef DEBUG_XEVENTS
    1.85 -  printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
    1.86 -#endif
    1.87 -		}
    1.88 -#ifdef DEBUG_XEVENTS
    1.89 -		if ( i == 10 ) {
    1.90 -			printf("Warning: didn't detect mouse warp motion\n");
    1.91 -		}
    1.92 -#endif
    1.93 -	}
    1.94 +	dx = rect->ul.x - centre_x;
    1.95 +	dy = rect->ul.y - centre_y;
    1.96 +
    1.97 +	posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
    1.98 +
    1.99 +	/* Move mouse cursor to middle of the window */
   1.100 +	PtGetAbsPosition( window, &abs_x, &abs_y );
   1.101 +	PhMoveCursorAbs( PhInputGroup(NULL),
   1.102 +			abs_x + centre_x,
   1.103 +			abs_y + centre_y );
   1.104 +
   1.105  	return(posted);
   1.106  }
   1.107 -*/
   1.108  
   1.109  /* Control which motion flags the window has set, a flags value of -1 sets
   1.110   * MOTION_BUTTON and MOTION_NOBUTTON */
   1.111 @@ -226,8 +181,13 @@
   1.112  			if ( SDL_VideoSurface ) {
   1.113  				pointerEvent = PhGetData( event );
   1.114  				rect = PhGetRects( event );
   1.115 -				posted = SDL_PrivateMouseMotion(0, 0,
   1.116 -						rect->ul.x, rect->ul.y);		
   1.117 +				if( mouse_relative )
   1.118 +				{
   1.119 +					posted = ph_WarpedMotion(this, event);
   1.120 +				}
   1.121 +				else
   1.122 +					posted = SDL_PrivateMouseMotion(0, 0,
   1.123 +							rect->ul.x, rect->ul.y);
   1.124  			}
   1.125  		}
   1.126  		break;
   1.127 @@ -291,10 +251,11 @@
   1.128  			{
   1.129  				set_motion_sensitivity(this, -1);
   1.130  				posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.131 -
   1.132 +#if 0
   1.133  				/* Queue entry into fullscreen mode */
   1.134  				switch_waiting = 0x01 | SDL_FULLSCREEN;
   1.135  				switch_time = SDL_GetTicks() + 1500;
   1.136 +#endif
   1.137  			}
   1.138  
   1.139  			/* request to quit */
   1.140 @@ -302,6 +263,13 @@
   1.141  			{
   1.142  				posted = SDL_PrivateQuit();
   1.143  			}
   1.144 +			else if (winEvent->event_f==Ph_WM_RESIZE)
   1.145 +			{
   1.146 +				PhDim_t *size;
   1.147 +
   1.148 +				PtGetResource( window, Pt_ARG_DIM, &size, 0 );
   1.149 +				SDL_PrivateResize(size->w,size->h);
   1.150 +			}
   1.151  		}
   1.152  		break;
   1.153  		
   1.154 @@ -445,6 +413,7 @@
   1.155  		Uint32 now;
   1.156  
   1.157  		now  = SDL_GetTicks();
   1.158 +#if 0
   1.159  		if ( pending || !SDL_VideoSurface ) {
   1.160  			/* Try again later... */
   1.161  			if ( switch_waiting & SDL_FULLSCREEN ) {
   1.162 @@ -473,6 +442,7 @@
   1.163  			}
   1.164  */
   1.165  		}
   1.166 +#endif
   1.167  	}
   1.168  }
   1.169  
   1.170 @@ -573,6 +543,7 @@
   1.171  	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   1.172  	We will assume it is valid.
   1.173  */
   1.174 +	/* FIXME: This needs to check whether the cap & scancode is valid */
   1.175  	cap = key->key_cap;
   1.176  	switch (cap>>8) {
   1.177              case 0x00:  /* Latin 1 */
   1.178 @@ -599,10 +570,27 @@
   1.179                  keysym->sym = MISC_keymap[cap&0xFF];
   1.180                  break;
   1.181              default:
   1.182 -                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap);
   1.183 +/*                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
   1.184 +		keysym->sym = SDLK_UNKNOWN;                
   1.185                  break;
   1.186  	}
   1.187  	keysym->scancode = key->key_scan;
   1.188 +	keysym->unicode = 0;
   1.189 +	if( SDL_TranslateUNICODE )
   1.190 +	{
   1.191 +		char utf8[MB_CUR_MAX];
   1.192 +		int utf8len;
   1.193 +		wchar_t unicode;
   1.194 +
   1.195 +		utf8len = PhKeyToMb( utf8, key );
   1.196 +		if( utf8len > 0 )
   1.197 +		{
   1.198 +			utf8len = mbtowc( &unicode, utf8, utf8len );
   1.199 +			if( utf8len > 0)
   1.200 +				keysym->unicode = unicode;
   1.201 +		}
   1.202 +	}
   1.203 +
   1.204  	return (keysym);
   1.205  }
   1.206