From f2f435ee4532f1e9839bfccbf3444bde1089f541 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Wed, 9 Dec 2015 21:34:56 -0500 Subject: [PATCH] WinRT: fixed bug: Back button(s) weren't working on Win10 Many thanks go to Sylvain Becker for providing details on the fix! --- src/core/winrt/SDL_winrtapp_direct3d.cpp | 22 +++++++++++++++++++--- src/core/winrt/SDL_winrtapp_direct3d.h | 4 +++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp index df650cd88..3ae134bd8 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -364,7 +364,10 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window) window->CharacterReceived += ref new TypedEventHandler(this, &SDL_WinRTApp::OnCharacterReceived); -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP +#if NTDDI_VERSION >= NTDDI_WIN10 + Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->BackRequested += + ref new EventHandler(this, &SDL_WinRTApp::OnBackButtonPressed); +#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP HardwareButtons::BackPressed += ref new EventHandler(this, &SDL_WinRTApp::OnBackButtonPressed); #endif @@ -785,8 +788,8 @@ void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Wi WINRT_ProcessCharacterReceivedEvent(args); } -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP -void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args) +template +static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args) { SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK); SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK); @@ -798,5 +801,18 @@ void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone: } } } + +#if NTDDI_VERSION == NTDDI_WIN10 +void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args) + +{ + WINRT_OnBackButtonPressed(args); +} +#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP +void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args) + +{ + WINRT_OnBackButtonPressed(args); +} #endif diff --git a/src/core/winrt/SDL_winrtapp_direct3d.h b/src/core/winrt/SDL_winrtapp_direct3d.h index 90fb7026b..341b2d85a 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.h +++ b/src/core/winrt/SDL_winrtapp_direct3d.h @@ -74,7 +74,9 @@ protected: void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP +#if NTDDI_VERSION >= NTDDI_WIN10 + void OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args); +#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args); #endif