🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

  1. /*
  2. Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. /* Program to test querying of display info */
  11. #include "SDL.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. static void
  15. print_mode(const char *prefix, const SDL_DisplayMode *mode)
  16. {
  17. if (!mode)
  18. return;
  19. SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
  20. prefix, SDL_GetPixelFormatName(mode->format),
  21. mode->w, mode->h, mode->refresh_rate);
  22. }
  23. int
  24. main(int argc, char *argv[])
  25. {
  26. SDL_DisplayMode mode;
  27. int num_displays, dpy;
  28. /* Enable standard application logging */
  29. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  30. /* Load the SDL library */
  31. if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  32. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
  33. return 1;
  34. }
  35. SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
  36. num_displays = SDL_GetNumVideoDisplays();
  37. SDL_Log("See %d displays.\n", num_displays);
  38. for (dpy = 0; dpy < num_displays; dpy++) {
  39. const int num_modes = SDL_GetNumDisplayModes(dpy);
  40. SDL_Rect rect = { 0, 0, 0, 0 };
  41. float ddpi, hdpi, vdpi;
  42. int m;
  43. SDL_GetDisplayBounds(dpy, &rect);
  44. 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);
  45. if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
  46. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
  47. } else {
  48. SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
  49. }
  50. if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
  51. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
  52. } else {
  53. print_mode("CURRENT", &mode);
  54. }
  55. if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
  56. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
  57. } else {
  58. print_mode("DESKTOP", &mode);
  59. }
  60. for (m = 0; m < num_modes; m++) {
  61. if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
  62. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
  63. } else {
  64. char prefix[64];
  65. SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m);
  66. print_mode(prefix, &mode);
  67. }
  68. }
  69. SDL_Log("\n");
  70. }
  71. SDL_Quit();
  72. return 0;
  73. }
  74. /* vi: set ts=4 sw=4 expandtab: */