From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: Free modifier key assignment (OS X) Date: Tue, 27 Sep 2005 12:45:22 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <1949F677-E294-4028-B103-F56D8CB48824@gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: sea.gmane.org 1127794900 17176 80.91.229.2 (27 Sep 2005 04:21:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 27 Sep 2005 04:21:40 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 27 06:21:30 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EK6xG-0005yH-Tq for ged-emacs-devel@m.gmane.org; Tue, 27 Sep 2005 06:20:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EK6xG-0005yx-AN for ged-emacs-devel@m.gmane.org; Tue, 27 Sep 2005 00:20:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EK6vE-0003zk-Fl for emacs-devel@gnu.org; Tue, 27 Sep 2005 00:18:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EK6vD-0003yn-Aa for emacs-devel@gnu.org; Tue, 27 Sep 2005 00:18:27 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EK6pl-0001qX-NI for emacs-devel@gnu.org; Tue, 27 Sep 2005 00:12:49 -0400 Original-Received: from [133.82.132.2] (helo=mathmail.math.s.chiba-u.ac.jp) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EK6PD-00025N-OQ for emacs-devel@gnu.org; Mon, 26 Sep 2005 23:45:24 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 681312CAA; Tue, 27 Sep 2005 12:45:22 +0900 (JST) Original-To: David Reitter In-Reply-To: <1949F677-E294-4028-B103-F56D8CB48824@gmail.com> 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) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:43278 Archived-At: >>>>> On Sun, 25 Sep 2005 21:34:18 +0100, David Reitter 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