From 6460cec4412a0f8bc5a16b91743423bef6c09e14 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Tue, 18 Aug 2020 23:41:08 +0100 Subject: [PATCH] Handle fn + functions keys better on NS (bug#42915) * doc/emacs/macos.texi (Mac / GNUstep Customization): Document the caveat regarding fn and function keys. * src/nsterm.m (EV_MODIFIERS2): Ignore ns_function_modifier if this is a function key. ([EmacsView keyDown:]): Get rid of the code that unsets the ns_function_modifier value in modifiers. --- doc/emacs/macos.texi | 4 ++++ src/nsterm.m | 23 ++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi index 00daa8b35d..3fb625b417 100644 --- a/doc/emacs/macos.texi +++ b/doc/emacs/macos.texi @@ -143,6 +143,10 @@ Mac / GNUstep Customization may also be set to @code{left}, which means to use the same behavior as the corresponding left-hand key. +Emacs is unable to detect when the @key{function} key is being used as +a modifier with function keys. As a result Emacs will ignore the +modifier set in @code{ns-function-modifier} with these keys. + @subsection Frame Variables @table @code diff --git a/src/nsterm.m b/src/nsterm.m index 98c5b69d68..1c306c1b8e 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -402,7 +402,7 @@ - (NSColor *)colorUsingDefaultColorSpace hyper_modifier : 0) \ | ((flags & NSEventModifierFlagShift) ? \ shift_modifier : 0) \ - | ((flags & NS_FUNCTION_KEY_MASK) \ + | (((flags & NS_FUNCTION_KEY_MASK) && kind == QCordinary) \ ? parse_solitary_modifier (mod_of_kind (ns_function_modifier, \ kind)) \ : 0) \ @@ -6505,25 +6505,22 @@ untranslated characters (returned by the we have both shift-like and control-like modifiers because the NSEvent API doesn’t let us ignore only some modifiers. In that case we use UCKeyTranslate (ns_get_shifted_character) - to look up the correct character. */ + to look up the correct character. - /* EV_MODIFIERS2 uses parse_solitary_modifier on all known + EV_MODIFIERS2 uses parse_solitary_modifier on all known modifier keys, which returns 0 for shift-like modifiers. Therefore its return value is the set of control-like - modifiers. */ - Lisp_Object kind = fnKeysym ? QCfunction : QCordinary; - emacs_event->modifiers = EV_MODIFIERS2 (flags, kind); + modifiers. - /* Function keys (such as the F-keys, arrow keys, etc.) set + Function keys (such as the F-keys, arrow keys, etc.) set modifiers as though the fn key has been pressed when it hasn't. Also some combinations of fn and a function key return a different key than was pressed (e.g. fn- gives - ). We need to unset the fn modifier in these cases. - FIXME: Can we avoid setting it in the first place? */ - if (fnKeysym && (flags & NS_FUNCTION_KEY_MASK)) - emacs_event->modifiers - ^= parse_solitary_modifier (mod_of_kind (ns_function_modifier, - QCfunction)); + ). EV_MODIFIERS2 avoids setting the the fn modifier in + these cases. */ + + Lisp_Object kind = fnKeysym ? QCfunction : QCordinary; + emacs_event->modifiers = EV_MODIFIERS2 (flags, kind); if (NS_KEYLOG) fprintf (stderr, "keyDown: code =%x\tfnKey =%x\tflags = %x\tmods = %x\n", -- 2.26.1