#6433 Fix WINRT_IsScreenKeyboardShown on Xbox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/src/video/winrt/SDL_winrtevents_c.h b/src/video/winrt/SDL_winrtevents_c.h
index 1123180..67c18b8 100644
--- a/src/video/winrt/SDL_winrtevents_c.h
+++ b/src/video/winrt/SDL_winrtevents_c.h
@@ -68,6 +68,7 @@ extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args);
extern void WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args);
#if NTDDI_VERSION >= NTDDI_WIN10
+extern void WINTRT_InitialiseInputPaneEvents(_THIS);
extern SDL_bool WINRT_HasScreenKeyboardSupport(_THIS);
extern void WINRT_ShowScreenKeyboard(_THIS, SDL_Window *window);
extern void WINRT_HideScreenKeyboard(_THIS, SDL_Window *window);
diff --git a/src/video/winrt/SDL_winrtkeyboard.cpp b/src/video/winrt/SDL_winrtkeyboard.cpp
index 40681cb..f6ff0a4 100644
--- a/src/video/winrt/SDL_winrtkeyboard.cpp
+++ b/src/video/winrt/SDL_winrtkeyboard.cpp
@@ -386,6 +386,30 @@ WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArg
#if NTDDI_VERSION >= NTDDI_WIN10
+static bool WINRT_InputPaneVisible = false;
+
+void WINTRT_OnInputPaneShowing(Windows::UI::ViewManagement::InputPane ^ sender, Windows::UI::ViewManagement::InputPaneVisibilityEventArgs ^ args)
+{
+ WINRT_InputPaneVisible = true;
+}
+
+void WINTRT_OnInputPaneHiding(Windows::UI::ViewManagement::InputPane ^ sender, Windows::UI::ViewManagement::InputPaneVisibilityEventArgs ^ args)
+{
+ WINRT_InputPaneVisible = false;
+}
+
+void WINTRT_InitialiseInputPaneEvents(_THIS)
+{
+ using namespace Windows::UI::ViewManagement;
+ InputPane ^ inputPane = InputPane::GetForCurrentView();
+ if (inputPane) {
+ inputPane->Showing += ref new Windows::Foundation::TypedEventHandler<Windows::UI::ViewManagement::InputPane ^,
+ Windows::UI::ViewManagement::InputPaneVisibilityEventArgs ^>(&WINTRT_OnInputPaneShowing);
+ inputPane->Hiding += ref new Windows::Foundation::TypedEventHandler<Windows::UI::ViewManagement::InputPane ^,
+ Windows::UI::ViewManagement::InputPaneVisibilityEventArgs ^>(&WINTRT_OnInputPaneHiding);
+ }
+}
+
SDL_bool WINRT_HasScreenKeyboardSupport(_THIS)
{
return SDL_TRUE;
@@ -414,12 +438,24 @@ SDL_bool WINRT_IsScreenKeyboardShown(_THIS, SDL_Window *window)
using namespace Windows::UI::ViewManagement;
InputPane ^ inputPane = InputPane::GetForCurrentView();
if (inputPane) {
- // dludwig@pobox.com: checking inputPane->Visible doesn't seem to detect visibility,
- // at least not on the Windows Phone 10.0.10240.0 emulator. Checking
- // the size of inputPane->OccludedRect, however, does seem to work.
- Windows::Foundation::Rect rect = inputPane->OccludedRect;
- if (rect.Width > 0 && rect.Height > 0) {
- return SDL_TRUE;
+ switch (SDL_WinRTGetDeviceFamily()) {
+ case SDL_WINRT_DEVICEFAMILY_XBOX:
+ //Documentation recommends using inputPane->Visible
+ //https://learn.microsoft.com/en-us/uwp/api/windows.ui.viewmanagement.inputpane.visible?view=winrt-22621
+ //This does not seem to work on latest UWP/Xbox.
+ //Workaround: Listen to Showing/Hiding events
+ if (WINRT_InputPaneVisible) {
+ return SDL_TRUE;
+ }
+ break;
+ default:
+ //OccludedRect is recommend on universal apps per docs
+ //https://learn.microsoft.com/en-us/uwp/api/windows.ui.viewmanagement.inputpane.visible?view=winrt-22621
+ Windows::Foundation::Rect rect = inputPane->OccludedRect;
+ if (rect.Width > 0 && rect.Height > 0) {
+ return SDL_TRUE;
+ }
+ break;
}
}
return SDL_FALSE;
@@ -427,4 +463,4 @@ SDL_bool WINRT_IsScreenKeyboardShown(_THIS, SDL_Window *window)
#endif // NTDDI_VERSION >= ...
-#endif // SDL_VIDEO_DRIVER_WINRT
+#endif // SDL_VIDEO_DRIVER_WINRT
\ No newline at end of file
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index a71ba9b..3a7b220 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -154,6 +154,8 @@ WINRT_CreateDevice(void)
device->ShowScreenKeyboard = WINRT_ShowScreenKeyboard;
device->HideScreenKeyboard = WINRT_HideScreenKeyboard;
device->IsScreenKeyboardShown = WINRT_IsScreenKeyboardShown;
+
+ WINTRT_InitialiseInputPaneEvents(device);
#endif
#ifdef SDL_VIDEO_OPENGL_EGL