Skip to content

Commit

Permalink
Try to start on the launch monitor on windows, sdl3
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Sanderson committed Oct 10, 2024
1 parent fd894f6 commit 7d62983
Showing 1 changed file with 70 additions and 9 deletions.
79 changes: 70 additions & 9 deletions project/src/sdl2/SDL2Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;i<count;i++)
{
SDL_Rect r;
SDL_GetDisplayBounds(displays[i], &r);
printf(" %d] %d,%d, %dx%d\n",i,r.x, r.y, r.w,r.h );
}
SDL_free(displays);
*/
}
}
}
#endif
#endif


//SDL_EnableUNICODE(1);
//SDL_EnableKeyRepeat(500,30);

Expand All @@ -2341,13 +2379,26 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
sgDesktopHeight = currentMode.h;
}
#else
SDL_DisplayID display_id = SDL_GetPrimaryDisplay();
const SDL_DisplayMode *modePtr = SDL_GetDesktopDisplayMode(display_id);
if (modePtr)

SDL_Rect bounds;
// SDL_GetDisplayUsableBounds?
if (SDL_GetDisplayBounds(startupDisplay, &bounds))
{
sgDesktopX = bounds.x;
sgDesktopY = bounds.y;
sgDesktopWidth = bounds.w;
sgDesktopHeight = bounds.h;
}
else
{
sgDesktopWidth = modePtr->w;
sgDesktopHeight = modePtr->h;
const SDL_DisplayMode *modePtr = SDL_GetDesktopDisplayMode(startupDisplay);
if (modePtr)
{
sgDesktopWidth = modePtr->w;
sgDesktopHeight = modePtr->h;
}
}

#endif

int windowFlags, requestWindowFlags = 0;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7d62983

Please sign in to comment.