diff --git a/configure.ac b/configure.ac index f2a8332d71..b5db45801d 100644 --- a/configure.ac +++ b/configure.ac @@ -5260,7 +5260,7 @@ AC_DEFUN if test "$HAVE_NS" = "yes"; then libs_nsgui="-framework AppKit" if test "$NS_IMPL_COCOA" = "yes"; then - libs_nsgui="$libs_nsgui -framework IOKit" + libs_nsgui="$libs_nsgui -framework IOKit -framework Carbon" fi else libs_nsgui= diff --git a/src/nsterm.m b/src/nsterm.m index 29aef0e9b6..2038c02e60 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -69,6 +69,8 @@ Updated by Christian Limpach (chris@nice.ch) #include "macfont.h" #endif +#include + static EmacsMenu *dockMenu; #ifdef NS_IMPL_COCOA static EmacsMenu *mainMenu; @@ -2681,6 +2683,45 @@ so some key presses (TAB) are swallowed by the system. */ } +static UniChar +ns_get_shifted_character (NSEvent *event) +{ + static UInt32 deadKeyState; + + CFDataRef layout_ref = (CFDataRef) TISGetInputSourceProperty + (TISCopyCurrentKeyboardLayoutInputSource (), kTISPropertyUnicodeKeyLayoutData); + UCKeyboardLayout* layout = CFDataGetBytePtr (layout_ref); + + UniChar buf[255]; + UniCharCount maxStringLength; + UniCharCount actualStringLength; + OSStatus result; + + unsigned int flags = [event modifierFlags]; + UInt32 modifiers = (flags & NSEventModifierFlagShift) ? shiftKey : 0; + modifiers |= ((flags & NSRightAlternateKeyMask) == NSRightAlternateKeyMask + && EQ (ns_right_alternate_modifier, Qnone)) ? rightOptionKey : 0; + modifiers |= ((flags & NSLeftAlternateKeyMask) == NSLeftAlternateKeyMask + && EQ (ns_alternate_modifier, Qnone)) ? optionKey : 0; + + modifiers |= ((flags & NSRightCommandKeyMask) == NSRightCommandKeyMask + && EQ (ns_right_command_modifier, Qnone)) ? cmdKey : 0; + modifiers |= ((flags & NSLeftCommandKeyMask) == NSLeftCommandKeyMask + && EQ (ns_command_modifier, Qnone)) ? cmdKey : 0; + + result = UCKeyTranslate (layout, + [event keyCode], kUCKeyActionDown, + (modifiers >> 8) & 0xFF, + LMGetKbdType (), kUCKeyTranslateNoDeadKeysBit, + &deadKeyState, 255, &actualStringLength, + buf); + + if (result != 0) + NSLog(@"Disaster!"); + + return buf[0]; +} + /* ========================================================================== @@ -6147,7 +6188,8 @@ most recently updated (I guess), which is not the correct one. */ /* FIXME: What should happen for key sequences with more than one character? */ code = ([[theEvent charactersIgnoringModifiers] length] == 0) ? - 0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: 0]; + 0 : //[[theEvent charactersIgnoringModifiers] characterAtIndex: 0]; + ns_get_shifted_character (theEvent); /* (Carbon way: [theEvent keyCode]) */