Displays are now referenced by instance ID instead of index

This commit is contained in:
Sam Lantinga
2023-01-29 19:25:15 -08:00
parent 758c0dd6d8
commit 22c69bccdf
157 changed files with 1620 additions and 1589 deletions
File diff suppressed because it is too large Load Diff
+14 -10
View File
@@ -15,22 +15,26 @@
int main(int argc, char **argv)
{
int total, i;
SDL_DisplayID *displays;
int i;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_Log("SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError());
return 1;
}
total = SDL_GetNumVideoDisplays();
for (i = 0; i < total; i++) {
SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 };
SDL_GetDisplayBounds(i, &bounds);
SDL_GetDisplayUsableBounds(i, &usable);
SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}",
i, SDL_GetDisplayName(i),
bounds.x, bounds.y, bounds.w, bounds.h,
usable.x, usable.y, usable.w, usable.h);
displays = SDL_GetDisplays(NULL);
if (displays) {
for (i = 0; displays[i]; i++) {
SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 };
SDL_GetDisplayBounds(displays[i], &bounds);
SDL_GetDisplayUsableBounds(displays[i], &usable);
SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}",
i, SDL_GetDisplayName(displays[i]),
bounds.x, bounds.y, bounds.w, bounds.h,
usable.x, usable.y, usable.w, usable.h);
}
SDL_free(displays);
}
SDL_Quit();
+7 -4
View File
@@ -31,8 +31,9 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
int main(int argc, char *argv[])
{
SDL_DisplayID *displays;
SDL_DisplayMode mode;
int num_displays, dpy;
int num_displays, i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -44,18 +45,19 @@ int main(int argc, char *argv[])
}
SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
num_displays = SDL_GetNumVideoDisplays();
displays = SDL_GetDisplays(&num_displays);
SDL_Log("See %d displays.\n", num_displays);
for (dpy = 0; dpy < num_displays; dpy++) {
for (i = 0; i < num_displays; i++) {
SDL_DisplayID dpy = displays[i];
const int num_modes = SDL_GetNumDisplayModes(dpy);
SDL_Rect rect = { 0, 0, 0, 0 };
float ddpi, hdpi, vdpi;
int m;
SDL_GetDisplayBounds(dpy, &rect);
SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
if (SDL_GetDisplayPhysicalDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
@@ -87,6 +89,7 @@ int main(int argc, char *argv[])
SDL_Log("\n");
}
SDL_free(displays);
SDL_Quit();
return 0;
+1 -1
View File
@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
swap_interval = 0;
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
ret_interval = SDL_GL_GetSwapInterval(&interval);
+1 -1
View File
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
+1 -1
View File
@@ -714,7 +714,7 @@ int main(int argc, char *argv[])
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Threaded : %s\n", threaded ? "yes" : "no");
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");
+1 -1
View File
@@ -602,7 +602,7 @@ int main(int argc, char *argv[])
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
+1 -1
View File
@@ -1104,7 +1104,7 @@ int main(int argc, char **argv)
return 1;
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
SDL_GetWindowSize(state->windows[0], &dw, &dh);
SDL_Log("Window Size : %d,%d\n", dw, dh);
+6 -6
View File
@@ -57,8 +57,8 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
SDL_DisplayMode mode;
char text[1024];
const int lineHeight = 10;
const int display_index = SDL_GetWindowDisplayIndex(window);
const int num_modes = SDL_GetNumDisplayModes(display_index);
const SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
const int num_modes = SDL_GetNumDisplayModes(displayID);
int i;
int column_chars = 0;
int text_length;
@@ -103,7 +103,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
for (i = 0; i < num_modes; ++i) {
SDL_FRect cell_rect;
if (0 != SDL_GetDisplayMode(display_index, i, &mode)) {
if (0 != SDL_GetDisplayMode(displayID, i, &mode)) {
return;
}
@@ -167,7 +167,7 @@ void loop()
event.window.windowID,
event.window.data1,
event.window.data2,
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
SDL_GetDisplayName(SDL_GetDisplayForWindow(window)));
}
}
if (event.type == SDL_EVENT_WINDOW_FOCUS_LOST) {
@@ -207,9 +207,9 @@ void loop()
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) {
SDL_Window *window = SDL_GetMouseFocus();
if (highlighted_mode != -1 && window != NULL) {
const int display_index = SDL_GetWindowDisplayIndex(window);
SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
SDL_DisplayMode mode;
if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) {
if (0 != SDL_GetDisplayMode(displayID, highlighted_mode, &mode)) {
SDL_Log("Couldn't get display mode");
} else {
SDL_SetWindowDisplayMode(window, &mode);