Tk Source Code

View Ticket
Login
Ticket UUID: 16ef161925327343dd07722e6696cfea36dcd53
Title: binding sequence not working anymore
Type: Bug Version: 8.6.9
Submitter: beric Created on: 2020-03-25 10:06:23
Subsystem: 01. Bindings Assigned To: fvogel
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2020-06-27 09:45:34
Resolution: Fixed Closed By: fvogel
    Closed on: 2020-06-27 09:45:34
Description:
I have used the key sequence <Escape><Control-c> to open the console in my application.
This is not working anymore since 8.6.10 and TIP 532.

<Escape>, <Control-c>, and <Escape><c> are all working.
Looks like the Control modifier in the <Escape><Control-c> sequence is lost somewhere.
User Comments: fvogel added on 2020-06-27 09:45:34:
Merged in core-8-6-branch and trunk.

fvogel added on 2020-06-21 16:12:14:

I have found another, very similar, issue.

One cannot trigger

<a><1>
normally through the keyboard.

It's possible to trigger it using

    event generate <a>...
    event generate <1>...
and this is what the test suite was doing so far.

But one cannot trigger

<a><1>
through the keyboard as one would expect, unless key "a" is not released before mouse button 1 is clicked.

This is because, when the user hits key "a" and releases it, the events are a KeyPress followed by a KeyRelease. The KeyPress event correctly promotes the sequence

<a><1>
but the KeyRelease event wrongly removes it from the promotion list. Then, when clicking
<1>
, the binding will not fire because the pattern sequence (
<a><1>
) is no longer promoted.

I have added two new tests exercising this case: bind-33.20 and bind-33.21 in [42c2602b]. They are exercising bindings to mixed types (Key and Button) events as sent by the keyboard (including the KeyRelease event) and mouse. These tests fail with TIP #532 implementation but pass with the old implementation featuring the event ring.

Then commit [50f16135] fixes the code and makes these tests pass by preventing removal of the promotion list in the specific case exercised by bind-33.20 and bind-33.21. All bind.test tests do pass.


fvogel added on 2020-05-03 09:34:41:

I have now committed a mixture of my fix with Gregor's one. See [3604f763ae]. The good thing is that all tests do pass again with this change.


fvogel added on 2020-05-02 19:49:15:

I have added a new test case in [d650a3bd]. All tests still pass at that point.

On top of that I have reverted my fix proposal and made the changes proposed by Gregor, see [28f17b89]. Unfortunately with these changes the newly added tests bind-33.16, -17, -18 that exercise this ticket do no longer pass. Moreover these changes introduce a regression in that bind-33.9 no longer passes. I will have an in-depth look at Gregor's proposal to understand what's wrong. We are close to the goal I think.


fvogel added on 2020-05-02 17:04:36:

I have committed a series of three test cases exercising the use case reported in the present ticket. See [a54810f8].

Also I have proposed a fix, see [dfa8bbc5]. No bind.test test case fails with this fix.

The test cases [a54810f8] fail before the fix [dfa8bbc5] and pass with this fix.

While committing I have just received information from Gregor about this ticket. I will analyze them and report.


fvogel added on 2020-04-12 21:33:43:

I have started a bugfix branch. No functional change at this stage.


fvogel added on 2020-04-12 20:16:45:

Digging in the history I have found the following:

The original work from Gregor Cramer in his removal of the event ring discarded KeyPress/KeyRelease events for modifiers. This can be seen in the very first versions in branch

In these early versions, the test script I have proposed below in the present ticket didn't fail.

However, in these versions you couldn't bind to modifier keys, for instance <Control_L>. Such events were discarded early in Tk_BindEvent.

On 2018-12-11 Gregor made a change that allowed to bind to modifier keys, see [087aca88].

And from this point on, bindings on event sequences involving a modifier such as Control were broken. For instance <Escape><Control-c> cannot be triggered when the user hits the keyboard because the sequence of events seen in Tk_BindEvent is <Escape><Control_L><Control-c> (letting alone the autorepeat of <Control_L> that is happening if the key is down long enough).


fvogel added on 2020-04-11 20:35:50:

Confirmed.

    package require Tk
    pack [frame .f -width 100 -height 80]
    update
    bind .f <Escape><Control-c> { puts "triggered" }
    # focus in .f and try to trigger the binding: it does not work

What is interesting is that the following works (with or without the "after" command), that is, the bound script runs:

    package require Tk
    pack [frame .f -width 100 -height 80]
    update
    bind .f <Escape><Control-c> { puts "triggered" }
    focus -force .f
    event generate .f <Escape>
    after 1500
    event generate .f <Control-c>

Analyzing what is happening in Tk_BindEvent in the first case (when the user manually hits the keyboard and the bound script does not run), the reason for this issue is that the event sequence seen is <Escape><Control_L><Control-c>, which does not match the pattern sequence <Escape><Control-c>.

The previous implementation of tkBind.c dealt with this issue, but it seems TIP #532 implementation does not, or not fuly correctly.