Tk Source Code

View Ticket
Login
2020-04-14
19:10
Fix [87bade7e14]: Aqua PressAndHold composition misbehaves. check-in: d6a43988 user: culler tags: trunk
19:09
Fix [87bade7e14]: Aqua PressAndHold composition misbehaves. check-in: 61e70e0f user: culler tags: core-8-6-branch
19:06 • Closed ticket [87bade7e]: Aqua PressAndHold composition sometimes misbehaves. plus 8 other changes artifact: 3b48e27f user: marc_culler
2020-03-24
16:25 • Ticket [87bade7e]: 4 changes artifact: 9a8f3678 user: marc_culler
16:22 • Ticket [87bade7e]: 4 changes artifact: 9714d5c6 user: marc_culler
15:26
Fix [87bade7e14]: PressAndHold composition misbehaves. closed check-in: 14376ab5 user: marc_culler tags: bug-87bade7e14
15:19 • Add attachment press_hold.tcl to ticket [87bade7e] artifact: b2379794 user: marc_culler
15:18 • New ticket [87bade7e] Aqua PressAndHold composition sometimes misbehaves.. artifact: 2b132bc5 user: marc_culler

Ticket UUID: 87bade7e14e345dd459e0fc2fdae59ce05da5c2e
Title: Aqua PressAndHold composition sometimes misbehaves.
Type: Bug Version: 8.6.10
Submitter: marc_culler Created on: 2020-03-24 15:18:33
Subsystem: 07. [entry] Assigned To: marc_culler
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2020-04-14 19:06:37
Resolution: Fixed Closed By: marc_culler
    Closed on: 2020-04-14 19:06:37
Description:
Apple's PressAndHold composition scheme provides a very convenient way of
entering accented Latin-1 characters into an Entry or Text widget.  If a user
presses a letter key, such as 's', and holds the key down for a period of time
long enough for the key to begin repeating, then a context menu pops up at the
cursor which allows selecting an accented variant of the letter by pressing a
digit key. In the case of 's' the choices are ß, ś and š.

Tk implements this by making the TkContentView support the NSTextInputClient
interface. This works fine when entering text into a Text or Entry widget.

However, there are two fundamental problems with the implementation:
1) KeyRelease events are not sent when the context menu is visible.
2) Widgets which are not designed for text input are forced to behave as
   NSTextInputClients even when that is inappropriate.

It is very common to use KeyPress and KeyRelease events for purposes other
than entering text.  A typical example is a 3D game which uses the asdw keys
to control motion.  I will attach a simple 2D script which illustrates the
problem.

To use the script, first click on the Entry widget at the bottom and verify
that the PressAndHold works to enter accented letters.  Then click on the
canvas displaying an airplane propeller.  The way this program is intended
to work is that when the a key is pressed the propeller rotates one way and
when the s key is pressed it rotates the other way.  Releasing either key
makes it stop.  What actually happens is that a short press and release of
the a key does the right thing.  But a long press causes the context menu to
appear on the Entry widget and releasing the a key has no effect.

I will post a fix for this shortly.  First, the fix makes it so that only
text-related widgets behave as NSTextInputClients and second it does not
drop the KeyRelease events.  The mechanism for doing this was already in place
in Tk, where it was part of the XIM implementation.  It uses TkFocusKeyEvent
to figure out which widget is receiving the key event and it uses the caretPtr
maintained by Tk_SetCaretPtr to decide whether to participate in the
NSTextInputClient protocol.  Also, it cleans up a bunch of code that I found
confusing in tkMacOSXKeyEvent.c.
User Comments: marc_culler (claiming to be Marc Culler) added on 2020-04-14 19:06:37:
Thanks to Kevin Walzer and François Vogel for reviewing this change.  Since
they agree that this achieves its purpose (preventing the text entry menu from
popping up in inappropriate places and restoring lost ButtonRelease events) I
am going to merge this branch and close this ticket.

marc_culler (claiming to be Marc Culler) added on 2020-03-24 16:25:15:

I meant commit 14376ab5.


marc_culler (claiming to be Marc Culler) added on 2020-03-24 16:22:59:

The bugfix branch is bug-87bade7e14 in commit 87bade7e14.


Attachments: