From d046bd88ad84f99789fbc7e544e8c8b929f14faf Mon Sep 17 00:00:00 2001 From: Rhody Lugo Date: Thu, 8 Jan 2015 02:56:27 -0430 Subject: [PATCH 1/2] OS X: Add keyboard layout detection and fix build --- drivers/theoraplayer/SCsub | 2 +- platform/osx/detect.py | 2 +- platform/osx/os_osx.h | 2 + platform/osx/os_osx.mm | 96 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/drivers/theoraplayer/SCsub b/drivers/theoraplayer/SCsub index 419f2b65ae6..09fb13d8e9e 100644 --- a/drivers/theoraplayer/SCsub +++ b/drivers/theoraplayer/SCsub @@ -70,7 +70,7 @@ if env["platform"] == "iphone": env_theora.Append(CPPFLAGS=["-D_IOS", "-D__ARM_NEON__", "-fstrict-aliasing", "-fmessage-length=210", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fcolor-diagnostics", "-Wno-trigraphs", "-fpascal-strings", "-fvisibility=hidden", "-fvisibility-inlines-hidden"]) env_theora.Append(CPPFLAGS=["-D_LIB", "-D__THEORA"]) # removed -D_YUV_C -env_theora.Append(CPPFLAGS=["-D_YUV_LIBYUV", "-DLIBYUV_NEON"]) +env_theora.Append(CPPFLAGS=["-D_YUV_LIBYUV"]) #env_theora.Append(CPPFLAGS=["-D_YUV_C"]) if env["platform"] == "iphone": diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 1b32838525e..141a876657f 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -78,7 +78,7 @@ def configure(env): env.Append(LIBS=['pthread']) #env.Append(CPPFLAGS=['-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-mmacosx-version-min=10.4']) #env.Append(LINKFLAGS=['-mmacosx-version-min=10.4', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk']) - env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit','-lz']) + env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit','-lz']) if (env["CXX"]=="clang++"): env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND']) diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 5df85bca2ab..24f7115938f 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -156,6 +156,8 @@ public: virtual String get_executable_path() const; + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + virtual void move_window_to_foreground(); void run(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 1703ae4c492..f8902283c6e 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -27,6 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #import + +#include #include #include #include @@ -835,11 +837,24 @@ void OS_OSX::initialize_core() { } +static bool keyboard_layout_dirty = true; +static void keyboardLayoutChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { + keyboard_layout_dirty = true; +} + void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { /*** OSX INITIALIZATION ***/ /*** OSX INITIALIZATION ***/ /*** OSX INITIALIZATION ***/ + + keyboard_layout_dirty = true; + + // Register to be notified on keyboard layout changes + CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), + NULL, keyboardLayoutChanged, + kTISNotifySelectedKeyboardInputSourceChanged, NULL, + CFNotificationSuspensionBehaviorDeliverImmediately); window_delegate = [[GodotWindowDelegate alloc] init]; @@ -1007,6 +1022,8 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } void OS_OSX::finalize() { + CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL); + } void OS_OSX::set_main_loop( MainLoop * p_main_loop ) { @@ -1241,6 +1258,85 @@ String OS_OSX::get_executable_path() const { } +// Returns string representation of keys, if they are printable. +// +static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) { + + TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); + if (!currentKeyboard) + return nil; + + CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData); + if (!layoutData) + return nil; + + const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData); + + OSStatus err; + CFMutableStringRef output = CFStringCreateMutable(NULL, 0); + + for (int i=0; i Date: Thu, 8 Jan 2015 10:31:10 -0430 Subject: [PATCH 2/2] Create the test string to detect kb layouts directly from the unicode chars --- platform/osx/os_osx.mm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index f8902283c6e..5bc47a74c18 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1297,9 +1297,7 @@ static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) { return nil; } - CFStringRef chararter = CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1); - CFStringAppend(output, chararter); - CFRelease(chararter); + CFStringAppendCharacters(output, chars, 1); } //CFStringUppercase(output, NULL);