Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Fri, 13 Jul 2007 18:44:43 +0000
branchSDL-1.2
changeset 40600b4ebec67cad
parent 4059 57b017e6aebf
child 4061 95ecf165f113
Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
src/video/gem/SDL_gemevents.c
src/video/gem/SDL_gemmouse.c
     1.1 --- a/src/video/gem/SDL_gemevents.c	Fri Jul 13 16:09:16 2007 +0000
     1.2 +++ b/src/video/gem/SDL_gemevents.c	Fri Jul 13 18:44:43 2007 +0000
     1.3 @@ -89,11 +89,8 @@
     1.4  		if (!GEM_fullscreen && (GEM_handle>=0)) {
     1.5  			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
     1.6  			event_mask |= MU_M1;
     1.7 -			if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
     1.8 -				mouse_event = MO_LEAVE;				
     1.9 -			} else {
    1.10 -				mouse_event = MO_ENTER;				
    1.11 -			}
    1.12 +			mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
    1.13 +				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
    1.14  		}
    1.15  
    1.16  		resultat = evnt_multi(
    1.17 @@ -123,22 +120,11 @@
    1.18  		/* Mouse entering/leaving window */
    1.19  		if (resultat & MU_M1) {
    1.20  			if (this->input_grab == SDL_GRAB_OFF) {
    1.21 -				if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
    1.22 -					SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    1.23 -					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
    1.24 -						graf_mouse(ARROW, NULL);
    1.25 -					}
    1.26 -				} else {
    1.27 -					SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    1.28 -					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
    1.29 -						if (GEM_cursor == (void *) -1) {
    1.30 -							graf_mouse(M_OFF, NULL);
    1.31 -						} else if (GEM_cursor) {
    1.32 -							graf_mouse(USER_DEF, GEM_cursor->mform_p);
    1.33 -						}
    1.34 -					}
    1.35 -				}
    1.36 +				/* Switch mouse focus state */
    1.37 +				SDL_PrivateAppActive((mouse_event == MO_ENTER),
    1.38 +					SDL_APPMOUSEFOCUS);
    1.39  			}
    1.40 +			GEM_CheckMouseMode(this);
    1.41  		}
    1.42  
    1.43  		/* Timer event ? */
    1.44 @@ -182,10 +168,10 @@
    1.45  
    1.46  static int do_messages(_THIS, short *message)
    1.47  {
    1.48 -	int quit, posted;
    1.49 +	int quit, posted, check_mouse_mode;
    1.50  	short x2,y2,w2,h2;
    1.51  
    1.52 -	quit=0;
    1.53 +	quit = check_mouse_mode = 0;
    1.54  	switch (message[0]) {
    1.55  		case WM_CLOSED:
    1.56  		case AP_TERM:    
    1.57 @@ -203,6 +189,7 @@
    1.58  			if (VDI_setpalette) {
    1.59  				VDI_setpalette(this, VDI_curpalette);
    1.60  			}
    1.61 +			check_mouse_mode = 1;
    1.62  			break;
    1.63  		case WM_REDRAW:
    1.64  			if (!GEM_lock_redraw) {
    1.65 @@ -222,6 +209,7 @@
    1.66  				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
    1.67  				GEM_refresh_name = SDL_FALSE;
    1.68  			}
    1.69 +			check_mouse_mode = 1;
    1.70  			break;
    1.71  		case WM_UNICONIFY:
    1.72  			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
    1.73 @@ -234,6 +222,7 @@
    1.74  				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
    1.75  				GEM_refresh_name = SDL_FALSE;
    1.76  			}
    1.77 +			check_mouse_mode = 1;
    1.78  			break;
    1.79  		case WM_SIZED:
    1.80  			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
    1.81 @@ -270,8 +259,13 @@
    1.82  			if (VDI_setpalette) {
    1.83  				VDI_setpalette(this, VDI_oldpalette);
    1.84  			}
    1.85 +			check_mouse_mode = 1;
    1.86  			break;
    1.87  	}
    1.88 +
    1.89 +	if (check_mouse_mode) {
    1.90 +		GEM_CheckMouseMode(this);
    1.91 +	}
    1.92  	
    1.93  	return quit;
    1.94  }
     2.1 --- a/src/video/gem/SDL_gemmouse.c	Fri Jul 13 16:09:16 2007 +0000
     2.2 +++ b/src/video/gem/SDL_gemmouse.c	Fri Jul 13 18:44:43 2007 +0000
     2.3 @@ -140,12 +140,8 @@
     2.4  int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
     2.5  {
     2.6  	GEM_cursor = cursor;
     2.7 -	if (cursor == NULL) {
     2.8 -		graf_mouse(M_OFF, NULL);
     2.9 -		GEM_cursor = (void *) -1;
    2.10 -	} else if (cursor->mform_p) {
    2.11 -		graf_mouse(USER_DEF, cursor->mform_p);
    2.12 -	}
    2.13 +
    2.14 +	GEM_CheckMouseMode(this);
    2.15  
    2.16  #ifdef DEBUG_VIDEO_GEM
    2.17  	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
    2.18 @@ -170,19 +166,39 @@
    2.19  
    2.20  void GEM_CheckMouseMode(_THIS)
    2.21  {
    2.22 +	const Uint8 full_focus = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
    2.23 +	int set_system_cursor = 1, show_system_cursor = 1;
    2.24 +
    2.25  #ifdef DEBUG_VIDEO_GEM
    2.26  	printf("sdl:video:gem: check mouse mode\n");
    2.27  #endif
    2.28  
    2.29  	/* If the mouse is hidden and input is grabbed, we use relative mode */
    2.30 -	if ( (!(SDL_cursorstate & CURSOR_VISIBLE)) &&
    2.31 -		(this->input_grab != SDL_GRAB_OFF) &&
    2.32 -             (SDL_GetAppState() & SDL_APPACTIVE) ) {
    2.33 -		SDL_AtariXbios_LockMousePosition(SDL_TRUE);
    2.34 -		GEM_mouse_relative = SDL_TRUE;
    2.35 +	GEM_mouse_relative = (!(SDL_cursorstate & CURSOR_VISIBLE))
    2.36 +		&& (this->input_grab != SDL_GRAB_OFF)
    2.37 +		&& (SDL_GetAppState() & SDL_APPACTIVE);
    2.38 +	SDL_AtariXbios_LockMousePosition(GEM_mouse_relative);
    2.39 +
    2.40 +	if (SDL_cursorstate & CURSOR_VISIBLE) {
    2.41 +		/* Application defined cursor only over the application window */
    2.42 +		if ((SDL_GetAppState() & full_focus) == full_focus) {
    2.43 +			if (GEM_cursor) {
    2.44 +				graf_mouse(USER_DEF, GEM_cursor->mform_p);
    2.45 +				set_system_cursor = 0;
    2.46 +			} else {
    2.47 +				show_system_cursor = 0;
    2.48 +			}
    2.49 +		}
    2.50  	} else {
    2.51 -		SDL_AtariXbios_LockMousePosition(SDL_FALSE);
    2.52 -		GEM_mouse_relative = SDL_FALSE;
    2.53 -		graf_mouse(M_ON, NULL);
    2.54 +		/* Mouse cursor hidden only over the application window */
    2.55 +		if ((SDL_GetAppState() & full_focus) == full_focus) {
    2.56 +			set_system_cursor = 0;
    2.57 +			show_system_cursor = 0;
    2.58 +		}
    2.59 +	}
    2.60 +
    2.61 +	graf_mouse(show_system_cursor ? M_ON : M_OFF, NULL);
    2.62 +	if (set_system_cursor) {
    2.63 +		graf_mouse(ARROW, NULL);
    2.64  	}
    2.65  }