diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 05c6e5639..152b0e072 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -1520,6 +1520,8 @@ bool CGraphicsBackend_SDL_GL::SetWindowScreen(int Index) { return false; } + // Todo SDL: remove this when fixed (changing screen when in fullscreen is bugged) + SDL_SetWindowBordered(m_pWindow, SDL_TRUE); //fixing primary monitor goes black when switch screen (borderless OpenGL) SDL_SetWindowPosition(m_pWindow, SDL_WINDOWPOS_CENTERED_DISPLAY(Index), diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 94d7d1d6d..c3f774511 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3878,19 +3878,27 @@ int CClient::HandleChecksum(int Conn, CUuid Uuid, CUnpacker *pUnpacker) void CClient::SwitchWindowScreen(int Index) { - // Todo SDL: remove this when fixed (changing screen when in fullscreen is bugged) - if(g_Config.m_GfxFullscreen) - { - SetWindowParams(0, g_Config.m_GfxBorderless); - if(Graphics()->SetWindowScreen(Index)) - g_Config.m_GfxScreen = Index; - SetWindowParams(g_Config.m_GfxFullscreen, g_Config.m_GfxBorderless); - } - else - { - if(Graphics()->SetWindowScreen(Index)) - g_Config.m_GfxScreen = Index; - } + //Tested on windows 11 64 bit (gtx 1660 super, intel UHD 630 opengl 1.2.0, 3.3.0 and vulkan 1.1.0) + int IsFullscreen = g_Config.m_GfxFullscreen; + int IsBorderless = g_Config.m_GfxBorderless; + + if(Graphics()->SetWindowScreen(Index)) + g_Config.m_GfxScreen = Index; + + SetWindowParams(3, false); // prevent DDNet to get stretch on monitors + + CVideoMode CurMode; + Graphics()->GetCurrentVideoMode(CurMode, Index); + + const int Depth = CurMode.m_Red + CurMode.m_Green + CurMode.m_Blue > 16 ? 24 : 16; + g_Config.m_GfxColorDepth = Depth; + g_Config.m_GfxScreenWidth = CurMode.m_WindowWidth; + g_Config.m_GfxScreenHeight = CurMode.m_WindowHeight; + g_Config.m_GfxScreenRefreshRate = CurMode.m_RefreshRate; + + Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate); + + SetWindowParams(IsFullscreen, IsBorderless); } void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 05b1f44f5..809be4a7b 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -2647,6 +2647,7 @@ bool CGraphics_Threaded::SetWindowScreen(int Index) for(auto &PropChangedListener : m_vPropChangeListeners) PropChangedListener(); + return true; } @@ -2969,6 +2970,11 @@ int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes, int Scre return NumModes; } +void CGraphics_Threaded::GetCurrentVideoMode(CVideoMode &CurMode, int Screen) +{ + m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, Screen); +} + extern IEngineGraphics *CreateEngineGraphicsThreaded() { return new CGraphics_Threaded(); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index ec47236d3..5871cb4c9 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -1265,6 +1265,7 @@ public: bool SetMultiSampling(uint32_t ReqMultiSamplingCount, uint32_t &MultiSamplingCountBackend) override; int GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen) override; + void GetCurrentVideoMode(CVideoMode &CurMode, int Screen) override; virtual int GetDesktopScreenWidth() const { return g_Config.m_GfxDesktopWidth; } virtual int GetDesktopScreenHeight() const { return g_Config.m_GfxDesktopHeight; } diff --git a/src/engine/graphics.h b/src/engine/graphics.h index b319b3f91..8a979d6a7 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -526,7 +526,7 @@ public: virtual void TakeScreenshot(const char *pFilename) = 0; virtual void TakeCustomScreenshot(const char *pFilename) = 0; virtual int GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen) = 0; - + virtual void GetCurrentVideoMode(CVideoMode &CurMode, int Screen) = 0; virtual void Swap() = 0; virtual int GetNumScreens() const = 0; virtual const char *GetScreenName(int Screen) const = 0; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 3d48f34ed..2bc87e699 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1577,10 +1577,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) s_ScreenDropDownState.m_SelectionPopupContext.m_pScrollRegion = &s_ScreenDropDownScrollRegion; const int NewScreen = UI()->DoDropDown(&ScreenDropDown, g_Config.m_GfxScreen, s_vpScreenNames.data(), s_vpScreenNames.size(), s_ScreenDropDownState); if(NewScreen != g_Config.m_GfxScreen) - { Client()->SwitchWindowScreen(NewScreen); - s_NumNodes = Graphics()->GetVideoModes(s_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen); - } } MainView.HSplitTop(2.0f, nullptr, &MainView);