From 5c7aacb954e5cb7f5499821c577cbb334f0707fd Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Wed, 3 Jul 2024 01:01:16 +0200 Subject: [PATCH] Make fullscreen mode with XWayland a bit less broken, #587 assert( ret.width == glConfig.winWidth && ret.height == glConfig.winHeight ); in GLimp_GetCurState() triggered, because SDL_GetWindowSize(), which was used to set glConfig.winWidth/Height in GLimp_UpdateWindowSize(), returned different values than SDL_GetWindowDisplayMode(). Now use SDL_GetWindowDisplayMode() in GLimp_UpdateWindowSize() so it's at least consistent. However it seems like SDL_GetWindowSize() returns the correct values (IN THAT CASE), because with this change the mouse cursor doesn't work that well (in the specific case described above). In the end this is an SDL or Wayland bug or something, and I can only recommend not using "real" fullscreen mode with Wayland, as it's fake anyway (Wayland doesn't allow switching the display resolution, so you get a magically scaled borderless fullscreen window at best) --- neo/sys/glimp.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/neo/sys/glimp.cpp b/neo/sys/glimp.cpp index 9129d814..dc4ca35b 100644 --- a/neo/sys/glimp.cpp +++ b/neo/sys/glimp.cpp @@ -719,6 +719,8 @@ glimpParms_t GLimp_GetCurState() ret.width = real_mode.w; ret.height = real_mode.h; ret.displayHz = real_mode.refresh_rate; + } else { + common->Warning( "GLimp_GetCurState(): Can't get display mode: %s\n", SDL_GetError() ); } } if ( ret.width == 0 && ret.height == 0 ) { // windowed mode or SDL_GetWindowDisplayMode() failed @@ -909,10 +911,30 @@ bool GLimp_SetWindowResizable( bool enableResizable ) void GLimp_UpdateWindowSize() { #if SDL_VERSION_ATLEAST(2, 0, 0) - int ww=0, wh=0; - SDL_GetWindowSize( window, &ww, &wh ); - glConfig.winWidth = ww; - glConfig.winHeight = wh; + Uint32 winFlags = SDL_GetWindowFlags( window ); + if ( (winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN ) { + // real fullscreen mode => must use SDL_GetWindowDisplayMode() + // TODO: well, theoretically SDL_GetWindowSize() should work for fullscreen mode as well, + // but not in all SDL versions, I think? + // And in fact it seems like with "real" fullscreen windows on XWayland SDL_GetWindowSize() + // returns the correct values and SDL_GetWindowDisplayMode() doesn't, when the fullscreen + // resolution is lower than the desktop resolution.. it's kind of messy. + SDL_DisplayMode dm = {}; + if ( SDL_GetWindowDisplayMode( window, &dm ) == 0 ) { + glConfig.winWidth = dm.w; + glConfig.winHeight = dm.h; + int ww=0, wh=0; + SDL_GetWindowSize( window, &ww, &wh ); + } else { + common->Warning( "GLimp_UpdateWindowSize(): SDL_GetWindowDisplayMode() failed: %s\n", SDL_GetError() ); + } + + } else { + int ww=0, wh=0; + SDL_GetWindowSize( window, &ww, &wh ); + glConfig.winWidth = ww; + glConfig.winHeight = wh; + } SDL_GL_GetDrawableSize( window, &glConfig.vidWidth, &glConfig.vidHeight ); #endif }