emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Free modifier key assignment (OS X)


From: YAMAMOTO Mitsuharu
Subject: Re: Free modifier key assignment (OS X)
Date: Tue, 27 Sep 2005 12:45:22 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/22.0.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Sun, 25 Sep 2005 21:34:18 +0100, David Reitter <address@hidden> said:

> Here is the latest version of mac-modifier-keys patch, which allows
> people to freely assign modifier keys on their keyboard to Emacs
> modifiers.

Let me make a few comments.

  * Please follow the convention written in the "Tips for
    Documentation Strings" node in the Emacs Lisp info.  Yes, the
    existing one is really bad in this sense.

  * I think the following kind of indentation is not used in Emacs
    sources unless preprocessor directives intervene.

!       if (
!         (mods & optionKey) &&
!         (
!          ( NILP(Vmac_pass_option_to_system) || 

  * I'd prefer a simple principle especially for the option key
    handling.  I'm anxious that too complicated one might become an
    obstacle when adding Unicode input support or TSM support.  A
    simple one would be useful not only for the maintenance of code
    but also for users to understand.  How about the following one?

      A Mac modifier key is passed to the system if it isn't mapped to
      any Emacs modifiers or the user requests that by setting
      mac-pass-{control,command}-to-system to non-nil.

      If the system didn't intercept the keyboard input, we obtain
      keycode using KeyTranslate after stripping off all the Mac
      modifier keys that are mapped to some Emacs modifiers.

   In particular, the option key works as the real option key if and
   only if it isn't mapped to any Emacs modifiers.  (I.e., don't
   introduce the variable `mac-pass-option-to-system'.)

   Then the conditionals becomes much simpler.  Note that this code is
   based on the current definition of macCtrlKey/macMetaKey/macAltKey.

        case autoKey:
          {
            int keycode = (er.message & keyCodeMask) >> 8;
            int xkeysym;
            EventModifiers modifiers;

            /* Obtain Mac modifier keys that are pressed and to be
               mapped to Emacs modifiers.  */
            modifiers = macCtrlKey | macMetaKey | macAltKey;
            if (!NILP (Vmac_option_modifier))
              modifiers |= optionKey;
            modifiers &= er.modifiers;

#if USE_CARBON_EVENTS && defined (MAC_OSX)
            /* When using Carbon Events, we need to pass raw keyboard
               events to the TSM ourselves.  If TSM handles it, it
               will pass back noErr, otherwise it will pass back
               "eventNotHandledErr" and we can process it
               normally.  */
            if (!((NILP (Vmac_pass_command_to_system)
                   && (modifiers & cmdKey))
                  || (NILP (Vmac_pass_control_to_system)
                      && (modifiers & controlKey))
                  || (modifiers & optionKey)))
              if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
                  != eventNotHandledErr)
                break;
#endif

            ...

            if (keycode_to_xkeysym (keycode, &xkeysym))
              {
                inev.code = 0xff00 | xkeysym;
                inev.kind = NON_ASCII_KEYSTROKE_EVENT;
              }
            else
              {
                if (modifiers)
                  {
                    /* This code comes from Keyboard Resource,
                       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 */
                    EventModifiers new_modifiers = er.modifiers & ~modifiers;
                    /* mask off modifiers */
                    UInt16 new_keycode = keycode | new_modifiers & 0xff00;
                    Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
                    UInt32 some_state = 0;

                    inev.code = KeyTranslate (kchr_ptr, new_keycode,
                                              &some_state) & 0xff;
                  }
                else
                  inev.code = er.message & charCodeMask;
                inev.kind = ASCII_KEYSTROKE_EVENT;
              }

                                     YAMAMOTO Mitsuharu
                                address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]