From 5a55fd5fd395bd6a385ff8f982a9df5835759703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 Mar 2023 22:17:53 +0100 Subject: [PATCH] And replace "graphics_restart", "toggle_fullscreen", etc --- Common/System/Request.h | 13 ++++++++ Common/System/System.h | 3 ++ Qt/QtMain.cpp | 9 +++--- SDL/SDLMain.cpp | 28 ++++++++--------- UI/ControlMappingScreen.cpp | 3 +- UI/EmuScreen.cpp | 3 +- UI/GameSettingsScreen.cpp | 6 ++-- UI/MainScreen.cpp | 2 +- UI/MemStickScreen.cpp | 2 +- UI/NativeApp.cpp | 6 ++-- UWP/PPSSPP_UWPMain.cpp | 21 ++++++------- Windows/main.cpp | 61 +++++++++++++++++++++---------------- android/jni/app-android.cpp | 3 ++ 13 files changed, 94 insertions(+), 66 deletions(-) diff --git a/Common/System/Request.h b/Common/System/Request.h index 0d32e8c491..1b801e962a 100644 --- a/Common/System/Request.h +++ b/Common/System/Request.h @@ -87,3 +87,16 @@ inline void System_CopyStringToClipboard(const std::string &string) { inline void System_ExitApp() { g_requestManager.MakeSystemRequest(SystemRequestType::EXIT_APP, nullptr, "", "", 0); } + +inline void System_RestartApp(const std::string ¶ms) { + g_requestManager.MakeSystemRequest(SystemRequestType::RESTART_APP, nullptr, params, "", 0); +} + +// The design is a little weird, just a holdover from the old message. Can either toggle or set to on or off. +inline void System_ToggleFullscreenState(const std::string ¶m) { + g_requestManager.MakeSystemRequest(SystemRequestType::TOGGLE_FULLSCREEN_STATE, nullptr, param, "", 0); +} + +inline void System_GraphicsBackendFailedAlert(const std::string ¶m) { + g_requestManager.MakeSystemRequest(SystemRequestType::GRAPHICS_BACKEND_FAILED_ALERT, nullptr, param, "", 0); +} diff --git a/Common/System/System.h b/Common/System/System.h index f4f8a5c294..e4e00b53f7 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -62,7 +62,10 @@ enum class SystemRequestType { BROWSE_FOR_FOLDER, EXIT_APP, + RESTART_APP, // For graphics backend changes COPY_TO_CLIPBOARD, + TOGGLE_FULLSCREEN_STATE, + GRAPHICS_BACKEND_FAILED_ALERT, }; // Implementations are supposed to process the request, and post the response to the g_RequestManager (see Message.h). diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 2b4ba23a66..293ea67056 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -334,6 +334,10 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string case SystemRequestType::EXIT_APP: qApp->exit(0); return true; + case SystemRequestType::RESTART_APP: + // Should find a way to properly restart the app. + qApp->exit(0); + return true; case SystemRequestType::COPY_TO_CLIPBOARD: QApplication::clipboard()->setText(parameter); return true; @@ -368,10 +372,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string } void System_SendMessage(const char *command, const char *parameter) { - if (!strcmp(command, "graphics_restart")) { - // Should find a way to properly restart the app. - qApp->exit(0); - } else if (!strcmp(command, "camera_command")) { + if (!strcmp(command, "camera_command")) { if (!strncmp(parameter, "startVideo", 10)) { int width = 0, height = 0; sscanf(parameter, "startVideo_%dx%d", &width, &height); diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index c998f79c9b..f6defed98f 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -171,12 +171,13 @@ void System_Vibrate(int length_ms) { bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { switch (type) { case SystemRequestType::EXIT_APP: + case SystemRequestType::RESTART_APP: // Not sure how we best do this, but do a clean exit, better than being stuck in a bad state. // Do a clean exit g_QuitRequested = true; - break; + return true; case SystemRequestType::COPY_TO_CLIPBOARD: SDL_SetClipboardText(param1.c_str()); - break; + return true; #if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) case SystemRequestType::BROWSE_FOR_FILE: { @@ -205,25 +206,24 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string return true; } #endif - } - return false; -} - -void System_SendMessage(const char *command, const char *parameter) { - if (!strcmp(command, "toggle_fullscreen")) { + case SystemRequestType::TOGGLE_FULLSCREEN_STATE: g_ToggleFullScreenNextFrame = true; - if (strcmp(parameter, "1") == 0) { + if (param1 == "1") { g_ToggleFullScreenType = 1; - } else if (strcmp(parameter, "0") == 0) { + } else if (param1 == "0") { g_ToggleFullScreenType = 0; } else { // Just toggle. g_ToggleFullScreenType = -1; } - } else if (!strcmp(command, "graphics_restart")) { - // Not sure how we best do this, but do a clean exit, better than being stuck in a bad state. - g_QuitRequested = true; - } else if (!strcmp(command, "audio_resetDevice")) { + return true; + default: + return false; + } +} + +void System_SendMessage(const char *command, const char *parameter) { + if (!strcmp(command, "audio_resetDevice")) { StopSDLAudioDevice(); InitSDLAudioDevice(); } diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index bfcb9e662c..de04aef59a 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -37,6 +37,7 @@ #include "Common/StringUtils.h" #include "Common/System/Display.h" #include "Common/System/System.h" +#include "Common/System/Request.h" #include "Common/TimeUtil.h" #include "Core/KeyMap.h" #include "Core/Host.h" @@ -726,7 +727,7 @@ UI::EventReturn TouchTestScreen::OnImmersiveModeChange(UI::EventParams &e) { UI::EventReturn TouchTestScreen::OnRenderingBackend(UI::EventParams &e) { g_Config.Save("GameSettingsScreen::RenderingBackend"); - System_SendMessage("graphics_restart", "--touchscreentest"); + System_RestartApp("--touchscreentest"); return UI::EVENT_DONE; } diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index e5c03ba69b..b367e3b067 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -41,6 +41,7 @@ using namespace std::placeholders; #include "Common/System/Display.h" #include "Common/System/System.h" #include "Common/System/NativeApp.h" +#include "Common/System/Request.h" #include "Common/Profiler/Profiler.h" #include "Common/Math/curves.h" #include "Common/TimeUtil.h" @@ -676,7 +677,7 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) { NativeMessageReceived("savestate_displayslot", ""); break; case VIRTKEY_TOGGLE_FULLSCREEN: - System_SendMessage("toggle_fullscreen", ""); + System_ToggleFullscreenState(""); break; case VIRTKEY_SCREENSHOT: diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index e3b571aa4e..50b47a5677 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1329,12 +1329,12 @@ UI::EventReturn GameSettingsScreen::OnChangeBackground(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnFullscreenChange(UI::EventParams &e) { g_Config.iForceFullScreen = -1; - System_SendMessage("toggle_fullscreen", g_Config.UseFullScreen() ? "1" : "0"); + System_ToggleFullscreenState(g_Config.UseFullScreen() ? "1" : "0"); return UI::EVENT_DONE; } UI::EventReturn GameSettingsScreen::OnFullscreenMultiChange(UI::EventParams &e) { - System_SendMessage("toggle_fullscreen", g_Config.UseFullScreen() ? "1" : "0"); + System_ToggleFullscreenState(g_Config.UseFullScreen() ? "1" : "0"); return UI::EVENT_DONE; } @@ -1477,7 +1477,7 @@ void GameSettingsScreen::TriggerRestart(const char *why) { } // Make sure the new instance is considered the first. ShutdownInstanceCounter(); - System_SendMessage("graphics_restart", param.c_str()); + System_RestartApp(param); } void GameSettingsScreen::CallbackRenderingBackend(bool yes) { diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 69e9486621..875d9c07b8 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1287,7 +1287,7 @@ UI::EventReturn MainScreen::OnFullScreenToggle(UI::EventParams &e) { } #if !defined(MOBILE_DEVICE) g_Config.bFullScreen = !g_Config.bFullScreen; - System_SendMessage("toggle_fullscreen", ""); + System_ToggleFullscreenState(""); #endif return UI::EVENT_DONE; } diff --git a/UI/MemStickScreen.cpp b/UI/MemStickScreen.cpp index 9b3def0b61..d5812885ad 100644 --- a/UI/MemStickScreen.cpp +++ b/UI/MemStickScreen.cpp @@ -771,7 +771,7 @@ void ConfirmMemstickMoveScreen::FinishFolderMove() { if (!initialSetup_) { // We restart the app here, to get the new settings. - System_SendMessage("graphics_restart", ""); + System_RestartApp(""); } else { // This is initial setup, we now switch to the main screen, if we were successful // (which we better have been...) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index babf0e1b6d..b42c9a037d 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -387,7 +387,7 @@ static void CheckFailedGPUBackends() { g_Config.iGPUBackend = g_Config.NextValidBackend(); if (lastBackend != g_Config.iGPUBackend) { std::string param = GPUBackendToString((GPUBackend)lastBackend) + " -> " + GPUBackendToString((GPUBackend)g_Config.iGPUBackend); - System_SendMessage("graphics_failedBackend", param.c_str()); + System_GraphicsBackendFailedAlert(param); WARN_LOG(LOADER, "Failed graphics backend switched from %s (%d to %d)", param.c_str(), lastBackend, g_Config.iGPUBackend); } // And then let's - for now - add the current to the failed list. @@ -640,11 +640,11 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch g_Config.bPauseMenuExitsEmulator = true; if (!strcmp(argv[i], "--fullscreen")) { g_Config.iForceFullScreen = 1; - System_SendMessage("toggle_fullscreen", "1"); + System_ToggleFullscreenState("1"); } if (!strcmp(argv[i], "--windowed")) { g_Config.iForceFullScreen = 0; - System_SendMessage("toggle_fullscreen", "0"); + System_ToggleFullscreenState("0"); } if (!strcmp(argv[i], "--touchscreentest")) gotoTouchScreenTest = true; diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 9e27c82f1a..0af1409d3d 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -486,20 +486,13 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string }); return true; } - } - - return false; -} - -void System_SendMessage(const char *command, const char *parameter) { - using namespace concurrency; - - if (!strcmp(command, "toggle_fullscreen")) { + case SystemRequestType::TOGGLE_FULLSCREEN_STATE: + { auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView(); bool flag = !view->IsFullScreenMode; - if (strcmp(parameter, "0") == 0) { + if (param1 == "0") { flag = false; - } else if (strcmp(parameter, "1") == 0){ + } else if (param1 == "1"){ flag = true; } if (flag) { @@ -507,9 +500,15 @@ void System_SendMessage(const char *command, const char *parameter) { } else { view->ExitFullScreenMode(); } + return true; + } + default: + return false; } } +void System_SendMessage(const char *command, const char *parameter) {} + void System_ShowFileInFolder(const char *path) { // Unsupported } diff --git a/Windows/main.cpp b/Windows/main.cpp index 1dd21cbc74..057522fc68 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -448,6 +448,19 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); } return true; + case SystemRequestType::RESTART_APP: + { + restartArgs = param1; + if (!restartArgs.empty()) + AddDebugRestartArgs(); + if (IsDebuggerPresent()) { + PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_RESTART_EMUTHREAD, 0, 0); + } else { + g_Config.bRestartRequired = true; + PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); + } + return true; + } case SystemRequestType::COPY_TO_CLIPBOARD: { std::wstring data = ConvertUTF8ToWString(param1); @@ -527,38 +540,32 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string } return true; } + case SystemRequestType::TOGGLE_FULLSCREEN_STATE: + { + bool flag = !MainWindow::IsFullscreen(); + if (param1 == "0") { + flag = false; + } else if (param1 == "1") { + flag = true; + } + MainWindow::SendToggleFullscreen(flag); + return true; + } + case SystemRequestType::GRAPHICS_BACKEND_FAILED_ALERT: + { + auto err = GetI18NCategory("Error"); + const char *backendSwitchError = err->T("GenericBackendSwitchCrash", "PPSSPP crashed while starting. This usually means a graphics driver problem. Try upgrading your graphics drivers.\n\nGraphics backend has been switched:"); + std::wstring full_error = ConvertUTF8ToWString(StringFromFormat("%s %s", backendSwitchError, param1.c_str())); + std::wstring title = ConvertUTF8ToWString(err->T("GenericGraphicsError", "Graphics Error")); + MessageBox(MainWindow::GetHWND(), full_error.c_str(), title.c_str(), MB_OK); + return true; + } default: return false; } } -void System_SendMessage(const char *command, const char *parameter) { - if (!strcmp(command, "graphics_restart")) { - restartArgs = parameter == nullptr ? "" : parameter; - if (!restartArgs.empty()) - AddDebugRestartArgs(); - if (IsDebuggerPresent()) { - PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_RESTART_EMUTHREAD, 0, 0); - } else { - g_Config.bRestartRequired = true; - PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); - } - } else if (!strcmp(command, "graphics_failedBackend")) { - auto err = GetI18NCategory("Error"); - const char *backendSwitchError = err->T("GenericBackendSwitchCrash", "PPSSPP crashed while starting. This usually means a graphics driver problem. Try upgrading your graphics drivers.\n\nGraphics backend has been switched:"); - std::wstring full_error = ConvertUTF8ToWString(StringFromFormat("%s %s", backendSwitchError, parameter)); - std::wstring title = ConvertUTF8ToWString(err->T("GenericGraphicsError", "Graphics Error")); - MessageBox(MainWindow::GetHWND(), full_error.c_str(), title.c_str(), MB_OK); - } else if (!strcmp(command, "toggle_fullscreen")) { - bool flag = !MainWindow::IsFullscreen(); - if (strcmp(parameter, "0") == 0) { - flag = false; - } else if (strcmp(parameter, "1") == 0) { - flag = true; - } - MainWindow::SendToggleFullscreen(flag); - } -} +void System_SendMessage(const char *command, const char *parameter) {} void System_AskForPermission(SystemPermission permission) {} PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 1b0e18af77..dec8285fe1 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1033,6 +1033,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string case SystemRequestType::EXIT_APP: PushCommand("finish", ""); return true; + case SystemRequestType::RESTART_APP: + PushCommand("graphics_restart", param1); + return true; case SystemRequestType::INPUT_TEXT_MODAL: { std::string serialized = StringFromFormat("%d:@:%s:@:%s", requestId, param1.c_str(), param2.c_str());