GDK build: move suspend/constrain setup back to previous compilation unit

This commit is contained in:
Daniel Ludwig
2024-07-24 15:11:03 +02:00
committed by Ozkan Sezer
parent 0a678a654e
commit 7e48d4522b
3 changed files with 67 additions and 46 deletions

View File

@@ -73,6 +73,66 @@ void GDK_DispatchTaskQueue(void)
}
}
extern "C"
int GDK_RegisterChangeNotifications(void)
{
/* Register suspend/resume handling */
plmSuspendComplete = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE);
if (!plmSuspendComplete) {
SDL_SetError("[GDK] Unable to create plmSuspendComplete event");
return -1;
}
auto rascn = [](BOOLEAN quiesced, PVOID context) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[GDK] in RegisterAppStateChangeNotification handler");
if (quiesced) {
ResetEvent(plmSuspendComplete);
SDL_SendAppEvent(SDL_EVENT_DID_ENTER_BACKGROUND);
// To defer suspension, we must wait to exit this callback.
// IMPORTANT: The app must call SDL_GDKSuspendComplete() to release this lock.
(void)WaitForSingleObject(plmSuspendComplete, INFINITE);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[GDK] in RegisterAppStateChangeNotification handler: plmSuspendComplete event signaled.");
} else {
SDL_SendAppEvent(SDL_EVENT_WILL_ENTER_FOREGROUND);
}
};
if (RegisterAppStateChangeNotification(rascn, NULL, &hPLM)) {
SDL_SetError("[GDK] Unable to call RegisterAppStateChangeNotification");
return -1;
}
/* Register constrain/unconstrain handling */
auto raccn = [](BOOLEAN constrained, PVOID context) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[GDK] in RegisterAppConstrainedChangeNotification handler");
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this) {
if (constrained) {
SDL_SetKeyboardFocus(NULL);
} else {
SDL_SetKeyboardFocus(_this->windows);
}
}
};
if (RegisterAppConstrainedChangeNotification(raccn, NULL, &hCPLM)) {
SDL_SetError("[GDK] Unable to call RegisterAppConstrainedChangeNotification");
return -1;
}
return 0;
}
extern "C"
void GDK_UnregisterChangeNotifications(void)
{
/* Unregister suspend/resume handling */
UnregisterAppStateChangeNotification(hPLM);
CloseHandle(plmSuspendComplete);
/* Unregister constrain/unconstrain handling */
UnregisterAppConstrainedChangeNotification(hCPLM);
}
extern "C"
void SDL_GDKSuspendComplete()
{