I am using SDL_SetWindowPosition
to position my window. Can I use this function to position my window on another monitor?
UPDATE
Using SDL_GetDisplayBounds
will not return the correct monitor positions when the text size is changed in Windows 10. Any ideas how to fix this?
SDL2 uses a global screen space coordinate system. Each display device has its own bounds inside this coordinate space. The following example places a window on a second display device:
Looking at the definition of
SDL_WINDOWPOS_CENTERED
inSDL_video.h
we see it is defined asso we could also use the macro
SDL_WINDOWPOS_CENTERED_DISPLAY( n )
wheren
is the display index.Update for Windows 10 - DPI scaling issue
It seems like there is indeed a bug with SDL2 and changing the DPI scale in Windows (i.e. text scale).
Here are two bug reports relevant to the problem. They are both still apparently unresolved.
https://bugzilla.libsdl.org/show_bug.cgi?id=3433
https://bugzilla.libsdl.org/show_bug.cgi?id=2713
Potential Solution
I am sure that the OP could use the WIN32 api to determine the dpi scale, for
scale != 100%
, and then correct the bounds by that.DPI scaling issue ("will not return the correct monitor positions when the text size is changed")
It's a known issue with SDL2 (I encountered it in those versions: 2.0.6, 2.0.7, 2.0.8, probably the older versions have this issue as well).
Solutions:
1) Use manifest file and set there:
(you need to include the manifest file to your app distribution)
2) Try SetProcessDPIAware().
Yes, you can use SetWindowPosition, if you know the boundaries of the second monitor. You can use the function SDL_GetDisplayBounds(int displayIndex,SDL_Rect* rect) to get them.