From: Alan Third <alan@idiocy.org>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: 21551@debbugs.gnu.org, Kai Yu Zhang <yeannylam@gmail.com>,
Mikhail Gusarov <dottedmag@dottedmag.net>,
Anders Lindgren <andlind@gmail.com>
Subject: bug#21551: Fix Mac OS X key bindings bug
Date: Tue, 13 Feb 2018 18:56:20 +0000 [thread overview]
Message-ID: <20180213185620.GA70726@breton.holly.idiocy.org> (raw)
In-Reply-To: <CAArVCkQGUd8hMECL-hZGzH7j95GyoTfLhc2=MqxQPdgo9QEXQw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]
On Sun, Feb 11, 2018 at 05:57:32PM +0000, Philipp Stephani wrote:
> Anders Lindgren <andlind@gmail.com> schrieb am Sa., 2. Jan. 2016 um
> 09:08 Uhr:
>
> > I found a case where the code in question is needed, which none of the
> > suggested patches handle correctly.
> >
> > Steps to repeat:
> >
> > (setq ns-alternate-modifier nil)
> >
> > Press left CMD-ALT-9
> >
> > An unmodified Emacs replies "s-]" is not bound. (This assumes a
> > Swedish keyboard layout, other layouts would yield a different character,
> > but the principle is the same).
> >
> > With either of the two patches, Emacs respond with "s-9" is not bound,
> > which isn't correct.
> >
>
> In the current master this is now interpreted as M-s-9, which is at least
> somewhat reasonable.
For me it’s s-9, not M-s-9.
> > Unfortunately, I don't know how to distinguish between the cases where we
> > need to strip away modifiers (C-s-a) and when we shouldn't, so I'm leaving
> > this open for now.
> >
>
> It seems like in the macOS input model, we can't: either we strip away all
> modifiers, or none.
It appears you can using some Carbon stuff. Half‐assed proof of
concept patch attached.
(It’s broken the arrow keys, and I don’t know why...)
--
Alan Third
[-- Attachment #2: poc.patch --]
[-- Type: text/plain, Size: 2958 bytes --]
diff --git a/configure.ac b/configure.ac
index f2a8332d71..b5db45801d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5260,7 +5260,7 @@ AC_DEFUN
if test "$HAVE_NS" = "yes"; then
libs_nsgui="-framework AppKit"
if test "$NS_IMPL_COCOA" = "yes"; then
- libs_nsgui="$libs_nsgui -framework IOKit"
+ libs_nsgui="$libs_nsgui -framework IOKit -framework Carbon"
fi
else
libs_nsgui=
diff --git a/src/nsterm.m b/src/nsterm.m
index 29aef0e9b6..2038c02e60 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -69,6 +69,8 @@ Updated by Christian Limpach (chris@nice.ch)
#include "macfont.h"
#endif
+#include <Carbon/Carbon.h>
+
static EmacsMenu *dockMenu;
#ifdef NS_IMPL_COCOA
static EmacsMenu *mainMenu;
@@ -2681,6 +2683,45 @@ so some key presses (TAB) are swallowed by the system. */
}
+static UniChar
+ns_get_shifted_character (NSEvent *event)
+{
+ static UInt32 deadKeyState;
+
+ CFDataRef layout_ref = (CFDataRef) TISGetInputSourceProperty
+ (TISCopyCurrentKeyboardLayoutInputSource (), kTISPropertyUnicodeKeyLayoutData);
+ UCKeyboardLayout* layout = CFDataGetBytePtr (layout_ref);
+
+ UniChar buf[255];
+ UniCharCount maxStringLength;
+ UniCharCount actualStringLength;
+ OSStatus result;
+
+ unsigned int flags = [event modifierFlags];
+ UInt32 modifiers = (flags & NSEventModifierFlagShift) ? shiftKey : 0;
+ modifiers |= ((flags & NSRightAlternateKeyMask) == NSRightAlternateKeyMask
+ && EQ (ns_right_alternate_modifier, Qnone)) ? rightOptionKey : 0;
+ modifiers |= ((flags & NSLeftAlternateKeyMask) == NSLeftAlternateKeyMask
+ && EQ (ns_alternate_modifier, Qnone)) ? optionKey : 0;
+
+ modifiers |= ((flags & NSRightCommandKeyMask) == NSRightCommandKeyMask
+ && EQ (ns_right_command_modifier, Qnone)) ? cmdKey : 0;
+ modifiers |= ((flags & NSLeftCommandKeyMask) == NSLeftCommandKeyMask
+ && EQ (ns_command_modifier, Qnone)) ? cmdKey : 0;
+
+ result = UCKeyTranslate (layout,
+ [event keyCode], kUCKeyActionDown,
+ (modifiers >> 8) & 0xFF,
+ LMGetKbdType (), kUCKeyTranslateNoDeadKeysBit,
+ &deadKeyState, 255, &actualStringLength,
+ buf);
+
+ if (result != 0)
+ NSLog(@"Disaster!");
+
+ return buf[0];
+}
+
/* ==========================================================================
@@ -6147,7 +6188,8 @@ most recently updated (I guess), which is not the correct one. */
/* FIXME: What should happen for key sequences with more than
one character? */
code = ([[theEvent charactersIgnoringModifiers] length] == 0) ?
- 0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: 0];
+ 0 : //[[theEvent charactersIgnoringModifiers] characterAtIndex: 0];
+ ns_get_shifted_character (theEvent);
/* (Carbon way: [theEvent keyCode]) */
next prev parent reply other threads:[~2018-02-13 18:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-24 13:19 bug#21551: [PATCH] Fix Mac OS X key bindings bug Kai Yu Zhang
2015-12-30 8:50 ` bug#21551: " Anders Lindgren
2016-01-02 8:08 ` Anders Lindgren
2016-12-26 20:12 ` bug#19977: " Mikhail Gusarov
2018-02-11 17:57 ` bug#21551: " Philipp Stephani
2018-02-13 18:56 ` Alan Third [this message]
2018-02-14 21:44 ` Alan Third
2018-02-17 12:36 ` Alan Third
2018-02-18 21:59 ` Philipp Stephani
2018-02-19 15:05 ` Richard Stallman
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180213185620.GA70726@breton.holly.idiocy.org \
--to=alan@idiocy.org \
--cc=21551@debbugs.gnu.org \
--cc=andlind@gmail.com \
--cc=dottedmag@dottedmag.net \
--cc=p.stephani2@gmail.com \
--cc=yeannylam@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.