aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2018-02-07 22:39:17 +0000
committerAlan Third2018-02-11 20:54:28 +0000
commit65ebf7890922156eb056a1e61421f77d7ce158ef (patch)
treedad233b31b952ecc1d2c4518b5b829ee57ddd217 /src
parent68d8925077928422cf57625b0ad4b441e233b830 (diff)
downloademacs-65ebf7890922156eb056a1e61421f77d7ce158ef.tar.gz
emacs-65ebf7890922156eb056a1e61421f77d7ce158ef.zip
Fix modifier keys on NS port
* src/nsterm.m (EV_MODIFIERS_OPTION): (EV_MODIFIERS_CONTROL): (EV_MODIFIERS_COMMAND): New macros. (ev_modifiers_helper): New function. (EV_MODIFIERS2): Use new helper function. (EmacsView::keyDown): Remove duplicate functionality and handle fn key correctly.
Diffstat (limited to 'src')
-rw-r--r--src/nsterm.m96
1 files changed, 60 insertions, 36 deletions
diff --git a/src/nsterm.m b/src/nsterm.m
index 56a1e01ba18..29aef0e9b6d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -352,31 +352,56 @@ static CGPoint menu_mouse_point;
352#define NSRightCommandKeyMask (0x000010 | NSEventModifierFlagCommand) 352#define NSRightCommandKeyMask (0x000010 | NSEventModifierFlagCommand)
353#define NSLeftAlternateKeyMask (0x000020 | NSEventModifierFlagOption) 353#define NSLeftAlternateKeyMask (0x000020 | NSEventModifierFlagOption)
354#define NSRightAlternateKeyMask (0x000040 | NSEventModifierFlagOption) 354#define NSRightAlternateKeyMask (0x000040 | NSEventModifierFlagOption)
355#define EV_MODIFIERS2(flags) \ 355
356 (((flags & NSEventModifierFlagHelp) ? \ 356static unsigned int
357 hyper_modifier : 0) \ 357ev_modifiers_helper (unsigned int flags, unsigned int left_mask,
358 | (!EQ (ns_right_alternate_modifier, Qleft) && \ 358 unsigned int right_mask, unsigned int either_mask,
359 ((flags & NSRightAlternateKeyMask) \ 359 Lisp_Object left_modifier, Lisp_Object right_modifier)
360 == NSRightAlternateKeyMask) ? \ 360{
361 parse_solitary_modifier (ns_right_alternate_modifier) : 0) \ 361 unsigned int modifiers = 0;
362 | ((flags & NSEventModifierFlagOption) ? \ 362
363 parse_solitary_modifier (ns_alternate_modifier) : 0) \ 363 if (flags & either_mask)
364 | ((flags & NSEventModifierFlagShift) ? \ 364 {
365 shift_modifier : 0) \ 365 BOOL left_key = (flags & left_mask) == left_mask;
366 | (!EQ (ns_right_control_modifier, Qleft) && \ 366 BOOL right_key = (flags & right_mask) == right_mask
367 ((flags & NSRightControlKeyMask) \ 367 && ! EQ (right_modifier, Qleft);
368 == NSRightControlKeyMask) ? \ 368
369 parse_solitary_modifier (ns_right_control_modifier) : 0) \ 369 if (right_key)
370 | ((flags & NSEventModifierFlagControl) ? \ 370 modifiers |= parse_solitary_modifier (right_modifier);
371 parse_solitary_modifier (ns_control_modifier) : 0) \ 371
372 | ((flags & NS_FUNCTION_KEY_MASK) ? \ 372 /* GNUstep (and possibly macOS in certain circumstances) doesn't
373 parse_solitary_modifier (ns_function_modifier) : 0) \ 373 differentiate between the left and right keys, so if we can't
374 | (!EQ (ns_right_command_modifier, Qleft) && \ 374 identify which key it is, we use the left key setting. */
375 ((flags & NSRightCommandKeyMask) \ 375 if (left_key || ! right_key)
376 == NSRightCommandKeyMask) ? \ 376 modifiers |= parse_solitary_modifier (left_modifier);
377 parse_solitary_modifier (ns_right_command_modifier) : 0) \ 377 }
378 | ((flags & NSEventModifierFlagCommand) ? \ 378
379 parse_solitary_modifier (ns_command_modifier):0)) 379 return modifiers;
380}
381
382#define EV_MODIFIERS2(flags) \
383 (((flags & NSEventModifierFlagHelp) ? \
384 hyper_modifier : 0) \
385 | ((flags & NSEventModifierFlagShift) ? \
386 shift_modifier : 0) \
387 | ((flags & NS_FUNCTION_KEY_MASK) ? \
388 parse_solitary_modifier (ns_function_modifier) : 0) \
389 | ev_modifiers_helper (flags, NSLeftControlKeyMask, \
390 NSRightControlKeyMask, \
391 NSEventModifierFlagControl, \
392 ns_control_modifier, \
393 ns_right_control_modifier) \
394 | ev_modifiers_helper (flags, NSLeftCommandKeyMask, \
395 NSRightCommandKeyMask, \
396 NSEventModifierFlagCommand, \
397 ns_command_modifier, \
398 ns_right_command_modifier) \
399 | ev_modifiers_helper (flags, NSLeftAlternateKeyMask, \
400 NSRightAlternateKeyMask, \
401 NSEventModifierFlagOption, \
402 ns_alternate_modifier, \
403 ns_right_alternate_modifier))
404
380#define EV_MODIFIERS(e) EV_MODIFIERS2 ([e modifierFlags]) 405#define EV_MODIFIERS(e) EV_MODIFIERS2 ([e modifierFlags])
381 406
382#define EV_UDMODIFIERS(e) \ 407#define EV_UDMODIFIERS(e) \
@@ -6158,15 +6183,6 @@ not_in_argv (NSString *arg)
6158 code = fnKeysym; 6183 code = fnKeysym;
6159 } 6184 }
6160 6185
6161 /* are there modifiers? */
6162 emacs_event->modifiers = 0;
6163
6164 if (flags & NSEventModifierFlagHelp)
6165 emacs_event->modifiers |= hyper_modifier;
6166
6167 if (flags & NSEventModifierFlagShift)
6168 emacs_event->modifiers |= shift_modifier;
6169
6170 /* The ⌘ and ⌥ modifiers can be either shift-like (for alternate 6186 /* The ⌘ and ⌥ modifiers can be either shift-like (for alternate
6171 character input) or control-like (as command prefix). If we 6187 character input) or control-like (as command prefix). If we
6172 have only shift-like modifiers, then we should use the 6188 have only shift-like modifiers, then we should use the
@@ -6183,8 +6199,16 @@ not_in_argv (NSString *arg)
6183 modifier keys, which returns 0 for shift-like modifiers. 6199 modifier keys, which returns 0 for shift-like modifiers.
6184 Therefore its return value is the set of control-like 6200 Therefore its return value is the set of control-like
6185 modifiers. */ 6201 modifiers. */
6186 unsigned int control_modifiers = EV_MODIFIERS2 (flags); 6202 emacs_event->modifiers = EV_MODIFIERS2 (flags);
6187 emacs_event->modifiers |= control_modifiers; 6203
6204 /* Function keys (such as the F-keys, arrow keys, etc.) set
6205 modifiers as though the fn key has been pressed when it
6206 hasn't. Also some combinations of fn and a function key
6207 return a different key than was pressed (e.g. fn-<left> gives
6208 <home>). We need to unset the fn modifier in these cases.
6209 FIXME: Can we avoid setting it in the first place. */
6210 if (fnKeysym && (flags & NS_FUNCTION_KEY_MASK))
6211 emacs_event->modifiers ^= parse_solitary_modifier (ns_function_modifier);
6188 6212
6189 if (NS_KEYLOG) 6213 if (NS_KEYLOG)
6190 fprintf (stderr, "keyDown: code =%x\tfnKey =%x\tflags = %x\tmods = %x\n", 6214 fprintf (stderr, "keyDown: code =%x\tfnKey =%x\tflags = %x\tmods = %x\n",