mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Fix OS X key names not following layout
This commit is contained in:
parent
7fd7dca375
commit
32f38b97d5
@ -200,6 +200,37 @@ static void createKeyTables(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve Unicode data for the current keyboard layout
|
||||||
|
//
|
||||||
|
static GLFWbool updateUnicodeDataNS(void)
|
||||||
|
{
|
||||||
|
if (_glfw.ns.inputSource)
|
||||||
|
{
|
||||||
|
CFRelease(_glfw.ns.inputSource);
|
||||||
|
_glfw.ns.inputSource = NULL;
|
||||||
|
_glfw.ns.unicodeData = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
_glfw.ns.inputSource = TISCopyCurrentKeyboardLayoutInputSource();
|
||||||
|
if (!_glfw.ns.inputSource)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Cocoa: Failed to retrieve keyboard layout input source");
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_glfw.ns.unicodeData = TISGetInputSourceProperty(_glfw.ns.inputSource,
|
||||||
|
kTISPropertyUnicodeKeyLayoutData);
|
||||||
|
if (!_glfw.ns.unicodeData)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Cocoa: Failed to retrieve keyboard layout Unicode data");
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GLFW_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Load HIToolbox.framework and the TIS symbols we need from it
|
// Load HIToolbox.framework and the TIS symbols we need from it
|
||||||
// This works only because Cocoa has already loaded it properly
|
// This works only because Cocoa has already loaded it properly
|
||||||
//
|
//
|
||||||
@ -216,6 +247,9 @@ static GLFWbool initializeTIS(void)
|
|||||||
CFStringRef* kPropertyUnicodeKeyLayoutData =
|
CFStringRef* kPropertyUnicodeKeyLayoutData =
|
||||||
CFBundleGetDataPointerForName(_glfw.ns.tis.bundle,
|
CFBundleGetDataPointerForName(_glfw.ns.tis.bundle,
|
||||||
CFSTR("kTISPropertyUnicodeKeyLayoutData"));
|
CFSTR("kTISPropertyUnicodeKeyLayoutData"));
|
||||||
|
CFStringRef* kNotifySelectedKeyboardInputSourceChanged =
|
||||||
|
CFBundleGetDataPointerForName(_glfw.ns.tis.bundle,
|
||||||
|
CFSTR("kTISNotifySelectedKeyboardInputSourceChanged"));
|
||||||
_glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource =
|
_glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource =
|
||||||
CFBundleGetFunctionPointerForName(_glfw.ns.tis.bundle,
|
CFBundleGetFunctionPointerForName(_glfw.ns.tis.bundle,
|
||||||
CFSTR("TISCopyCurrentKeyboardLayoutInputSource"));
|
CFSTR("TISCopyCurrentKeyboardLayoutInputSource"));
|
||||||
@ -227,6 +261,7 @@ static GLFWbool initializeTIS(void)
|
|||||||
CFSTR("LMGetKbdType"));
|
CFSTR("LMGetKbdType"));
|
||||||
|
|
||||||
if (!kPropertyUnicodeKeyLayoutData ||
|
if (!kPropertyUnicodeKeyLayoutData ||
|
||||||
|
!kNotifySelectedKeyboardInputSourceChanged ||
|
||||||
!TISCopyCurrentKeyboardLayoutInputSource ||
|
!TISCopyCurrentKeyboardLayoutInputSource ||
|
||||||
!TISGetInputSourceProperty ||
|
!TISGetInputSourceProperty ||
|
||||||
!LMGetKbdType)
|
!LMGetKbdType)
|
||||||
@ -236,22 +271,26 @@ static GLFWbool initializeTIS(void)
|
|||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfw.ns.tis.kPropertyUnicodeKeyLayoutData = *kPropertyUnicodeKeyLayoutData;
|
_glfw.ns.tis.kPropertyUnicodeKeyLayoutData =
|
||||||
|
*kPropertyUnicodeKeyLayoutData;
|
||||||
|
_glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged =
|
||||||
|
*kNotifySelectedKeyboardInputSourceChanged;
|
||||||
|
|
||||||
// TODO: Catch kTISNotifySelectedKeyboardInputSourceChanged and update
|
return updateUnicodeDataNS();
|
||||||
|
|
||||||
_glfw.ns.inputSource = TISCopyCurrentKeyboardLayoutInputSource();
|
|
||||||
if (!_glfw.ns.inputSource)
|
|
||||||
return GLFW_FALSE;
|
|
||||||
|
|
||||||
_glfw.ns.unicodeData = TISGetInputSourceProperty(_glfw.ns.inputSource,
|
|
||||||
kTISPropertyUnicodeKeyLayoutData);
|
|
||||||
if (!_glfw.ns.unicodeData)
|
|
||||||
return GLFW_FALSE;
|
|
||||||
|
|
||||||
return GLFW_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface GLFWLayoutListener : NSObject
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation GLFWLayoutListener
|
||||||
|
|
||||||
|
- (void)selectedKeyboardInputSourceChanged:(NSObject* )object
|
||||||
|
{
|
||||||
|
updateUnicodeDataNS();
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW platform API //////
|
////// GLFW platform API //////
|
||||||
@ -261,6 +300,13 @@ int _glfwPlatformInit(void)
|
|||||||
{
|
{
|
||||||
_glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
_glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
_glfw.ns.listener = [[GLFWLayoutListener alloc] init];
|
||||||
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
|
addObserver:_glfw.ns.listener
|
||||||
|
selector:@selector(selectedKeyboardInputSourceChanged:)
|
||||||
|
name:(__bridge NSString*)kTISNotifySelectedKeyboardInputSourceChanged
|
||||||
|
object:nil];
|
||||||
|
|
||||||
#if defined(_GLFW_USE_CHDIR)
|
#if defined(_GLFW_USE_CHDIR)
|
||||||
changeToResourcesDirectory();
|
changeToResourcesDirectory();
|
||||||
#endif
|
#endif
|
||||||
@ -294,6 +340,7 @@ void _glfwPlatformTerminate(void)
|
|||||||
{
|
{
|
||||||
CFRelease(_glfw.ns.inputSource);
|
CFRelease(_glfw.ns.inputSource);
|
||||||
_glfw.ns.inputSource = NULL;
|
_glfw.ns.inputSource = NULL;
|
||||||
|
_glfw.ns.unicodeData = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_glfw.ns.eventSource)
|
if (_glfw.ns.eventSource)
|
||||||
@ -309,6 +356,16 @@ void _glfwPlatformTerminate(void)
|
|||||||
_glfw.ns.delegate = nil;
|
_glfw.ns.delegate = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_glfw.ns.listener)
|
||||||
|
{
|
||||||
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
|
removeObserver:_glfw.ns.listener
|
||||||
|
name:(__bridge NSString*)kTISNotifySelectedKeyboardInputSourceChanged
|
||||||
|
object:nil];
|
||||||
|
[_glfw.ns.listener release];
|
||||||
|
_glfw.ns.listener = nil;
|
||||||
|
}
|
||||||
|
|
||||||
[_glfw.ns.cursor release];
|
[_glfw.ns.cursor release];
|
||||||
_glfw.ns.cursor = nil;
|
_glfw.ns.cursor = nil;
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ typedef void* id;
|
|||||||
|
|
||||||
// HIToolbox.framework pointer typedefs
|
// HIToolbox.framework pointer typedefs
|
||||||
#define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
|
#define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
|
||||||
|
#define kTISNotifySelectedKeyboardInputSourceChanged _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged
|
||||||
typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void);
|
typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void);
|
||||||
#define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource
|
#define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource
|
||||||
typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef);
|
typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef);
|
||||||
@ -92,6 +93,7 @@ typedef struct _GLFWlibraryNS
|
|||||||
id cursor;
|
id cursor;
|
||||||
TISInputSourceRef inputSource;
|
TISInputSourceRef inputSource;
|
||||||
id unicodeData;
|
id unicodeData;
|
||||||
|
id listener;
|
||||||
|
|
||||||
char keyName[64];
|
char keyName[64];
|
||||||
short int publicKeys[256];
|
short int publicKeys[256];
|
||||||
@ -104,6 +106,7 @@ typedef struct _GLFWlibraryNS
|
|||||||
PFN_TISGetInputSourceProperty GetInputSourceProperty;
|
PFN_TISGetInputSourceProperty GetInputSourceProperty;
|
||||||
PFN_LMGetKbdType GetKbdType;
|
PFN_LMGetKbdType GetKbdType;
|
||||||
CFStringRef kPropertyUnicodeKeyLayoutData;
|
CFStringRef kPropertyUnicodeKeyLayoutData;
|
||||||
|
CFStringRef kNotifySelectedKeyboardInputSourceChanged;
|
||||||
} tis;
|
} tis;
|
||||||
|
|
||||||
} _GLFWlibraryNS;
|
} _GLFWlibraryNS;
|
||||||
|
Loading…
Reference in New Issue
Block a user