Skip to content

Commit 7e42cb9

Browse files
committed
sdl2, vulkan_sdl2: validate parameters
similar to [vulkan_]sdl3
1 parent b96080e commit 7e42cb9

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/video_display/sdl2.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,23 @@ print_renderer_info(SDL_Renderer *renderer)
520520
SDL_GetPixelFormatName(renderer_info.texture_formats[i]));
521521
}
522522

523+
static void
524+
display_sdl2_validate_params(struct state_sdl2 *s)
525+
{
526+
if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") != 0) {
527+
return;
528+
}
529+
if (s->display_idx != -1 && !s->fs) {
530+
MSG(WARNING, "In Wayland, display specification is available "
531+
"only together with fullscreen flag ':fs'!\n");
532+
}
533+
if (s->x != SDL_WINDOWPOS_UNDEFINED ||
534+
s->y != SDL_WINDOWPOS_UNDEFINED) {
535+
MSG(WARNING,
536+
"Window positon should not be specified with Wayland!\n");
537+
}
538+
}
539+
523540
static bool
524541
display_sdl2_reconfigure_real(void *state, struct video_desc desc)
525542
{
@@ -546,8 +563,10 @@ display_sdl2_reconfigure_real(void *state, struct video_desc desc)
546563
}
547564
int width = s->fixed_w ? s->fixed_w : desc.width;
548565
int height = s->fixed_h ? s->fixed_h : desc.height;
549-
int x = s->x == SDL_WINDOWPOS_UNDEFINED ? (int) SDL_WINDOWPOS_CENTERED_DISPLAY(s->display_idx) : s->x;
550-
int y = s->y == SDL_WINDOWPOS_UNDEFINED ? (int) SDL_WINDOWPOS_CENTERED_DISPLAY(s->display_idx) : s->y;
566+
int display_idx = s->display_idx == -1 ? 0 : s->display_idx;
567+
int x = s->x == SDL_WINDOWPOS_UNDEFINED ? (int) SDL_WINDOWPOS_CENTERED_DISPLAY(display_idx) : s->x;
568+
int y = s->y == SDL_WINDOWPOS_UNDEFINED ? (int) SDL_WINDOWPOS_CENTERED_DISPLAY(display_idx) : s->y;
569+
display_sdl2_validate_params(s);
551570
s->window = SDL_CreateWindow(window_title, x, y, width, height, flags);
552571
if (!s->window) {
553572
log_msg(LOG_LEVEL_ERROR, "[SDL] Unable to create window: %s\n", SDL_GetError());
@@ -675,6 +694,7 @@ static void *display_sdl2_init(struct module *parent, const char *fmt, unsigned
675694
struct state_sdl2 *s = calloc(1, sizeof *s);
676695

677696
s->magic = MAGIC_SDL2;
697+
s->display_idx = -1;
678698
s->x = s->y = SDL_WINDOWPOS_UNDEFINED;
679699
s->vsync = true;
680700

src/video_display/vulkan/vulkan_sdl2.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ struct command_line_arguments {
584584
bool tearing_permitted = false;
585585
bool validation = false;
586586

587-
int display_idx = 0;
587+
int display_idx = -1;
588588
int x = SDL_WINDOWPOS_UNDEFINED;
589589
int y = SDL_WINDOWPOS_UNDEFINED;
590590

@@ -693,6 +693,24 @@ bool parse_command_line_arguments(command_line_arguments& args, state_vulkan_sdl
693693
return true;
694694
}
695695

696+
void
697+
vulkan_sdl2_validate_params(state_vulkan_sdl2 *s,
698+
const command_line_arguments *args)
699+
{
700+
if (strcmp(SDL_GetCurrentVideoDriver(), "wayland") != 0) {
701+
return;
702+
}
703+
if (args->display_idx != -1 && !s->fullscreen) {
704+
MSG(WARNING, "In Wayland, display specification is available "
705+
"only together with fullscreen flag ':fs'!\n");
706+
}
707+
if (args->x != SDL_WINDOWPOS_UNDEFINED ||
708+
args->y != SDL_WINDOWPOS_UNDEFINED) {
709+
MSG(WARNING,
710+
"Window positon should not be specified with Wayland!\n");
711+
}
712+
}
713+
696714
void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
697715
if (flags & DISPLAY_FLAG_AUDIO_ANY) {
698716
log_msg(LOG_LEVEL_ERROR, "UltraGrid VULKAN_SDL2 module currently doesn't support audio!\n");
@@ -739,8 +757,9 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
739757
window_title = get_commandline_param("window-title");
740758
}
741759

742-
int x = (args.x == SDL_WINDOWPOS_UNDEFINED ? SDL_WINDOWPOS_CENTERED_DISPLAY(args.display_idx) : args.x);
743-
int y = (args.y == SDL_WINDOWPOS_UNDEFINED ? SDL_WINDOWPOS_CENTERED_DISPLAY(args.display_idx) : args.y);
760+
int display_idx = args.display_idx == -1 ? 0 : args.display_idx;
761+
int x = (args.x == SDL_WINDOWPOS_UNDEFINED ? SDL_WINDOWPOS_CENTERED_DISPLAY(display_idx) : args.x);
762+
int y = (args.y == SDL_WINDOWPOS_UNDEFINED ? SDL_WINDOWPOS_CENTERED_DISPLAY(display_idx) : args.y);
744763
if(s->width == -1 && s->height == -1){
745764
SDL_DisplayMode mode;
746765
int display_index = 0;
@@ -762,6 +781,7 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
762781
window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
763782
}
764783

784+
vulkan_sdl2_validate_params(s.get(), &args);
765785
s->window = SDL_CreateWindow(window_title, x, y, s->width, s->height, window_flags);
766786
if (!s->window) {
767787
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unable to create window : %s\n", SDL_GetError());

0 commit comments

Comments
 (0)