Skip to content

Commit 2c2dcc2

Browse files
committed
sdl3/vulkan_sdl3: allow ID for display
This is a bit tricky because the ID seems to be a (small) ordinal and may potentially clash with the index... Index is considered first, this approach may bbe re-evaluated (eg. letters for the indexes?).
1 parent 14e6920 commit 2c2dcc2

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/video_display/sdl3.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ sdl3_print_displays()
466466
if (dname == NULL) {
467467
dname = SDL_GetError();
468468
}
469-
color_printf(TBOLD("%d") " - %s", i, dname);
469+
color_printf(TBOLD("%d") " - %s (ID: %d)", i, dname, displays[i]);
470470
}
471471
}
472472

@@ -481,7 +481,12 @@ get_display_id_from_idx(int idx)
481481
if (idx < count) {
482482
return displays[idx];
483483
}
484-
MSG(ERROR, "Display index %d out of range!\n", idx);
484+
for (int i = 0; i < count; ++i) {
485+
if (displays[i] == (unsigned) idx) {
486+
return idx;
487+
}
488+
}
489+
MSG(ERROR, "Display index %d out of range or ID invalid!\n", idx);
485490
return 0;
486491
}
487492

@@ -494,7 +499,7 @@ show_help(const char *driver, bool full)
494499
SDL_CHECK(SDL_InitSubSystem(SDL_INIT_VIDEO));
495500
printf("SDL options:\n");
496501
color_printf(TBOLD(TRED(
497-
"\t-d sdl") "[[:fs|:d|:display=<didx>|:driver=<drv>|:novsync|:"
502+
"\t-d sdl") "[[:fs|:d|:display=<d>|:driver=<drv>|:novsync|:"
498503
"renderer=<name[s]>|:nodecorate|:size[=WxH]|:window_"
499504
"flags=<f>|:keep-aspect]*]") "\n");
500505
color_printf(TBOLD(
@@ -504,7 +509,7 @@ show_help(const char *driver, bool full)
504509
"\td[force]") " - deinterlace (force even for progressive video)\n");
505510
color_printf(TBOLD("\t fs") " - fullscreen\n");
506511
color_printf(
507-
TBOLD("\t <didx>") " - display index, available indices: ");
512+
TBOLD("\t <d>") " - display index or ID, available indices: ");
508513
sdl3_print_displays();
509514
color_printf("%s\n", (driver == NULL ? TBOLD(" *") : ""));
510515
color_printf(TBOLD("\t <drv>") " - one of following: ");

src/video_display/vulkan/vulkan_sdl3.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void sdl3_print_displays() {
424424
if (dname == nullptr) {
425425
dname = SDL_GetError();
426426
}
427-
col() << SBOLD(displays[i]) << " - " << dname;
427+
col() << SBOLD(i) << " - " << dname << " (ID: " << displays[i] << ")" ;
428428
}
429429
std::cout << "\n";
430430
}
@@ -460,7 +460,7 @@ void show_help() {
460460

461461
col() << "VULKAN_SDL3 options:\n";
462462
col() << SBOLD(SRED("\t-d vulkan")
463-
<< "[:d|:fs|:keep-aspect|:nocursor|:nodecorate|:novsync|:tearing|:validation|:display=<dis_id>|"
463+
<< "[:d|:fs|:keep-aspect|:nocursor|:nodecorate|:novsync|:tearing|:validation|:display=<d>|"
464464
":driver=<drv>|:gpu=<gpu_id>|:pos=<x>,<y>|:size=<W>x<H>|:window_flags=<f>|:help])") << "\n";
465465

466466
col() << ("\twhere:\n");
@@ -475,7 +475,7 @@ void show_help() {
475475
col() << SBOLD("\t tearing") << " - permits screen tearing\n";
476476
col() << SBOLD("\t validation") << " - enable vulkan validation layers\n";
477477

478-
col() << SBOLD("\tdisplay=<dis_id>") << " - display index, available indices: ";
478+
col() << SBOLD("\t display=<d>") << " - display index or ID, available indices: ";
479479
sdl3_print_displays();
480480
col() << SBOLD("\t driver=<drv>") << " - available drivers: ";
481481
print_drivers();
@@ -734,7 +734,12 @@ get_display_id_from_idx(int idx)
734734
if (idx < count) {
735735
return displays[idx];
736736
}
737-
MSG(ERROR, "Display index %d out of range!\n", idx);
737+
for (int i = 0; i < count; ++i) {
738+
if (displays[i] == (unsigned) idx) {
739+
return idx;
740+
}
741+
}
742+
MSG(ERROR, "Display index %d out of range or ID invalid!\n", idx);
738743
return 0;
739744
}
740745

0 commit comments

Comments
 (0)