From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Reitter Newsgroups: gmane.emacs.devel Subject: Re: Mac: modifier key remapping revised [patch] Date: Mon, 2 May 2005 22:25:12 +0100 Message-ID: <0bc4b04a711abb4a986ff9894b0416be@gmail.com> References: <622c88af84f92a1149662bd6ba5bf4e1@gmail.com> <87u0ll7br4.fsf@wigwam.deepwood.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1115087462 25287 80.91.229.2 (3 May 2005 02:31:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 3 May 2005 02:31:02 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 03 04:30:56 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DSnBN-0004Kv-Ji for ged-emacs-devel@m.gmane.org; Tue, 03 May 2005 04:30:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DSnIO-000841-A1 for ged-emacs-devel@m.gmane.org; Mon, 02 May 2005 22:38:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DSiep-0003AR-BV for emacs-devel@gnu.org; Mon, 02 May 2005 17:40:51 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DSiS0-0006k3-Hq for emacs-devel@gnu.org; Mon, 02 May 2005 17:27:45 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DSiRy-0006gA-8J for emacs-devel@gnu.org; Mon, 02 May 2005 17:27:34 -0400 Original-Received: from [64.233.184.195] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DSiUC-0000Ll-7f for emacs-devel@gnu.org; Mon, 02 May 2005 17:29:52 -0400 Original-Received: by wproxy.gmail.com with SMTP id 36so1899884wra for ; Mon, 02 May 2005 14:25:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-mailer; b=KiB4ZfYMJLCKjDjkm2Np/YeSyW5Oyc8FZl2aexus6Ht/wBl4zyCh2BIYSwkjA45gjBNkl9JSl0zD5Hcr0LwClntJirRgIX3g61yVYO56fM/ukmZ1Bthsg0TfoFVIZ32c9H7w+WVSFoFHCoS2V5Dnod2xupJigkXsgJ9/9KKQI2M= Original-Received: by 10.54.83.1 with SMTP id g1mr788887wrb; Mon, 02 May 2005 14:25:16 -0700 (PDT) Original-Received: from ?10.0.0.58? ([82.20.46.25]) by mx.gmail.com with ESMTP id 12sm787240wrl.2005.05.02.14.25.15; Mon, 02 May 2005 14:25:16 -0700 (PDT) In-Reply-To: <87u0ll7br4.fsf@wigwam.deepwood.net> Original-To: emacs-devel@gnu.org X-Mailer: Apple Mail (2.622) 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:36607 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:36607 Since Daniel Brockman suggested that I repost this patch in context=20 format, there we go. It applies to the current version. Steven Tamm=20 suggested a while ago that the 'fn' key (on Powerbook keyboards left of=20= the ctrl key) be included, and I think this would be a very neat idea=20 for someone to do. Index: macterm.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/src/macterm.c,v retrieving revision 1.113 diff -c -r1.113 macterm.c *** macterm.c 24 Apr 2005 06:06:39 -0000 1.113 --- macterm.c 2 May 2005 20:47:24 -0000 *************** *** 86,101 **** #include "composite.h" #include "coding.h" ! /* Set of macros that handle mapping of Mac modifier keys to emacs. =20= */ ! #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 :=20 optionKey) #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon=20 (wp))->mFP) =0C /* Non-nil means Emacs uses toolkit scroll bars. */ --- 86,115 ---- #include "composite.h" #include "coding.h" ! /* Set of macros that handle mapping of Mac modifier keys to emacs. ! If any of the newer-style mac_*_modifier variables is set, these=20 macros are basically out of function, ! they just map to the normal keys - except for Meta, which is then=20= (ESC or) command-control-option. ! */ ! ! #define macOldModifierSetting ( NILP(Vmac_control_modifier) &&=20 NILP(Vmac_option_modifier) && NILP(Vmac_command_modifier) ) ! ! #define macCtrlKey (macOldModifierSetting ? \ ! (NILP(Vmac_reverse_ctrl_meta) ? controlKey : = \ ! (NILP(Vmac_command_key_is_meta) ? = optionKey : cmdKey)) : \ ! controlKey) #define macShiftKey (shiftKey) ! ! #define macMetaKey (macOldModifierSetting ? \ ! (NILP(Vmac_reverse_ctrl_meta) ? \ ! (NILP(Vmac_command_key_is_meta) ? optionKey : = cmdKey) :=20 controlKey) : \ ! (cmdKey | controlKey | optionKey)) ! ! #define macAltKey (macOldModifierSetting ? =20 (NILP(Vmac_command_key_is_meta) ? cmdKey : optionKey) : optionKey) ! ! #define macCmdKey (cmdKey) #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon=20 (wp))->mFP) + =0C /* Non-nil means Emacs uses toolkit scroll bars. */ *************** *** 238,244 **** /* The keysyms to use for the various modifiers. */ ! static Lisp_Object Qalt, Qhyper, Qsuper, Qmodifier_value; static Lisp_Object Qvendor_specific_keysyms; --- 252,258 ---- /* The keysyms to use for the various modifiers. */ ! static Lisp_Object Qalt, Qhyper, Qsuper, Qctrl, Qmeta,=20 Qmodifier_value; static Lisp_Object Qvendor_specific_keysyms; *************** *** 7113,7125 **** /* Contains the string "reverse", which is a constant for mouse=20 button emu.*/ Lisp_Object Qreverse; ! /* True if using command key as meta key. */ Lisp_Object Vmac_command_key_is_meta; /* Modifier associated with the option key, or nil for normal=20 behavior. */ Lisp_Object Vmac_option_modifier; ! /* True if the ctrl and meta keys should be reversed. */ Lisp_Object Vmac_reverse_ctrl_meta; /* True if the option and command modifiers should be used to emulate --- 7127,7147 ---- /* Contains the string "reverse", which is a constant for mouse=20 button emu.*/ Lisp_Object Qreverse; ! /* True if using command key as meta key. ! Deprecated; only use if macOldModifierSetting evaluates to true. */ Lisp_Object Vmac_command_key_is_meta; + /* Modifier associated with the control key, or nil for normal=20 behavior. */ + Lisp_Object Vmac_control_modifier; + /* Modifier associated with the option key, or nil for normal=20 behavior. */ Lisp_Object Vmac_option_modifier; ! /* Modifier associated with the command key, or nil for normal=20 behavior. */ ! Lisp_Object Vmac_command_modifier; ! ! /* True if the ctrl and meta keys should be reversed. ! Deprecated; only use if macOldModifierSetting evaluates to true. = */ Lisp_Object Vmac_reverse_ctrl_meta; /* True if the option and command modifiers should be used to emulate *************** *** 7194,7210 **** unsigned int result =3D 0; if (mods & macShiftKey) result |=3D shift_modifier; ! if (mods & macCtrlKey) ! result |=3D ctrl_modifier; ! if (mods & macMetaKey) ! result |=3D meta_modifier; ! if (NILP (Vmac_command_key_is_meta) && (mods & macAltKey)) ! result |=3D alt_modifier; ! if (!NILP (Vmac_option_modifier) && (mods & optionKey)) { ! Lisp_Object val =3D Fget(Vmac_option_modifier, Qmodifier_value); ! if (!NILP(val)) result |=3D XUINT(val); ! } return result; } --- 7216,7259 ---- unsigned int result =3D 0; if (mods & macShiftKey) result |=3D shift_modifier; ! ! if (macOldModifierSetting) /* compatibility with old-style=20 modifier keys */ ! { ! if (mods & macCtrlKey) ! result |=3D ctrl_modifier; ! if (mods & macMetaKey) ! result |=3D meta_modifier; ! ! if ( NILP (Vmac_command_key_is_meta) && (mods & macAltKey) ) ! result |=3D alt_modifier; ! } else ! { ! /* new-style modifier keys */ ! if (!NILP (Vmac_option_modifier) && (mods & optionKey)) { ! Lisp_Object val =3D Fget(Vmac_option_modifier, Qmodifier_value); ! if (!NILP(val)) result |=3D XUINT(val); ! } else { /* default behavior if modifier variable is not set */ ! if (mods & macAltKey) ! result |=3D alt_modifier; ! } ! if (!NILP (Vmac_command_modifier) && (mods & cmdKey)) { ! Lisp_Object val =3D Fget(Vmac_command_modifier, = Qmodifier_value); ! if (!NILP(val)) ! result |=3D XUINT(val); ! } else { /* default behavior if modifier variable is not set:=20 assign hyper*/ ! if (mods & macCmdKey) ! result |=3D hyper_modifier; ! } ! if (!NILP (Vmac_control_modifier) && (mods & controlKey)) { ! Lisp_Object val =3D Fget(Vmac_control_modifier, = Qmodifier_value); ! if (!NILP(val)) ! result |=3D XUINT(val); ! } else { /* default behavior if modifier variable is not set */ ! if (mods & macCtrlKey) ! result |=3D ctrl_modifier; ! } ! } return result; } *************** *** 9029,9037 **** } else { ! if (er.modifiers & (controlKey | ! (NILP (Vmac_command_key_is_meta) ? = optionKey ! : cmdKey))) { /* This code comes from Keyboard Resource, Appendix C of IM - Text. This is necessary --- 9078,9087 ---- } else { ! if (er.modifiers & (controlKey | ! ((macOldModifierSetting && ! NILP (Vmac_command_key_is_meta)) = ? ! optionKey : cmdKey))) { /* This code comes from Keyboard Resource, Appendix C of IM - Text. This is necessary *************** *** 9048,9072 **** inev.code =3D 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 =3D er.modifiers & ~optionKey; int new_keycode =3D keycode | new_modifiers; Ptr kchr_ptr =3D (Ptr) GetScriptManagerVariable = (smKCHRCache); unsigned long some_state =3D 0; inev.code =3D KeyTranslate (kchr_ptr, new_keycode, &some_state) & 0xff; ! } ! else inev.code =3D er.message & charCodeMask; inev.kind =3D ASCII_KEYSTROKE_EVENT; } } ! #if USE_CARBON_EVENTS inev.modifiers =3D mac_event_to_emacs_modifiers (eventRef); #else --- 9098,9127 ---- inev.code =3D KeyTranslate (kchr_ptr, new_keycode, &some_state) & 0xff; } ! else if (!macOldModifierSetting ! && (er.modifiers & (optionKey | controlKey | = cmdKey) )) { ! /* When using a key as an emacs modifier, convert the pressed key code back to one ! without the Mac modifier applied. ! ! Could we do something like ! new_modifiers =3D er.modifiers & shiftKey ! instead? ! */ ! int new_modifiers =3D er.modifiers & ~controlKey & = ~optionKey &=20 ~cmdKey; int new_keycode =3D keycode | new_modifiers; Ptr kchr_ptr =3D (Ptr) GetScriptManagerVariable = (smKCHRCache); unsigned long some_state =3D 0; inev.code =3D KeyTranslate (kchr_ptr, new_keycode, &some_state) & 0xff; ! } else inev.code =3D er.message & charCodeMask; + inev.kind =3D ASCII_KEYSTROKE_EVENT; } } ! =09 #if USE_CARBON_EVENTS inev.modifiers =3D mac_event_to_emacs_modifiers (eventRef); #else *************** *** 9760,9765 **** --- 9815,9824 ---- #if TARGET_API_MAC_CARBON init_required_apple_events (); + Qctrl =3D intern ("ctrl"); + Fput (Qctrl, Qmodifier_value, make_number (ctrl_modifier)); + Qmeta =3D intern ("meta"); + Fput (Qmeta, Qmodifier_value, make_number (meta_modifier)); #if USE_CARBON_EVENTS #ifdef MAC_OSX init_service_handler (); *************** *** 9810,9815 **** --- 9869,9877 ---- #ifdef MAC_OSX Fprovide (intern ("mac-carbon"), Qnil); #endif + /* Deprecated variables to configure modifier key assignment. + Retained for backward-compatibility. */ + =09 staticpro (&Qreverse); Qreverse =3D intern ("reverse"); *************** *** 9846,9864 **** DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta, doc: /* Non-nil means that the command key is used as the Emacs=20= meta key. ! Otherwise the option key is used. */); Vmac_command_key_is_meta =3D Qt; DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier, doc: /* Modifier to use for the Mac alt/option key. The value = can be alt, hyper, or super for the respective modifier. If the value is ! nil then the key will act as the normal Mac option modifier. */); Vmac_option_modifier =3D Qnil; ! DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta, ! doc: /* Non-nil means that the control and meta keys are=20 reversed. This is ! useful for non-standard keyboard layouts. */); ! Vmac_reverse_ctrl_meta =3D Qnil; DEFVAR_LISP ("mac-emulate-three-button-mouse", &Vmac_emulate_three_button_mouse, --- 9908,9952 ---- DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta, doc: /* Non-nil means that the command key is used as the Emacs=20= meta key. ! Otherwise the option key is used. This variable is DEPRECATED. ! It is only in effect if all of the variables mac-*-modifier are nil.=20= */); Vmac_command_key_is_meta =3D Qt; + + DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta, + doc: /* Non-nil means that the control and meta keys are=20 reversed. This is + useful for non-standard keyboard layouts. This variable is DEPRECATED. + It is only in effect if none of the variables mac-*-modifier is=20 non-nil. */); + Vmac_reverse_ctrl_meta =3D Qnil; + + + /* Variables to configure modifier key assignment. */ + =09 + DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier, + doc: /* Modifier to use for the Mac control key. The value can + be alt, hyper, or super for the respective modifier. If the value is + nil then the key will act as the normal Mac control modifier. =20 However, if all + values of mac-{command|control|option}-modifier are nil, the=20 deprecated + default assignment determined by mac-command-key-is-meta and + mac-reverse-ctrl-meta is used. */); + Vmac_control_modifier =3D Qnil; DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier, doc: /* Modifier to use for the Mac alt/option key. The value = can be alt, hyper, or super for the respective modifier. If the value is ! nil then the key will act as the normal Mac option modifier. However,=20= if all ! values of mac-{command|control|option}-modifier are nil, the=20 deprecated ! default assignment determined by mac-command-key-is-meta and ! mac-reverse-ctrl-meta is used. */); Vmac_option_modifier =3D Qnil; ! DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier, ! doc: /* Modifier to use for the Mac command key. The value can ! be alt, hyper, or super for the respective modifier. If the value is ! nil then the key will act as the normal Mac option modifier. However,=20= if all ! values of mac-{command|control|option}-modifier are nil, the=20 deprecated ! default assignment determined by mac-command-key-is-meta and ! mac-reverse-ctrl-meta is used. */); ! Vmac_command_modifier =3D Qnil; DEFVAR_LISP ("mac-emulate-three-button-mouse", &Vmac_emulate_three_button_mouse,