Skip to content

Commit d6e0d29

Browse files
dkosmariDaniel K. O. (dkosmari)
andauthored
Wii U: Implemented FOREGROUND/BACKGROUND events. (#102)
* Implemented FOREGROUND/BACKGROUND events. * - Only send foreground events if handleProcUI is true. - Ensure window hidden event is sent when handleProcUI is false. * Refactored the enteringBackground condition for clarity. * Fixed typo. --------- Co-authored-by: Daniel K. O. (dkosmari) <none@none>
1 parent 7210c2f commit d6e0d29

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

src/video/wiiu/SDL_wiiuvideo.c

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

354396
static SDL_VideoDevice *WIIU_CreateDevice(void)

src/video/wiiu/SDL_wiiuvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct WIIU_VideoData
3838
SDL_bool handleProcUI;
3939

4040
SDL_bool hasForeground;
41+
SDL_bool enteringBackground;
4142

4243
void *commandBufferPool;
4344

0 commit comments

Comments
 (0)