@@ -702,9 +702,6 @@ sdl_set_log_level()
702702SDL_DisplayID
703703get_display_id_from_idx (int idx)
704704{
705- if (idx == -1 ) {
706- idx = 0 ;
707- }
708705 int count = 0 ;
709706 SDL_DisplayID *displays = SDL_GetDisplays (&count);
710707 if (idx < count) {
@@ -721,9 +718,20 @@ get_display_id_from_idx(int idx)
721718
722719void
723720vulkan_sdl3_set_window_position (state_vulkan_sdl3 *s,
724- const command_line_arguments *args, int x,
725- int y)
721+ const command_line_arguments *args)
726722{
723+ if (args->display_idx == -1 && args->x == SDL_WINDOWPOS_UNDEFINED &&
724+ args->y == SDL_WINDOWPOS_UNDEFINED) {
725+ return ;
726+ }
727+ int x = args->x ;
728+ int y = args->y ;
729+ if (args->display_idx != -1 ) {
730+ const SDL_DisplayID display_id =
731+ get_display_id_from_idx (args->display_idx );
732+ x = SDL_WINDOWPOS_CENTERED_DISPLAY (display_id);
733+ y = SDL_WINDOWPOS_CENTERED_DISPLAY (display_id);
734+ }
727735 if (SDL_SetWindowPosition (s->window , x, y)) {
728736 return ;
729737 }
@@ -736,10 +744,7 @@ vulkan_sdl3_set_window_position(state_vulkan_sdl3 *s,
736744 SDL_GetError ());
737745 return ;
738746 }
739- const int ll = !is_wayland || args->x != SDL_WINDOWPOS_UNDEFINED ||
740- args->y != SDL_WINDOWPOS_UNDEFINED
741- ? LOG_LEVEL_ERROR
742- : LOG_LEVEL_VERBOSE;
747+ const int ll = !is_wayland ? LOG_LEVEL_ERROR : LOG_LEVEL_VERBOSE;
743748 log_msg (ll, MOD_NAME " Error (SDL_SetWindowPosition): %s\n " ,
744749 SDL_GetError ());
745750}
@@ -797,9 +802,6 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
797802 window_title = get_commandline_param (" window-title" );
798803 }
799804
800- const SDL_DisplayID display_id = get_display_id_from_idx (args.display_idx );
801- int x = (args.x == SDL_WINDOWPOS_UNDEFINED ? SDL_WINDOWPOS_CENTERED_DISPLAY (display_id) : args.x );
802- int y = (args.y == SDL_WINDOWPOS_UNDEFINED ? SDL_WINDOWPOS_CENTERED_DISPLAY (display_id) : args.y );
803805 if (s->width == -1 && s->height == -1 ){
804806 int display_index = 0 ;
805807 const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode (display_index);
@@ -827,7 +829,7 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
827829 return nullptr ;
828830 }
829831 s->window_callback = new WindowCallback (s->window );
830- vulkan_sdl3_set_window_position (s.get (), &args, x, y );
832+ vulkan_sdl3_set_window_position (s.get (), &args);
831833
832834 uint32_t extension_count = 0 ;
833835 const char *const *extensions = SDL_Vulkan_GetInstanceExtensions (&extension_count);
0 commit comments