comparison src/macterm.c @ 57783:4cb8cebc3255

2004-10-28 Will <will@glozer.net> * macterm.c: allow user to assign key modifiers to the Mac Option key via a 'mac-option-modifier' variable.
author John Wiegley <johnw@newartisans.com>
date Fri, 29 Oct 2004 00:00:43 +0000
parents 0867872551d9
children c936fa56eb60 4056279af756 e24e2e78deda
comparison
equal deleted inserted replaced
57782:7c925282bd47 57783:4cb8cebc3255
225 extern int errno; 225 extern int errno;
226 226
227 /* A mask of extra modifier bits to put into every keyboard char. */ 227 /* A mask of extra modifier bits to put into every keyboard char. */
228 228
229 extern int extra_keyboard_modifiers; 229 extern int extra_keyboard_modifiers;
230
231 /* The keysyms to use for the various modifiers. */
232
233 static Lisp_Object Qalt, Qhyper, Qsuper, Qmodifier_value;
230 234
231 static Lisp_Object Qvendor_specific_keysyms; 235 static Lisp_Object Qvendor_specific_keysyms;
232 236
233 #if 0 237 #if 0
234 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); 238 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
6986 Lisp_Object Qreverse; 6990 Lisp_Object Qreverse;
6987 6991
6988 /* True if using command key as meta key. */ 6992 /* True if using command key as meta key. */
6989 Lisp_Object Vmac_command_key_is_meta; 6993 Lisp_Object Vmac_command_key_is_meta;
6990 6994
6995 /* Modifier associated with the option key, or nil for normal behavior. */
6996 Lisp_Object Vmac_option_modifier;
6997
6991 /* True if the ctrl and meta keys should be reversed. */ 6998 /* True if the ctrl and meta keys should be reversed. */
6992 Lisp_Object Vmac_reverse_ctrl_meta; 6999 Lisp_Object Vmac_reverse_ctrl_meta;
6993 7000
6994 /* True if the option and command modifiers should be used to emulate 7001 /* True if the option and command modifiers should be used to emulate
6995 a three button mouse */ 7002 a three button mouse */
7067 result |= ctrl_modifier; 7074 result |= ctrl_modifier;
7068 if (mods & macMetaKey) 7075 if (mods & macMetaKey)
7069 result |= meta_modifier; 7076 result |= meta_modifier;
7070 if (NILP (Vmac_command_key_is_meta) && (mods & macAltKey)) 7077 if (NILP (Vmac_command_key_is_meta) && (mods & macAltKey))
7071 result |= alt_modifier; 7078 result |= alt_modifier;
7079 if (!NILP (Vmac_option_modifier) && (mods & optionKey)) {
7080 Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value);
7081 if (!NILP(val))
7082 result |= XUINT(val);
7083 }
7084
7072 return result; 7085 return result;
7073 } 7086 }
7074 7087
7075 static int 7088 static int
7076 mac_get_emulated_btn ( UInt32 modifiers ) 7089 mac_get_emulated_btn ( UInt32 modifiers )
8547 int new_keycode = keycode | new_modifiers; 8560 int new_keycode = keycode | new_modifiers;
8548 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); 8561 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
8549 unsigned long some_state = 0; 8562 unsigned long some_state = 0;
8550 inev.code = KeyTranslate (kchr_ptr, new_keycode, 8563 inev.code = KeyTranslate (kchr_ptr, new_keycode,
8551 &some_state) & 0xff; 8564 &some_state) & 0xff;
8552 } 8565 } else if (!NILP(Vmac_option_modifier) && (er.modifiers & optionKey))
8566 {
8567 /* When using the option key as an emacs modifier, convert
8568 the pressed key code back to one without the Mac option
8569 modifier applied. */
8570 int new_modifiers = er.modifiers & ~optionKey;
8571 int new_keycode = keycode | new_modifiers;
8572 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
8573 unsigned long some_state = 0;
8574 inev.code = KeyTranslate (kchr_ptr, new_keycode,
8575 &some_state) & 0xff;
8576 }
8553 else 8577 else
8554 inev.code = er.message & charCodeMask; 8578 inev.code = er.message & charCodeMask;
8555 inev.kind = ASCII_KEYSTROKE_EVENT; 8579 inev.kind = ASCII_KEYSTROKE_EVENT;
8556 } 8580 }
8557 } 8581 }
9246 #if 0 9270 #if 0
9247 staticpro (&x_error_message_string); 9271 staticpro (&x_error_message_string);
9248 x_error_message_string = Qnil; 9272 x_error_message_string = Qnil;
9249 #endif 9273 #endif
9250 9274
9275 Qmodifier_value = intern ("modifier-value");
9276 Qalt = intern ("alt");
9277 Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
9278 Qhyper = intern ("hyper");
9279 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
9280 Qsuper = intern ("super");
9281 Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
9282
9251 Fprovide (intern ("mac-carbon"), Qnil); 9283 Fprovide (intern ("mac-carbon"), Qnil);
9252 9284
9253 staticpro (&Qreverse); 9285 staticpro (&Qreverse);
9254 Qreverse = intern ("reverse"); 9286 Qreverse = intern ("reverse");
9255 9287
9301 9333
9302 DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta, 9334 DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta,
9303 doc: /* Non-nil means that the command key is used as the Emacs meta key. 9335 doc: /* Non-nil means that the command key is used as the Emacs meta key.
9304 Otherwise the option key is used. */); 9336 Otherwise the option key is used. */);
9305 Vmac_command_key_is_meta = Qt; 9337 Vmac_command_key_is_meta = Qt;
9338
9339 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier,
9340 doc: /* Modifier to use for the Mac alt/option key. The value can
9341 be alt, hyper, or super for the respective modifier. If the value is
9342 nil then the key will act as the normal Mac option modifier. */);
9343 Vmac_option_modifier = Qnil;
9306 9344
9307 DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta, 9345 DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta,
9308 doc: /* Non-nil means that the control and meta keys are reversed. This is 9346 doc: /* Non-nil means that the control and meta keys are reversed. This is
9309 useful for non-standard keyboard layouts. */); 9347 useful for non-standard keyboard layouts. */);
9310 Vmac_reverse_ctrl_meta = Qnil; 9348 Vmac_reverse_ctrl_meta = Qnil;