Skip to content

Commit e9d29cd

Browse files
committed
[vulkan_]sdl3: do not set pos if not req
if neither of display/x/y is set, do not set the window position
1 parent 2fd4d2e commit e9d29cd

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

src/video_display/sdl3.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,6 @@ sdl3_print_displays()
473473
static SDL_DisplayID
474474
get_display_id_from_idx(int idx)
475475
{
476-
if (idx == -1) {
477-
idx = 0;
478-
}
479476
int count = 0;
480477
SDL_DisplayID *displays = SDL_GetDisplays(&count);
481478
if (idx < count) {
@@ -782,7 +779,19 @@ vulkan_warn(const char *req_renderers_name, const char *actual_renderer_name)
782779
}
783780

784781
static void
785-
sdl3_set_window_position(struct state_sdl3 *s, int x, int y) {
782+
sdl3_set_window_position(struct state_sdl3 *s) {
783+
if (s->display_idx == -1 && s->x == SDL_WINDOWPOS_UNDEFINED &&
784+
s->y == SDL_WINDOWPOS_UNDEFINED) {
785+
return;
786+
}
787+
int x = s->x;
788+
int y = s->y;
789+
if (s->display_idx != -1) {
790+
const SDL_DisplayID display_id =
791+
get_display_id_from_idx(s->display_idx);
792+
x = (int) SDL_WINDOWPOS_CENTERED_DISPLAY(display_id);
793+
y = (int) SDL_WINDOWPOS_CENTERED_DISPLAY(display_id);
794+
}
786795
if (SDL_SetWindowPosition(s->window, x, y)) {
787796
return;
788797
}
@@ -795,10 +804,7 @@ sdl3_set_window_position(struct state_sdl3 *s, int x, int y) {
795804
SDL_GetError());
796805
return;
797806
}
798-
const int ll = !is_wayland || s->x != SDL_WINDOWPOS_UNDEFINED ||
799-
s->y != SDL_WINDOWPOS_UNDEFINED
800-
? LOG_LEVEL_ERROR
801-
: LOG_LEVEL_VERBOSE;
807+
const int ll = !is_wayland ? LOG_LEVEL_ERROR : LOG_LEVEL_VERBOSE;
802808
log_msg(ll, MOD_NAME "Error (SDL_SetWindowPosition): %s\n",
803809
SDL_GetError());
804810
}
@@ -828,19 +834,12 @@ display_sdl3_reconfigure_real(void *state, struct video_desc desc)
828834
}
829835
int width = s->fixed_w ? s->fixed_w : desc.width;
830836
int height = s->fixed_h ? s->fixed_h : desc.height;
831-
const SDL_DisplayID display_id = get_display_id_from_idx(s->display_idx);
832-
int x = s->x == SDL_WINDOWPOS_UNDEFINED
833-
? (int) SDL_WINDOWPOS_CENTERED_DISPLAY(display_id)
834-
: s->x;
835-
int y = s->y == SDL_WINDOWPOS_UNDEFINED
836-
? (int) SDL_WINDOWPOS_CENTERED_DISPLAY(display_id)
837-
: s->y;
838837
s->window = SDL_CreateWindow(window_title, width, height, flags);
839838
if (!s->window) {
840839
MSG(ERROR, "Unable to create window: %s\n", SDL_GetError());
841840
return false;
842841
}
843-
sdl3_set_window_position(s, x, y);
842+
sdl3_set_window_position(s);
844843

845844
if (s->renderer) {
846845
SDL_DestroyRenderer(s->renderer);

src/video_display/vulkan/vulkan_sdl3.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,6 @@ sdl_set_log_level()
702702
SDL_DisplayID
703703
get_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

722719
void
723720
vulkan_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

Comments
 (0)