WinRT: fixed bug: Back button(s) weren't working on Win10
authorDavid Ludwig <dludwig@pobox.com>
Wed, 09 Dec 2015 21:34:56 -0500
changeset 99570be86b512d34
parent 9956 0b3b1f767eb1
child 9958 687e118144c7
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
src/core/winrt/SDL_winrtapp_direct3d.h
     1.1 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp	Wed Dec 09 12:11:40 2015 -0800
     1.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp	Wed Dec 09 21:34:56 2015 -0500
     1.3 @@ -364,7 +364,10 @@
     1.4      window->CharacterReceived +=
     1.5          ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(this, &SDL_WinRTApp::OnCharacterReceived);
     1.6  
     1.7 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     1.8 +#if NTDDI_VERSION >= NTDDI_WIN10
     1.9 +    Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->BackRequested +=
    1.10 +        ref new EventHandler<BackRequestedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
    1.11 +#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.12      HardwareButtons::BackPressed +=
    1.13          ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
    1.14  #endif
    1.15 @@ -785,8 +788,8 @@
    1.16      WINRT_ProcessCharacterReceivedEvent(args);
    1.17  }
    1.18  
    1.19 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.20 -void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
    1.21 +template <typename BackButtonEventArgs>
    1.22 +static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args)
    1.23  {
    1.24      SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
    1.25      SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);
    1.26 @@ -798,5 +801,18 @@
    1.27          }
    1.28      }
    1.29  }
    1.30 +
    1.31 +#if NTDDI_VERSION == NTDDI_WIN10
    1.32 +void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args)
    1.33 +
    1.34 +{
    1.35 +    WINRT_OnBackButtonPressed(args);
    1.36 +}
    1.37 +#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.38 +void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
    1.39 +
    1.40 +{
    1.41 +    WINRT_OnBackButtonPressed(args);
    1.42 +}
    1.43  #endif
    1.44  
     2.1 --- a/src/core/winrt/SDL_winrtapp_direct3d.h	Wed Dec 09 12:11:40 2015 -0800
     2.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.h	Wed Dec 09 21:34:56 2015 -0500
     2.3 @@ -74,7 +74,9 @@
     2.4      void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
     2.5      void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
     2.6  
     2.7 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     2.8 +#if NTDDI_VERSION >= NTDDI_WIN10
     2.9 +    void OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args);
    2.10 +#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    2.11      void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
    2.12  #endif
    2.13