From e432237b5d3926e65a127f072b99703697036b0e Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 16 Sep 2024 17:53:43 -0400 Subject: [PATCH] Return owning pointer type --- src/SFML/Window/macOS/HIDInputManager.hpp | 2 +- src/SFML/Window/macOS/HIDInputManager.mm | 14 ++++++-------- src/SFML/Window/macOS/HIDJoystickManager.cpp | 6 ++---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/SFML/Window/macOS/HIDInputManager.hpp b/src/SFML/Window/macOS/HIDInputManager.hpp index 64935c5c5..1287ad8d9 100644 --- a/src/SFML/Window/macOS/HIDInputManager.hpp +++ b/src/SFML/Window/macOS/HIDInputManager.hpp @@ -94,7 +94,7 @@ public: /// \return a retained CFDictionaryRef /// //////////////////////////////////////////////////////////// - static CFDictionaryRef copyDevicesMask(std::uint32_t page, std::uint32_t usage); + static CFPtr copyDevicesMask(std::uint32_t page, std::uint32_t usage); //////////////////////////////////////////////////////////// /// \brief Try to convert a character into a SFML key code diff --git a/src/SFML/Window/macOS/HIDInputManager.mm b/src/SFML/Window/macOS/HIDInputManager.mm index 85f906a75..6ced4cf1e 100644 --- a/src/SFML/Window/macOS/HIDInputManager.mm +++ b/src/SFML/Window/macOS/HIDInputManager.mm @@ -69,21 +69,19 @@ long HIDInputManager::getLocationID(IOHIDDeviceRef device) //////////////////////////////////////////////////////////// -CFDictionaryRef HIDInputManager::copyDevicesMask(std::uint32_t page, std::uint32_t usage) +CFPtr HIDInputManager::copyDevicesMask(std::uint32_t page, std::uint32_t usage) { // Create the dictionary. - CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, - 2, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + auto dict = CFPtr( + CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); // Add the page value. auto value = CFPtr(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page)); - CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), value.get()); + CFDictionarySetValue(dict.get(), CFSTR(kIOHIDDeviceUsagePageKey), value.get()); // Add the usage value (which is only valid if page value exists). value = CFPtr(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage)); - CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), value.get()); + CFDictionarySetValue(dict.get(), CFSTR(kIOHIDDeviceUsageKey), value.get()); return dict; } @@ -929,7 +927,7 @@ void HIDInputManager::freeUp() CFPtr HIDInputManager::copyDevices(std::uint32_t page, std::uint32_t usage) { // Filter and keep only the requested devices - const auto mask = CFPtr(copyDevicesMask(page, usage)); + const auto mask = copyDevicesMask(page, usage); IOHIDManagerSetDeviceMatching(m_manager.get(), mask.get()); diff --git a/src/SFML/Window/macOS/HIDJoystickManager.cpp b/src/SFML/Window/macOS/HIDJoystickManager.cpp index 4432b5cfc..f005dd979 100644 --- a/src/SFML/Window/macOS/HIDJoystickManager.cpp +++ b/src/SFML/Window/macOS/HIDJoystickManager.cpp @@ -72,11 +72,9 @@ HIDJoystickManager::HIDJoystickManager() { m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - const auto mask0 = CFPtr( - HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick)); + const auto mask0 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick); - const auto mask1 = CFPtr( - HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad)); + const auto mask1 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad); std::array maskArray = {mask0.get(), mask1.get()}; const auto mask = CFPtr(