From: Holger Schemel Date: Wed, 7 Sep 2022 15:07:33 +0000 (+0200) Subject: added command line option to select display to open program window X-Git-Tag: 4.3.3.0~62 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=14ef59d8e791fc8a0d52978873555dc36d2d5ee0;p=rocksndiamonds.git added command line option to select display to open program window --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 7c3e04fc..f0858f4a 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -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")) { diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index f586bd8b..fe859452 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -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; } diff --git a/src/libgame/system.h b/src/libgame/system.h index cf2b0ca6..301e9fac 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1098,6 +1098,8 @@ struct OptionInfo char *identifier; char *level_nr; + int display_nr; + boolean mytapes; boolean serveronly; boolean network; diff --git a/src/main.c b/src/main.c index b72a521c..e03681c7 100644 --- a/src/main.c +++ b/src/main.c @@ -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"