From 8d5fe1f1c4e05e955c6de4b8e18f18ed6009feef Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Thu, 13 Jul 2017 12:55:50 -0700 Subject: [PATCH 1/3] RenderWidget: mark 'event' function as override --- Source/Core/DolphinQt2/RenderWidget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt2/RenderWidget.h b/Source/Core/DolphinQt2/RenderWidget.h index 0db0ee4d3c..641bd0b82a 100644 --- a/Source/Core/DolphinQt2/RenderWidget.h +++ b/Source/Core/DolphinQt2/RenderWidget.h @@ -14,7 +14,7 @@ class RenderWidget final : public QWidget public: explicit RenderWidget(QWidget* parent = nullptr); - bool event(QEvent* event); + bool event(QEvent* event) override; signals: void EscapePressed(); From 8e55374662eb7d5b89b732bd329e744d6894a8c3 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Thu, 13 Jul 2017 12:56:33 -0700 Subject: [PATCH 2/3] RenderWidget: watch for activation/deactivation, not focus in/out "Focus" refers mainly to keyboard focus. "Window focus" is exposed through the window activation and deactivation events. --- Source/Core/DolphinQt2/RenderWidget.cpp | 9 +++++---- Source/Core/DolphinQt2/RenderWidget.h | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/DolphinQt2/RenderWidget.cpp b/Source/Core/DolphinQt2/RenderWidget.cpp index 3022e00ec2..d01d4dd17b 100644 --- a/Source/Core/DolphinQt2/RenderWidget.cpp +++ b/Source/Core/DolphinQt2/RenderWidget.cpp @@ -14,7 +14,6 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent) setAttribute(Qt::WA_NoSystemBackground, true); connect(Host::GetInstance(), &Host::RequestTitle, this, &RenderWidget::setWindowTitle); - connect(this, &RenderWidget::FocusChanged, Host::GetInstance(), &Host::SetRenderFocus); connect(this, &RenderWidget::StateChanged, Host::GetInstance(), &Host::SetRenderFullscreen); connect(this, &RenderWidget::HandleChanged, Host::GetInstance(), &Host::SetRenderHandle); emit HandleChanged((void*)winId()); @@ -43,9 +42,11 @@ bool RenderWidget::event(QEvent* event) case QEvent::WinIdChange: emit HandleChanged((void*)winId()); break; - case QEvent::FocusIn: - case QEvent::FocusOut: - emit FocusChanged(hasFocus()); + case QEvent::WindowActivate: + Host::GetInstance()->SetRenderFocus(true); + break; + case QEvent::WindowDeactivate: + Host::GetInstance()->SetRenderFocus(false); break; case QEvent::WindowStateChange: emit StateChanged(isFullScreen()); diff --git a/Source/Core/DolphinQt2/RenderWidget.h b/Source/Core/DolphinQt2/RenderWidget.h index 641bd0b82a..4c7eb6b792 100644 --- a/Source/Core/DolphinQt2/RenderWidget.h +++ b/Source/Core/DolphinQt2/RenderWidget.h @@ -20,7 +20,6 @@ signals: void EscapePressed(); void Closed(); void HandleChanged(void* handle); - void FocusChanged(bool focus); void StateChanged(bool fullscreen); private: From ebeac1847204703293c1925e66dfb23b1cdd3602 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Thu, 13 Jul 2017 12:58:26 -0700 Subject: [PATCH 3/3] DolphinQt2/Host: cleanup --- Source/Core/DolphinQt2/Host.cpp | 15 +++------------ Source/Core/DolphinQt2/Host.h | 13 +++++-------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Source/Core/DolphinQt2/Host.cpp b/Source/Core/DolphinQt2/Host.cpp index fdd3b5aecd..21faff73c8 100644 --- a/Source/Core/DolphinQt2/Host.cpp +++ b/Source/Core/DolphinQt2/Host.cpp @@ -4,55 +4,46 @@ #include #include -#include #include "Common/Common.h" #include "Core/Host.h" #include "DolphinQt2/Host.h" -#include "DolphinQt2/MainWindow.h" -Host* Host::m_instance = nullptr; +Host::Host() = default; Host* Host::GetInstance() { - if (m_instance == nullptr) - m_instance = new Host(); - return m_instance; + static Host* s_instance = new Host(); + return s_instance; } void* Host::GetRenderHandle() { - QMutexLocker locker(&m_lock); return m_render_handle; } void Host::SetRenderHandle(void* handle) { - QMutexLocker locker(&m_lock); m_render_handle = handle; } bool Host::GetRenderFocus() { - QMutexLocker locker(&m_lock); return m_render_focus; } void Host::SetRenderFocus(bool focus) { - QMutexLocker locker(&m_lock); m_render_focus = focus; } bool Host::GetRenderFullscreen() { - QMutexLocker locker(&m_lock); return m_render_fullscreen; } void Host::SetRenderFullscreen(bool fullscreen) { - QMutexLocker locker(&m_lock); m_render_fullscreen = fullscreen; } diff --git a/Source/Core/DolphinQt2/Host.h b/Source/Core/DolphinQt2/Host.h index 325e682384..d779c84b4b 100644 --- a/Source/Core/DolphinQt2/Host.h +++ b/Source/Core/DolphinQt2/Host.h @@ -4,9 +4,8 @@ #pragma once -#include #include -#include +#include // Singleton that talks to the Core via the interface defined in Core/Host.h. // Because Host_* calls might come from different threads than the MainWindow, @@ -35,11 +34,9 @@ signals: void RequestRenderSize(int w, int h); private: - Host() {} - static Host* m_instance; - QMutex m_lock; + Host(); - void* m_render_handle; - bool m_render_focus; - bool m_render_fullscreen; + std::atomic m_render_handle; + std::atomic m_render_focus; + std::atomic m_render_fullscreen; };