From ee087f595343ff258ef7a85eea2b59b5ba2790e3 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 16 Jul 2014 10:21:22 -0400 Subject: [PATCH 1/2] Revert "Frame: Fix RendererHasFocus" This reverts commit ff918df88991710d58d983aa2e5dbcf03f2064ab. This changed it from "RendererHasFocus" to "UIHasFocus", which is wrong. Specifically, it broke for non-Render to Main Window cases where the renderer window isn't managed by wx. It also broke the pending exclusive fullscreen support, which checks this function to determine if the renderer is on top so it can full-screen it. We'll add a new hook, "UIHasFocus", in the next commit. --- Source/Core/DolphinWX/Frame.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 12fcb5f3bf..d0f379b78a 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -753,15 +753,24 @@ void CFrame::OnRenderWindowSizeRequest(int width, int height) bool CFrame::RendererHasFocus() { - // RendererHasFocus should return true any time any one of our - // windows has the focus, including any dialogs or other windows. - // - // wxGetActiveWindow() returns the current wxWindow which has - // focus. If it's not one of our windows, then it will return - // null. - - wxWindow *focusWindow = wxGetActiveWindow(); - return (focusWindow != nullptr); + if (m_RenderParent == nullptr) + return false; +#ifdef _WIN32 + if (m_RenderParent->GetParent()->GetHWND() == GetForegroundWindow()) + return true; +#else + wxWindow *window = wxWindow::FindFocus(); + if (window == nullptr) + return false; + // Why these different cases? + if (m_RenderParent == window || + m_RenderParent == window->GetParent() || + m_RenderParent->GetParent() == window->GetParent()) + { + return true; + } +#endif + return false; } void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event)) From 44307c950888a4942a35b0176e2601c266894983 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 16 Jul 2014 10:24:40 -0400 Subject: [PATCH 2/2] Host: Add a new "UIHasFocus" hook to determine if the UI has focus We can't use RendererHasFocus for this purpose because of some issues with exclusive fullscreen, and the new RendererHasFocus implementation didn't work for non-Render to Main Window cases, since the renderer window wasn't managed by wx. --- Source/Core/Core/Host.h | 1 + Source/Core/DolphinWX/Frame.cpp | 13 +++++++++++++ Source/Core/DolphinWX/Frame.h | 1 + Source/Core/DolphinWX/Main.cpp | 5 +++++ Source/Core/DolphinWX/MainAndroid.cpp | 5 +++++ Source/Core/DolphinWX/MainNoGUI.cpp | 5 +++++ .../Core/InputCommon/ControllerInterface/Device.cpp | 2 +- 7 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/Host.h b/Source/Core/Core/Host.h index 0f68338d25..32061242f2 100644 --- a/Source/Core/Core/Host.h +++ b/Source/Core/Core/Host.h @@ -23,6 +23,7 @@ // The host can be just a command line app that opens a window, or a full blown debugger // interface. +bool Host_UIHasFocus(); bool Host_RendererHasFocus(); void Host_ConnectWiimote(int wm_idx, bool connect); void Host_GetRenderWindowSize(int& x, int& y, int& width, int& height); diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index d0f379b78a..b57f18ad69 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -773,6 +773,19 @@ bool CFrame::RendererHasFocus() return false; } +bool CFrame::UIHasFocus() +{ + // UIHasFocus should return true any time any one of our UI + // windows has the focus, including any dialogs or other windows. + // + // wxGetActiveWindow() returns the current wxWindow which has + // focus. If it's not one of our windows, then it will return + // null. + + wxWindow *focusWindow = wxGetActiveWindow(); + return (focusWindow != nullptr); +} + void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event)) { // Show all platforms and regions if... diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index 9811e43148..900753174e 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -138,6 +138,7 @@ public: void OnRenderParentClose(wxCloseEvent& event); void OnRenderParentMove(wxMoveEvent& event); bool RendererHasFocus(); + bool UIHasFocus(); void DoFullscreen(bool bF); void ToggleDisplayMode (bool bFullscreen); void UpdateWiiMenuChoice(wxMenuItem *WiiMenuItem=nullptr); diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index ba63864728..ad6d049635 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -678,6 +678,11 @@ void Host_SetWiiMoteConnectionState(int _State) main_frame->GetEventHandler()->AddPendingEvent(event); } +bool Host_UIHasFocus() +{ + return main_frame->UIHasFocus(); +} + bool Host_RendererHasFocus() { return main_frame->RendererHasFocus(); diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index a5cde56e91..d24be7f954 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -98,6 +98,11 @@ void Host_SetStartupDebuggingParameters() { } +bool Host_UIHasFocus() +{ + return true; +} + bool Host_RendererHasFocus() { return true; diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 7605d22075..351d818c2c 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -95,6 +95,11 @@ void Host_SetStartupDebuggingParameters() StartUp.bBootToPause = false; } +bool Host_UIHasFocus() +{ + return false; +} + bool Host_RendererHasFocus() { return rendererHasFocus; diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 61057c8162..84af8649a8 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -84,7 +84,7 @@ bool Device::Control::InputGateOn() { if (SConfig::GetInstance().m_BackgroundInput) return true; - else if (Host_RendererHasFocus()) + else if (Host_RendererHasFocus() || Host_UIHasFocus()) return true; else return false;