/[emacs]/emacs/src/macterm.c
ViewVC logotype

Diff of /emacs/src/macterm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.141 by mituharu, Tue Oct 25 08:13:16 2005 UTC revision 1.142 by tamm, Fri Nov 11 16:33:44 2005 UTC
# Line 86  Boston, MA 02110-1301, USA.  */ Line 86  Boston, MA 02110-1301, USA.  */
86  #include "intervals.h"  #include "intervals.h"
87  #include "atimer.h"  #include "atimer.h"
88  #include "keymap.h"  #include "keymap.h"
89    
 /* Set of macros that handle mapping of Mac modifier keys to emacs.  */  
 #define macCtrlKey     (NILP (Vmac_reverse_ctrl_meta) ? controlKey :    \  
                         (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))  
 #define macShiftKey    (shiftKey)  
 #define macMetaKey     (NILP (Vmac_reverse_ctrl_meta) ?                 \  
                         (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \  
                         : controlKey)  
 #define macAltKey      (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey)  
90    
91    
92  /* Non-nil means Emacs uses toolkit scroll bars.  */  /* Non-nil means Emacs uses toolkit scroll bars.  */
# Line 207  extern EMACS_INT extra_keyboard_modifier Line 199  extern EMACS_INT extra_keyboard_modifier
199    
200  /* The keysyms to use for the various modifiers.  */  /* The keysyms to use for the various modifiers.  */
201    
202  static Lisp_Object Qalt, Qhyper, Qsuper, Qmodifier_value;  static Lisp_Object Qalt, Qhyper, Qsuper, Qctrl,
203      Qmeta, Qmodifier_value;
204    
205  extern int inhibit_window_system;  extern int inhibit_window_system;
206    
# Line 7920  x_find_ccl_program (fontp) Line 7913  x_find_ccl_program (fontp)
7913  /* Contains the string "reverse", which is a constant for mouse button emu.*/  /* Contains the string "reverse", which is a constant for mouse button emu.*/
7914  Lisp_Object Qreverse;  Lisp_Object Qreverse;
7915    
 /* True if using command key as meta key.  */  
 Lisp_Object Vmac_command_key_is_meta;  
7916    
7917  /* Modifier associated with the option key, or nil for normal behavior. */  /* Modifier associated with the control key, or nil to ignore. */
7918    Lisp_Object Vmac_control_modifier;
7919    
7920    /* Modifier associated with the option key, or nil to ignore. */
7921  Lisp_Object Vmac_option_modifier;  Lisp_Object Vmac_option_modifier;
7922    
7923  /* True if the ctrl and meta keys should be reversed.  */  /* Modifier associated with the command key, or nil to ignore. */
7924  Lisp_Object Vmac_reverse_ctrl_meta;  Lisp_Object Vmac_command_modifier;
7925    
7926    /* Modifier associated with the function key, or nil to ignore. */
7927    Lisp_Object Vmac_function_modifier;
7928    
7929  /* True if the option and command modifiers should be used to emulate  /* True if the option and command modifiers should be used to emulate
7930     a three button mouse */     a three button mouse */
# Line 8001  mac_to_emacs_modifiers (EventModifiers m Line 7998  mac_to_emacs_modifiers (EventModifiers m
7998  #endif  #endif
7999  {  {
8000    unsigned int result = 0;    unsigned int result = 0;
8001    if (mods & macShiftKey)    if (mods & shiftKey)
8002      result |= shift_modifier;      result |= shift_modifier;
8003    if (mods & macCtrlKey)  
8004      result |= ctrl_modifier;  
8005    if (mods & macMetaKey)  
8006      result |= meta_modifier;    /* Deactivated to simplify configuration:
8007    if (NILP (Vmac_command_key_is_meta) && (mods & macAltKey))       if Vmac_option_modifier is non-NIL, we fully process the Option
8008      result |= alt_modifier;       key. Otherwise, we only process it if an additional Ctrl or Command
8009         is pressed. That way the system may convert the character to a
8010         composed one.
8011         if ((mods & optionKey) &&
8012          (( !NILP(Vmac_option_modifier) ||
8013          ((mods & cmdKey) || (mods & controlKey))))) */
8014    
8015    if (!NILP (Vmac_option_modifier) && (mods & optionKey)) {    if (!NILP (Vmac_option_modifier) && (mods & optionKey)) {
8016        Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value);      Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value);
8017        if (!NILP(val))      if (INTEGERP(val))
8018            result |= XUINT(val);        result |= XUINT(val);
8019    }    }
8020      if (!NILP (Vmac_command_modifier) && (mods & cmdKey)) {
8021        Lisp_Object val = Fget(Vmac_command_modifier, Qmodifier_value);
8022        if (INTEGERP(val))
8023          result |= XUINT(val);
8024      }  
8025      if (!NILP (Vmac_control_modifier) && (mods & controlKey)) {
8026        Lisp_Object val = Fget(Vmac_control_modifier, Qmodifier_value);
8027        if (INTEGERP(val))
8028          result |= XUINT(val);
8029      }  
8030    
8031    #ifdef MAC_OSX
8032      if (!NILP (Vmac_function_modifier) && (mods & kEventKeyModifierFnMask)) {
8033        Lisp_Object val = Fget(Vmac_function_modifier, Qmodifier_value);
8034        if (INTEGERP(val))
8035          result |= XUINT(val);
8036      }
8037    #endif
8038    
8039    return result;    return result;
8040  }  }
8041    
# Line 8035  mac_get_emulated_btn ( UInt32 modifiers Line 8056  mac_get_emulated_btn ( UInt32 modifiers
8056  #if USE_CARBON_EVENTS  #if USE_CARBON_EVENTS
8057  /* Obtains the event modifiers from the event ref and then calls  /* Obtains the event modifiers from the event ref and then calls
8058     mac_to_emacs_modifiers.  */     mac_to_emacs_modifiers.  */
8059  static int  static UInt32
8060  mac_event_to_emacs_modifiers (EventRef eventRef)  mac_event_to_emacs_modifiers (EventRef eventRef)
8061  {  {
8062    UInt32 mods = 0;    UInt32 mods = 0;
# Line 9385  static unsigned char keycode_to_xkeysym_ Line 9406  static unsigned char keycode_to_xkeysym_
9406    /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0    /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
9407  };  };
9408    
9409  static int  
9410    static int
9411  keycode_to_xkeysym (int keyCode, int *xKeySym)  keycode_to_xkeysym (int keyCode, int *xKeySym)
9412  {  {
9413    *xKeySym = keycode_to_xkeysym_table [keyCode & 0x7f];    *xKeySym = keycode_to_xkeysym_table [keyCode & 0x7f];
9414    return *xKeySym != 0;    return *xKeySym != 0;
9415  }  }
9416    
9417    static unsigned char fn_keycode_to_xkeysym_table[] = {
9418      /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9419      /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9420      /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9421    
9422      /*0x30*/ 0, 0, 0, 0,
9423      /*0x34*/ 0, 0, 0, 0,
9424      /*0x38*/ 0, 0, 0, 0,
9425      /*0x3C*/ 0, 0, 0, 0,
9426    
9427      /*0x40*/ 0, 0x2e /*kp-. = .*/, 0, 0x50 /*kp-* = 'p'*/,
9428      /*0x44*/ 0, '/' /*kp-+*/, 0, 0,
9429      /*0x48*/ 0, 0, 0, 0x30 /*kp-/ = '0'*/,
9430      /*0x4C*/ 0, 0, 0x3b /*kp-- = ';'*/, 0,
9431    
9432      /*0x50*/ 0, 0x2d /*kp-= = '-'*/, 0x6d /*kp-0 = 'm'*/, 0x6a /*kp-1 = 'j'*/,
9433      /*0x54*/ 0x6b /*kp-2 = 'k'*/, 0x6c /*kp-3 = 'l'*/, 'u' /*kp-4*/, 'i' /*kp-5*/,
9434      /*0x58*/ 'o' /*kp-6*/, '7' /*kp-7*/, 0, '8' /*kp-8*/,
9435      /*0x5C*/ '9' /*kp-9*/, 0, 0, 0,
9436    
9437      /*0x60*/ 0, 0, 0, 0,
9438      /*0x64*/ 0, 0, 0, 0,
9439      /*0x68*/ 0, 0, 0, 0,
9440      /*0x6C*/ 0, 0, 0, 0,
9441    
9442      /*0x70*/ 0, 0, 0, 0,
9443      /*0x74*/ 0, 0, 0, 0,
9444      /*0x78*/ 0, 0, 0, 0,
9445      /*0x7C*/ 0, 0, 0, 0
9446    };
9447    static int
9448    convert_fn_keycode (EventRef eventRef, int keyCode, int *newCode)
9449    {
9450    #ifdef MAC_OSX
9451      /* Use the special map to translate keys when function modifier is
9452         to be caught. KeyTranslate can't be used in that case.
9453         We can't detect the function key using the input_event.modifiers,
9454         because this uses the high word of an UInt32. Therefore,
9455         we'll just read it out of the original eventRef.
9456      */
9457    
9458    
9459      /* TODO / known issues
9460    
9461      - Fn-Shift-j is regonized as Fn-j and not Fn-J.
9462      The above table always translates to lower characters. We need to use
9463      the KCHR keyboard resource (KeyTranslate() ) to map k->K and 8->*.
9464    
9465      - The table is meant for English language keyboards, and it will work
9466      for many others with the exception of key combinations like Fn-ö on
9467      a German keyboard, which is currently mapped to Fn-;.
9468      How to solve this without keeping separate tables for all keyboards
9469      around? KeyTranslate isn't of much help here, as it only takes a 16-bit
9470      value for keycode with the modifiers in he high byte, i.e. no room for the
9471      Fn modifier. That's why we need the table.
9472    
9473      */
9474    
9475      UInt32 mods = 0;
9476      if (!NILP(Vmac_function_modifier))  
9477        {
9478          GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL,
9479                             sizeof (UInt32), NULL, &mods);
9480          if (mods & kEventKeyModifierFnMask)
9481            {  *newCode = fn_keycode_to_xkeysym_table [keyCode & 0x7f];
9482              
9483              return (*newCode != 0);
9484            }
9485        }
9486    #endif
9487      return false;
9488    }
9489    
9490    static int
9491    backtranslate_modified_keycode(int mods, int keycode, int def)
9492    {
9493      if  (mods &
9494           (controlKey |
9495            (NILP (Vmac_option_modifier) ? 0 : optionKey) |
9496            cmdKey))
9497        {
9498          /* This code comes from Keyboard Resource,
9499             Appendix C of IM - Text.  This is necessary
9500             since shift is ignored in KCHR table
9501             translation when option or command is pressed.
9502             It also does not translate correctly
9503             control-shift chars like C-% so mask off shift
9504             here also.
9505    
9506             Not done for combinations with the option key (alt)
9507             unless it is to be caught by Emacs:  this is
9508             to preserve key combinations translated by the OS
9509             such as Alt-3.
9510          */
9511          /* mask off option and command */
9512          int new_modifiers = mods & 0xe600;
9513          /* set high byte of keycode to modifier high byte*/
9514          int new_keycode = keycode | new_modifiers;
9515          Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
9516          unsigned long some_state = 0;
9517          return (int) KeyTranslate (kchr_ptr, new_keycode,
9518                               &some_state) & 0xff;
9519          /* TO DO: Recognize two separate resulting characters, "for
9520             example, when the user presses Option-E followed by N, you
9521             can map this through the KeyTranslate function using the
9522             U.S. 'KCHR' resource to produce ´n, which KeyTranslate
9523             returns as two characters in the bytes labeled Character code
9524             1 and Character code 2." (from Carbon API doc) */
9525    
9526        }
9527      else
9528        return def;
9529    }
9530    
9531    
9532  #if !USE_CARBON_EVENTS  #if !USE_CARBON_EVENTS
9533  static RgnHandle mouse_region = NULL;  static RgnHandle mouse_region = NULL;
9534    
# Line 9936  XTread_socket (sd, expected, hold_quit) Line 10073  XTread_socket (sd, expected, hold_quit)
10073                   || !(er.modifiers & cmdKey))                   || !(er.modifiers & cmdKey))
10074                  && (!NILP (Vmac_pass_control_to_system)                  && (!NILP (Vmac_pass_control_to_system)
10075                      || !(er.modifiers & controlKey))                      || !(er.modifiers & controlKey))
10076                  && (!NILP (Vmac_command_key_is_meta)                  && (NILP (Vmac_option_modifier)
                     && NILP (Vmac_option_modifier)  
10077                      || !(er.modifiers & optionKey)))                      || !(er.modifiers & optionKey)))
10078                if (SendEventToEventTarget (eventRef, toolbox_dispatcher)                if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
10079                    != eventNotHandledErr)                    != eventNotHandledErr)
# Line 9981  XTread_socket (sd, expected, hold_quit) Line 10117  XTread_socket (sd, expected, hold_quit)
10117                  dpyinfo->mouse_face_hidden = 1;                  dpyinfo->mouse_face_hidden = 1;
10118                }                }
10119    
10120              if (keycode_to_xkeysym (keycode, &xkeysym))              /* translate the keycode back to determine the original key */
10121                {              /* Convert key code if function key is pressed.
10122                  inev.code = 0xff00 | xkeysym;                 Otherwise, if non-ASCII-event, take care of that
10123                  inev.kind = NON_ASCII_KEYSTROKE_EVENT;                 without re-translating the key code. */
10124                }  #if USE_CARBON_EVENTS
10125              else              if (convert_fn_keycode (eventRef, keycode, &xkeysym))
10126                {                {
10127                  if (er.modifiers & (controlKey |                  inev.code = xkeysym;
10128                                      (NILP (Vmac_command_key_is_meta) ? optionKey                  /* this doesn't work - tried to add shift modifiers */
10129                                       : cmdKey)))                    inev.code =  
10130                    {                      backtranslate_modified_keycode(er.modifiers & (~0x2200),
10131                      /* This code comes from Keyboard Resource,                                                     xkeysym | 0x80,  xkeysym);
                        Appendix C of IM - Text.  This is necessary  
                        since shift is ignored in KCHR table  
                        translation when option or command is pressed.  
                        It also does not translate correctly  
                        control-shift chars like C-% so mask off shift  
                        here also */  
                     int new_modifiers = er.modifiers & 0xe600;  
                     /* mask off option and command */  
                     int new_keycode = keycode | new_modifiers;  
                     Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);  
                     unsigned long some_state = 0;  
                     inev.code = KeyTranslate (kchr_ptr, new_keycode,  
                                               &some_state) & 0xff;  
                   }  
                 else if (!NILP (Vmac_option_modifier)  
                          && (er.modifiers & optionKey))  
                   {  
                     /* When using the option key as an emacs modifier,  
                        convert the pressed key code back to one  
                        without the Mac option modifier applied. */  
                     int new_modifiers = er.modifiers & ~optionKey;  
                     int new_keycode = keycode | new_modifiers;  
                     Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);  
                     unsigned long some_state = 0;  
                     inev.code = KeyTranslate (kchr_ptr, new_keycode,  
                                               &some_state) & 0xff;  
                   }  
                 else  
                   inev.code = er.message & charCodeMask;  
10132                  inev.kind = ASCII_KEYSTROKE_EVENT;                  inev.kind = ASCII_KEYSTROKE_EVENT;
10133                }                }
10134                else
10135    #endif      
10136                  if (keycode_to_xkeysym (keycode, &xkeysym))
10137                    {
10138                      inev.code = 0xff00 | xkeysym;
10139                      inev.kind = NON_ASCII_KEYSTROKE_EVENT;
10140                    }
10141                  else
10142                    {
10143    
10144                      inev.code =
10145                        backtranslate_modified_keycode(er.modifiers, keycode,
10146                                                       er.message & charCodeMask);
10147                      inev.kind = ASCII_KEYSTROKE_EVENT;
10148    
10149                    }
10150            }            }
10151    
10152  #if USE_CARBON_EVENTS  #if USE_CARBON_EVENTS
# Line 10463  mac_determine_quit_char_modifiers() Line 10586  mac_determine_quit_char_modifiers()
10586    
10587    /* Map modifiers */    /* Map modifiers */
10588    mac_quit_char_modifiers = 0;    mac_quit_char_modifiers = 0;
10589    if (qc_modifiers & ctrl_modifier)  mac_quit_char_modifiers |= macCtrlKey;    if (qc_modifiers & ctrl_modifier)  mac_quit_char_modifiers |= controlKey;
10590    if (qc_modifiers & shift_modifier) mac_quit_char_modifiers |= macShiftKey;    if (qc_modifiers & shift_modifier) mac_quit_char_modifiers |= shiftKey;
10591    if (qc_modifiers & meta_modifier)  mac_quit_char_modifiers |= macMetaKey;    if (qc_modifiers & alt_modifier)   mac_quit_char_modifiers |= optionKey;
   if (qc_modifiers & alt_modifier)   mac_quit_char_modifiers |= macAltKey;  
10592  }  }
10593    
10594  static void  static void
# Line 10623  syms_of_macterm () Line 10745  syms_of_macterm ()
10745  #endif  #endif
10746    
10747    Qmodifier_value = intern ("modifier-value");    Qmodifier_value = intern ("modifier-value");
10748      Qctrl = intern ("ctrl");
10749      Fput (Qctrl, Qmodifier_value, make_number (ctrl_modifier));
10750      Qmeta = intern ("meta");
10751      Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));
10752    Qalt = intern ("alt");    Qalt = intern ("alt");
10753    Fput (Qalt, Qmodifier_value, make_number (alt_modifier));    Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
10754    Qhyper = intern ("hyper");    Qhyper = intern ("hyper");
# Line 10674  syms_of_macterm () Line 10800  syms_of_macterm ()
10800    
10801    staticpro (&last_mouse_motion_frame);    staticpro (&last_mouse_motion_frame);
10802    last_mouse_motion_frame = Qnil;    last_mouse_motion_frame = Qnil;
10803    
10804    
10805    
10806    DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta,  /* Variables to configure modifier key assignment.  */
10807      doc: /* Non-nil means that the command key is used as the Emacs meta key.          
10808  Otherwise the option key is used.  */);    DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier,
10809    Vmac_command_key_is_meta = Qt;      doc: /* Modifier key assumed when the Mac control key is pressed.  
10810    The value can be `alt', `ctrl', `hyper', or `super' for the respective
10811    modifier.  The default is `ctrl'.  */);
10812      Vmac_control_modifier = Qctrl;
10813    
10814    DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier,    DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier,
10815      doc: /* Modifier to use for the Mac alt/option key.  The value can      doc: /* Modifier key assumed when the Mac alt/option key is pressed.
10816  be alt, hyper, or super for the respective modifier.  If the value is  The value can be `alt', `ctrl', `hyper', or `super' for the respective
10817  nil then the key will act as the normal Mac option modifier.  */);  modifier.  If the value is nil then the key will act as the normal
10818    Mac control modifier, and the option key can be used to compose
10819    characters depending on the chosen Mac keyboard setting. */);
10820    Vmac_option_modifier = Qnil;    Vmac_option_modifier = Qnil;
10821    
10822    DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta,    DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier,
10823      doc: /* Non-nil means that the control and meta keys are reversed.  This is      doc: /* Modifier key assumed when the Mac command key is pressed.  
10824  useful for non-standard keyboard layouts.  */);  The value can be `alt', `ctrl', `hyper', or `super' for the respective
10825    Vmac_reverse_ctrl_meta = Qnil;  modifier. The default is `meta'. */);
10826      Vmac_command_modifier = Qmeta;
10827    
10828      DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier,
10829        doc: /* Modifier key assumed when the Mac function key is pressed.  
10830    The value can be `alt', `ctrl', `hyper', or `super' for the respective
10831    modifier. Note that remapping the function key may lead to unexpected
10832    results for some keys on non-US/GB keyboards.  */);
10833      Vmac_function_modifier = Qnil;
10834    
10835    DEFVAR_LISP ("mac-emulate-three-button-mouse",    DEFVAR_LISP ("mac-emulate-three-button-mouse",
10836                 &Vmac_emulate_three_button_mouse,                 &Vmac_emulate_three_button_mouse,

Legend:
Removed from v.1.141  
changed lines
  Added in v.1.142

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26