From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#21551: Fix Mac OS X key bindings bug Date: Tue, 13 Feb 2018 18:56:20 +0000 Message-ID: <20180213185620.GA70726@breton.holly.idiocy.org> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="zYM0uCDKw75PZbzx" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1518548152 27593 195.159.176.226 (13 Feb 2018 18:55:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Feb 2018 18:55:52 +0000 (UTC) User-Agent: Mutt/1.9.3 (2018-01-21) Cc: 21551@debbugs.gnu.org, Kai Yu Zhang , Mikhail Gusarov , Anders Lindgren To: Philipp Stephani Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 13 19:55:47 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elfjZ-00056U-RK for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Feb 2018 19:55:18 +0100 Original-Received: from localhost ([::1]:38698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elflb-00056x-Fq for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Feb 2018 13:57:23 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elflJ-00055W-9Y for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2018 13:57:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elflG-0003mX-7V for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2018 13:57:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33887) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1elflG-0003mN-1Y for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2018 13:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1elflF-0007P6-Qg for bug-gnu-emacs@gnu.org; Tue, 13 Feb 2018 13:57:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Feb 2018 18:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21551 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 21551-submit@debbugs.gnu.org id=B21551.151854819328424 (code B ref 21551); Tue, 13 Feb 2018 18:57:01 +0000 Original-Received: (at 21551) by debbugs.gnu.org; 13 Feb 2018 18:56:33 +0000 Original-Received: from localhost ([127.0.0.1]:41784 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elfkm-0007ON-KI for submit@debbugs.gnu.org; Tue, 13 Feb 2018 13:56:32 -0500 Original-Received: from mail-wr0-f170.google.com ([209.85.128.170]:33745) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elfkk-0007O9-CJ for 21551@debbugs.gnu.org; Tue, 13 Feb 2018 13:56:31 -0500 Original-Received: by mail-wr0-f170.google.com with SMTP id s5so19654758wra.0 for <21551@debbugs.gnu.org>; Tue, 13 Feb 2018 10:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=+LnWwDjMaBYjLnGCplLNOeVXtwWtYZYlfUO1teusnH8=; b=Ra4ioR8NqloIMBTDX3jwd2JdQ275UJ7zXBPJvqQzoaiSmMKb7rTW2WZBCT5j29nipr SKNPo8CZHfzDKXJ16Umajq4g5Fk8ZzYM+hil8jehiHGTE8JvP7VH09CsvLHVT3XWSszS 4u6+OwlPqtIIcj0JYnlS6VIl6ZwcZvOcgA/EesXXDNHzfu6F6zSm3LoeBw/CfaNLvrps HPlby7S0xzZ8SsRrR/XsB0cXq6HHBOegEQfMoKKeLQ1sUTCU/kluYnYwyi7XfA73/dWL 8t9ec8bY2ZbgUXHmmBC42P+RkI/MhHfv7SA7lPpfx+QlYh4ZOY66g0ILsNfpcWqHKx6u w20A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=+LnWwDjMaBYjLnGCplLNOeVXtwWtYZYlfUO1teusnH8=; b=dtynIzq+2TJTB3RHqxWpUo9pBQhMD7YNcgAd2z5ASkHs9pSiZ0s7KFt7F7d2MhlmAf g3Eg0dW/KBWYE1kyM/8rKSrz/ojmwbmIoPEOqqtVGvfY/4Kn4zbjU6AKseapnF9TU9Uu o6THZKpd47L3HSE1EkVDQub3Fg7oby2h4KjK5p1fJXm/yy/gkJLVVQOZIHCa1GMkxWuK c4MeOEoKHmTj9Evf9HUPHpRFzaGCtQhs5I9Ccd6hjceW2IaQe/xrLDC624hnrapT5oN1 BDou6dOICsWufEiCNTw8/HT0RRMnVgOBk1se8kxgQ2I0vgctFFtRXQAyz1m7oJxVgOJj lCug== X-Gm-Message-State: APf1xPB4NYW2cZ+LXZrp/IvUmNxVZtJNMFC5Gw5mVM+411J5bnnnS0xx WK+/GZKQ+XXp1C+lDfwRWAk= X-Google-Smtp-Source: AH8x225CIcjxnqOIEPzhz+0Sq0QXUinlB4jsBBobxc2cKnqVEBCu2RVpdE0CW2J7y6b2lCIzRosT5Q== X-Received: by 10.223.150.194 with SMTP id u60mr2108282wrb.47.1518548184142; Tue, 13 Feb 2018 10:56:24 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-0d0e-7c04-950c-8f24.holly.idiocy.org. [2001:8b0:3f8:8129:d0e:7c04:950c:8f24]) by smtp.gmail.com with ESMTPSA id 137sm8821320wmm.46.2018.02.13.10.56.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 10:56:22 -0800 (PST) Content-Disposition: inline In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:143256 Archived-At: --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Feb 11, 2018 at 05:57:32PM +0000, Philipp Stephani wrote: > Anders Lindgren 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 --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="poc.patch" 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 + 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]) */ --zYM0uCDKw75PZbzx--