diff --git a/project/src/sdl2/SDL2Stage.cpp b/project/src/sdl2/SDL2Stage.cpp index 3e37ba8c3..2f3a9f3e1 100644 --- a/project/src/sdl2/SDL2Stage.cpp +++ b/project/src/sdl2/SDL2Stage.cpp @@ -63,6 +63,8 @@ typedef int MousePosType; namespace nme { +static int sgDesktopX = 0; +static int sgDesktopY = 0; static int sgDesktopWidth = 0; static int sgDesktopHeight = 0; static Rect sgWindowRect = Rect(0, 0, 0, 0); @@ -2255,13 +2257,13 @@ static SDL_Renderer *sgMainRenderer = 0; void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, unsigned int inFlags, const char *inTitle, Surface *inIcon) { bool isMain = sgSDLFrame==nullptr; - #ifdef HX_MACOS if (isMain) MacBoot(); #endif + bool fullscreen = (inFlags & wfFullScreen) != 0; #if defined(NME_OGL) && defined(NME_METAL) nmeOpenglRenderer = !(inFlags & wfHardwareMetal); @@ -2324,6 +2326,42 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, } } + + #ifdef NME_SDL3 + SDL_DisplayID startupDisplay = SDL_GetPrimaryDisplay(); + #if defined(HX_WINDOWS) && !defined(HX_WINRT) + if (isMain) + { + HWND fg = GetForegroundWindow(); + if (fg!=0) + { + RECT rect; + if (GetWindowRect(fg,&rect)) + { + SDL_Point p; + p.x = (rect.left + rect.right)>>1; + p.y = (rect.top + rect.bottom)>>1; + startupDisplay = SDL_GetDisplayForPoint(&p); + /* + printf("Found startup display %d,%d -> %d\n", p.x, p.y, (int)startupDisplay); + int count = 0; + SDL_DisplayID *displays = SDL_GetDisplays(&count); + printf(" display count:%d\n", count); + for(int i=0;iw; - sgDesktopHeight = modePtr->h; + const SDL_DisplayMode *modePtr = SDL_GetDesktopDisplayMode(startupDisplay); + if (modePtr) + { + sgDesktopWidth = modePtr->w; + sgDesktopHeight = modePtr->h; + } } + #endif int windowFlags, requestWindowFlags = 0; @@ -2444,17 +2495,27 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, int borderH = r.bottom-r.top - 100; if (targetH + borderH > sgDesktopHeight) { - targetY = -r.top; + targetY = sgDesktopX-r.top; targetH = sgDesktopHeight - borderH; } + else if (sgDesktopX!=0 || sgDesktopY!=0) + { + targetY = sgDesktopY + ((sgDesktopHeight-borderH-targetH)>>1); + } + if (targetW + borderW > sgDesktopWidth) { - targetX = -r.left; + targetX = sgDesktopY-r.left; targetW = sgDesktopWidth - borderW; } + else if (sgDesktopX!=0 || sgDesktopY!=0) + { + targetX = sgDesktopX + ((sgDesktopWidth-borderW-targetW)>>1); + } + } #endif - + #ifdef HX_LINUX int setWidth = targetW; int setHeight = targetH;