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 4060 0b4ebec67cad
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
--- a/src/video/gem/SDL_gemevents.c	Fri Jul 13 16:09:16 2007 +0000
+++ b/src/video/gem/SDL_gemevents.c	Fri Jul 13 18:44:43 2007 +0000
@@ -89,11 +89,8 @@
 		if (!GEM_fullscreen && (GEM_handle>=0)) {
 			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
 			event_mask |= MU_M1;
-			if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
-				mouse_event = MO_LEAVE;				
-			} else {
-				mouse_event = MO_ENTER;				
-			}
+			mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
+				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
 		}
 
 		resultat = evnt_multi(
@@ -123,22 +120,11 @@
 		/* Mouse entering/leaving window */
 		if (resultat & MU_M1) {
 			if (this->input_grab == SDL_GRAB_OFF) {
-				if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
-					SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
-					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
-						graf_mouse(ARROW, NULL);
-					}
-				} else {
-					SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
-					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
-						if (GEM_cursor == (void *) -1) {
-							graf_mouse(M_OFF, NULL);
-						} else if (GEM_cursor) {
-							graf_mouse(USER_DEF, GEM_cursor->mform_p);
-						}
-					}
-				}
+				/* Switch mouse focus state */
+				SDL_PrivateAppActive((mouse_event == MO_ENTER),
+					SDL_APPMOUSEFOCUS);
 			}
+			GEM_CheckMouseMode(this);
 		}
 
 		/* Timer event ? */
@@ -182,10 +168,10 @@
 
 static int do_messages(_THIS, short *message)
 {
-	int quit, posted;
+	int quit, posted, check_mouse_mode;
 	short x2,y2,w2,h2;
 
-	quit=0;
+	quit = check_mouse_mode = 0;
 	switch (message[0]) {
 		case WM_CLOSED:
 		case AP_TERM:    
@@ -203,6 +189,7 @@
 			if (VDI_setpalette) {
 				VDI_setpalette(this, VDI_curpalette);
 			}
+			check_mouse_mode = 1;
 			break;
 		case WM_REDRAW:
 			if (!GEM_lock_redraw) {
@@ -222,6 +209,7 @@
 				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
 				GEM_refresh_name = SDL_FALSE;
 			}
+			check_mouse_mode = 1;
 			break;
 		case WM_UNICONIFY:
 			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
@@ -234,6 +222,7 @@
 				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
 				GEM_refresh_name = SDL_FALSE;
 			}
+			check_mouse_mode = 1;
 			break;
 		case WM_SIZED:
 			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
@@ -270,8 +259,13 @@
 			if (VDI_setpalette) {
 				VDI_setpalette(this, VDI_oldpalette);
 			}
+			check_mouse_mode = 1;
 			break;
 	}
+
+	if (check_mouse_mode) {
+		GEM_CheckMouseMode(this);
+	}
 	
 	return quit;
 }
--- a/src/video/gem/SDL_gemmouse.c	Fri Jul 13 16:09:16 2007 +0000
+++ b/src/video/gem/SDL_gemmouse.c	Fri Jul 13 18:44:43 2007 +0000
@@ -140,12 +140,8 @@
 int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
 {
 	GEM_cursor = cursor;
-	if (cursor == NULL) {
-		graf_mouse(M_OFF, NULL);
-		GEM_cursor = (void *) -1;
-	} else if (cursor->mform_p) {
-		graf_mouse(USER_DEF, cursor->mform_p);
-	}
+
+	GEM_CheckMouseMode(this);
 
 #ifdef DEBUG_VIDEO_GEM
 	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
@@ -170,19 +166,39 @@
 
 void GEM_CheckMouseMode(_THIS)
 {
+	const Uint8 full_focus = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
+	int set_system_cursor = 1, show_system_cursor = 1;
+
 #ifdef DEBUG_VIDEO_GEM
 	printf("sdl:video:gem: check mouse mode\n");
 #endif
 
 	/* If the mouse is hidden and input is grabbed, we use relative mode */
-	if ( (!(SDL_cursorstate & CURSOR_VISIBLE)) &&
-		(this->input_grab != SDL_GRAB_OFF) &&
-             (SDL_GetAppState() & SDL_APPACTIVE) ) {
-		SDL_AtariXbios_LockMousePosition(SDL_TRUE);
-		GEM_mouse_relative = SDL_TRUE;
+	GEM_mouse_relative = (!(SDL_cursorstate & CURSOR_VISIBLE))
+		&& (this->input_grab != SDL_GRAB_OFF)
+		&& (SDL_GetAppState() & SDL_APPACTIVE);
+	SDL_AtariXbios_LockMousePosition(GEM_mouse_relative);
+
+	if (SDL_cursorstate & CURSOR_VISIBLE) {
+		/* Application defined cursor only over the application window */
+		if ((SDL_GetAppState() & full_focus) == full_focus) {
+			if (GEM_cursor) {
+				graf_mouse(USER_DEF, GEM_cursor->mform_p);
+				set_system_cursor = 0;
+			} else {
+				show_system_cursor = 0;
+			}
+		}
 	} else {
-		SDL_AtariXbios_LockMousePosition(SDL_FALSE);
-		GEM_mouse_relative = SDL_FALSE;
-		graf_mouse(M_ON, NULL);
+		/* Mouse cursor hidden only over the application window */
+		if ((SDL_GetAppState() & full_focus) == full_focus) {
+			set_system_cursor = 0;
+			show_system_cursor = 0;
+		}
+	}
+
+	graf_mouse(show_system_cursor ? M_ON : M_OFF, NULL);
+	if (set_system_cursor) {
+		graf_mouse(ARROW, NULL);
 	}
 }