unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: emacs-devel@gnu.org
Subject: Re: Free modifier key assignment (OS X)
Date: Tue, 27 Sep 2005 12:45:22 +0900	[thread overview]
Message-ID: <wlzmpzfa25.wl%mituharu@math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <1949F677-E294-4028-B103-F56D8CB48824@gmail.com>

>>>>> On Sun, 25 Sep 2005 21:34:18 +0100, David Reitter <david.reitter@gmail.com> 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
				mituharu@math.s.chiba-u.ac.jp

  parent reply	other threads:[~2005-09-27  3:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-25 20:34 Free modifier key assignment (OS X) David Reitter
2005-09-26 13:18 ` Stefan Monnier
2005-09-27  3:45 ` YAMAMOTO Mitsuharu [this message]
2005-09-27 10:01   ` David Reitter
2005-09-28  8:28     ` YAMAMOTO Mitsuharu
2006-05-20  8:26       ` YAMAMOTO Mitsuharu
2005-12-13  3:26   ` Carbon port: M-§ not recognized (Italian keyboards) YAMAMOTO Mitsuharu
  -- strict thread matches above, loose matches on Subject: below --
2005-12-11 17:33 David Reitter
2005-12-12  2:41 ` YAMAMOTO Mitsuharu
2006-01-17  0:26   ` David Reitter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=wlzmpzfa25.wl%mituharu@math.s.chiba-u.ac.jp \
    --to=mituharu@math.s.chiba-u.ac.jp \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).