unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: "Ryan C. Thompson" <rct@thompsonclan.org>
Cc: 42915@debbugs.gnu.org
Subject: bug#42915: 27.1; Setting ns-function-modifier to control breaks control for certain keys
Date: Wed, 19 Aug 2020 00:50:44 +0200 (CEST)	[thread overview]
Message-ID: <20200818225041.GB6536@breton.holly.idiocy.org> (raw)
In-Reply-To: <de39299f-4507-5d6d-8b6e-284a41b82206@thompsonclan.org>

[-- Attachment #1: Type: text/plain, Size: 974 bytes --]

On Tue, Aug 18, 2020 at 10:22:18AM -0400, Ryan C. Thompson wrote:
> On a mac, run:
> 
> emacs -Q --eval "(setq ns-function-modifier 'control)"
> 
> Then try C-right, C-home, and similar key combinations. Emacs will act as if
> control is not being held down, i.e. C-right will run right-char instead of
> right-word. Indeed, C-h k C-right shows the key binding for right, not
> C-right. However, other key combinations, such as C-f, work as expected.
> 
> As far as I can tell, this only started happening after I updated to Emacs
> 27. I was previously using this config with Emacs 26.3 and never saw this
> issue. So I believe this is a new bug in Emacs 27.

Can you please try the attached patch?

Note that there may be some change to how "function" keys, like return
and the arrow keys, are handled when using the fn key. I can't
remember exactly how they worked with Emacs 26, but I believe the new
behaviour should be more consistent across the board.
-- 
Alan Third

[-- Attachment #2: 0001-Handle-fn-functions-keys-better-on-NS-bug-42915.patch --]
[-- Type: text/plain, Size: 3824 bytes --]

From 6460cec4412a0f8bc5a16b91743423bef6c09e14 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
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-<left> gives
-         <home>).  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));
+         <home>).  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


  reply	other threads:[~2020-08-18 22:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18 14:22 bug#42915: 27.1; Setting ns-function-modifier to control breaks control for certain keys Ryan C. Thompson
2020-08-18 22:50 ` Alan Third [this message]
2021-06-12 12:49   ` Lars Ingebrigtsen
2021-06-12 12:58     ` Ryan C. Thompson
2021-06-12 13:07     ` Alan Third
2021-06-12 13:13       ` Alan Third
2021-07-10 16:29         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200818225041.GB6536@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=42915@debbugs.gnu.org \
    --cc=rct@thompsonclan.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).