diff --git a/src/SFML/Window/OSX/HIDInputManager.hpp b/src/SFML/Window/OSX/HIDInputManager.hpp index 6bdb579b..7ead4dc2 100644 --- a/src/SFML/Window/OSX/HIDInputManager.hpp +++ b/src/SFML/Window/OSX/HIDInputManager.hpp @@ -206,10 +206,15 @@ private: void loadKey(IOHIDElementRef key); //////////////////////////////////////////////////////////// - /// Regenerate the mappings from/to Key and Scancode + /// Regenerate the mappings from/to Key and Scancode. + /// + /// It is public to allow regular callback to forward the + /// information to the manager. /// //////////////////////////////////////////////////////////// +public: void buildMappings(); +private: //////////////////////////////////////////////////////////// /// \brief Release all resources diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index 0e833f74..ac8d2bcb 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -30,6 +30,15 @@ #include #include +namespace +{ + void keyboardChanged(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef) + { + sf::priv::HIDInputManager* manager = static_cast(observer); + manager->buildMappings(); + } +} + namespace sf { namespace priv @@ -228,8 +237,19 @@ m_manager(0) return; } + // Build up our knownledge of the hardware initializeKeyboard(); buildMappings(); + + // Register for notification on keyboard layout changes + CFNotificationCenterAddObserver( + CFNotificationCenterGetDistributedCenter(), + this, + keyboardChanged, // callback + kTISNotifySelectedKeyboardInputSourceChanged, + NULL, // use callback + CFNotificationSuspensionBehaviorDeliverImmediately + ); } @@ -237,6 +257,8 @@ m_manager(0) HIDInputManager::~HIDInputManager() { freeUp(); + + CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDistributedCenter(), this); }