WinRT: fixed bug whereby landscape-only apps, as configured via an app's Package.appxmanifest file, would report an incorrect display mode on app init, if the device was in portrait mode
authorDavid Ludwig <dludwig@pobox.com>
Sun, 26 May 2013 20:27:13 -0400
changeset 8475 a325f77bae36
parent 8474 cbf580f6ea1b
child 8476 25883bdf3cab
WinRT: fixed bug whereby landscape-only apps, as configured via an app's Package.appxmanifest file, would report an incorrect display mode on app init, if the device was in portrait mode
src/video/windowsrt/SDL_winrtvideo.cpp
--- a/src/video/windowsrt/SDL_winrtvideo.cpp	Sun May 26 19:40:12 2013 -0400
+++ b/src/video/windowsrt/SDL_winrtvideo.cpp	Sun May 26 20:27:13 2013 -0400
@@ -121,10 +121,49 @@
 int
 WINRT_VideoInit(_THIS)
 {
+    // Pump events once, in order to flush out and process any pending
+    // window-size change events.  Doing this addresses the following:
+    //
+    // 1. An app, set to start up as a Landscape-only app (via a
+    //    Package.appxmanifest file), starts up on a device that is in Portrait
+    //    mode.
+    // 2. Control of the app reaches this function (WINRT_VideoInit).
+    // 3. The 'Size' property of the app's CoreWindow (a WinRT-defined object)
+    //    is not sized as if it were running on a device in landscape mode, but
+    //    rather, it's sized in portrait mode.  To note, this property will
+    //    normally changes as a device rotates, however it hasn't changed just yet.
+    // 4. WINRT_VideoInit calls WINRT_InitModes, which uses the app's
+    //    CoreWindow to register a display mode, whose width and height are
+    //    still oriented in portrait.
+    // 5. Once WINRT_VideoInit returns, and once control leaves SDL (and back
+    //    into its calling app), SDL_GetDisplayMode is called, which returns the
+    //    portrait-oriented display mode.  (Remember, this is supposed to be a
+    //    landscape-only app.)
+    // 6. The portrait-oriented display mode is used to initialize other
+    //    things.  The CoreWindow's size eventually changes (and window-resize
+    //    events are sent out accordingly), but damage has already been done,
+    //    as a variety of things were set up using the portrait-oriented
+    //    display mode (rather than a landscape-oriented display mode).
+    //
+    // By pumping events once, WinRT will make sure that the app's
+    // CoreWindow will get its size updated, and that a correctly-oriented
+    // display mode gets registered.
+    //
+    // Please note that if SDL_SetHint is used to set the app's orientation
+    // (in conjunction with SDL_HINT_ORIENTATION), then this technique will
+    // not work.  The size of the app's CoreWindow will still be off.  This
+    // technique is only known to fix cases where an app's orientation is set
+    // via its app-settings file, Package.appxmanifest.
+    SDL_WinRTGlobalApp->PumpEvents();
+
+    //
+    // Now that any pending window-size change events have been processed,
+    // continue initializing the SDL/WinRT video backend:
+    //
+
     if (WINRT_InitModes(_this) < 0) {
         return -1;
     }
-
     WINRT_InitMouse(_this);
 
     return 0;