From 8583b6751abe08334329c7cae99c83df82683ce2 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 11 Mar 2024 02:28:18 -0500 Subject: [PATCH] InputCommon: Handle window change in Quartz. --- .../ControllerInterface/ControllerInterface.cpp | 3 +-- .../ControllerInterface/Quartz/Quartz.h | 4 ++++ .../ControllerInterface/Quartz/Quartz.mm | 15 +++++++++++++++ .../Quartz/QuartzKeyboardAndMouse.mm | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 9c272fdec4..b82cba645e 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -128,7 +128,6 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) // or removing them as we are populating them (causing missing or duplicate devices). std::lock_guard lk_population(m_devices_population_mutex); -#if defined(CIFACE_USE_WIN32) && !defined(CIFACE_USE_OSX) // If only the window changed, avoid removing and re-adding all devices. // Instead only refresh devices that require the window handle. if (reason == RefreshReason::WindowChangeOnly) @@ -140,9 +139,9 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) if (m_populating_devices_counter.fetch_sub(1) == 1) InvokeDevicesChangedCallbacks(); + return; } -#endif m_populating_devices_counter.fetch_add(1); diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h index 34219e9828..b2c6906e42 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.h @@ -3,9 +3,13 @@ #pragma once +#include + #include "InputCommon/ControllerInterface/InputBackend.h" namespace ciface::Quartz { +std::string GetSourceName(); + 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 75054f08b9..5d52595835 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm @@ -7,11 +7,17 @@ namespace ciface::Quartz { +std::string GetSourceName() +{ + return "Quartz"; +} + class InputBackend final : public ciface::InputBackend { public: using ciface::InputBackend::InputBackend; void PopulateDevices() override; + void HandleWindowChange() override; }; std::unique_ptr CreateInputBackend(ControllerInterface* controller_interface) @@ -19,6 +25,15 @@ std::unique_ptr CreateInputBackend(ControllerInterface* co return std::make_unique(controller_interface); } +void InputBackend::HandleWindowChange() +{ + const std::string source_name = GetSourceName(); + GetControllerInterface().RemoveDevice( + [&](const auto* dev) { return dev->GetSource() == source_name; }, true); + + PopulateDevices(); +} + void InputBackend::PopulateDevices() { const WindowSystemInfo wsi = GetControllerInterface().GetWindowSystemInfo(); diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index b21eb48ab4..55f212900d 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -280,7 +280,7 @@ std::string KeyboardAndMouse::GetName() const std::string KeyboardAndMouse::GetSource() const { - return "Quartz"; + return Quartz::GetSourceName(); } ControlState KeyboardAndMouse::Cursor::GetState() const