From 95c03b2feefb7944b7e9a519e34e3ea77159b2c3 Mon Sep 17 00:00:00 2001 From: Reece Mackie <20544390+Rover656@users.noreply.github.com> Date: Thu, 30 Apr 2020 15:02:01 +0100 Subject: [PATCH] Fix game closing on Xbox when B is pressed. --- projects/VS2017.UWP/raylib.App.UWP/App.cpp | 10 ++++++++++ projects/VS2017.UWP/raylib.App.UWP/App.h | 1 + 2 files changed, 11 insertions(+) diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index 517672d3c..a1faa70d2 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -83,6 +83,10 @@ void App::SetWindow(Windows::UI::Core::CoreWindow^ window) // The CoreWindow has been created, we can pass this to raylib for EGL context creation when it's time UWPSetCoreWindowPtr((void*)window); + + // Register backrequested event to stop window from being closed (Most noticable on XBox when B is pressed) + auto navigation = SystemNavigationManager::GetForCurrentView(); + navigation->BackRequested += ref new Windows::Foundation::EventHandler(this, &raylibUWP::App::OnBackRequested); } void App::Load(Platform::String ^entryPoint) {} // Ignored for this example @@ -454,6 +458,12 @@ void App::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI UWPKeyCharEvent(args->KeyCode); } +void App::OnBackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args) +{ + // This simply stops the program from closing. + args->Handled = true; +} + // AppSource implementation Windows::ApplicationModel::Core::IFrameworkView ^AppSource::CreateView() { diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.h b/projects/VS2017.UWP/raylib.App.UWP/App.h index 892d85922..a3b7577f4 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.h +++ b/projects/VS2017.UWP/raylib.App.UWP/App.h @@ -40,6 +40,7 @@ namespace raylibUWP void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); + void OnBackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args); }; ref class AppSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource