2015-07-15 04:28:26 +03:00
|
|
|
/*
|
2023-01-09 20:41:41 +03:00
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
2015-07-15 04:28:26 +03:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely.
|
|
|
|
*/
|
|
|
|
|
2015-07-15 22:10:38 +03:00
|
|
|
/* Program to test querying of display info */
|
2015-07-15 04:28:26 +03:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-11-27 07:43:38 +03:00
|
|
|
#include <SDL3/SDL.h>
|
2022-12-15 07:58:20 +03:00
|
|
|
#include <SDL3/SDL_main.h>
|
2022-11-26 12:41:46 +03:00
|
|
|
|
2015-07-15 04:28:26 +03:00
|
|
|
static void
|
|
|
|
print_mode(const char *prefix, const SDL_DisplayMode *mode)
|
|
|
|
{
|
2022-11-27 19:38:43 +03:00
|
|
|
if (mode == NULL) {
|
2015-07-15 04:28:26 +03:00
|
|
|
return;
|
2022-11-27 19:38:43 +03:00
|
|
|
}
|
2015-07-15 04:28:26 +03:00
|
|
|
|
2023-01-27 21:46:51 +03:00
|
|
|
SDL_Log("%s: fmt=%s w=%d h=%d scale=%d%% refresh=%gHz\n",
|
2015-07-15 04:28:26 +03:00
|
|
|
prefix, SDL_GetPixelFormatName(mode->format),
|
2023-01-27 21:46:51 +03:00
|
|
|
mode->pixel_w, mode->pixel_h, (int)(mode->display_scale * 100.0f), mode->refresh_rate);
|
2015-07-15 04:28:26 +03:00
|
|
|
}
|
|
|
|
|
2022-11-30 23:51:59 +03:00
|
|
|
int main(int argc, char *argv[])
|
2015-07-15 04:28:26 +03:00
|
|
|
{
|
2023-01-30 00:30:55 +03:00
|
|
|
SDL_DisplayID *displays;
|
2015-07-15 04:28:26 +03:00
|
|
|
SDL_DisplayMode mode;
|
2023-01-30 00:30:55 +03:00
|
|
|
int num_displays, i;
|
2015-07-15 04:28:26 +03:00
|
|
|
|
2015-11-25 23:39:28 +03:00
|
|
|
/* Enable standard application logging */
|
|
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
2015-07-15 04:28:26 +03:00
|
|
|
|
|
|
|
/* Load the SDL library */
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
|
2023-01-30 00:30:55 +03:00
|
|
|
displays = SDL_GetDisplays(&num_displays);
|
2015-07-15 04:28:26 +03:00
|
|
|
|
|
|
|
SDL_Log("See %d displays.\n", num_displays);
|
|
|
|
|
2023-01-30 00:30:55 +03:00
|
|
|
for (i = 0; i < num_displays; i++) {
|
|
|
|
SDL_DisplayID dpy = displays[i];
|
2015-07-15 04:28:26 +03:00
|
|
|
const int num_modes = SDL_GetNumDisplayModes(dpy);
|
|
|
|
SDL_Rect rect = { 0, 0, 0, 0 };
|
2016-01-07 22:02:37 +03:00
|
|
|
float ddpi, hdpi, vdpi;
|
2015-07-15 04:28:26 +03:00
|
|
|
int m;
|
|
|
|
|
|
|
|
SDL_GetDisplayBounds(dpy, &rect);
|
2023-01-30 00:30:55 +03:00
|
|
|
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);
|
2015-07-15 04:28:26 +03:00
|
|
|
|
2023-01-25 10:32:16 +03:00
|
|
|
if (SDL_GetDisplayPhysicalDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
|
2016-01-07 22:02:37 +03:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
|
|
|
|
} else {
|
|
|
|
SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
|
|
|
|
}
|
|
|
|
|
2015-07-15 04:28:26 +03:00
|
|
|
if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
|
|
|
|
} else {
|
|
|
|
print_mode("CURRENT", &mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
|
|
|
|
} else {
|
|
|
|
print_mode("DESKTOP", &mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (m = 0; m < num_modes; m++) {
|
|
|
|
if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
|
|
|
|
} else {
|
|
|
|
char prefix[64];
|
2022-12-02 00:07:03 +03:00
|
|
|
(void)SDL_snprintf(prefix, sizeof prefix, " MODE %d", m);
|
2015-07-15 04:28:26 +03:00
|
|
|
print_mode(prefix, &mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Log("\n");
|
|
|
|
}
|
2023-01-30 00:30:55 +03:00
|
|
|
SDL_free(displays);
|
2015-07-15 04:28:26 +03:00
|
|
|
|
2015-08-07 08:00:14 +03:00
|
|
|
SDL_Quit();
|
2015-07-15 04:28:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|