@@ -470,8 +470,12 @@ sdl3_print_displays()
470470 }
471471}
472472
473- static SDL_DisplayID get_display_id_to_idx (int idx )
473+ static SDL_DisplayID
474+ get_display_id_from_idx (int idx )
474475{
476+ if (idx == -1 ) {
477+ idx = 0 ;
478+ }
475479 int count = 0 ;
476480 SDL_DisplayID * displays = SDL_GetDisplays (& count );
477481 if (idx < count ) {
@@ -772,6 +776,24 @@ vulkan_warn(const char *req_renderers_name, const char *actual_renderer_name)
772776 explicit ? "" : " Please report!" );
773777}
774778
779+ static void
780+ sdl3_set_window_position (struct state_sdl3 * s , int x , int y ) {
781+ if (SDL_SetWindowPosition (s -> window , x , y )) {
782+ return ;
783+ }
784+ const bool is_wayland =
785+ strcmp (SDL_GetCurrentVideoDriver (), "wayland" ) == 0 ;
786+ if (is_wayland && s -> display_idx != -1 && !s -> fs ) {
787+ MSG (ERROR , "In Wayland, display specification is available "
788+ "only together with fullscreen flag ':fs'!\n" );
789+ } else if (!is_wayland || s -> x != SDL_WINDOWPOS_UNDEFINED ||
790+ s -> y != SDL_WINDOWPOS_UNDEFINED ) {
791+ MSG (ERROR , "Error (SDL_SetWindowPosition): %s\n" ,
792+ SDL_GetError ());
793+ }
794+ // no warning if wayland and x/y unspecified
795+ }
796+
775797static bool
776798display_sdl3_reconfigure_real (void * state , struct video_desc desc )
777799{
@@ -797,7 +819,7 @@ display_sdl3_reconfigure_real(void *state, struct video_desc desc)
797819 }
798820 int width = s -> fixed_w ? s -> fixed_w : desc .width ;
799821 int height = s -> fixed_h ? s -> fixed_h : desc .height ;
800- const SDL_DisplayID display_id = get_display_id_to_idx (s -> display_idx );
822+ const SDL_DisplayID display_id = get_display_id_from_idx (s -> display_idx );
801823 int x = s -> x == SDL_WINDOWPOS_UNDEFINED
802824 ? (int ) SDL_WINDOWPOS_CENTERED_DISPLAY (display_id )
803825 : s -> x ;
@@ -809,7 +831,7 @@ display_sdl3_reconfigure_real(void *state, struct video_desc desc)
809831 MSG (ERROR , "Unable to create window: %s\n" , SDL_GetError ());
810832 return false;
811833 }
812- SDL_SetWindowPosition ( s -> window , x , y );
834+ sdl3_set_window_position ( s , x , y );
813835
814836 if (s -> renderer ) {
815837 SDL_DestroyRenderer (s -> renderer );
@@ -945,6 +967,7 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
945967 struct state_sdl3 * s = calloc (1 , sizeof * s );
946968
947969 s -> magic = MAGIC_SDL3 ;
970+ s -> display_idx = -1 ;
948971 s -> x = s -> y = SDL_WINDOWPOS_UNDEFINED ;
949972 s -> vsync = true;
950973
0 commit comments