Implemented querying the orientation of displays on Windows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c
index e8b1fc1..3abb5d4 100644
--- a/src/video/windows/SDL_windowsmodes.c
+++ b/src/video/windows/SDL_windowsmodes.c
@@ -108,8 +108,50 @@ WIN_UpdateDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode *
}
}
+static SDL_DisplayOrientation
+WIN_GetDisplayOrientation(DEVMODE *mode)
+{
+ int width = mode->dmPelsWidth;
+ int height = mode->dmPelsHeight;
+
+ /* Use unrotated width/height to guess orientation */
+ if (mode->dmDisplayOrientation == DMDO_90 || mode->dmDisplayOrientation == DMDO_270) {
+ int temp = width;
+ width = height;
+ height = temp;
+ }
+
+ if (width >= height) {
+ switch (mode->dmDisplayOrientation) {
+ case DMDO_DEFAULT:
+ return SDL_ORIENTATION_LANDSCAPE;
+ case DMDO_90:
+ return SDL_ORIENTATION_PORTRAIT;
+ case DMDO_180:
+ return SDL_ORIENTATION_LANDSCAPE_FLIPPED;
+ case DMDO_270:
+ return SDL_ORIENTATION_PORTRAIT_FLIPPED;
+ default:
+ return SDL_ORIENTATION_UNKNOWN;
+ }
+ } else {
+ switch (mode->dmDisplayOrientation) {
+ case DMDO_DEFAULT:
+ return SDL_ORIENTATION_PORTRAIT;
+ case DMDO_90:
+ return SDL_ORIENTATION_LANDSCAPE_FLIPPED;
+ case DMDO_180:
+ return SDL_ORIENTATION_PORTRAIT_FLIPPED;
+ case DMDO_270:
+ return SDL_ORIENTATION_LANDSCAPE;
+ default:
+ return SDL_ORIENTATION_UNKNOWN;
+ }
+ }
+}
+
static SDL_bool
-WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mode)
+WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mode, SDL_DisplayOrientation *orientation)
{
SDL_DisplayModeData *data;
DEVMODE devmode;
@@ -135,6 +177,11 @@ WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mod
/* Fill in the mode information */
WIN_UpdateDisplayMode(_this, deviceName, index, mode);
+
+ if (orientation) {
+ *orientation = WIN_GetDisplayOrientation(&devmode);
+ }
+
return SDL_TRUE;
}
@@ -145,13 +192,14 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se
SDL_VideoDisplay display;
SDL_DisplayData *displaydata;
SDL_DisplayMode mode;
+ SDL_DisplayOrientation orientation;
DISPLAY_DEVICEW device;
#ifdef DEBUG_MODES
SDL_Log("Display: %s\n", WIN_StringToUTF8W(info->szDevice));
#endif
- if (!WIN_GetDisplayMode(_this, info->szDevice, ENUM_CURRENT_SETTINGS, &mode)) {
+ if (!WIN_GetDisplayMode(_this, info->szDevice, ENUM_CURRENT_SETTINGS, &mode, &orientation)) {
return SDL_FALSE;
}
@@ -183,6 +231,7 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se
}
display.desktop_mode = mode;
display.current_mode = mode;
+ display.orientation = orientation;
display.driverdata = displaydata;
SDL_AddVideoDisplay(&display, send_event);
SDL_free(display.name);
@@ -357,7 +406,7 @@ WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
SDL_DisplayMode mode;
for (i = 0;; ++i) {
- if (!WIN_GetDisplayMode(_this, data->DeviceName, i, &mode)) {
+ if (!WIN_GetDisplayMode(_this, data->DeviceName, i, &mode, NULL)) {
break;
}
if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {