src/video/winrt/SDL_winrtvideo_cpp.h
author David Ludwig
Sat, 20 Aug 2016 13:46:45 -0400
changeset 10222 29d7289e9055
parent 9998 f67cf37e9cd4
child 10293 db77073d402d
permissions -rw-r--r--
WinRT: fixed bug where Win10 GameBar, when shown + hidden, might not restore a cursor's hidden state

The repro steps were this:
1. run an sdl2 winrt/uwp app, on Win10, v10.0.10586.0 or higher
2. hide the cursor, via a call to SDL_ShowCursor(0)
3. make the Win10 game bar appear, by pressing the Windows + G hotkey
4. observe that the mouse cursor appears, in order to interact with the
game bar (this is expected behavior)
5. make the Win10 game bar disappear, either by pressing the Windows + G hotkey
again, or clicking somewhere in the app

EXPECTED RESULT: cursor disappears, as game bar disappears

ACTUAL RESULT: cursor didn't always disappear
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /* Windows includes: */
    23 #include <windows.h>
    24 #ifdef __cplusplus_winrt
    25 #include <agile.h>
    26 #endif
    27 
    28 /* SDL includes: */
    29 #include "SDL_video.h"
    30 #include "SDL_events.h"
    31 
    32 #if NTDDI_VERSION >= NTDDI_WINBLUE  /* ApplicationView's functionality only becomes
    33                                        useful for SDL in Win[Phone] 8.1 and up.
    34                                        Plus, it is not available at all in WinPhone 8.0. */
    35 #define SDL_WINRT_USE_APPLICATIONVIEW 1
    36 #endif
    37 
    38 extern "C" {
    39 #include "../SDL_sysvideo.h"
    40 #include "../SDL_egl_c.h"
    41 }
    42 
    43 /* Private display data */
    44 typedef struct SDL_VideoData {
    45     /* An object created by ANGLE/WinRT (OpenGL ES 2 for WinRT) that gets
    46      * passed to eglGetDisplay and eglCreateWindowSurface:
    47      */
    48     IUnknown *winrtEglWindow;
    49 
    50     /* Event token(s), for unregistering WinRT event handler(s).
    51        These are just a struct with a 64-bit integer inside them
    52     */
    53     Windows::Foundation::EventRegistrationToken gameBarIsInputRedirectedToken;
    54 } SDL_VideoData;
    55 
    56 /* The global, WinRT, SDL Window.
    57    For now, SDL/WinRT only supports one window (due to platform limitations of
    58    WinRT.
    59 */
    60 extern SDL_Window * WINRT_GlobalSDLWindow;
    61 
    62 /* Updates one or more SDL_Window flags, by querying the OS' native windowing APIs.
    63    SDL_Window flags that can be updated should be specified in 'mask'.
    64 */
    65 extern void WINRT_UpdateWindowFlags(SDL_Window * window, Uint32 mask);
    66 extern "C" Uint32 WINRT_DetectWindowFlags(SDL_Window * window);  /* detects flags w/o applying them */
    67 
    68 /* Display mode internals */
    69 //typedef struct
    70 //{
    71 //    Windows::Graphics::Display::DisplayOrientations currentOrientation;
    72 //} SDL_DisplayModeData;
    73 
    74 #ifdef __cplusplus_winrt
    75 
    76 /* A convenience macro to get a WinRT display property */
    77 #if NTDDI_VERSION > NTDDI_WIN8
    78 #define WINRT_DISPLAY_PROPERTY(NAME) (Windows::Graphics::Display::DisplayInformation::GetForCurrentView()->NAME)
    79 #else
    80 #define WINRT_DISPLAY_PROPERTY(NAME) (Windows::Graphics::Display::DisplayProperties::NAME)
    81 #endif
    82 
    83 /* Converts DIPS to/from physical pixels */
    84 #define WINRT_DIPS_TO_PHYSICAL_PIXELS(DIPS)     ((int)(0.5f + (((float)(DIPS) * (float)WINRT_DISPLAY_PROPERTY(LogicalDpi)) / 96.f)))
    85 #define WINRT_PHYSICAL_PIXELS_TO_DIPS(PHYSPIX)  (((float)(PHYSPIX) * 96.f)/WINRT_DISPLAY_PROPERTY(LogicalDpi))
    86 
    87 /* Internal window data */
    88 struct SDL_WindowData
    89 {
    90     SDL_Window *sdlWindow;
    91     Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
    92 #ifdef SDL_VIDEO_OPENGL_EGL
    93     EGLSurface egl_surface;
    94 #endif
    95 #if SDL_WINRT_USE_APPLICATIONVIEW
    96     Windows::UI::ViewManagement::ApplicationView ^ appView;
    97 #endif
    98 };
    99 
   100 #endif // ifdef __cplusplus_winrt