From ffcf52c710bc664f91cfca1929f7792a520ee41e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 15 May 2020 17:51:32 +0200 Subject: [PATCH] Made game launching more seamless and prevent minimizing of window when switching applications. Also added menu entry to choose between normal fullscreen mode and borderless fullscren mode --- es-app/src/FileData.cpp | 5 ++-- es-app/src/guis/GuiMenu.cpp | 18 +++++++++++++++ es-app/src/main.cpp | 37 +++++++++++++++++------------- es-core/src/Settings.cpp | 3 +-- es-core/src/renderers/Renderer.cpp | 20 +++++++++++++++- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index dc5bb3c9c..a8a010d1c 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -281,7 +281,8 @@ void FileData::launchGame(Window* window) AudioManager::getInstance()->deinit(); VolumeControl::getInstance()->deinit(); - window->deinit(); + +// window->deinit(); std::string command = mEnvData->mLaunchCommand; @@ -305,7 +306,7 @@ void FileData::launchGame(Window* window) Scripting::fireEvent("game-end"); - window->init(); +// window->init(); VolumeControl::getInstance()->init(); window->normalizeNextUpdate(); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 80869c66f..73bba31a2 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -231,6 +231,24 @@ void GuiMenu::openUISettings() } }); + // fullscreen mode + auto fullscreen_mode = std::make_shared< OptionListComponent >(mWindow, "FULLSCREEN MODE", false); + std::vector screenmode; + screenmode.push_back("normal"); + screenmode.push_back("borderless"); + for(auto it = screenmode.cbegin(); it != screenmode.cend(); it++) + fullscreen_mode->add(*it, *it, Settings::getInstance()->getString("FullscreenMode") == *it); + s->addWithLabel("FULLSCREEN MODE (RESTART REQUIRED)", fullscreen_mode); + s->addSaveFunc([fullscreen_mode] { + if (Settings::getInstance()->getString("FullscreenMode") == "normal" + && fullscreen_mode->getSelected() != "normal") + { + Settings::getInstance()->setString("PowerSaverMode", "default"); + PowerSaver::init(); + } + Settings::getInstance()->setString("FullscreenMode", fullscreen_mode->getSelected()); + }); + // screensaver ComponentListRow screensaver_row; screensaver_row.elements.clear(); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index dd6538b8f..ef92da03d 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -124,9 +124,12 @@ bool parseArgs(int argc, char* argv[]) Settings::getInstance()->setBool("Debug", true); Settings::getInstance()->setBool("HideConsole", false); Log::setReportingLevel(LogDebug); + }else if(strcmp(argv[i], "--fullscreen-normal") == 0) + { + Settings::getInstance()->setString("FullscreenMode", "normal"); }else if(strcmp(argv[i], "--fullscreen-borderless") == 0) { - Settings::getInstance()->setBool("FullscreenBorderless", true); + Settings::getInstance()->setString("FullscreenMode", "borderless"); }else if(strcmp(argv[i], "--windowed") == 0) { Settings::getInstance()->setBool("Windowed", true); @@ -170,22 +173,24 @@ bool parseArgs(int argc, char* argv[]) "Written by Alec \"Aloshi\" Lofquist.\n" "Version " << PROGRAM_VERSION_STRING << ", built " << PROGRAM_BUILT_STRING << "\n\n" "Command line arguments:\n" - "--resolution [width] [height] try and force a particular resolution\n" - "--gamelist-only skip automatic game search, only read from gamelist.xml\n" - "--ignore-gamelist ignore the gamelist (useful for troubleshooting)\n" - "--draw-framerate display the framerate\n" - "--no-exit don't show the exit option in the menu\n" - "--no-splash don't show the splash screen\n" - "--debug more logging, show console on Windows\n" - "--scrape scrape using command line interface\n" - "--windowed not fullscreen, should be used with --resolution\n" - "--vsync [1/on or 0/off] turn vsync on or off (default is on)\n" + "--resolution [width] [height] Try and force a particular resolution\n" + "--gamelist-only Skip automatic game search, only read from gamelist.xml\n" + "--ignore-gamelist Ignore the gamelist (useful for troubleshooting)\n" + "--draw-framerate Display the framerate\n" + "--no-exit Don't show the exit option in the menu\n" + "--no-splash Don't show the splash screen\n" + "--debug More logging, show console on Windows\n" + "--scrape Scrape using command line interface\n" + "--windowed Not fullscreen, should be used with --resolution\n" + "--fullscreen-normal Run in normal fullscreen mode\n" + "--fullscreen-borderless Run in borderless fullscreen mode (always on top)\n" + "--vsync [1/on or 0/off] Turn vsync on or off (default is on)\n" "--max-vram [size] Max VRAM to use in Mb before swapping. 0 for unlimited\n" - "--force-kid Force the UI mode to be Kid\n" - "--force-kiosk Force the UI mode to be Kiosk\n" + "--force-kid Force the UI mode to be Kid\n" + "--force-kiosk Force the UI mode to be Kiosk\n" "--force-disable-filters Force the UI to ignore applied filters in gamelist\n" - "--home [path] Directory to use as home path\n" - "--help, -h summon a sentient, angry tuba\n\n" + "--home [path] Directory to use as home path\n" + "--help, -h Summon a sentient, angry tuba\n\n" "More information available in README.md.\n"; return false; //exit after printing help } @@ -322,7 +327,7 @@ int main(int argc, char* argv[]) LOG(LogError) << "Window failed to initialize!"; return 1; } - + if(splashScreen) { std::string progressText = "Loading..."; diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index a5142bdab..400dd686c 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -25,7 +25,6 @@ std::vector settings_dont_save { { "SplashScreen" }, { "SplashScreenProgress" }, { "VSync" }, - { "FullscreenBorderless" }, { "Windowed" }, { "WindowWidth" }, { "WindowHeight" }, @@ -63,7 +62,6 @@ void Settings::setDefaults() mBoolMap["ShowExit"] = true; mBoolMap["ShowRestartSystem"] = true; mBoolMap["ShowShutdownSystem"] = true; - mBoolMap["FullscreenBorderless"] = false; mBoolMap["Windowed"] = false; mBoolMap["SplashScreen"] = true; mBoolMap["SplashScreenProgress"] = true; @@ -94,6 +92,7 @@ void Settings::setDefaults() mIntMap["MaxVRAM"] = 100; #endif + mStringMap["FullscreenMode"] = "normal"; mStringMap["TransitionStyle"] = "fade"; mStringMap["ThemeSet"] = ""; mStringMap["ScreenSaverBehavior"] = "dim"; diff --git a/es-core/src/renderers/Renderer.cpp b/es-core/src/renderers/Renderer.cpp index 003e4ac48..52630f911 100644 --- a/es-core/src/renderers/Renderer.cpp +++ b/es-core/src/renderers/Renderer.cpp @@ -79,9 +79,27 @@ namespace Renderer screenOffsetY = Settings::getInstance()->getInt("ScreenOffsetY") ? Settings::getInstance()->getInt("ScreenOffsetY") : 0; screenRotate = Settings::getInstance()->getInt("ScreenRotate") ? Settings::getInstance()->getInt("ScreenRotate") : 0; + // Prevent ES window from minimizing when switching windows + // (when launching games or when manually switching windows using task switcher) + SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); + setupWindow(); - unsigned int windowFlags = (Settings::getInstance()->getBool("Windowed") ? 0 : (Settings::getInstance()->getBool("FullscreenBorderless") ? SDL_WINDOW_BORDERLESS : SDL_WINDOW_FULLSCREEN)) | getWindowFlags(); + unsigned int windowFlags; + + if (Settings::getInstance()->getBool("Windowed")) + { + windowFlags = getWindowFlags(); + + } + else if (Settings::getInstance()->getString("FullscreenMode") == "borderless") + { + windowFlags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALWAYS_ON_TOP | getWindowFlags(); + } + else + { + windowFlags = SDL_WINDOW_FULLSCREEN | getWindowFlags(); + } if((sdlWindow = SDL_CreateWindow("EmulationStation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowWidth, windowHeight, windowFlags)) == nullptr) {