X11 -- choosing which screen to appear on

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
filbo
Posts: 594
Joined: Fri Jun 20, 2014 10:06 am

X11 -- choosing which screen to appear on

Post by filbo »

Hi, this is a bit obscure but maybe there's a solution?

I'm using 2 screens on my Linux system. Still LinuxMint 17.3 (very out of date). MATE desktop environment 1.12.0, Marco window manager, SDL2 2.0.2; RnD 4.2.3.1

I have a main screen which is 1280x1024; and a giant 43" TV, in portrait mode, which is attached to all 3 of my main machines and swapped between them depending what I'm doing. All 3 maintain windows on it, but obviously I can only see the ones belonging to the machine whose HDMI connection is currently 'active'.

So I'm sitting here on my personal desktop, looking at the 1280x1024 screen. I start RnD, and -- it appears -- or doesn't appear -- on the giant vertical screen. To retrieve it I have to switch the HDMI input on the TV, drag it back, then switch the TV back.(*)

This shows how the system sees the 2 screens:

Code: Select all

$ xrandr | grep -w connected
HDMI1 connected primary 2160x3840+1280+0 right (normal left inverted right x axis y axis) 800mm x 450mm
VGA1 connected 1280x1024+0+2160 (normal left inverted right x axis y axis) 338mm x 270mm
(and I see that it has the dot pitch of the large screen wrong, but that's irrelevant...)

So, for instance, `xterm -geometry +0+2160` pops up an xterm in the upper left corner of the small screen.

Unfortunately:

Code: Select all

$ ./rocksndiamonds -geometry +20+2180
[FATAL] unrecognized option '-geometry'
[FATAL] try option '--help' for more information
[FATAL] aborting
(same with --geometry)

I looked for SDL options and the closest I could find was the environment variable SDL_VIDEO_CENTERED=center, but that doesn't even seem to apply to SDL2.

So I'm looking for a way to specify an X11 geometry or a Xinerama screen number or an Xrandr screen number (I've never really properly understood the relationship between or distinction between Xinerama and Xrandr...)

(*)The reality is somewhat more complex. The HDMI screen is 'still there' while the physical display is connected to a different host or powered off. I can mouse over and grab the window without actually seeing what I'm doing, but it's quite hard to actually hit it. Not as hard as having to catch its titlebar, because my window manager recognizes Alt+drag (anywhere within a window) as drag-to-move. AND, having to deal with this all the time, I actually have `x11vnc` running to cast the HDMI screen, and a VNC client in a window on the small screen, showing the big screen in 1/4 scale, and normally minimized. So I can, without powering on or switching the big screen, pop up the VNC and drag the window across the horizontal boundary between screens, onto the small screen. But this is still a hassle.

None of this bizarrity is actually relevant; the baseline problem is: give me a way to tell RnD which of multiple X11 screens to appear on! -geometry (or --geometry) would be perfect, since it lets you set size as well as position; RnD should come up at the specified location in the specified dimensions (doing whatever it does to fix aspect ratio -- which appears to be, allow the window to have 'wrong' aspect ratio, just use the largest interior rectangle which has the correct aspect ratio). --geometry of course allows either or both of location & size to be specified. There is surely X library code to parse it (looks like xparsegeometry(3)).

Really, SDL itself, when built for X11, ought to intercept those args. But maybe it is not set up to fool around with argv outside the control of the calling program. Maybe there's something RnD needs to do to tell it 'hey, parse this here --geometry flag I received'. SDL doesn't intend that all SDL programs be fullscreen, so it ought to have a way to bridge the local OS's way of specifying a size into the generic program inside...
filbo
Posts: 594
Joined: Fri Jun 20, 2014 10:06 am

Re: X11 -- choosing which screen to appear on

Post by filbo »

TLDR :)

Please make a way to specify on command line which of N displays to appear on; or, best, just implement the standard X11 --geometry flag.
User avatar
Holger
Site Admin
Posts: 3748
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: X11 -- choosing which screen to appear on

Post by Holger »

Hi filbo,

yes, support for the standard X11 style "-geometry" flag in R'n'D would be nice. I assume that SDL does not support it directly because X11 is only one of many targets of that library, and Windows, Mac, Android etc. do not have it. (And probably most people are generally not starting GUI programs via command line anymore nowadays.)

As a quick workaround to ease your pain, please try the following patch:

Code: Select all

--- a/src/libgame/sdl.c
+++ b/src/libgame/sdl.c
@@ -593,8 +593,8 @@ static boolean SDLCreateScreen(boolean fullscreen)

   if (sdl_window == NULL)
     sdl_window = SDL_CreateWindow(program.window_title,
-                                 SDL_WINDOWPOS_CENTERED,
-                                 SDL_WINDOWPOS_CENTERED,
+                                 SDL_WINDOWPOS_CENTERED_DISPLAY(1),
+                                 SDL_WINDOWPOS_CENTERED_DISPLAY(1),
                                  video.window_width,
                                  video.window_height,
                                  surface_flags);
@@ -794,7 +794,7 @@ void SDLSetWindowFullscreen(boolean fullscreen)
   {
     SDLSetWindowScaling(setup.window_scaling_percent);
     SDL_SetWindowPosition(sdl_window,
-                         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
+                         SDL_WINDOWPOS_CENTERED_DISPLAY(1), SDL_WINDOWPOS_CENTERED_DISPLAY(1));

     video.fullscreen_initial = FALSE;
   }
Maybe I could also add a "-screen <nr>" option to use that (so the patch would work in a more generic way).

BTW: I've successfully tested this patch on a Mac with two screens.

Hope that helps!
filbo
Posts: 594
Joined: Fri Jun 20, 2014 10:06 am

Re: X11 -- choosing which screen to appear on

Post by filbo »

Thanks, that seems to do it!

New bug you will now hear: 'always starts on the first screen'! :)

So yes, -screen would be good.

I don't know how SDL counts its screens, there will probably be cases where the 'first' screen isn't the one that's wanted... No, wait, this patches it to use '2nd screen'! It's a patch just for my system!

Right, definitely needs a flag...
User avatar
Holger
Site Admin
Posts: 3748
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: X11 -- choosing which screen to appear on

Post by Holger »

While fiddling around with window positioning (also see here), I've also just added a new option "--display <number>" to open the game window on the specified display, which seems to work fine.

Still have to test this with some multi-monitor setups, though...
Post Reply