summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinWX/Frame.cpp
diff options
context:
space:
mode:
authorRenaKunisaki <hyperhacker@gmail.com>2016-05-16 15:09:59 -0400
committeraldelaro5 <aldelaro5@gmail.com>2016-10-28 18:47:08 -0400
commit2005b4430fa91a89da35e39b356317a72cf86cf0 (patch)
treea0ab1d2fe82a2aa976370976f09914bce2ce4cca /Source/Core/DolphinWX/Frame.cpp
parent2536e37ec518c8d0e949ec7780ee0fb53e8b066e (diff)
Fix window focus detection on Linux
On Linux, the FindFocus method from wx simply doesn't work, it would on some environment report that dolphin has the focus while it doesn't have it. This is why an alternative method has to be used which is to set a focus flag whenever the render frame gets activated.
Diffstat (limited to 'Source/Core/DolphinWX/Frame.cpp')
-rw-r--r--Source/Core/DolphinWX/Frame.cpp63
1 files changed, 12 insertions, 51 deletions
diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp
index 5978dfc49d..c0e09ebdfb 100644
--- a/Source/Core/DolphinWX/Frame.cpp
+++ b/Source/Core/DolphinWX/Frame.cpp
@@ -504,18 +504,25 @@ void CFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
// Events
void CFrame::OnActive(wxActivateEvent& event)
{
+ m_bHasFocus = (event.GetActive() && event.GetEventObject() == m_RenderFrame);
if (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
{
- if (event.GetActive() && event.GetEventObject() == m_RenderFrame)
+ if (m_bHasFocus)
{
if (SConfig::GetInstance().bRenderToMain)
m_RenderParent->SetFocus();
+ if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::CORE_PAUSE)
+ DoPause();
+
if (SConfig::GetInstance().bHideCursor && Core::GetState() == Core::CORE_RUN)
m_RenderParent->SetCursor(wxCURSOR_BLANK);
}
else
{
+ if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::CORE_RUN)
+ DoPause();
+
if (SConfig::GetInstance().bHideCursor)
m_RenderParent->SetCursor(wxNullCursor);
}
@@ -769,27 +776,11 @@ bool CFrame::RendererHasFocus()
{
if (m_RenderParent == nullptr)
return false;
-#ifdef _WIN32
- HWND window = GetForegroundWindow();
- if (window == nullptr)
- return false;
-
- if (m_RenderFrame->GetHWND() == window)
- 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;
+ return m_bRendererHasFocus;
}
+// Returns true any time any one of our UI windows
+// has the focus, including any dialogs or other windows.
bool CFrame::UIHasFocus()
{
// UIHasFocus should return true any time any one of our UI
@@ -799,8 +790,7 @@ bool CFrame::UIHasFocus()
// focus. If it's not one of our windows, then it will return
// null.
- wxWindow* focusWindow = wxWindow::FindFocus();
- return (focusWindow != nullptr);
+ return m_bHasFocus;
}
void CFrame::OnGameListCtrlItemActivated(wxListEvent& WXUNUSED(event))
@@ -1139,35 +1129,6 @@ void CFrame::OnMouse(wxMouseEvent& event)
event.Skip();
}
-void CFrame::OnFocusChange(wxFocusEvent& event)
-{
- if (SConfig::GetInstance().m_PauseOnFocusLost && Core::IsRunningAndStarted())
- {
- if (RendererHasFocus())
- {
- if (Core::GetState() == Core::CORE_PAUSE)
- {
- Core::SetState(Core::CORE_RUN);
- if (SConfig::GetInstance().bHideCursor)
- m_RenderParent->SetCursor(wxCURSOR_BLANK);
- }
- }
- else
- {
- if (Core::GetState() == Core::CORE_RUN)
- {
- Core::SetState(Core::CORE_PAUSE);
- if (SConfig::GetInstance().bHideCursor)
- m_RenderParent->SetCursor(wxNullCursor);
- Core::UpdateTitle();
- }
- }
- UpdateGUI();
- }
-
- event.Skip();
-}
-
void CFrame::DoFullscreen(bool enable_fullscreen)
{
if (g_Config.bExclusiveMode && Core::GetState() == Core::CORE_PAUSE)