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