I am writing a program that displays an animation that is dependent on the size of the display. In order to get this to work with multiple displays, I have an array of display_data objects:
struct window_data
{
SDL_Rect bounds;
SDL_Window *window;
};
and initialize these for each display:
int numdisplays = SDL_GetNumVideoDisplays();
std::vector< window_data > screens( numdisplays );
for( int i = 0 ; i < numdisplays ; ++i )
{
SDL_GetDisplayBounds( i, &( screens[ i ].bounds ) );
screens[ i ].window
= SDL_CreateWindow( "Display", screens[ i ].bounds.x,
screens[ i ].bounds.y, screens[ i ].bounds.w,
screens[ i ].bounds.h, SDL_WINDOW_FULLSCREEN );
}
This works fine as long as my mouse cursor is in the primary display, but if I start the program with the cursor in the secondary display, it will draw both windows in the secondary display, resulting in only the second window being visible. This behavior seems to depend only on the location of the cursor and not the terminal window from which I run the program.
I have verified that the same display numbers and bounds are found regardless of the cursor location, so I am perplexed by the variation in the program behavior. Is this the intended behavior of SDL2, or a bug? In either case, could anyone suggest a workaround?
EDIT: The mouse dependency shows up on Debian with XFCE. I have tried this on Windows as well and it outputs both windows on the second monitor, regardless of the mouse position.