Attachment "tkwait-visibility.patch" to
ticket [7b8d4e4b]
added by
carenas
2021-08-27 03:58:30.
diff --git a/doc/tkwait.n b/doc/tkwait.n
index 82d51ba03..d2dd6b997 100644
--- a/doc/tkwait.n
+++ b/doc/tkwait.n
@@ -30,7 +30,8 @@ If the first argument is \fBvisibility\fR (or any abbreviation
of it) then the second argument is the name of a window and the
\fBtkwait\fR command waits for a change in its
visibility state (as indicated by the arrival of a VisibilityNotify
-event). This form is typically used to wait for a newly-created
+event, unless the window is already visible).
+This form is typically used to wait for a newly-created
window to appear on the screen before taking some action.
If the first argument is \fBwindow\fR (or any abbreviation
of it) then the second argument is the name of a window and the
diff --git a/generic/tkCmds.c b/generic/tkCmds.c
index 36981af05..8a2aba6ec 100644
--- a/generic/tkCmds.c
+++ b/generic/tkCmds.c
@@ -25,7 +25,7 @@
/*
* Forward declarations for functions defined later in this file:
*/
-
+static int GetWindowVisibility(TkWindow *winPtr);
static TkWindow * GetTopHierarchy(Tk_Window tkwin);
static char * WaitVariableProc(ClientData clientData,
Tcl_Interp *interp, const char *name1,
@@ -1036,6 +1036,10 @@ Tk_TkwaitObjCmd(
if (window == NULL) {
return TCL_ERROR;
}
+ if (GetWindowVisibility((TkWindow *)window)) {
+ code = TCL_OK;
+ break;
+ }
Tk_CreateEventHandler(window,
VisibilityChangeMask|StructureNotifyMask,
WaitVisibilityProc, &done);
@@ -1497,18 +1501,7 @@ Tk_WinfoObjCmd(
}
break;
case WIN_VIEWABLE: {
- int viewable = 0;
-
- for ( ; ; winPtr = winPtr->parentPtr) {
- if ((winPtr == NULL) || !(winPtr->flags & TK_MAPPED)) {
- break;
- }
- if (winPtr->flags & TK_TOP_HIERARCHY) {
- viewable = 1;
- break;
- }
- }
-
+ int viewable = GetWindowVisibility(winPtr);
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(viewable));
break;
}
@@ -1817,7 +1810,6 @@ Tk_WinfoObjCmd(
return TCL_OK;
}
-
/*
*----------------------------------------------------------------------
*
@@ -1913,6 +1905,43 @@ TkDeadAppObjCmd(
return TCL_ERROR;
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * GetWindowVisibility --
+ *
+ * Looks at the provided window and all its parents to determine
+ * if they are "viewable".
+ *
+ * Results:
+ * Returns a boolean value indicating if the window and all its
+ * parents are mapped.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+GetWindowVisibility(
+ TkWindow *winPtr) /* Window for which the visibility
+ * should be determined. */
+{
+ int viewable = 0;
+
+ for ( ; ; winPtr = winPtr->parentPtr) {
+ if ((winPtr == NULL) || !(winPtr->flags & TK_MAPPED)) {
+ break;
+ }
+ if (winPtr->flags & TK_TOP_HIERARCHY) {
+ viewable = 1;
+ break;
+ }
+ }
+ return viewable;
+}
+
/*
*----------------------------------------------------------------------
*