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.1 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj Wed Aug 17 21:05:00 2016 +0200
1.2 +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj Sat Aug 20 13:46:45 2016 -0400
1.3 @@ -156,6 +156,7 @@
1.4 <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
1.5 <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
1.6 <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
1.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
1.8 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
1.9 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
1.10 <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
1.11 @@ -311,6 +312,14 @@
1.12 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
1.13 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
1.14 </ClCompile>
1.15 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
1.16 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
1.17 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
1.18 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
1.19 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
1.20 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
1.21 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
1.22 + </ClCompile>
1.23 <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
1.24 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
1.25 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
2.1 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters Wed Aug 17 21:05:00 2016 +0200
2.2 +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters Sat Aug 20 13:46:45 2016 -0400
2.3 @@ -402,6 +402,9 @@
2.4 <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2.h">
2.5 <Filter>Source Files</Filter>
2.6 </ClInclude>
2.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
2.8 + <Filter>Source Files</Filter>
2.9 + </ClInclude>
2.10 </ItemGroup>
2.11 <ItemGroup>
2.12 <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
2.13 @@ -716,5 +719,8 @@
2.14 <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2.c">
2.15 <Filter>Source Files</Filter>
2.16 </ClCompile>
2.17 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
2.18 + <Filter>Source Files</Filter>
2.19 + </ClCompile>
2.20 </ItemGroup>
2.21 </Project>
2.22 \ No newline at end of file
3.1 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj Wed Aug 17 21:05:00 2016 +0200
3.2 +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj Sat Aug 20 13:46:45 2016 -0400
3.3 @@ -273,6 +273,7 @@
3.4 <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
3.5 <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
3.6 <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
3.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
3.8 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
3.9 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
3.10 <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
3.11 @@ -408,6 +409,12 @@
3.12 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
3.13 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
3.14 </ClCompile>
3.15 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
3.16 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
3.17 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
3.18 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
3.19 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
3.20 + </ClCompile>
3.21 <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
3.22 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
3.23 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
4.1 --- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters Wed Aug 17 21:05:00 2016 +0200
4.2 +++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters Sat Aug 20 13:46:45 2016 -0400
4.3 @@ -372,6 +372,9 @@
4.4 <ClInclude Include="..\..\src\video\SDL_egl_c.h">
4.5 <Filter>Source Files</Filter>
4.6 </ClInclude>
4.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
4.8 + <Filter>Source Files</Filter>
4.9 + </ClInclude>
4.10 </ItemGroup>
4.11 <ItemGroup>
4.12 <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
4.13 @@ -674,5 +677,8 @@
4.14 <ClCompile Include="..\..\src\video\SDL_egl.c">
4.15 <Filter>Source Files</Filter>
4.16 </ClCompile>
4.17 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
4.18 + <Filter>Source Files</Filter>
4.19 + </ClCompile>
4.20 </ItemGroup>
4.21 </Project>
4.22 \ No newline at end of file
5.1 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj Wed Aug 17 21:05:00 2016 +0200
5.2 +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj Sat Aug 20 13:46:45 2016 -0400
5.3 @@ -139,6 +139,7 @@
5.4 <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
5.5 <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
5.6 <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
5.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
5.8 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
5.9 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
5.10 <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
5.11 @@ -275,6 +276,12 @@
5.12 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
5.13 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
5.14 </ClCompile>
5.15 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
5.16 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
5.17 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
5.18 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
5.19 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
5.20 + </ClCompile>
5.21 <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
5.22 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
5.23 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
6.1 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters Wed Aug 17 21:05:00 2016 +0200
6.2 +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters Sat Aug 20 13:46:45 2016 -0400
6.3 @@ -381,6 +381,9 @@
6.4 <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
6.5 <Filter>Source Files</Filter>
6.6 </ClInclude>
6.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
6.8 + <Filter>Source Files</Filter>
6.9 + </ClInclude>
6.10 </ItemGroup>
6.11 <ItemGroup>
6.12 <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
6.13 @@ -686,5 +689,8 @@
6.14 <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c">
6.15 <Filter>Source Files</Filter>
6.16 </ClCompile>
6.17 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
6.18 + <Filter>Source Files</Filter>
6.19 + </ClCompile>
6.20 </ItemGroup>
6.21 </Project>
6.22 \ No newline at end of file
7.1 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj Wed Aug 17 21:05:00 2016 +0200
7.2 +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj Sat Aug 20 13:46:45 2016 -0400
7.3 @@ -175,6 +175,14 @@
7.4 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
7.5 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
7.6 </ClCompile>
7.7 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
7.8 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
7.9 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
7.10 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
7.11 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
7.12 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
7.13 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
7.14 + </ClCompile>
7.15 <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
7.16 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
7.17 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
7.18 @@ -353,6 +361,7 @@
7.19 <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
7.20 <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
7.21 <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
7.22 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
7.23 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
7.24 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
7.25 <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
8.1 --- a/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters Wed Aug 17 21:05:00 2016 +0200
8.2 +++ b/VisualC-WinRT/WinRT80_VS2012/SDL-WinRT80.vcxproj.filters Sat Aug 20 13:46:45 2016 -0400
8.3 @@ -316,6 +316,9 @@
8.4 <ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c">
8.5 <Filter>Source Files</Filter>
8.6 </ClCompile>
8.7 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
8.8 + <Filter>Source Files</Filter>
8.9 + </ClCompile>
8.10 </ItemGroup>
8.11 <ItemGroup>
8.12 <ClInclude Include="..\..\include\begin_code.h">
8.13 @@ -714,6 +717,9 @@
8.14 <ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h">
8.15 <Filter>Source Files</Filter>
8.16 </ClInclude>
8.17 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
8.18 + <Filter>Source Files</Filter>
8.19 + </ClInclude>
8.20 </ItemGroup>
8.21 <ItemGroup>
8.22 <Filter Include="Header Files">
9.1 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj Wed Aug 17 21:05:00 2016 +0200
9.2 +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj Sat Aug 20 13:46:45 2016 -0400
9.3 @@ -153,6 +153,7 @@
9.4 <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
9.5 <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
9.6 <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
9.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h" />
9.8 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h" />
9.9 <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h" />
9.10 <ClInclude Include="..\..\src\video\winrt\SDL_winrtopengles.h" />
9.11 @@ -309,6 +310,14 @@
9.12 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
9.13 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
9.14 </ClCompile>
9.15 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
9.16 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
9.17 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
9.18 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
9.19 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
9.20 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
9.21 + <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
9.22 + </ClCompile>
9.23 <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
9.24 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
9.25 <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
10.1 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters Wed Aug 17 21:05:00 2016 +0200
10.2 +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters Sat Aug 20 13:46:45 2016 -0400
10.3 @@ -393,6 +393,9 @@
10.4 <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h">
10.5 <Filter>Source Files</Filter>
10.6 </ClInclude>
10.7 + <ClInclude Include="..\..\src\video\winrt\SDL_winrtgamebar_cpp.h">
10.8 + <Filter>Source Files</Filter>
10.9 + </ClInclude>
10.10 </ItemGroup>
10.11 <ItemGroup>
10.12 <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
10.13 @@ -710,5 +713,8 @@
10.14 <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c">
10.15 <Filter>Source Files</Filter>
10.16 </ClCompile>
10.17 + <ClCompile Include="..\..\src\video\winrt\SDL_winrtgamebar.cpp">
10.18 + <Filter>Source Files</Filter>
10.19 + </ClCompile>
10.20 </ItemGroup>
10.21 </Project>
10.22 \ No newline at end of file
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/src/video/winrt/SDL_winrtgamebar.cpp Sat Aug 20 13:46:45 2016 -0400
11.3 @@ -0,0 +1,196 @@
11.4 +/*
11.5 + Simple DirectMedia Layer
11.6 + Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
11.7 +
11.8 + This software is provided 'as-is', without any express or implied
11.9 + warranty. In no event will the authors be held liable for any damages
11.10 + arising from the use of this software.
11.11 +
11.12 + Permission is granted to anyone to use this software for any purpose,
11.13 + including commercial applications, and to alter it and redistribute it
11.14 + freely, subject to the following restrictions:
11.15 +
11.16 + 1. The origin of this software must not be misrepresented; you must not
11.17 + claim that you wrote the original software. If you use this software
11.18 + in a product, an acknowledgment in the product documentation would be
11.19 + appreciated but is not required.
11.20 + 2. Altered source versions must be plainly marked as such, and must not be
11.21 + misrepresented as being the original software.
11.22 + 3. This notice may not be removed or altered from any source distribution.
11.23 +*/
11.24 +#include "../../SDL_internal.h"
11.25 +
11.26 +#if SDL_VIDEO_DRIVER_WINRT
11.27 +
11.28 +/* Windows includes */
11.29 +#include <roapi.h>
11.30 +#include <windows.foundation.h>
11.31 +#include <EventToken.h>
11.32 +
11.33 +
11.34 +/* SDL includes */
11.35 +extern "C" {
11.36 +#include "SDL_mouse.h"
11.37 +#include "../SDL_sysvideo.h"
11.38 +}
11.39 +#include "SDL_winrtvideo_cpp.h"
11.40 +
11.41 +
11.42 +/* Game Bar events can come in off the main thread. Use the following
11.43 + WinRT CoreDispatcher to deal with them on SDL's thread.
11.44 +*/
11.45 +static Platform::WeakReference WINRT_MainThreadDispatcher;
11.46 +
11.47 +
11.48 +/* Win10's initial SDK (the 10.0.10240.0 release) does not include references
11.49 + to Game Bar APIs, as the Game Bar was released via Win10 10.0.10586.0.
11.50 +
11.51 + Declare its WinRT/COM interface here, to allow compilation with earlier
11.52 + Windows SDKs.
11.53 +*/
11.54 +MIDL_INTERFACE("1DB9A292-CC78-4173-BE45-B61E67283EA7")
11.55 +IGameBarStatics_ : public IInspectable
11.56 +{
11.57 +public:
11.58 + virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged(
11.59 + __FIEventHandler_1_IInspectable *handler,
11.60 + Windows::Foundation::EventRegistrationToken *token) = 0;
11.61 +
11.62 + virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged(
11.63 + Windows::Foundation::EventRegistrationToken token) = 0;
11.64 +
11.65 + virtual HRESULT STDMETHODCALLTYPE add_IsInputRedirectedChanged(
11.66 + __FIEventHandler_1_IInspectable *handler,
11.67 + Windows::Foundation::EventRegistrationToken *token) = 0;
11.68 +
11.69 + virtual HRESULT STDMETHODCALLTYPE remove_IsInputRedirectedChanged(
11.70 + Windows::Foundation::EventRegistrationToken token) = 0;
11.71 +
11.72 + virtual HRESULT STDMETHODCALLTYPE get_Visible(
11.73 + boolean *value) = 0;
11.74 +
11.75 + virtual HRESULT STDMETHODCALLTYPE get_IsInputRedirected(
11.76 + boolean *value) = 0;
11.77 +};
11.78 +
11.79 +/* Declare the game bar's COM GUID */
11.80 +static GUID IID_IGameBarStatics_ = { MAKELONG(0xA292, 0x1DB9), 0xCC78, 0x4173, { 0xBE, 0x45, 0xB6, 0x1E, 0x67, 0x28, 0x3E, 0xA7 } };
11.81 +
11.82 +/* Retrieves a pointer to the game bar, or NULL if it is not available.
11.83 + If a pointer is returned, it's ->Release() method must be called
11.84 + after the caller has finished using it.
11.85 +*/
11.86 +static IGameBarStatics_ *
11.87 +WINRT_GetGameBar()
11.88 +{
11.89 + wchar_t *wClassName = L"Windows.Gaming.UI.GameBar";
11.90 + HSTRING hClassName;
11.91 + IActivationFactory *pActivationFactory = NULL;
11.92 + IGameBarStatics_ *pGameBar = NULL;
11.93 + HRESULT hr;
11.94 +
11.95 + hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName);
11.96 + if (FAILED(hr)) {
11.97 + goto done;
11.98 + }
11.99 +
11.100 + hr = Windows::Foundation::GetActivationFactory(hClassName, &pActivationFactory);
11.101 + if (FAILED(hr)) {
11.102 + goto done;
11.103 + }
11.104 +
11.105 + pActivationFactory->QueryInterface(IID_IGameBarStatics_, (void **) &pGameBar);
11.106 +
11.107 +done:
11.108 + if (pActivationFactory) {
11.109 + pActivationFactory->Release();
11.110 + }
11.111 + if (hClassName) {
11.112 + ::WindowsDeleteString(hClassName);
11.113 + }
11.114 + return pGameBar;
11.115 +}
11.116 +
11.117 +static void
11.118 +WINRT_HandleGameBarIsInputRedirected_MainThread()
11.119 +{
11.120 + IGameBarStatics_ *gameBar;
11.121 + boolean isInputRedirected = 0;
11.122 + if (!WINRT_MainThreadDispatcher) {
11.123 + /* The game bar event handler has been deregistered! */
11.124 + return;
11.125 + }
11.126 + gameBar = WINRT_GetGameBar();
11.127 + if (!gameBar) {
11.128 + /* Shouldn't happen, but just in case... */
11.129 + return;
11.130 + }
11.131 + if (SUCCEEDED(gameBar->get_IsInputRedirected(&isInputRedirected))) {
11.132 + if ( ! isInputRedirected) {
11.133 + /* Input-control is now back to the SDL app. Restore the cursor,
11.134 + in case Windows does not (it does not in either Win10
11.135 + 10.0.10240.0 or 10.0.10586.0, maybe later version(s) too.
11.136 + */
11.137 + SDL_Cursor *cursor = SDL_GetCursor();
11.138 + SDL_SetCursor(cursor);
11.139 + }
11.140 + }
11.141 + gameBar->Release();
11.142 +}
11.143 +
11.144 +static void
11.145 +WINRT_HandleGameBarIsInputRedirected_NonMainThread(Platform::Object ^ o1, Platform::Object ^o2)
11.146 +{
11.147 + Windows::UI::Core::CoreDispatcher ^dispatcher = WINRT_MainThreadDispatcher.Resolve<Windows::UI::Core::CoreDispatcher>();
11.148 + if (dispatcher) {
11.149 + dispatcher->RunAsync(
11.150 + Windows::UI::Core::CoreDispatcherPriority::Normal,
11.151 + ref new Windows::UI::Core::DispatchedHandler(&WINRT_HandleGameBarIsInputRedirected_MainThread));
11.152 + }
11.153 +}
11.154 +
11.155 +void
11.156 +WINRT_InitGameBar(_THIS)
11.157 +{
11.158 + SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata;
11.159 + IGameBarStatics_ *gameBar = WINRT_GetGameBar();
11.160 + if (gameBar) {
11.161 + /* GameBar.IsInputRedirected events can come in via something other than
11.162 + the main/SDL thread.
11.163 +
11.164 + Get a WinRT 'CoreDispatcher' that can be used to call back into the
11.165 + SDL thread.
11.166 + */
11.167 + WINRT_MainThreadDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
11.168 + Windows::Foundation::EventHandler<Platform::Object ^> ^handler = \
11.169 + ref new Windows::Foundation::EventHandler<Platform::Object ^>(&WINRT_HandleGameBarIsInputRedirected_NonMainThread);
11.170 + __FIEventHandler_1_IInspectable * pHandler = reinterpret_cast<__FIEventHandler_1_IInspectable *>(handler);
11.171 + gameBar->add_IsInputRedirectedChanged(pHandler, &driverdata->gameBarIsInputRedirectedToken);
11.172 + gameBar->Release();
11.173 + }
11.174 +}
11.175 +
11.176 +void
11.177 +WINRT_QuitGameBar(_THIS)
11.178 +{
11.179 + SDL_VideoData *driverdata;
11.180 + IGameBarStatics_ *gameBar;
11.181 + if (!_this || !_this->driverdata) {
11.182 + return;
11.183 + }
11.184 + gameBar = WINRT_GetGameBar();
11.185 + if (!gameBar) {
11.186 + return;
11.187 + }
11.188 + driverdata = (SDL_VideoData *)_this->driverdata;
11.189 + if (driverdata->gameBarIsInputRedirectedToken.Value) {
11.190 + gameBar->remove_IsInputRedirectedChanged(driverdata->gameBarIsInputRedirectedToken);
11.191 + driverdata->gameBarIsInputRedirectedToken.Value = 0;
11.192 + }
11.193 + WINRT_MainThreadDispatcher = nullptr;
11.194 + gameBar->Release();
11.195 +}
11.196 +
11.197 +#endif /* SDL_VIDEO_DRIVER_WINRT */
11.198 +
11.199 +/* vi: set ts=4 sw=4 expandtab: */
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/src/video/winrt/SDL_winrtgamebar_cpp.h Sat Aug 20 13:46:45 2016 -0400
12.3 @@ -0,0 +1,35 @@
12.4 +/*
12.5 + Simple DirectMedia Layer
12.6 + Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
12.7 +
12.8 + This software is provided 'as-is', without any express or implied
12.9 + warranty. In no event will the authors be held liable for any damages
12.10 + arising from the use of this software.
12.11 +
12.12 + Permission is granted to anyone to use this software for any purpose,
12.13 + including commercial applications, and to alter it and redistribute it
12.14 + freely, subject to the following restrictions:
12.15 +
12.16 + 1. The origin of this software must not be misrepresented; you must not
12.17 + claim that you wrote the original software. If you use this software
12.18 + in a product, an acknowledgment in the product documentation would be
12.19 + appreciated but is not required.
12.20 + 2. Altered source versions must be plainly marked as such, and must not be
12.21 + misrepresented as being the original software.
12.22 + 3. This notice may not be removed or altered from any source distribution.
12.23 +*/
12.24 +#include "SDL_config.h"
12.25 +
12.26 +#ifndef _SDL_winrtgamebar_h
12.27 +#define _SDL_winrtgamebar_h
12.28 +
12.29 +#ifdef __cplusplus
12.30 +/* These are exported as C++ functions, rather than C, to fix a compilation
12.31 + bug with MSVC 2013, for Windows 8.x builds. */
12.32 +extern void WINRT_InitGameBar(_THIS);
12.33 +extern void WINRT_QuitGameBar(_THIS);
12.34 +#endif
12.35 +
12.36 +#endif /* _SDL_winrtmouse_h */
12.37 +
12.38 +/* vi: set ts=4 sw=4 expandtab: */
13.1 --- a/src/video/winrt/SDL_winrtvideo.cpp Wed Aug 17 21:05:00 2016 +0200
13.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp Sat Aug 20 13:46:45 2016 -0400
13.3 @@ -61,6 +61,7 @@
13.4 #include "../../core/winrt/SDL_winrtapp_xaml.h"
13.5 #include "SDL_winrtvideo_cpp.h"
13.6 #include "SDL_winrtevents_c.h"
13.7 +#include "SDL_winrtgamebar_cpp.h"
13.8 #include "SDL_winrtmouse_c.h"
13.9 #include "SDL_main.h"
13.10 #include "SDL_system.h"
13.11 @@ -177,6 +178,7 @@
13.12 }
13.13 WINRT_InitMouse(_this);
13.14 WINRT_InitTouch(_this);
13.15 + WINRT_InitGameBar(_this);
13.16
13.17 return 0;
13.18 }
13.19 @@ -419,6 +421,7 @@
13.20 void
13.21 WINRT_VideoQuit(_THIS)
13.22 {
13.23 + WINRT_QuitGameBar(_this);
13.24 WINRT_QuitMouse(_this);
13.25 }
13.26
14.1 --- a/src/video/winrt/SDL_winrtvideo_cpp.h Wed Aug 17 21:05:00 2016 +0200
14.2 +++ b/src/video/winrt/SDL_winrtvideo_cpp.h Sat Aug 20 13:46:45 2016 -0400
14.3 @@ -46,6 +46,11 @@
14.4 * passed to eglGetDisplay and eglCreateWindowSurface:
14.5 */
14.6 IUnknown *winrtEglWindow;
14.7 +
14.8 + /* Event token(s), for unregistering WinRT event handler(s).
14.9 + These are just a struct with a 64-bit integer inside them
14.10 + */
14.11 + Windows::Foundation::EventRegistrationToken gameBarIsInputRedirectedToken;
14.12 } SDL_VideoData;
14.13
14.14 /* The global, WinRT, SDL Window.