From db063a2321c17cfbfb9d85eada5ea6d38749d326 Mon Sep 17 00:00:00 2001 From: beaglejoe Date: Mon, 12 Sep 2022 21:35:42 +0000 Subject: [PATCH] Added a multi-monitor fullscreen mode git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8501 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: b667a89e7a255bc31d2042386857c37f171f2ea6 Former-commit-id: 63eaa4d24a4484f540dcb5010212cd92ae0fffd4 --- src/libs/tgfclient/guimenu.cpp | 1 + src/libs/tgfclient/guiscreen.cpp | 127 ++++++++++++++++++++++++++++++- src/libs/tgfclient/tgfclient.h | 1 + 3 files changed, 127 insertions(+), 2 deletions(-) diff --git a/src/libs/tgfclient/guimenu.cpp b/src/libs/tgfclient/guimenu.cpp index 5cb5eff1d..81b74bdd2 100644 --- a/src/libs/tgfclient/guimenu.cpp +++ b/src/libs/tgfclient/guimenu.cpp @@ -90,6 +90,7 @@ GfuiMenuDefaultKeysAdd(void* scr) if(GfScrUsingResizableWindow()) { GfuiAddKey(scr, GFUIK_RETURN, GFUIM_ALT, "Toggle Full-screen", (void*)0, GfScrToggleFullScreen, NULL); + GfuiAddKey(scr, GFUIK_RETURN, GFUIM_CTRL | GFUIM_ALT, "Toggle Multi Full-screens", (void*)0, GfScrToggleMultiFullScreens, NULL); } } diff --git a/src/libs/tgfclient/guiscreen.cpp b/src/libs/tgfclient/guiscreen.cpp index 1a266f4e6..089c23897 100644 --- a/src/libs/tgfclient/guiscreen.cpp +++ b/src/libs/tgfclient/guiscreen.cpp @@ -62,6 +62,8 @@ void GfScrInitialWindowedPosition(); void gfScrSaveWindowState(); bool gfScrAAOpenGLSetup(); void gfScrDisableResizable(); +bool GfscrAllowMultiFullScreens(); +SDL_Rect GetMultiFullScreenBounds(); // The screen properties. @@ -1207,10 +1209,18 @@ void GfScrInitialWindowedPosition() SDL_SetWindowSize(GfuiWindow, w, h); if(max) + { SDL_MaximizeWindow(GfuiWindow); + } - if(full) + if(full == 1) + { SDL_SetWindowFullscreen(GfuiWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); + } + else if(full == 2) + { + GfScrToggleMultiFullScreens(NULL); + } } bool GfScrInitSDL2() @@ -1283,11 +1293,118 @@ void GfScrToggleFullScreen(void* unused) } else { + if (flags & SDL_WINDOW_BORDERLESS) // we are MultiFullScreen + { + GfScrToggleMultiFullScreens(NULL); + } GfScrSetFullscreen(true); } return; } +SDL_Rect GetMultiFullScreenBounds() +{ + SDL_Rect bounds; + SDL_Rect maxBounds; + int nDisplays = SDL_GetNumVideoDisplays(); + for(int i = 0;i < nDisplays;i++) + { + if(SDL_GetDisplayBounds(i, &bounds) == 0) + { + if(i == 0) + { + maxBounds = bounds; + } + else + { + if(bounds.x < maxBounds.x) + maxBounds.x = bounds.x; + + maxBounds.w += bounds.w; + } + } + } + return maxBounds; +} + +bool GfscrAllowMultiFullScreens() +{ + bool bRet = false; + SDL_Rect bounds; + + int nDisplays = SDL_GetNumVideoDisplays(); + if(nDisplays > 1) + { + int height = 0; + int top = 0; + for(int i = 0;i < nDisplays;i++) + { + if(SDL_GetDisplayBounds(i, &bounds) == 0) + { + if(i == 0) + { + top = bounds.y; + height = bounds.h; + bRet = true; + continue; + } + if((bounds.h != height) || (bounds.y != top)) + { + bRet = false; + break; + } + } + else + { + bRet = false; + break; + } + } + } + + return bRet; +} + +void GfScrToggleMultiFullScreens(void* unused) +{ + static int restoreX = 0; + static int restoreY = 0; + static int restoreW = 800; + static int restoreH = 600; + Uint32 flags = SDL_GetWindowFlags(GfuiWindow); + + if (flags & SDL_WINDOW_BORDERLESS) // we are MultiFullScreen + { + SDL_SetWindowBordered(GfuiWindow, SDL_TRUE); + SDL_SetWindowPosition(GfuiWindow, restoreX, restoreY); + SDL_SetWindowSize(GfuiWindow, restoreW, restoreH); + } + else if(GfscrAllowMultiFullScreens()) // NOT in Full-multiscreen + { + if ((flags & SDL_WINDOW_FULLSCREEN) || (flags & SDL_WINDOW_FULLSCREEN_DESKTOP)) + { + GfScrSetFullscreen(false); + } + + SDL_GetWindowPosition(GfuiWindow, &restoreX, &restoreY); + SDL_GetWindowSize(GfuiWindow, &restoreW, &restoreH); + + SDL_SetWindowBordered(GfuiWindow, SDL_FALSE); + SDL_Rect bounds = GetMultiFullScreenBounds(); + + if(!SDL_RectEmpty(&bounds)) + { + SDL_SetWindowPosition(GfuiWindow,bounds.x, bounds.y); + SDL_SetWindowSize(GfuiWindow, bounds.w, bounds.h); + } + else + { + GfLogError("GetMultiFullScreenBounds() returned an empty rectangle.\n"); + } + } + return; +} + void gfScrSaveWindowState() { GfLogTrace("Saving resizable window state.\n"); @@ -1296,12 +1413,18 @@ void gfScrSaveWindowState() int x = 0; int y = 0; int w = 0; - int h = 0; + int h = 0; int full = 0; int max = 0; + int dispIndex = SDL_GetWindowDisplayIndex(GfuiWindow); Uint32 flags = SDL_GetWindowFlags(GfuiWindow); + if (flags & SDL_WINDOW_BORDERLESS) // we are MultiFullScreen + { + full = 2; + GfScrToggleMultiFullScreens(NULL); + } if ((flags & SDL_WINDOW_FULLSCREEN) || (flags & SDL_WINDOW_FULLSCREEN_DESKTOP)) { full = 1; diff --git a/src/libs/tgfclient/tgfclient.h b/src/libs/tgfclient/tgfclient.h index 1f90294b3..b0ae3a651 100644 --- a/src/libs/tgfclient/tgfclient.h +++ b/src/libs/tgfclient/tgfclient.h @@ -98,6 +98,7 @@ TGFCLIENT_API tScreenSize GfScrGetCurrentDisplaySize(int nDisplayIndex); TGFCLIENT_API bool GfScrUsingResizableWindow(); TGFCLIENT_API void GfScrToggleFullScreen(void* unused); +TGFCLIENT_API void GfScrToggleMultiFullScreens(void* unused); /******************** * Music Interface *