From 43ba6df7afe6ddf7d4dc47056aa423a0f119bc76 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 29 May 2018 18:06:04 +0200 Subject: [PATCH] Fix mostly the fullscreen switching with more than 1 display It concerns the issue #59. It's not perfect but it works much better (at leats on Linux). The idea is to move the window to the top left corner of the current display. --- src/event.cxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/event.cxx b/src/event.cxx index 50feb1d..f464fa0 100644 --- a/src/event.cxx +++ b/src/event.cxx @@ -1666,10 +1666,36 @@ CEvent::SetFullScreen (bool bFullScreen) SDL_SetWindowSize (g_window, LXIMAGE, LYIMAGE); g_bFullScreen = bFullScreen; + + int displayIndex = SDL_GetWindowDisplayIndex (g_window); + + if (g_bFullScreen) + { + int displays = SDL_GetNumVideoDisplays (); + + std::vector displayBounds; + for (int i = 0; i < displays; i++) + { + displayBounds.push_back (SDL_Rect ()); + SDL_GetDisplayBounds (i, &displayBounds.back ()); + } + + /* It seems that the fullscreen switching works better when the window + * is at the top left corner of the current display. + */ + SDL_SetWindowPosition ( + g_window, displayBounds[displayIndex].x, displayBounds[displayIndex].y); + } + SDL_SetWindowFullscreen (g_window, bFullScreen ? SDL_WINDOW_FULLSCREEN : 0); SDL_SetWindowBordered (g_window, bFullScreen ? SDL_FALSE : SDL_TRUE); SDL_SetWindowGrab (g_window, bFullScreen ? SDL_TRUE : SDL_FALSE); + if (!g_bFullScreen) + SDL_SetWindowPosition ( + g_window, SDL_WINDOWPOS_CENTERED_DISPLAY (displayIndex), + SDL_WINDOWPOS_CENTERED_DISPLAY (displayIndex)); + m_pPixmap->LoadCursors (g_zoom); m_pPixmap->ReloadTargetTextures ();