unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* Mac OSX keyboard input fails for custom layouts
@ 2005-12-14  8:58 Nikolaj Schumacher
  0 siblings, 0 replies; only message in thread
From: Nikolaj Schumacher @ 2005-12-14  8:58 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

In Mac OSX there are two kind of keyboard resources: classic and  
unicode. XML .keylayout files only provide a unicode resource and  
Emacs currently only uses the classic resource. As a result keys  
pressed with modifiers will result in a completely wrong key (while  
normal text input works correctly).

I've written a short patch for emacs-20.0.50.2 which solved the issue  
for me. It should be rather save to include since most of the code is  
only executed when no classic resource is available anyway. However  
it will only work on OSX >= 10.2. Is that implied by #define MAC_OSX?  
Some of the code I've seen seemed to suggest that. If not, how do I  
check for it?

regards,
Nikolaj Schumacher


[-- Attachment #2: emacs_mac_unicode_keyboard.patch --]
[-- Type: application/octet-stream, Size: 2074 bytes --]

Index: src/macterm.c
===================================================================
RCS file: /sources/emacs/emacs/src/macterm.c,v
retrieving revision 1.146
diff -p -u -r1.146 macterm.c
--- src/macterm.c	10 Dec 2005 01:49:53 -0000	1.146
+++ src/macterm.c	13 Dec 2005 14:29:16 -0000
@@ -9434,9 +9434,45 @@ backtranslate_modified_keycode(int mods,
       /* set high byte of keycode to modifier high byte*/
       int new_keycode = keycode | new_modifiers;
       Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
-      unsigned long some_state = 0;
-      return (int) KeyTranslate (kchr_ptr, new_keycode,
-			   &some_state) & 0xff;
+      unsigned long dead_key_state = 0;
+
+#ifdef MAC_OSX
+      /* requires 10.2! */
+      KeyboardLayoutRef layout_ref;
+      KeyboardLayoutKind layout_kind;
+      if (KLGetCurrentKeyboardLayout (&layout_ref) == noErr)
+	KLGetKeyboardLayoutProperty (layout_ref, kKLKind,
+				     (const void**) &layout_kind);
+
+      /* There are two kind of keyboard resources: classic and unicode.
+	 layout_kind currently can have these values:
+	 kKLuchrKind: unicode keyboard
+	 kKLKHCRKind: normal keyboard
+	 kKLKHCRuchrKind: both
+      */
+
+      if (layout_kind == kKLuchrKind)
+	{
+	  UCKeyboardLayout *layout;
+	  KLGetKeyboardLayoutProperty (layout_ref, kKLuchrData,
+				       (const void**) &layout);
+	  UniCharCount output_length = 1;
+	  UniChar output[output_length];
+	  UCKeyTranslate (layout, keycode, kUCKeyActionDown, new_modifiers >> 8,
+			  LMGetKbdType (), 0, &dead_key_state, output_length,
+			  &output_length, output);
+	  if (output_length < 1)
+	    /* Fall back to returning the keycode which is wrong.
+	       See TO DO below. */
+	    return keycode;
+	  return output[0];
+	} else
+#endif /* MAC_OSX */
+	{
+	  return (int) KeyTranslate (kchr_ptr, new_keycode,
+				     &dead_key_state) & 0xff;
+	}
+
       /* TO DO: Recognize two separate resulting characters, "for
 	 example, when the user presses Option-E followed by N, you
 	 can map this through the KeyTranslate function using the

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-12-14  8:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-14  8:58 Mac OSX keyboard input fails for custom layouts Nikolaj Schumacher

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).