*** empty log message ***
authorSam Lantinga <slouken@libsdl.org>
Thu, 01 Nov 2001 16:45:40 +0000
changeset 2207861d904fb77
parent 219 f928da36f0e9
child 221 50620ec9c86a
*** empty log message ***
src/video/photon/SDL_ph_events.c
     1.1 --- a/src/video/photon/SDL_ph_events.c	Thu Nov 01 16:21:40 2001 +0000
     1.2 +++ b/src/video/photon/SDL_ph_events.c	Thu Nov 01 16:45:40 2001 +0000
     1.3 @@ -159,6 +159,41 @@
     1.4  }
     1.5  */
     1.6  
     1.7 +/* Control which motion flags the window has set, a flags value of -1 sets
     1.8 + * MOTION_BUTTON and MOTION_NOBUTTON */
     1.9 +static void set_motion_sensitivity(_THIS, unsigned int flags)
    1.10 +{
    1.11 +	int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
    1.12 +	PhRegion_t region;
    1.13 +
    1.14 +	if( window )
    1.15 +	{
    1.16 +		rid = PtWidgetRid( window );
    1.17 +		if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
    1.18 +		{
    1.19 +			region.events_sense = ( region.events_sense & ~fields ) |
    1.20 +				( flags & fields );
    1.21 +			PhRegionChange( Ph_REGION_EV_SENSE, 0, &region,
    1.22 +					NULL, NULL );
    1.23 +		}
    1.24 +	}
    1.25 +}
    1.26 +
    1.27 +/* Convert the photon button state value to an SDL value */
    1.28 +static Uint8 ph2sdl_mousebutton( unsigned short button_state )
    1.29 +{
    1.30 +	Uint8 mouse_button = 0;
    1.31 +
    1.32 +	if( button_state & Ph_BUTTON_SELECT )
    1.33 +			mouse_button |= SDL_BUTTON_LEFT;
    1.34 +	if( button_state & Ph_BUTTON_MENU )
    1.35 +			mouse_button |= SDL_BUTTON_RIGHT;
    1.36 +	if( button_state & Ph_BUTTON_ADJUST )
    1.37 +			mouse_button |= SDL_BUTTON_MIDDLE;
    1.38 +
    1.39 +	return( mouse_button );
    1.40 +}
    1.41 +
    1.42  static int ph_DispatchEvent(_THIS)
    1.43  {
    1.44  	int posted;
    1.45 @@ -166,7 +201,7 @@
    1.46  	PhPointerEvent_t* pointerEvent;
    1.47  	PhKeyEvent_t* keyEvent;
    1.48  	PhWindowEvent_t* winEvent;
    1.49 -	int i;
    1.50 +	int i, buttons;
    1.51  	SDL_Rect sdlrects[50]; 
    1.52  	
    1.53  	posted = 0;
    1.54 @@ -174,7 +209,6 @@
    1.55  	switch (event->type) {
    1.56  		case Ph_EV_BOUNDARY:
    1.57  		{
    1.58 -		
    1.59  			if (event->subtype == Ph_EV_PTR_ENTER)
    1.60  				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    1.61  			else if (event->subtype ==Ph_EV_PTR_LEAVE)
    1.62 @@ -185,46 +219,61 @@
    1.63  		case Ph_EV_PTR_MOTION_BUTTON:
    1.64  		case Ph_EV_PTR_MOTION_NOBUTTON:
    1.65  		{
    1.66 -		
    1.67  			if ( SDL_VideoSurface ) {
    1.68  				pointerEvent = PhGetData( event );
    1.69  				rect = PhGetRects( event );
    1.70 -				posted = SDL_PrivateMouseMotion(0, 1,
    1.71 -                		pointerEvent->pos.x - rect[0].ul.x,
    1.72 -                		pointerEvent->pos.y - rect[0].ul.y);		
    1.73 +				posted = SDL_PrivateMouseMotion(0, 0,
    1.74 +						rect->ul.x, rect->ul.y);		
    1.75  			}
    1.76  		}
    1.77  		break;
    1.78  
    1.79  		case Ph_EV_BUT_PRESS:
    1.80  		{
    1.81 -
    1.82  			pointerEvent = PhGetData( event );
    1.83 -			/* TODO: is 'buttons' the right mapping? */
    1.84 -			posted = SDL_PrivateMouseButton(SDL_PRESSED,
    1.85 -                        	pointerEvent->buttons, 0, 0);
    1.86 +			buttons = ph2sdl_mousebutton( pointerEvent->buttons );
    1.87 +			if( buttons != 0 )
    1.88 +			posted = SDL_PrivateMouseButton( SDL_PRESSED, buttons,
    1.89 +					0, 0 );
    1.90  		}
    1.91  		break;
    1.92  
    1.93  		case Ph_EV_BUT_RELEASE:
    1.94  		{
    1.95 -			
    1.96 -			pointerEvent = PhGetData( event );
    1.97 -			 posted = SDL_PrivateMouseButton(SDL_RELEASED,
    1.98 -         			pointerEvent->buttons, 0, 0);
    1.99 +			pointerEvent = PhGetData(event);
   1.100 +			buttons = ph2sdl_mousebutton(pointerEvent->buttons);
   1.101 +			if( event->subtype == Ph_EV_RELEASE_REAL && 
   1.102 +					buttons != 0 )
   1.103 +			{
   1.104 +				posted = SDL_PrivateMouseButton( SDL_RELEASED,
   1.105 +						buttons, 0, 0 );
   1.106 +			}
   1.107 +			else if( event->subtype == Ph_EV_RELEASE_PHANTOM )
   1.108 +			{
   1.109 +				/* If the mouse is outside the window,
   1.110 +				 * only a phantom release event is sent, so
   1.111 +				 * check if the window doesn't have mouse focus.
   1.112 +				 * Not perfect, maybe checking the mouse button
   1.113 +				 * state for Ph_EV_BOUNDARY events would be
   1.114 +				 * better. */
   1.115 +				if( ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == 0 )
   1.116 +				{
   1.117 +					posted = SDL_PrivateMouseButton( SDL_RELEASED,
   1.118 +						buttons, 0, 0 );
   1.119 +				}
   1.120 +			}
   1.121  		}
   1.122  		break;
   1.123  
   1.124  		case Ph_EV_WM:
   1.125  		{
   1.126 -
   1.127 -		
   1.128  			winEvent = PhGetData( event );
   1.129  			
   1.130  			/* losing focus */
   1.131  			if ((winEvent->event_f==Ph_WM_FOCUS)&&
   1.132  				(winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
   1.133  			{
   1.134 +				set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
   1.135  				posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   1.136  
   1.137  				/* Queue leaving fullscreen mode */
   1.138 @@ -236,6 +285,7 @@
   1.139  			else if ((winEvent->event_f==Ph_WM_FOCUS)&&
   1.140  					(winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   1.141  			{
   1.142 +				set_motion_sensitivity(this, -1);
   1.143  				posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.144  
   1.145  				/* Queue entry into fullscreen mode */
   1.146 @@ -254,24 +304,20 @@
   1.147  		/* window has been resized, moved or removed */
   1.148  		case Ph_EV_EXPOSE:
   1.149  		{
   1.150 -
   1.151  			if (SDL_VideoSurface)
   1.152  			{
   1.153 -			  
   1.154 -			  
   1.155 -					rect = PhGetRects( event );
   1.156 +				rect = PhGetRects( event );
   1.157  
   1.158  				//PgSetClipping(1, rect );
   1.159 -				 for(i=0;i<event->num_rects;i++)
   1.160 -			   {
   1.161 -			      sdlrects[i].x = rect[i].ul.x;
   1.162 -			      sdlrects[i].y = rect[i].ul.y;
   1.163 -			      sdlrects[i].w = rect[i].lr.x - rect[i].ul.x;
   1.164 -			      sdlrects[i].h = rect[i].lr.y - rect[i].ul.y;
   1.165 -			      	
   1.166 +				for(i=0;i<event->num_rects;i++)
   1.167 +				{
   1.168 +					sdlrects[i].x = rect[i].ul.x;
   1.169 +					sdlrects[i].y = rect[i].ul.y;
   1.170 +					sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   1.171 +					sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   1.172  				}
   1.173 -			
   1.174 -					this->UpdateRects(this, event->num_rects, sdlrects);
   1.175 +
   1.176 +				this->UpdateRects(this, event->num_rects, sdlrects);
   1.177  
   1.178  			}
   1.179  		}
   1.180 @@ -313,9 +359,7 @@
   1.181  /* perform a blocking read if no events available */
   1.182  int ph_Pending(_THIS)
   1.183  {
   1.184 -	
   1.185  	/* Flush the display connection and look to see if events are queued */
   1.186 -
   1.187  	PgFlush();
   1.188  
   1.189       while( 1 )
   1.190 @@ -526,7 +570,7 @@
   1.191  	We will assume it is valid.
   1.192  */
   1.193  	cap = key->key_cap;
   1.194 -    switch (cap>>8) {
   1.195 +	switch (cap>>8) {
   1.196              case 0x00:  /* Latin 1 */
   1.197              case 0x01:  /* Latin 2 */
   1.198              case 0x02:  /* Latin 3 */
   1.199 @@ -553,13 +597,13 @@
   1.200              default:
   1.201                  fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap);
   1.202                  break;
   1.203 -    }	
   1.204 +	}
   1.205 +	keysym->scancode = key->key_scan;
   1.206  	return (keysym);
   1.207  }
   1.208  
   1.209  void ph_InitOSKeymap(_THIS)
   1.210  {
   1.211 -
   1.212  	ph_InitKeymap();
   1.213  }
   1.214