Tk Source Code

View Ticket
Login
Ticket UUID: 220902
Title: Canvas widget loses track of mouse
Type: Bug Version: 8.2.3, 8.6.18, 9.0.5, 9.1b1
Submitter: welch Created on: 2000-11-01 01:32:46
Subsystem: 04. Canvas Basics Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-12 13:37:47
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-10-12 13:37:47
Description:
OriginalBugID: 4408 Bug
Version: 8.2.3
SubmitDate: '2000-03-20'
LastModified: '2000-03-30'
Severity: MED
Status: UnAssn
Submitter: techsupp
ChangedBy: hobbs
OS: Linux-Red Hat


Name:

Mark Smith


ReproducibleScript:

Have a look at the following code in CanvasBindProc() in generic/tkCanvas.c:


        } else {

            /*

             * Button release: first process the event, with the button

             * still considered to be down.  Then repick the current

             * item under the assumption that the button is no longer down.

             */


            canvasPtr->state = eventPtr->xbutton.state;

            CanvasDoEvent(canvasPtr, eventPtr);

            eventPtr->xbutton.state ^= mask;

            canvasPtr->state = eventPtr->xbutton.state;

            PickCurrentItem(canvasPtr, eventPtr);

            eventPtr->xbutton.state ^= mask;

        }


The problem is that CanvasDoEvent might not return until the mouse has been moved

by the user.  This can happen, for example, if the programmer creates a canvas item that

simulates a button with a popup dialog to fire upon ButtonRelease.  When the popup dialog

is done, the user has moved the mouse far from where the original ButtonRelease event says

that it is.  This can cause undesirable effects, such as the display of a ToolTip on the wrong

canvas item.


DesiredBehavior:

The position of the mouse should be checked again after the CanvasDoEvent() is done.

You can't assume it's still valid.
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-12 13:37:47:

Serhiy, many thanks for fixing this very long-standing bug! Merged into main, core-9-0-branch, and core-8-6-branch by commits [46d1b6c3], [a87dacb0], and [20f9cded].


serhiy.storchaka added on 2026-09-21 17:14:51:

Still present in 8.6 and 9.1. Fixed on branch canvas-release-repick in [5d12b3ec2c]: if the pointer moved while the <ButtonRelease> binding script processed events, the current item is repicked with the last known pointer position instead of the position in the release event.