Tk Source Code

View Ticket
Login
2026-09-18
14:12 • Ticket [a7729b3d] linux: rapid entry create/destroy with keyboard events leads to permanent drops of all keyboard events status still Open with 3 other changes artifact: 6d0a3e76 user: serhiy.storchaka
2015-12-04
15:18 • Ticket [a7729b3d]: 3 changes artifact: 28c93ee5 user: danckaert
2015-11-18
18:20 • Ticket [a7729b3d]: 4 changes artifact: 178dcfe8 user: anonymous
2015-11-15
16:35 • Ticket [a7729b3d]: 4 changes artifact: 88d53d8d user: anonymous
16:22 • New ticket [a7729b3d]. artifact: f6f6bc0f user: anonymous

Ticket UUID: a7729b3d586a13cd0f4c98f5f1f92d905e8c82dd
Title: linux: rapid entry create/destroy with keyboard events leads to permanent drops of all keyboard events
Type: Bug Version: 8.6.4
Submitter: anonymous Created on: 2015-11-15 16:22:59
Subsystem: 69. Events Assigned To: nobody
Priority: 5 Medium Severity: Critical
Status: Open Last Modified: 2026-09-18 14:12:37
Resolution: None Closed By: nobody
    Closed on:
Description:
OS: Linux 3.13.0-68-generic Ubuntu x86-64
found in: Tcl/Tk 8.6.1
reproduced in: Tcl/Tk 8.6.4

My application creates and destroys entry boxes in response to mouse motion and clicks on a canvas (as a part of a mechanism for allowing the user to edit the canvas contents).  When simultaneously typing and rapidly creating/deleting entry boxes with mouse clicks and motion, I reach a condition in which Tk permanently and completely refuses to forward keyboard events to my application.  Mouse events are unaffected (they are forwarded to my application properly).  The condition is only resolved by an application restart.

While the bug is happening, the call in tkUnixEvent.c to XFilterEvent(&event.x, w) returns true on every keyboard event, which is the proximate cause of the drops.  It's not clear how we arrived in that state.

The bug can be reproduced by running the program appended below and typing on the keyboard.  Reproduction usually happens within 10 or 20 keystrokes.

Looking at the ChangeLog, I see this (from [81fa441963865bfb]):

2010-01-01  Donal K. Fellows  <[email protected]>

        * unix/tkUnixEvent.c (TransferXEventsToTcl): [Bug 1924761]: Move the
        * generic/tkEvent.c (Tk_HandleEvent):        passing of key events to
        XFilterEvent to the low level point where all other events are
        handled, where it should have been all along. This makes more input
        methods work, stops [event generate] from interfering with input
        methods, and allows the simplification of tkEvent.c by removing half
        of InvokeInputMethods and allowing the rest - which was not full input
        method handling - to be rolled back into Tk_HandleEvent. Introduces a
        small potential bug when a focus change and input method handling are
        too close together in the Tk event queue, but that should be less
        deadly to usability than the previous problems where input methods
        could fail completely or reorder key presses...

To someone unfamiliar with the X API, however, it is not entirely clear what DKF meant by this.

Program text for reproduction (type on the keyboard while running it):

==
#!/usr/bin/env wish

canvas .c
pack .c

set ::blah {}
proc create {} {
  catch {destroy .c.e}
  entry .c.e -textvariable ::blah
  pack .c.e
  focus .c.e
  .c.e icursor end
  after 100 ::create
}
create
User Comments: serhiy.storchaka added on 2026-09-18 14:12:37:

Cannot reproduce with the script from the ticket on Tk 8.6.4, 8.6.18 and main, with the ibus XIM server (XMODIFIERS=@im=ibus) and with the built-in Xlib input method, typing with XTEST while the entry is destroyed and recreated every 100 ms: only keys typed during the recreation are lost, keyboard input never stops. So this was specific to SCIM, which is no longer maintained.


danckaert added on 2015-12-04 15:18:46:
I had a similar problem some years ago. It turned out to be related to SCIM (https://en.wikipedia.org/wiki/Smart_Common_Input_Method). I could solve it by disabling SCIM on my Linux System. Don't know whether it was a bug in SCIM or in Tk.

anonymous (claiming to be original submitter) added on 2015-11-18 18:20:35:
Another user on the associated comp.lang.tcl thread verifies that they can also reproduce: 

https://groups.google.com/d/msg/comp.lang.tcl/ALr1oEzeDQM/1Anff0rmCwAJ

anonymous (claiming to be original submitter) added on 2015-11-15 16:35:53:
I note that the intervening canvas is unnecessary for reproduction.  Thus the reproduction program may be simplified to:

==
#!/usr/bin/env wish

set ::blah {}
proc create {} {
  catch {destroy .e}
  entry .e -textvariable ::blah
  pack .e
  focus .e
  .e icursor end
  after 100 ::create
}
create