diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 24653acdd1..ba3740214a 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -65,7 +65,7 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi) // nothing needed #endif #ifdef CIFACE_USE_OSX -// nothing needed for Quartz + m_input_backends.emplace_back(ciface::Quartz::CreateInputBackend(this)); #endif #ifdef CIFACE_USE_SDL m_input_backends.emplace_back(ciface::SDL::CreateInputBackend(this)); @@ -166,12 +166,6 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) if (m_wsi.type == WindowSystemType::X11) ciface::XInput2::PopulateDevices(m_wsi.render_window); #endif -#ifdef CIFACE_USE_OSX - if (m_wsi.type == WindowSystemType::MacOS) - { - ciface::Quartz::PopulateDevices(m_wsi.render_window); - } -#endif #ifdef CIFACE_USE_ANDROID ciface::Android::PopulateDevices(); #endif @@ -223,9 +217,6 @@ void ControllerInterface::Shutdown() #ifdef CIFACE_USE_XLIB // nothing needed #endif -#ifdef CIFACE_USE_OSX - ciface::Quartz::DeInit(); -#endif #ifdef CIFACE_USE_ANDROID ciface::Android::Shutdown(); #endif diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h index 8818425344..34219e9828 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h @@ -3,8 +3,9 @@ #pragma once +#include "InputCommon/ControllerInterface/InputBackend.h" + namespace ciface::Quartz { -void PopulateDevices(void* window); -void DeInit(); +std::unique_ptr CreateInputBackend(ControllerInterface* controller_interface); } // namespace ciface::Quartz diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm index 22dc4074d9..75054f08b9 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm @@ -7,15 +7,25 @@ namespace ciface::Quartz { -void PopulateDevices(void* window) +class InputBackend final : public ciface::InputBackend { - if (!window) +public: + using ciface::InputBackend::InputBackend; + void PopulateDevices() override; +}; + +std::unique_ptr CreateInputBackend(ControllerInterface* controller_interface) +{ + return std::make_unique(controller_interface); +} + +void InputBackend::PopulateDevices() +{ + const WindowSystemInfo wsi = GetControllerInterface().GetWindowSystemInfo(); + if (wsi.type != WindowSystemType::MacOS) return; - g_controller_interface.AddDevice(std::make_shared(window)); + GetControllerInterface().AddDevice(std::make_shared(wsi.render_window)); } -void DeInit() -{ -} } // namespace ciface::Quartz diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index e41c370edf..b21eb48ab4 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -12,6 +12,7 @@ #include "Core/Host.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" +#include "InputCommon/ControllerInterface/Quartz/Quartz.h" /// Helper class to get window position data from threads other than the main thread @interface DolWindowPositionObserver : NSObject