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.
This commit is contained in:
Stenzek 2018-10-27 20:06:35 +10:00
parent a7f334dc2a
commit 52828901ef
4 changed files with 20 additions and 0 deletions

View File

@ -456,6 +456,10 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
return; 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; bool init_controllers = false;
if (!g_controller_interface.IsInit()) if (!g_controller_interface.IsInit())
{ {
@ -467,6 +471,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
else else
{ {
// Update references in case controllers were refreshed // Update references in case controllers were refreshed
g_controller_interface.ChangeWindow(wsi.render_surface);
Pad::LoadConfig(); Pad::LoadConfig();
Keyboard::LoadConfig(); Keyboard::LoadConfig();
} }

View File

@ -940,6 +940,11 @@ void MainWindow::HideRenderWidget(bool reinit)
if (m_render_widget->isFullScreen()) if (m_render_widget->isFullScreen())
SetFullScreenResolution(focus); 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);
} }
} }

View File

@ -80,6 +80,15 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi)
RefreshDevices(); RefreshDevices();
} }
void ControllerInterface::ChangeWindow(void* hwnd)
{
if (!m_is_init)
return;
m_wsi.render_surface = hwnd;
RefreshDevices();
}
void ControllerInterface::RefreshDevices() void ControllerInterface::RefreshDevices()
{ {
if (!m_is_init) if (!m_is_init)

View File

@ -42,6 +42,7 @@ class ControllerInterface : public ciface::Core::DeviceContainer
public: public:
ControllerInterface() : m_is_init(false) {} ControllerInterface() : m_is_init(false) {}
void Initialize(const WindowSystemInfo& wsi); void Initialize(const WindowSystemInfo& wsi);
void ChangeWindow(void* hwnd);
void RefreshDevices(); void RefreshDevices();
void Shutdown(); void Shutdown();
void AddDevice(std::shared_ptr<ciface::Core::Device> device); void AddDevice(std::shared_ptr<ciface::Core::Device> device);