diff --git a/src/Core/Platform/DisplayMode.hpp b/src/Core/Platform/DisplayMode.hpp new file mode 100644 index 0000000000..75e6f94cc9 --- /dev/null +++ b/src/Core/Platform/DisplayMode.hpp @@ -0,0 +1,20 @@ +#ifndef CORE_PLATFORM_DISPLAYMODE +#define CORE_PLATFORM_DISPLAYMODE + +namespace Core::Platform { + + /** + * Each DisplayMode struct represents the settings which the users monitors is capable of displaying. + * Exists as a compatibility layer between `Core/` and `RageUtil/`. Without this, includes to `RageUtil` + * would be necessary in `Core`. + */ + struct DisplayMode { + DisplayMode() = default; + int width{0}; + int height{0}; + int refreshRate{0}; + }; + +} + +#endif //CORE_PLATFORM_DISPLAYMODE \ No newline at end of file diff --git a/src/Core/Platform/Window/GLFWWindowBackend.cpp b/src/Core/Platform/Window/GLFWWindowBackend.cpp index 14cf8a58bb..10621e0a55 100644 --- a/src/Core/Platform/Window/GLFWWindowBackend.cpp +++ b/src/Core/Platform/Window/GLFWWindowBackend.cpp @@ -198,6 +198,31 @@ namespace Core::Platform::Window { return videoMode->refreshRate; } + std::vector GLFWWindowBackend::getDisplayModes() const { + std::vector res; + int modeCount = 0; + auto *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &modeCount); + for(int i = 0; i < modeCount; i++){ + GLFWvidmode mode = modes[i]; + res.push_back(DisplayMode{mode.width, mode.height, mode.refreshRate}); + } + return res; + } + + DisplayMode GLFWWindowBackend::getCurrentDisplayMode() const { + auto mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + return DisplayMode{mode->width, mode->height, mode->refreshRate}; + } + + bool GLFWWindowBackend::setVideoMode(const VideoMode& p) { + this->videoMode = p; + int px, py; + glfwGetWindowPos(this->windowHandle, &px, &py); + glfwSetWindowMonitor(this->windowHandle, p.isFullscreen ? glfwGetPrimaryMonitor() : nullptr, px, py, p.width, p.height, p.refreshRate); + glfwSetInputMode(this->windowHandle, GLFW_CURSOR, p.isFullscreen ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL); + return true; + } + DeviceButton GLFWWindowBackend::convertKeyToLegacy(int keycode, int mods){ // GLFW keycodes are all uppercase ascii. If we're in that ascii, determine if uppercase // or lowercase, and convert if necessary. diff --git a/src/Core/Platform/Window/GLFWWindowBackend.hpp b/src/Core/Platform/Window/GLFWWindowBackend.hpp index f663f70699..c0d3b195a3 100644 --- a/src/Core/Platform/Window/GLFWWindowBackend.hpp +++ b/src/Core/Platform/Window/GLFWWindowBackend.hpp @@ -26,6 +26,9 @@ class GLFWWindowBackend : public IWindowBackend { void setTitle(const std::string &title) override; Dimensions getFrameBufferSize() const override; int getRefreshRate() const override; + std::vector getDisplayModes() const override; + DisplayMode getCurrentDisplayMode() const override; + bool setVideoMode(const VideoMode& p) override; static void setWindowHint(int hint, int value); diff --git a/src/Core/Platform/Window/IWindowBackend.hpp b/src/Core/Platform/Window/IWindowBackend.hpp index 083da1c109..11613fffd2 100644 --- a/src/Core/Platform/Window/IWindowBackend.hpp +++ b/src/Core/Platform/Window/IWindowBackend.hpp @@ -3,8 +3,10 @@ #include "Core/Utility/ActionDelegate.hpp" #include "Core/Platform/Window/VideoMode.hpp" +#include "Core/Platform/DisplayMode.hpp" #include +#include namespace Core::Platform::Window { struct Dimensions { @@ -30,7 +32,10 @@ namespace Core::Platform::Window { virtual void setTitle(const std::string& title) = 0; virtual Dimensions getFrameBufferSize() const = 0; virtual int getRefreshRate() const = 0; + virtual std::vector getDisplayModes() const = 0; + virtual DisplayMode getCurrentDisplayMode() const = 0; + virtual bool setVideoMode(const VideoMode& p) = 0; const VideoMode& getVideoMode() const; // Callback Registration diff --git a/src/Etterna/Globals/StepMania.cpp b/src/Etterna/Globals/StepMania.cpp index fb6911e03e..62f34a80ce 100644 --- a/src/Etterna/Globals/StepMania.cpp +++ b/src/Etterna/Globals/StepMania.cpp @@ -911,7 +911,7 @@ namespace StepMania { paramsOut.width = iWidth; paramsOut.height = PREFSMAN->m_iDisplayHeight; paramsOut.refreshRate = PREFSMAN->m_iRefreshRate; - paramsOut.isFullscreen = PREFSMAN->m_bFullscreenIsBorderlessWindow; + paramsOut.isFullscreen = !PREFSMAN->m_bWindowed; paramsOut.isBorderless = PREFSMAN->m_bFullscreenIsBorderlessWindow; paramsOut.isVsyncEnabled = PREFSMAN->m_bVsync; } @@ -933,9 +933,10 @@ namespace StepMania { void ApplyGraphicOptions(){ bool bNeedReload = false; -// VideoModeParams params; -// GetPreferredVideoModeParams(params); - std::string sError = "";//DISPLAY->SetVideoMode(params, bNeedReload); + VideoMode params; + GetPreferredVideoModeParams(params); + DISPLAY->SetVideoMode(params, bNeedReload); + std::string sError; if (!sError.empty()) RageException::Throw("%s", sError.c_str()); diff --git a/src/RageUtil/Graphics/RageDisplay_OGL.cpp b/src/RageUtil/Graphics/RageDisplay_OGL.cpp index 2b3d76cab4..6e6926fd15 100644 --- a/src/RageUtil/Graphics/RageDisplay_OGL.cpp +++ b/src/RageUtil/Graphics/RageDisplay_OGL.cpp @@ -524,6 +524,20 @@ void RageDisplay_Legacy::GetDisplaySpecs(DisplaySpecs& out) const { out.clear(); + // Prepare DisplayMode for following DisplaySpec + std::set available; + for(auto mode : this->window->getDisplayModes()){ + available.insert(DisplayMode{ + static_cast(mode.width), + static_cast(mode.height), + static_cast(mode.refreshRate)}); + } + + // Current Mode + auto current = this->window->getCurrentDisplayMode(); + DisplayMode m{static_cast(current.width), static_cast(current.height), static_cast(current.refreshRate)}; + RectI bounds = {0, 0, static_cast(current.width), static_cast(current.height)}; + out.insert(DisplaySpec("", "Fullscreen", available, m, bounds)); } static void @@ -747,6 +761,7 @@ RageDisplay_Legacy::TryVideoMode(const VideoMode& p, bool& bNewDeviceOut) // p.windowed, p.width, p.height, p.bpp, p.rate, p.vsync ); std::string err; + window->setVideoMode(p); if (!err.empty()) return err; // failed to set video mode