Subject: 30.0.60; [PATCH] NS: support passing key events to the system

From: Kai Ma <[email-masked]>
Date: Sat, 10 Aug 2024 13:47:48 +0200

The attached patch adds ns-pass-keys-to-system and makes Emacs to send
the key events to the system input manager when it's set.  This can
correct a number of problems that are hard to work around due to the
current key handling logic of Emacs NSport.

(1) The keydown event of Shift+Enter is never sent to the system input
method.  This causes an annoying problem for system input methods: if
you press Shift+Enter in Emacs (that is three events: Shift down,
Shift+Enter down, Shift up), the input method only sees Shift down and
up.  However, many input methods interprets a click of Shift differently
(mostly toggling ASCII mode), and this causes unwanted behavior.  (This
was reported as #38293 in 2019.)

This can only be fixed by Emacs, because to input methods, Shift+Enter
is indistinguishable from a single Shift.

(2) The input method may define some special keys and Emacs cannot make
use of them.

(3) Some system level shortcuts never work in Emacs.  For example,
Rectangle (think of it as a third-party window manager in macOS) will
not receive any requests from Emacs windows.

The fix is mostly modeled after Mitsuharu's Mac port, with a few
adjustments for NS port.  I've been using it for some time and there are
no more defects known to me, so I decide it's time to send it to you.

Regards,
Kai