mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7937 from Peakies/switch_screen_pr
fix switch screen and blackscreen on opengl + window borderless
This commit is contained in:
commit
fbc4181809
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue