The SDL forums have moved to
This is just a read-only archive of the previous forums, to keep old links working.

SDL Forum Index
Simple Directmedia Layer Forums
SDL2 and Multiple Screens in Linux

Joined: 28 Nov 2012
Posts: 10
I seem to recall from having used SDL 1.2 many, many years ago that I could do something like this to get two instances of my application running on separate X screens:

export DISPLAY=:0.0
./my_awesome_sdl_app &
export DISPLAY=:0.1
./my_awesome_sdl_app &

I tried this with SDL 1.3 back in June or so and discovered that the DISPLAY variable no longer worked -- all instances of my program would go to the primary screen (:0.0). Looking at the test programs I discovered that the screen is passed in via the x,y position in SDL_CreateWindow using the SDL_WINDOWPOS_UNDEFINED_DISPLAY and SDL_WINDOWPOS_CENTERED_DISPLAY macros. (What was the rationale for this? What is wrong with the good 'ol DISPLAY environment variable?) That worked. Yay.

Then I updated to the latest (as of a couple of weeks ago) SDL (changeset c34a64af7751) and my program stopped working; all instances now go to the primary screen.

Is this a known issue or is there a new preferred way of specifying the desired display?

Joined: 28 Nov 2012
Posts: 10
I finally had some time to look through SDL to see if I could figure why specifying the display doesn't work.

The problem appears to be that the display number doesn't propagate past SDL_CreateWindow (SDL_video.c:1185) so when X11_CreateWindow (SDL_x11window.c:330) calls SDL_GetDisplayForWindow to get the SDL_DisplayData it always gets back the DisplayData for Display 0.

I'm using testwm2 to test this. When I run testwm2 --display 1 this is what happens...

1) In SDL_CreateWindow window->x and window->y initially gets set to the x,y position with the display number embedded.
2) SDL_GetDisplayWindow returns the SDL_VideoDisplay structure for Display 1 as expected since window->x and window->y have the display number embedded.
3) window->x and window->y now get set so that the window will be centered on the display. In my case, that's x=640, y=360.
4) When X11_CreateWindow gets called window now has x and y set to 640,360, i.e., there's no display number embedded anymore.
5) X11_CreateWindow calls SDL_GetDisplayForWindow to get the SDL_DisplayData from which it gets the screen number.
6) In SDL_GetDisplayForWindowIndex the checks for the embedded display number fail, of course, then the display is chosen by which display encloses the center point of the window. This check succeeds for display 0 and immediately returns.

On my setup I have two graphics cards connected to two separate displays and the X server is configured for two separate X screens. So as far as SDL is concerned I have two displays with bounds of 0,0-2560,1440 and 0,0-1920,1200. The check in step 6 will always select that first 2560x1440 display (assuming positive value of x,y).

My guess is that the way code is setup now works fine for TwinView or Xinerama but it seems to me to be broken for separate X screens.