@@ -101,6 +101,11 @@ static int WIIU_ForegroundAcquired(_THIS)
101
101
GX2Invalidate (GX2_INVALIDATE_MODE_CPU , videodata -> drcScanBuffer , videodata -> drcScanBufferSize );
102
102
GX2SetDRCBuffer (videodata -> drcScanBuffer , videodata -> drcScanBufferSize , videodata -> drcRenderMode , GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8 , GX2_BUFFERING_MODE_DOUBLE );
103
103
104
+ if (videodata -> handleProcUI ) {
105
+ SDL_SendAppEvent (SDL_APP_WILLENTERFOREGROUND );
106
+ SDL_SendAppEvent (SDL_APP_DIDENTERFOREGROUND );
107
+ }
108
+
104
109
while (window ) {
105
110
SDL_Renderer * renderer = SDL_GetRenderer (window );
106
111
@@ -146,8 +151,14 @@ static int WIIU_ForegroundReleased(_THIS)
146
151
while (window ) {
147
152
SDL_Renderer * renderer = SDL_GetRenderer (window );
148
153
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
+ }
151
162
152
163
// Destroy window texture, we no longer have access to foreground memory
153
164
if (renderer ) {
@@ -187,7 +198,7 @@ static int WIIU_VideoInit(_THIS)
187
198
// check if the user already set up procui or if we should handle it
188
199
if (!ProcUIIsRunning ()) {
189
200
ProcUIInitEx (WiiU_SaveCallback , NULL );
190
-
201
+
191
202
videodata -> handleProcUI = SDL_TRUE ;
192
203
}
193
204
@@ -334,21 +345,52 @@ static void WIIU_PumpEvents(_THIS)
334
345
WIIU_VideoData * videodata = (WIIU_VideoData * ) _this -> driverdata ;
335
346
336
347
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 ;
341
352
ProcUIDrawDoneRelease ();
342
353
}
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
+ }
343
385
}
344
386
345
387
SDL_WIIU_PumpKeyboardEvents (_this );
346
388
}
347
389
348
- static void WIIU_DeleteDevice (SDL_VideoDevice * device )
390
+ static void WIIU_DeleteDevice (_THIS )
349
391
{
350
- SDL_free (device -> driverdata );
351
- SDL_free (device );
392
+ SDL_free (_this -> driverdata );
393
+ SDL_free (_this );
352
394
}
353
395
354
396
static SDL_VideoDevice * WIIU_CreateDevice (void )
0 commit comments