Handle layout changes on macOS

This commit is contained in:
Marco Antognini 2017-05-26 11:03:21 +02:00 committed by Lukas Dürrenberger
parent e806048904
commit cabf1a3c34
2 changed files with 28 additions and 1 deletions

View File

@ -206,10 +206,15 @@ private:
void loadKey(IOHIDElementRef key); 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(); void buildMappings();
private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Release all resources /// \brief Release all resources

View File

@ -30,6 +30,15 @@
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
namespace
{
void keyboardChanged(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef)
{
sf::priv::HIDInputManager* manager = static_cast<sf::priv::HIDInputManager*>(observer);
manager->buildMappings();
}
}
namespace sf namespace sf
{ {
namespace priv namespace priv
@ -228,8 +237,19 @@ m_manager(0)
return; return;
} }
// Build up our knownledge of the hardware
initializeKeyboard(); initializeKeyboard();
buildMappings(); 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() HIDInputManager::~HIDInputManager()
{ {
freeUp(); freeUp();
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDistributedCenter(), this);
} }