src/video/windows/SDL_windowsmodes.c
author Alex Szpakowski <slime73@gmail.com>
Mon, 23 May 2016 15:29:25 -0300
changeset 10179 7cbfd97f1430
parent 10174 284022a7f51e
permissions -rw-r--r--
Windows: Fix other window positions/sizes being changed when exiting exclusive fullscreen (bug #3315, thanks Simon Hug!)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9889
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8086
diff changeset
    21
#include "../../SDL_internal.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_WINDOWS
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    24
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4569
diff changeset
    25
#include "SDL_windowsvideo.h"
10031
2b3baddd9afa Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 10019
diff changeset
    26
#include "../../../include/SDL_assert.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    28
/* Windows CE compatibility */
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    29
#ifndef CDS_FULLSCREEN
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    30
#define CDS_FULLSCREEN 0
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
    31
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    33
typedef struct _WIN_GetMonitorDPIData {
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    34
    SDL_VideoData *vid_data;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    35
    SDL_DisplayMode *mode;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    36
    SDL_DisplayModeData *mode_data;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    37
} WIN_GetMonitorDPIData;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    38
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    39
static BOOL CALLBACK
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    40
WIN_GetMonitorDPI(HMONITOR hMonitor,
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    41
                  HDC      hdcMonitor,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    42
                  LPRECT   lprcMonitor,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    43
                  LPARAM   dwData)
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    44
{
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    45
    WIN_GetMonitorDPIData *data = (WIN_GetMonitorDPIData*) dwData;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    46
    UINT hdpi, vdpi;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    47
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    48
    if (data->vid_data->GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &hdpi, &vdpi) == S_OK &&
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    49
        hdpi > 0 &&
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    50
        vdpi > 0) {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    51
        float hsize, vsize;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    52
        
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    53
        data->mode_data->HorzDPI = (float)hdpi;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    54
        data->mode_data->VertDPI = (float)vdpi;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    55
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    56
        // Figure out the monitor size and compute the diagonal DPI.
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    57
        hsize = data->mode->w / data->mode_data->HorzDPI;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    58
        vsize = data->mode->h / data->mode_data->VertDPI;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    59
        
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    60
        data->mode_data->DiagDPI = SDL_ComputeDiagonalDPI( data->mode->w,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    61
                                                           data->mode->h,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    62
                                                           hsize,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    63
                                                           vsize );
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    64
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    65
        // We can only handle one DPI per display mode so end the enumeration.
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    66
        return FALSE;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    67
    }
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    68
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    69
    // We didn't get DPI information so keep going.
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    70
    return TRUE;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    71
}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    72
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
    73
static void
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
    74
WIN_UpdateDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
{
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
    76
    SDL_VideoData *vid_data = (SDL_VideoData *) _this->driverdata;
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
    77
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    HDC hdc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    data->DeviceMode.dmFields =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
        (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
         DM_DISPLAYFLAGS);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    84
    if (index == ENUM_CURRENT_SETTINGS
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    85
        && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
        char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
        LPBITMAPINFO bmi;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
        HBITMAP hbm;
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    89
        int logical_width = GetDeviceCaps( hdc, HORZRES );
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    90
        int logical_height = GetDeviceCaps( hdc, VERTRES );
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
    91
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
    92
        data->ScaleX = (float)logical_width / data->DeviceMode.dmPelsWidth;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
    93
        data->ScaleY = (float)logical_height / data->DeviceMode.dmPelsHeight;
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    94
        mode->w = logical_width;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    95
        mode->h = logical_height;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    97
        // WIN_GetMonitorDPI needs mode->w and mode->h
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    98
        // so only call after those are set.
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
    99
        if (vid_data->GetDpiForMonitor) {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   100
            WIN_GetMonitorDPIData dpi_data;
9819
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   101
            RECT monitor_rect;
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   102
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   103
            dpi_data.vid_data = vid_data;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   104
            dpi_data.mode = mode;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   105
            dpi_data.mode_data = data;
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   106
            monitor_rect.left = data->DeviceMode.dmPosition.x;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   107
            monitor_rect.top = data->DeviceMode.dmPosition.y;
9819
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   108
            monitor_rect.right = monitor_rect.left + 1;
2361f732e8cb Fix up monitor enumeration for Windows 8.1 case.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9813
diff changeset
   109
            monitor_rect.bottom = monitor_rect.top + 1;
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   110
            EnumDisplayMonitors(NULL, &monitor_rect, WIN_GetMonitorDPI, (LPARAM)&dpi_data);
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   111
        } else {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   112
            // We don't have the Windows 8.1 routine so just
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   113
            // get system DPI.
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   114
            data->HorzDPI = (float)GetDeviceCaps( hdc, LOGPIXELSX );
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   115
            data->VertDPI = (float)GetDeviceCaps( hdc, LOGPIXELSY );
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   116
            if (data->HorzDPI == data->VertDPI) {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   117
                data->DiagDPI = data->HorzDPI;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   118
            } else {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   119
                data->DiagDPI = SDL_ComputeDiagonalDPI( mode->w,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   120
                                                        mode->h,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   121
                                                        (float)GetDeviceCaps( hdc, HORZSIZE ) / 25.4f,
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   122
                                                        (float)GetDeviceCaps( hdc, VERTSIZE ) / 25.4f );
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   123
            }
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   124
        }
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   125
        
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
        SDL_zero(bmi_data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
        bmi = (LPBITMAPINFO) bmi_data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
        hbm = CreateCompatibleBitmap(hdc, 1, 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
        DeleteObject(hbm);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
        DeleteDC(hdc);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
        if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
            switch (*(Uint32 *) bmi->bmiColors) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
            case 0x00FF0000:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   138
                mode->format = SDL_PIXELFORMAT_RGB888;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
            case 0x000000FF:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   141
                mode->format = SDL_PIXELFORMAT_BGR888;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
            case 0xF800:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   144
                mode->format = SDL_PIXELFORMAT_RGB565;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
            case 0x7C00:
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   147
                mode->format = SDL_PIXELFORMAT_RGB555;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
        } else if (bmi->bmiHeader.biBitCount == 8) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1913
diff changeset
   151
            mode->format = SDL_PIXELFORMAT_INDEX8;
3175
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   152
        } else if (bmi->bmiHeader.biBitCount == 4) {
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   153
            mode->format = SDL_PIXELFORMAT_INDEX4LSB;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
        }
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   155
    } else if (mode->format == SDL_PIXELFORMAT_UNKNOWN) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   156
        /* FIXME: Can we tell what this will be? */
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   157
        if ((data->DeviceMode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   158
            switch (data->DeviceMode.dmBitsPerPel) {
3175
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   159
            case 32:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   160
                mode->format = SDL_PIXELFORMAT_RGB888;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   161
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   162
            case 24:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   163
                mode->format = SDL_PIXELFORMAT_RGB24;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   164
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   165
            case 16:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   166
                mode->format = SDL_PIXELFORMAT_RGB565;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   167
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   168
            case 15:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   169
                mode->format = SDL_PIXELFORMAT_RGB555;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   170
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   171
            case 8:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   172
                mode->format = SDL_PIXELFORMAT_INDEX8;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   173
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   174
            case 4:
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   175
                mode->format = SDL_PIXELFORMAT_INDEX4LSB;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   176
                break;
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   177
            }
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3175
diff changeset
   178
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    }
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   180
}
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   181
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   182
static SDL_bool
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   183
WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   184
{
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   185
    SDL_DisplayModeData *data;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   186
    DEVMODE devmode;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   187
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   188
    devmode.dmSize = sizeof(devmode);
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   189
    devmode.dmDriverExtra = 0;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   190
    if (!EnumDisplaySettings(deviceName, index, &devmode)) {
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   191
        return SDL_FALSE;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   192
    }
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   193
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   194
    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   195
    if (!data) {
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   196
        return SDL_FALSE;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   197
    }
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   198
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   199
    mode->driverdata = data;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   200
    data->DeviceMode = devmode;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   201
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   202
    /* Default basic information */
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   203
    data->ScaleX = 1.0f;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   204
    data->ScaleY = 1.0f;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   205
    data->DiagDPI = 0.0f;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   206
    data->HorzDPI = 0.0f;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   207
    data->VertDPI = 0.0f;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   208
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   209
    mode->format = SDL_PIXELFORMAT_UNKNOWN;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   210
    mode->w = data->DeviceMode.dmPelsWidth;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   211
    mode->h = data->DeviceMode.dmPelsHeight;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   212
    mode->refresh_rate = data->DeviceMode.dmDisplayFrequency;
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   213
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   214
    /* Fill in the mode information */
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   215
    WIN_UpdateDisplayMode(_this, deviceName, index, mode);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
    return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   219
static SDL_bool
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   220
WIN_AddDisplay(_THIS, LPTSTR DeviceName)
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   221
{
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   222
    SDL_VideoDisplay display;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   223
    SDL_DisplayData *displaydata;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   224
    SDL_DisplayMode mode;
6793
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   225
    DISPLAY_DEVICE device;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   226
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   227
#ifdef DEBUG_MODES
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   228
    printf("Display: %s\n", WIN_StringToUTF8(DeviceName));
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   229
#endif
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   230
    if (!WIN_GetDisplayMode(_this, DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   231
        return SDL_FALSE;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   232
    }
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   233
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   234
    displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   235
    if (!displaydata) {
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   236
        return SDL_FALSE;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   237
    }
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   238
    SDL_memcpy(displaydata->DeviceName, DeviceName,
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   239
               sizeof(displaydata->DeviceName));
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   240
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   241
    SDL_zero(display);
6793
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   242
    device.cb = sizeof(device);
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   243
    if (EnumDisplayDevices(DeviceName, 0, &device, 0)) {
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   244
        display.name = WIN_StringToUTF8(device.DeviceString);
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   245
    }
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   246
    display.desktop_mode = mode;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   247
    display.current_mode = mode;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   248
    display.driverdata = displaydata;
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   249
    SDL_AddVideoDisplay(&display);
6793
c8d1036975b7 Implemented getting the display name on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   250
    SDL_free(display.name);
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   251
    return SDL_TRUE;
2119
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   252
}
9341a884a4d9 Fixed running on Windows under VMware
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   253
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   254
int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
WIN_InitModes(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
{
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   257
    int pass;
2149
eba4fd03b4f6 Fixed mode code under VMware running Windows 98
Sam Lantinga <slouken@libsdl.org>
parents: 2119
diff changeset
   258
    DWORD i, j, count;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
    DISPLAY_DEVICE device;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
    device.cb = sizeof(device);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   263
    /* Get the primary display in the first pass */
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   264
    for (pass = 0; pass < 2; ++pass) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   265
        for (i = 0; ; ++i) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   266
            TCHAR DeviceName[32];
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   267
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   268
            if (!EnumDisplayDevices(NULL, i, &device, 0)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
            if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
                continue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
            }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   274
            if (pass == 0) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   275
                if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   276
                    continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   277
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   278
            } else {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   279
                if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   280
                    continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   281
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   282
            }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   283
            SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   284
#ifdef DEBUG_MODES
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   285
            printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   286
#endif
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   287
            count = 0;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   288
            for (j = 0; ; ++j) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   289
                if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   290
                    break;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   291
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   292
                if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   293
                    continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   294
                }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   295
                if (pass == 0) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   296
                    if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   297
                        continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   298
                    }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   299
                } else {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   300
                    if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   301
                        continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   302
                    }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   303
                }
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   304
                count += WIN_AddDisplay(_this, device.DeviceName);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   305
            }
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   306
            if (count == 0) {
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   307
                WIN_AddDisplay(_this, DeviceName);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   308
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    }
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   311
    if (_this->num_displays == 0) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   312
        return SDL_SetError("No displays available");
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   313
    }
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   314
    return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   317
int
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   318
WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   319
{
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   320
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   321
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   322
    rect->x = (int)SDL_ceil(data->DeviceMode.dmPosition.x * data->ScaleX);
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   323
    rect->y = (int)SDL_ceil(data->DeviceMode.dmPosition.y * data->ScaleY);
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   324
    rect->w = (int)SDL_ceil(data->DeviceMode.dmPelsWidth * data->ScaleX);
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   325
    rect->h = (int)SDL_ceil(data->DeviceMode.dmPelsHeight * data->ScaleY);
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
   326
3528
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   327
    return 0;
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   328
}
59ff7a2beb57 Added an API function to query geometry of multiple monitors:
Sam Lantinga <slouken@libsdl.org>
parents: 3521
diff changeset
   329
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   330
int
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   331
WIN_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   332
{
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   333
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   334
9889
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   335
    if (ddpi) {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   336
        *ddpi = data->DiagDPI;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   337
    }
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   338
    if (hdpi) {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   339
        *hdpi = data->HorzDPI;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   340
    }
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   341
    if (vdpi) {
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   342
        *vdpi = data->VertDPI;
7cb2c3ec8205 Converted tabs to spaces for SDL style
Sam Lantinga <slouken@libsdl.org>
parents: 9819
diff changeset
   343
    }
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   344
10174
284022a7f51e Windows: Fixed missing error message if SDL_GetDisplayDPI() failed.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 10117
diff changeset
   345
    return data->DiagDPI != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   346
}
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   347
10019
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   348
int
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   349
WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   350
{
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   351
    const SDL_DisplayModeData *data = (const SDL_DisplayModeData *) display->current_mode.driverdata;
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   352
    const DEVMODE *pDevMode = &data->DeviceMode;
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   353
    POINT pt = {
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   354
        /* !!! FIXME: no scale, right? */
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   355
        (LONG) (pDevMode->dmPosition.x + (pDevMode->dmPelsWidth / 2)),
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   356
        (LONG) (pDevMode->dmPosition.y + (pDevMode->dmPelsHeight / 2))
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   357
    };
10031
2b3baddd9afa Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 10019
diff changeset
   358
    HMONITOR hmon = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL);
10019
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   359
    MONITORINFO minfo;
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   360
    const RECT *work;
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   361
    BOOL rc = FALSE;
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   362
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   363
    SDL_assert(hmon != NULL);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   364
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   365
    if (hmon != NULL) {
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   366
        SDL_zero(minfo);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   367
        minfo.cbSize = sizeof (MONITORINFO);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   368
        rc = GetMonitorInfo(hmon, &minfo);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   369
        SDL_assert(rc);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   370
    }
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   371
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   372
    if (!rc) {
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   373
        return SDL_SetError("Couldn't find monitor data");
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   374
    }
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   375
10031
2b3baddd9afa Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 10019
diff changeset
   376
    work = &minfo.rcWork;
10019
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   377
    rect->x = (int)SDL_ceil(work->left * data->ScaleX);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   378
    rect->y = (int)SDL_ceil(work->top * data->ScaleY);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   379
    rect->w = (int)SDL_ceil((work->right - work->left) * data->ScaleX);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   380
    rect->h = (int)SDL_ceil((work->bottom - work->top) * data->ScaleY);
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   381
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   382
    return 0;
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   383
}
36f7e8084508 Added SDL_GetDisplayUsableBounds().
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   384
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   386
WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
{
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   388
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
    DWORD i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
    SDL_DisplayMode mode;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
    for (i = 0;; ++i) {
9813
0652406e46c6 Add SDL_GetDisplayDPI routine and implement for Windows.
Alfred Reynolds <alfred@valvesoftware.com>
parents: 9619
diff changeset
   393
        if (!WIN_GetDisplayMode(_this, data->DeviceName, i, &mode)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
        }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   396
        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   397
            /* We don't support palettized modes now */
7102
b9fa5a2acbfd Bug 1786 - memory leak in WIN_GetDisplayModes by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   398
            SDL_free(mode.driverdata);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   399
            continue;
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   400
        }
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   401
        if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   402
            if (!SDL_AddDisplayMode(display, &mode)) {
3175
e6c113f1ea43 Fixed support for 4bpp video modes enumeration, otherwise mode with zero bpp appears in the list.
Mike Gorchak <lestat@i.com.ua>
parents: 3139
diff changeset
   403
                SDL_free(mode.driverdata);
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3175
diff changeset
   404
            }
8086
b744b3f8754b Fixed display mode calculations for applications which are not DPI aware.
Sam Lantinga <slouken@libsdl.org>
parents: 7102
diff changeset
   405
        } else {
7102
b9fa5a2acbfd Bug 1786 - memory leak in WIN_GetDisplayModes by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   406
            SDL_free(mode.driverdata);
b9fa5a2acbfd Bug 1786 - memory leak in WIN_GetDisplayModes by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   407
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   412
WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
{
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   414
    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    LONG status;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3097
diff changeset
   417
8795
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   418
    if (mode->driverdata == display->desktop_mode.driverdata) {
10179
7cbfd97f1430 Windows: Fix other window positions/sizes being changed when exiting exclusive fullscreen (bug #3315, thanks Simon Hug!)
Alex Szpakowski <slime73@gmail.com>
parents: 10174
diff changeset
   419
        status = ChangeDisplaySettingsEx(displaydata->DeviceName, NULL, NULL, CDS_FULLSCREEN, NULL);
8795
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   420
    } else {
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   421
        status = ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL);
513d97ffe10d Fullscreen to windowed mode switch
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   422
    }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   423
    if (status != DISP_CHANGE_SUCCESSFUL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
        const char *reason = "Unknown reason";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
        switch (status) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
        case DISP_CHANGE_BADFLAGS:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
            reason = "DISP_CHANGE_BADFLAGS";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
        case DISP_CHANGE_BADMODE:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
            reason = "DISP_CHANGE_BADMODE";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
        case DISP_CHANGE_BADPARAM:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
            reason = "DISP_CHANGE_BADPARAM";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
        case DISP_CHANGE_FAILED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
            reason = "DISP_CHANGE_FAILED";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
        }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   439
        return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
    }
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   441
    EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
10117
7552aa4c1c6d Pick up new display mode information after a mode change (Windows only right now).
Sam Lantinga <slouken@libsdl.org>
parents: 10031
diff changeset
   442
    WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   443
    return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
WIN_QuitModes(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
{
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   449
    /* All fullscreen windows should have restored modes by now */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   452
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   453
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
/* vi: set ts=4 sw=4 expandtab: */