From 52828901efedb146cb572573b2381e73d2ada4d9 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 27 Oct 2018 20:06:35 +1000 Subject: [PATCH] Core: Switch controller interface to render widget on booting Previously, the Qt frontend would initialize the controller interface on starting, resulting in the cursor position being relative to the main window, instead of the render window. --- Source/Core/Core/Core.cpp | 5 +++++ Source/Core/DolphinQt/MainWindow.cpp | 5 +++++ .../ControllerInterface/ControllerInterface.cpp | 9 +++++++++ .../ControllerInterface/ControllerInterface.h | 1 + 4 files changed, 20 insertions(+) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index fff3e6bfff..b5a4b13ce0 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -456,6 +456,10 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi return; } + // The frontend will likely have initialized the controller interface, as it needs + // it to provide the configuration dialogs. In this case, instead of re-initializing + // entirely, we switch the window used for inputs to the render window. This way, the + // cursor position is relative to the render window, instead of the main window. bool init_controllers = false; if (!g_controller_interface.IsInit()) { @@ -467,6 +471,7 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi else { // Update references in case controllers were refreshed + g_controller_interface.ChangeWindow(wsi.render_surface); Pad::LoadConfig(); Keyboard::LoadConfig(); } diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index f02542da95..e2b9e15791 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -940,6 +940,11 @@ void MainWindow::HideRenderWidget(bool reinit) if (m_render_widget->isFullScreen()) SetFullScreenResolution(focus); }); + + // The controller interface will still be registered to the old render widget, if the core + // has booted. Therefore, we should re-bind it to the main window for now. When the core + // is next started, it will be swapped back to the new render widget. + g_controller_interface.ChangeWindow(GetWindowSystemInfo(windowHandle()).render_surface); } } diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 7be22d4a8d..9f6e7c5179 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -80,6 +80,15 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi) RefreshDevices(); } +void ControllerInterface::ChangeWindow(void* hwnd) +{ + if (!m_is_init) + return; + + m_wsi.render_surface = hwnd; + RefreshDevices(); +} + void ControllerInterface::RefreshDevices() { if (!m_is_init) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 2e078e8934..d5567222a4 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -42,6 +42,7 @@ class ControllerInterface : public ciface::Core::DeviceContainer public: ControllerInterface() : m_is_init(false) {} void Initialize(const WindowSystemInfo& wsi); + void ChangeWindow(void* hwnd); void RefreshDevices(); void Shutdown(); void AddDevice(std::shared_ptr device);