@@ -101,6 +101,11 @@ static int WIIU_ForegroundAcquired(_THIS)
101101 GX2Invalidate (GX2_INVALIDATE_MODE_CPU , videodata -> drcScanBuffer , videodata -> drcScanBufferSize );
102102 GX2SetDRCBuffer (videodata -> drcScanBuffer , videodata -> drcScanBufferSize , videodata -> drcRenderMode , GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8 , GX2_BUFFERING_MODE_DOUBLE );
103103
104+ if (videodata -> handleProcUI ) {
105+ SDL_SendAppEvent (SDL_APP_WILLENTERFOREGROUND );
106+ SDL_SendAppEvent (SDL_APP_DIDENTERFOREGROUND );
107+ }
108+
104109 while (window ) {
105110 SDL_Renderer * renderer = SDL_GetRenderer (window );
106111
@@ -146,8 +151,14 @@ static int WIIU_ForegroundReleased(_THIS)
146151 while (window ) {
147152 SDL_Renderer * renderer = SDL_GetRenderer (window );
148153
149- // No longer in foreground, window is no longer visible
150- SDL_SendWindowEvent (window , SDL_WINDOWEVENT_HIDDEN , 0 , 0 );
154+ // Avoid sending the event if we're handling ProcUI, since we send this
155+ // event from inside WIIU_PumpEvents().
156+ // Note: the application won't receive this event until after we return to
157+ // the foreground.
158+ if (!videodata -> handleProcUI ) {
159+ // No longer in foreground, window is no longer visible.
160+ SDL_SendWindowEvent (window , SDL_WINDOWEVENT_HIDDEN , 0 , 0 );
161+ }
151162
152163 // Destroy window texture, we no longer have access to foreground memory
153164 if (renderer ) {
@@ -187,7 +198,7 @@ static int WIIU_VideoInit(_THIS)
187198 // check if the user already set up procui or if we should handle it
188199 if (!ProcUIIsRunning ()) {
189200 ProcUIInitEx (WiiU_SaveCallback , NULL );
190-
201+
191202 videodata -> handleProcUI = SDL_TRUE ;
192203 }
193204
@@ -334,21 +345,52 @@ static void WIIU_PumpEvents(_THIS)
334345 WIIU_VideoData * videodata = (WIIU_VideoData * ) _this -> driverdata ;
335346
336347 if (videodata -> handleProcUI ) {
337- ProcUIStatus status = ProcUIProcessMessages (TRUE);
338- if ( status == PROCUI_STATUS_EXITING ) {
339- SDL_SendQuit ();
340- } else if ( status == PROCUI_STATUS_RELEASE_FOREGROUND ) {
348+ if ( videodata -> enteringBackground ) {
349+ // The previous ProcUIProcessMessages() received a
350+ // PROCUI_STATUS_RELEASE_FOREGROUND.
351+ videodata -> enteringBackground = SDL_FALSE ;
341352 ProcUIDrawDoneRelease ();
342353 }
354+
355+ if (ProcUIIsRunning () && !ProcUIInShutdown ()) {
356+ ProcUIStatus status = ProcUIProcessMessages (TRUE);
357+ switch (status ) {
358+ case PROCUI_STATUS_IN_FOREGROUND :
359+ videodata -> enteringBackground = SDL_FALSE ;
360+ break ;
361+ case PROCUI_STATUS_IN_BACKGROUND :
362+ break ;
363+ case PROCUI_STATUS_RELEASE_FOREGROUND : {
364+ SDL_Window * window = _this -> windows ;
365+ while (window ) {
366+ // No longer in foreground, window is no longer
367+ // visible.
368+ SDL_SendWindowEvent (window , SDL_WINDOWEVENT_HIDDEN , 0 , 0 );
369+ window = window -> next ;
370+ }
371+ SDL_SendAppEvent (SDL_APP_WILLENTERBACKGROUND );
372+ SDL_SendAppEvent (SDL_APP_DIDENTERBACKGROUND );
373+ // Note: we don't call ProcUIDrawDoneRelease() here to give
374+ // the application a chance to receive and process the
375+ // events queued above. The next call to WIIU_PumpEvents()
376+ // is the one that actually enters the background.
377+ videodata -> enteringBackground = SDL_TRUE ;
378+ break ;
379+ }
380+ case PROCUI_STATUS_EXITING :
381+ SDL_SendQuit ();
382+ break ;
383+ }
384+ }
343385 }
344386
345387 SDL_WIIU_PumpKeyboardEvents (_this );
346388}
347389
348- static void WIIU_DeleteDevice (SDL_VideoDevice * device )
390+ static void WIIU_DeleteDevice (_THIS )
349391{
350- SDL_free (device -> driverdata );
351- SDL_free (device );
392+ SDL_free (_this -> driverdata );
393+ SDL_free (_this );
352394}
353395
354396static SDL_VideoDevice * WIIU_CreateDevice (void )
0 commit comments