mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 14:21:04 +08:00
Use lazy loading for keyboard scancodes on macos (backport)
This commit is contained in:
parent
54c7edb2a0
commit
5545df7290
@ -22,6 +22,7 @@
|
||||
- [Windows] Close the clipboard if we fail to empty it (#3043)
|
||||
- [Android] Remove use of deprecated `ALooper_pollAll` (#3181, #3189)
|
||||
- [macOS] Fix how macOS fullscreen video modes are detected (#2300, #3151)
|
||||
- [macOS] Prevent unnecessary macOS input monitoring permission prompts (#2843, #3235)
|
||||
|
||||
### Graphics
|
||||
|
||||
|
@ -281,6 +281,7 @@ private:
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
IOHIDManagerRef m_manager; ///< Underlying HID Manager
|
||||
bool m_keysInitialized; ///< Has initializeKeyboard been called at least once?
|
||||
IOHIDElements m_keys[Keyboard::Scan::ScancodeCount]; ///< All the keys on any connected keyboard
|
||||
Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
||||
Keyboard::Key m_scancodeToKeyMapping[Keyboard::Scan::ScancodeCount]; ///< Mapping from Scancode to Key
|
||||
|
@ -555,6 +555,13 @@ bool HIDInputManager::isKeyPressed(Keyboard::Key key)
|
||||
////////////////////////////////////////////////////////////
|
||||
bool HIDInputManager::isKeyPressed(Keyboard::Scancode code)
|
||||
{
|
||||
// Lazy load m_keys to prevent unnecessary macOS input monitoring permission requests
|
||||
if (!m_keysInitialized)
|
||||
{
|
||||
initializeKeyboard();
|
||||
m_keysInitialized = true;
|
||||
}
|
||||
|
||||
return (code != Keyboard::Scan::Unknown) && isPressed(m_keys[code]);
|
||||
}
|
||||
|
||||
@ -694,7 +701,8 @@ String HIDInputManager::getDescription(Keyboard::Scancode code)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
HIDInputManager::HIDInputManager() :
|
||||
m_manager(0)
|
||||
m_manager(0),
|
||||
m_keysInitialized(false)
|
||||
{
|
||||
// Create an HID Manager reference
|
||||
m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
||||
@ -708,7 +716,6 @@ m_manager(0)
|
||||
}
|
||||
|
||||
// Build up our knownledge of the hardware
|
||||
initializeKeyboard();
|
||||
buildMappings();
|
||||
|
||||
// Register for notification on keyboard layout changes
|
||||
@ -908,6 +915,8 @@ void HIDInputManager::freeUp()
|
||||
CFRelease(m_manager);
|
||||
m_manager = 0;
|
||||
|
||||
if (m_keysInitialized)
|
||||
{
|
||||
for (unsigned int i = 0; i < Keyboard::KeyCount; ++i)
|
||||
{
|
||||
for (IOHIDElements::iterator it = m_keys[i].begin(); it != m_keys[i].end(); ++it)
|
||||
@ -916,6 +925,8 @@ void HIDInputManager::freeUp()
|
||||
m_keys[i].clear();
|
||||
}
|
||||
}
|
||||
m_keysInitialized = false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user