| Ticket UUID: | 480158 | |||
| Title: | initial focus fails in child interp | |||
| Type: | Bug | Version: | final: 8.2.3 | |
| Submitter: | adunsmoor | Created on: | 2001-11-09 20:10:45 | |
| Subsystem: | 55. [focus] | Assigned To: | hobbs | |
| Priority: | 5 Medium | Severity: | ||
| Status: | Closed | Last Modified: | 2026-10-22 17:22:36 | |
| Resolution: | Duplicate | Closed By: | serhiy.storchaka | |
| Closed on: | 2026-09-19 16:22:13 | |||
| Description: |
I was trying to create a child interpreter which could
create a set of widgets and embed that within a frame
in the main interpreter. Most widgets work fine but
anything that depends on getting focus won't work
reliably on different platforms or with different
window managers.
To reproduce, create an interp within the main
interpreter and create a Tk text widget within the
child. It is difficult to get the text widget to take
the focus by clicking. This means that the "I" cursor
does not get inserted and the black line indicating
that the text area is ready for editing does not
appear. I played around with varying configurations
including packing and depth within the window hierarchy
with different results.
The following example always failed for me on Windows
2000 but seemed to work more often on Solaris using
CDE.
interp create child
toplevel .t
frame .t.f -container 1
pack .t.f -fill both -expand yes
interp eval child "lappend argv -use [winfo id .t.f]"
interp eval child {
load {} Tk
text .text
pack .text -fill both -expand yes
}
| |||
| User Comments: |
serhiy.storchaka added on 2026-09-19 16:22:13:
The Windows part was fixed by the embedding rewrite in 8.4.9: the container did not handle the TK_CLAIMFOCUS message, now it sets the focus to the embedded window. Works on Windows 11. The remaining X11 failure (focus lost when the window manager sets the focus to the toplevel after the click) is [a4fa3ad2d6], fixed in [eb2b41d5b3]; verified with the script from this ticket. hobbs added on 2001-11-17 07:46:00: Logged In: YES user_id=72656 This provides focus into the window on Windows (Linux works before and after), but I still can't type into the window. adunsmoor added on 2001-11-10 03:19:56: Logged In: YES
user_id=372263
The following patch seems to fix my problems under Solaris
2.7/CDE and Windows 2000. I'm applying it locally but more
feedback would be useful.
-Ahran
diff -c tkFocus.c.bak tkFocus.c
*** tkFocus.c.bakFri Nov 9 15:16:37 2001
--- tkFocus.cFri Nov 9 15:16:37 2001
***************
*** 645,651 ****
if ((topLevelPtr->flags & TK_EMBEDDED)
&& (displayFocusPtr->focusWinPtr == NULL)) {
! TkpClaimFocus(topLevelPtr, force);
} else if ((displayFocusPtr->focusWinPtr != NULL) ||
force) {
/*
* Generate events to shift focus between Tk windows.
--- 645,665 ----
if ((topLevelPtr->flags & TK_EMBEDDED)
&& (displayFocusPtr->focusWinPtr == NULL)) {
!
! /*
! * Fixes SF BUG 480158 'initial focus fails in child
interp'
! * Generate our own internal focus events just prior
to
! * sending out the external X events.
! */
! serial =
TkpChangeFocus(TkpGetWrapperWindow(topLevelPtr), force);
! if (serial != 0) {
! displayFocusPtr->focusSerial = serial;
! }
! GenerateFocusEvents(displayFocusPtr->focusWinPtr,
winPtr);
! displayFocusPtr->focusWinPtr = winPtr;
! winPtr->dispPtr->focusPtr = winPtr;
!
! TkpClaimFocus(topLevelPtr, force);
} else if ((displayFocusPtr->focusWinPtr != NULL) ||
force) {
/*
* Generate events to shift focus between Tk windows.
| |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki