src/video/gem/SDL_gemevents.c
branchSDL-1.2
changeset 6583 15c1dc6ac329
parent 6582 8b7e21749630
child 6584 6b04ece9686b
     1.1 --- a/src/video/gem/SDL_gemevents.c	Fri Oct 12 18:25:28 2012 +0200
     1.2 +++ b/src/video/gem/SDL_gemevents.c	Fri Oct 12 18:35:50 2012 +0200
     1.3 @@ -52,7 +52,8 @@
     1.4  static int do_messages(_THIS, short *message);
     1.5  static void do_keyboard(short kc);
     1.6  static void do_keyboard_special(short ks);
     1.7 -static void do_mouse(_THIS, short mx, short my, short mb);
     1.8 +static void do_mouse_motion(_THIS, short mx, short my);
     1.9 +static void do_mouse_buttons(_THIS, short mb);
    1.10  
    1.11  /* Functions */
    1.12  
    1.13 @@ -70,7 +71,7 @@
    1.14  void GEM_PumpEvents(_THIS)
    1.15  {
    1.16  	short prevkc;
    1.17 -	static short maskmouseb=0;
    1.18 +	static short prevmb=0;
    1.19  	int i;
    1.20  	SDL_keysym	keysym;
    1.21  
    1.22 @@ -99,7 +100,7 @@
    1.23  
    1.24  		resultat = evnt_multi(
    1.25  			event_mask,
    1.26 -			0x101,7,maskmouseb,
    1.27 +			0x101,7,prevmb,
    1.28  			mouse_event,x2,y2,w2,h2,
    1.29  			0,0,0,0,0,
    1.30  			buffer,
    1.31 @@ -138,8 +139,9 @@
    1.32  
    1.33  		/* Mouse button event ? */
    1.34  		if (resultat & MU_BUTTON) {
    1.35 -			do_mouse(this, mousex, mousey, mouseb);
    1.36 -			maskmouseb = mouseb & 7;
    1.37 +			do_mouse_motion(this, mousex, mousey);
    1.38 +			do_mouse_buttons(this, mouseb);
    1.39 +			prevmb = mouseb & 7;
    1.40  		}
    1.41  
    1.42  		/* Timer event ? */
    1.43 @@ -304,9 +306,9 @@
    1.44  		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
    1.45  }
    1.46  
    1.47 -static void do_mouse(_THIS, short mx, short my, short mb)
    1.48 +static void do_mouse_motion(_THIS, short mx, short my)
    1.49  {
    1.50 -	static short prevmousex=0, prevmousey=0, prevmouseb=0;
    1.51 +	static short prevmousex=0, prevmousey=0;
    1.52  	short x2, y2, w2, h2;
    1.53  
    1.54  	/* Don't return mouse events if out of window */
    1.55 @@ -320,11 +322,6 @@
    1.56  	h2 = VDI_h;
    1.57  	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
    1.58  		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
    1.59 -
    1.60 -		/* Do not generate mouse button event if out of window working area */
    1.61 -		if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
    1.62 -			mb=prevmouseb;
    1.63 -		}
    1.64  	}
    1.65  
    1.66  	/* Mouse motion ? */
    1.67 @@ -351,24 +348,33 @@
    1.68  		prevmousex = mx;
    1.69  		prevmousey = my;
    1.70  	}
    1.71 +}
    1.72  
    1.73 -	/* Mouse button ? */
    1.74 -	if (prevmouseb!=mb) {
    1.75 -		int i;
    1.76 +static void do_mouse_buttons(_THIS, short mb)
    1.77 +{
    1.78 +	static short prevmouseb=0;
    1.79 +	int i;
    1.80  
    1.81 -		for (i=0;i<3;i++) {
    1.82 -			int curbutton, prevbutton;
    1.83 +	/* Don't return mouse events if out of window */
    1.84 +	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0)
    1.85 +		return;
    1.86 +
    1.87 +	if (prevmouseb==mb)
    1.88 +		return;
    1.89 +
    1.90 +	for (i=0;i<3;i++) {
    1.91 +		int curbutton, prevbutton;
    1.92  		
    1.93 -			curbutton = mb & (1<<i);
    1.94 -			prevbutton = prevmouseb & (1<<i);
    1.95 -		
    1.96 -			if (curbutton && !prevbutton) {
    1.97 -				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
    1.98 -			}
    1.99 -			if (!curbutton && prevbutton) {
   1.100 -				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   1.101 -			}
   1.102 +		curbutton = mb & (1<<i);
   1.103 +		prevbutton = prevmouseb & (1<<i);
   1.104 +	
   1.105 +		if (curbutton && !prevbutton) {
   1.106 +			SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
   1.107  		}
   1.108 -		prevmouseb = mb;
   1.109 +		if (!curbutton && prevbutton) {
   1.110 +			SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   1.111 +		}
   1.112  	}
   1.113 +
   1.114 +	prevmouseb = mb;
   1.115  }