added command line option to select display to open program window
authorHolger Schemel <info@artsoft.org>
Wed, 7 Sep 2022 15:07:33 +0000 (17:07 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 7 Sep 2022 15:07:33 +0000 (17:07 +0200)
src/libgame/misc.c
src/libgame/sdl.c
src/libgame/system.h
src/main.c

index 7c3e04fca21eaa297b0a5398bfb98b1c604c2618..f0858f4a20c5ee731339cd52073d05246cf3fd97 100644 (file)
@@ -1350,6 +1350,8 @@ void GetOptions(int argc, char *argv[],
   options.identifier = NULL;
   options.level_nr = NULL;
 
+  options.display_nr = 0;
+
   options.mytapes = FALSE;
   options.serveronly = FALSE;
   options.network = FALSE;
@@ -1549,6 +1551,23 @@ void GetOptions(int argc, char *argv[],
       if (option_arg == next_option)
        options_left++;
     }
+    else if (strncmp(option, "-display", option_len) == 0)
+    {
+      if (option_arg == NULL)
+       FailWithHelp("option '%s' requires an argument", option_str);
+
+      if (option_arg == next_option)
+       options_left++;
+
+      int display_nr = atoi(option_arg);
+
+      options.display_nr =
+       MAX(0, MIN(display_nr, SDL_GetNumVideoDisplays() - 1));
+
+      if (display_nr != options.display_nr)
+       Warn("invalid display %d -- using display %d",
+            display_nr, options.display_nr);
+    }
 #if defined(PLATFORM_MAC)
     else if (strPrefix(option, "-psn"))
     {
index f586bd8baaf59cad189720185aa0b0853622c310..fe859452a07fc7fed8d6ca2b47b3114d735a628a 100644 (file)
@@ -553,6 +553,7 @@ static boolean SDLCreateScreen(boolean fullscreen)
   int screen_height = video.screen_height;
   int surface_flags = (fullscreen ? surface_flags_fullscreen :
                       surface_flags_window);
+  int display_nr = options.display_nr;
 
   // default window size is unscaled
   video.window_width  = screen_width;
@@ -595,8 +596,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(display_nr),
+                                 SDL_WINDOWPOS_CENTERED_DISPLAY(display_nr),
                                  video.window_width,
                                  video.window_height,
                                  surface_flags);
@@ -796,7 +797,8 @@ void SDLSetWindowFullscreen(boolean fullscreen)
   {
     SDLSetWindowScaling(setup.window_scaling_percent);
     SDL_SetWindowPosition(sdl_window,
-                         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
+                         SDL_WINDOWPOS_CENTERED_DISPLAY(options.display_nr),
+                         SDL_WINDOWPOS_CENTERED_DISPLAY(options.display_nr));
 
     video.fullscreen_initial = FALSE;
   }
index cf2b0ca6be1ba5ee826e07ea5f2d9f7dae1a9b68..301e9fac9d65fd19ea6caa7d0890ea1ac5b8f9a8 100644 (file)
@@ -1098,6 +1098,8 @@ struct OptionInfo
   char *identifier;
   char *level_nr;
 
+  int display_nr;
+
   boolean mytapes;
   boolean serveronly;
   boolean network;
index b72a521ca7588a236d1c112e457048071ef1b421..e03681c799198310d4c85d8cfc148deafb5311b7 100644 (file)
@@ -7714,6 +7714,7 @@ static void print_usage(void)
        "  -g, --graphics DIRECTORY         alternative graphics DIRECTORY\n"
        "  -s, --sounds DIRECTORY           alternative sounds DIRECTORY\n"
        "  -m, --music DIRECTORY            alternative music DIRECTORY\n"
+       "      --display NR                 open program window on display NR\n"
        "      --mytapes                    use private tapes for tape tests\n"
        "  -n, --network                    network multiplayer game\n"
        "      --serveronly                 only start network server\n"