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.
This commit is contained in:
parent
2536e37ec5
commit
2005b4430f
|
@ -504,18 +504,25 @@ void CFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
// Events
|
// Events
|
||||||
void CFrame::OnActive(wxActivateEvent& event)
|
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 (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
|
||||||
{
|
{
|
||||||
if (event.GetActive() && event.GetEventObject() == m_RenderFrame)
|
if (m_bHasFocus)
|
||||||
{
|
{
|
||||||
if (SConfig::GetInstance().bRenderToMain)
|
if (SConfig::GetInstance().bRenderToMain)
|
||||||
m_RenderParent->SetFocus();
|
m_RenderParent->SetFocus();
|
||||||
|
|
||||||
|
if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::CORE_PAUSE)
|
||||||
|
DoPause();
|
||||||
|
|
||||||
if (SConfig::GetInstance().bHideCursor && Core::GetState() == Core::CORE_RUN)
|
if (SConfig::GetInstance().bHideCursor && Core::GetState() == Core::CORE_RUN)
|
||||||
m_RenderParent->SetCursor(wxCURSOR_BLANK);
|
m_RenderParent->SetCursor(wxCURSOR_BLANK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::CORE_RUN)
|
||||||
|
DoPause();
|
||||||
|
|
||||||
if (SConfig::GetInstance().bHideCursor)
|
if (SConfig::GetInstance().bHideCursor)
|
||||||
m_RenderParent->SetCursor(wxNullCursor);
|
m_RenderParent->SetCursor(wxNullCursor);
|
||||||
}
|
}
|
||||||
|
@ -769,27 +776,11 @@ bool CFrame::RendererHasFocus()
|
||||||
{
|
{
|
||||||
if (m_RenderParent == nullptr)
|
if (m_RenderParent == nullptr)
|
||||||
return false;
|
return false;
|
||||||
#ifdef _WIN32
|
return m_bRendererHasFocus;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true any time any one of our UI windows
|
||||||
|
// has the focus, including any dialogs or other windows.
|
||||||
bool CFrame::UIHasFocus()
|
bool CFrame::UIHasFocus()
|
||||||
{
|
{
|
||||||
// UIHasFocus should return true any time any one of our UI
|
// 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
|
// focus. If it's not one of our windows, then it will return
|
||||||
// null.
|
// null.
|
||||||
|
|
||||||
wxWindow* focusWindow = wxWindow::FindFocus();
|
return m_bHasFocus;
|
||||||
return (focusWindow != nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFrame::OnGameListCtrlItemActivated(wxListEvent& WXUNUSED(event))
|
void CFrame::OnGameListCtrlItemActivated(wxListEvent& WXUNUSED(event))
|
||||||
|
@ -1139,35 +1129,6 @@ void CFrame::OnMouse(wxMouseEvent& event)
|
||||||
event.Skip();
|
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)
|
void CFrame::DoFullscreen(bool enable_fullscreen)
|
||||||
{
|
{
|
||||||
if (g_Config.bExclusiveMode && Core::GetState() == Core::CORE_PAUSE)
|
if (g_Config.bExclusiveMode && Core::GetState() == Core::CORE_PAUSE)
|
||||||
|
|
|
@ -158,6 +158,7 @@ private:
|
||||||
bool m_bNoDocking = false;
|
bool m_bNoDocking = false;
|
||||||
bool m_bGameLoading = false;
|
bool m_bGameLoading = false;
|
||||||
bool m_bClosing = false;
|
bool m_bClosing = false;
|
||||||
|
bool m_bHasFocus = false;
|
||||||
bool m_confirmStop = false;
|
bool m_confirmStop = false;
|
||||||
bool m_tried_graceful_shutdown = false;
|
bool m_tried_graceful_shutdown = false;
|
||||||
int m_saveSlot = 1;
|
int m_saveSlot = 1;
|
||||||
|
@ -306,8 +307,6 @@ private:
|
||||||
void OnKeyDown(wxKeyEvent& event); // Keyboard
|
void OnKeyDown(wxKeyEvent& event); // Keyboard
|
||||||
void OnMouse(wxMouseEvent& event); // Mouse
|
void OnMouse(wxMouseEvent& event); // Mouse
|
||||||
|
|
||||||
void OnFocusChange(wxFocusEvent& event);
|
|
||||||
|
|
||||||
void OnHostMessage(wxCommandEvent& event);
|
void OnHostMessage(wxCommandEvent& event);
|
||||||
|
|
||||||
void OnMemcard(wxCommandEvent& event); // Misc
|
void OnMemcard(wxCommandEvent& event); // Misc
|
||||||
|
|
|
@ -733,8 +733,6 @@ void CFrame::StartGame(const std::string& filename)
|
||||||
wxTheApp->Bind(wxEVT_MIDDLE_DOWN, &CFrame::OnMouse, this);
|
wxTheApp->Bind(wxEVT_MIDDLE_DOWN, &CFrame::OnMouse, this);
|
||||||
wxTheApp->Bind(wxEVT_MIDDLE_UP, &CFrame::OnMouse, this);
|
wxTheApp->Bind(wxEVT_MIDDLE_UP, &CFrame::OnMouse, this);
|
||||||
wxTheApp->Bind(wxEVT_MOTION, &CFrame::OnMouse, this);
|
wxTheApp->Bind(wxEVT_MOTION, &CFrame::OnMouse, this);
|
||||||
wxTheApp->Bind(wxEVT_SET_FOCUS, &CFrame::OnFocusChange, this);
|
|
||||||
wxTheApp->Bind(wxEVT_KILL_FOCUS, &CFrame::OnFocusChange, this);
|
|
||||||
m_RenderParent->Bind(wxEVT_SIZE, &CFrame::OnRenderParentResize, this);
|
m_RenderParent->Bind(wxEVT_SIZE, &CFrame::OnRenderParentResize, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -926,6 +924,8 @@ void CFrame::OnStopped()
|
||||||
m_RenderFrame->SetWindowStyle(m_RenderFrame->GetWindowStyle() & ~wxSTAY_ON_TOP);
|
m_RenderFrame->SetWindowStyle(m_RenderFrame->GetWindowStyle() & ~wxSTAY_ON_TOP);
|
||||||
}
|
}
|
||||||
m_RenderParent = nullptr;
|
m_RenderParent = nullptr;
|
||||||
|
m_bRendererHasFocus = false;
|
||||||
|
m_RenderFrame = nullptr;
|
||||||
|
|
||||||
// Clean framerate indications from the status bar.
|
// Clean framerate indications from the status bar.
|
||||||
GetStatusBar()->SetStatusText(" ", 0);
|
GetStatusBar()->SetStatusText(" ", 0);
|
||||||
|
|
Loading…
Reference in New Issue