Tk Source Code

View Ticket
Login
Ticket UUID: 583286
Title: Strange focus handling
Type: Bug Version: obsolete: 8.4b2
Submitter: dkf Created on: 2002-07-18 09:58:43
Subsystem: 18. [text] Assigned To: vincentdarley
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2003-11-13 00:39:08
Resolution: Fixed Closed By: vincentdarley
    Closed on: 2003-11-12 17:39:08
Description:
Execute the following script:

  pack [text .t]
  .t window create 1.0 -window [button .t.b -text hi]
  .t insert end " some random text "
  focus .t.b

Now, pressing the space bar operates the button (which
is good) but the insertion cursor is flashing in the
text widget while this is happening as if keypresses
will be inserted there (which is bad.)  Surely the
insertion cursor should only flash when the focus is
directed to the text widget, and not to one of its
children?
User Comments: jenglish added on 2002-07-19 07:17:08:

File Added - 27352: tkText.patch

Logged In: YES 
user_id=68433

This is caused by the following test in  TextEventProc
(tkTest.c, ~line 1270):

if (eventPtr->xfocus.detail != NotifyInferior) { ... }

Skipping FocusIn and FocusOut events where detail ==
NotifyInferior is the correct test if you want to monitor
whether the widget *contains* the focus (i.e., it or one of
its descendants has the focus).  However, in this case we
want to track  whether the the widget itself *has* the
focus.  

To do this the right test is to filter out "virtual
crossing" events (NotifyVirtual and NotifyNonlinearVirtual;
and possibly NotifyPointer, NotifyPointerRoot,
NotifyDetailNone, but I can't tell if the latter three are
ever delivered to Tk widgets). 

The attached patch fixes this problem.  Something similar
should be applied to the Canvas widget too.

Test suite: text.test still passes;  focus.test passes
except for two tests which were failing before on my
$DISPLAY anyway.

Attachments: