Attachment "wm.patch" to
ticket [561708ff]
added by
mdejong
2002-05-29 05:16:10.
2002-05-28 Mo DeJong <[email protected]>
* changes: Add note about new transient behavior.
* tests/unixWm.test: Check that the WM_TRANSIENT_FOR
property for a transient window is being cleared
when the master is destroyed.
* tests/wm.test: Source defs.tcl instead of using
tcltest to match the rest of Tk's test files.
Add new tests that ensure that a transient's state
mirrors the state of the master.
* unix/tkUnixWm.c (WmInfo, TkWmNewWindow, TkWmMapWindow,
TkWmDeadWindow, Tk_WmCmd, WmWaitMapProc): Add numTransients
member to WmInfo structure. Keep state of master and
transient in sync using a callback that tracks MapNotify
and UnmapNotify events. When the master is mapped, map
the transient. When the master is unmapped or iconified,
withdraw the transient.
* win/tkWinWm.c (TkWmMapWindow, TkpWmSetState,
TkWmDeadWindow, Tk_WmCmd, WmWaitVisibilityOrMapProc):
Keep state of master and transient in sync using a
callback that tracks MapNotify and UnmapNotify events.
Move masterPtr check from TkpWmSetState into TkWmMapWindow
to deal with WM_NEVER_MAPPED transients. Cleanup
numTransients and the callback in TkWmDeadWindow.
Cleanup numTransients and the callback only after
deleting a master in wm transient command to avoid
deleting the callback when an error is raised.
Add support for MapNotify and UnmapNotify events
to the master callback.
Index: changes
===================================================================
RCS file: /cvsroot/tktoolkit/tk/changes,v
retrieving revision 1.52
diff -u -r1.52 changes
--- changes 27 May 2002 22:54:42 -0000 1.52
+++ changes 28 May 2002 21:57:51 -0000
@@ -5185,3 +5185,7 @@
--- Released 8.4a4, March 5, 2002 --- See ChangeLog for details ---
2002-05-27 (feature change) [wm transient .t .t] now raises an error
+
+2002-05-28 (feature change) A transient toplevel now mirrors state
+canges in the master.
+
Index: tests/unixWm.test
===================================================================
RCS file: /cvsroot/tktoolkit/tk/tests/unixWm.test,v
retrieving revision 1.15
diff -u -r1.15 unixWm.test
--- tests/unixWm.test 24 May 2002 09:50:11 -0000 1.15
+++ tests/unixWm.test 28 May 2002 21:57:52 -0000
@@ -1279,7 +1279,18 @@
destroy .t2
set result
} {{} {} .t 0 {} 0x0}
-test unixWm-37.4 {Tk_WmCmd procedure, "transient" option, create master wrapper} {unixOnly} {
+test unixWm-37.4 {TkWmDeadWindow, destroy on master should clear transient} {unixOnly} {
+ catch {destroy .t2}
+ toplevel .t2
+ catch {destroy .t3}
+ toplevel .t3
+ wm transient .t2 .t3
+ update
+ destroy .t3
+ update
+ list [wm transient .t2] [testprop [testwrapper .t2] WM_TRANSIENT_FOR]
+} {{} 0x0}
+test unixWm-37.5 {Tk_WmCmd procedure, "transient" option, create master wrapper} {unixOnly} {
catch {destroy .t2}
catch {destroy .t3}
toplevel .t2 -width 120 -height 300
Index: tests/wm.test
===================================================================
RCS file: /cvsroot/tktoolkit/tk/tests/wm.test,v
retrieving revision 1.8
diff -u -r1.8 wm.test
--- tests/wm.test 27 May 2002 22:54:42 -0000 1.8
+++ tests/wm.test 28 May 2002 21:57:53 -0000
@@ -14,8 +14,7 @@
# platform should be placed in unixWm.test or winWm.test.
if {[lsearch [namespace children] ::tcltest] == -1} {
- package require tcltest
- namespace import -force ::tcltest::*
+ source [file join [pwd] [file dirname [info script]] defs.tcl]
}
proc deleteWindows {} {
@@ -381,6 +380,134 @@
wm transient .subject
} {.master}
+test wm-transient-3.1 { transient toplevel is withdrawn
+ when mapped if master is withdrawn } {
+ deleteWindows
+ toplevel .master
+ wm withdraw .master
+ update
+ toplevel .subject
+ wm transient .subject .master
+ update
+ list [wm state .subject] [winfo ismapped .subject]
+} {withdrawn 0}
+
+test wm-transient-3.2 { already mapped transient toplevel
+ takes on withdrawn state of master } {
+ deleteWindows
+ toplevel .master
+ wm withdraw .master
+ update
+ toplevel .subject
+ update
+ wm transient .subject .master
+ update
+ list [wm state .subject] [winfo ismapped .subject]
+} {withdrawn 0}
+
+test wm-transient-3.3 { withdraw/deiconify on the master
+ also does a withdraw/deiconify on the transient } {
+ deleteWindows
+ set results [list]
+ toplevel .master
+ toplevel .subject
+ update
+ wm transient .subject .master
+ wm withdraw .master
+ update
+ lappend results [wm state .subject] \
+ [winfo ismapped .subject]
+ wm deiconify .master
+ update
+ lappend results [wm state .subject] \
+ [winfo ismapped .subject]
+ set results
+} {withdrawn 0 normal 1}
+
+test wm-transient-4.1 { transient toplevel is withdrawn
+ when mapped if master is iconic } {
+ deleteWindows
+ toplevel .master
+ wm iconify .master
+ update
+ toplevel .subject
+ wm transient .subject .master
+ update
+ list [wm state .subject] [winfo ismapped .subject]
+} {withdrawn 0}
+
+test wm-transient-4.2 { already mapped transient toplevel
+ is withdrawn if master is iconic } {
+ deleteWindows
+ toplevel .master
+ wm iconify .master
+ update
+ toplevel .subject
+ update
+ wm transient .subject .master
+ update
+ list [wm state .subject] [winfo ismapped .subject]
+} {withdrawn 0}
+
+test wm-transient-4.3 { iconify/deiconify on the master
+ does a withdraw/deiconify on the transient } {
+ deleteWindows
+ set results [list]
+ toplevel .master
+ toplevel .subject
+ update
+ wm transient .subject .master
+ wm iconify .master
+ update
+ lappend results [wm state .subject] \
+ [winfo ismapped .subject]
+ wm deiconify .master
+ update
+ lappend results [wm state .subject] \
+ [winfo ismapped .subject]
+ set results
+} {withdrawn 0 normal 1}
+
+test wm-transient-5.1 { an error during transient command should not
+ cause the map/unmap binding to be deleted } {
+ deleteWindows
+ set results [list]
+ toplevel .master
+ toplevel .subject
+ update
+ wm transient .subject .master
+ # Expect a bad window path error here
+ lappend results [catch {wm transient .subject .bad}]
+ wm withdraw .master
+ update
+ lappend results [wm state .subject]
+ wm deiconify .master
+ update
+ lappend results [wm state .subject]
+ set results
+} {1 withdrawn normal}
+
+test wm-transient-5.2 { remove transient property when master
+ is destroyed } {
+ deleteWindows
+ toplevel .master
+ toplevel .subject
+ wm transient .subject .master
+ update
+ destroy .master
+ update
+ wm transient .subject
+} {}
+
+test wm-transient-5.3 { remove transient property from window
+ that had never been mapped when master is destroyed } {
+ deleteWindows
+ toplevel .master
+ toplevel .subject
+ wm transient .subject .master
+ destroy .master
+ wm transient .subject
+} {}
test wm-state-1.1 {usage} {
Index: unix/tkUnixWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixWm.c,v
retrieving revision 1.20
diff -u -r1.20 tkUnixWm.c
--- unix/tkUnixWm.c 27 May 2002 22:54:42 -0000 1.20
+++ unix/tkUnixWm.c 28 May 2002 21:57:56 -0000
@@ -197,6 +197,7 @@
char *clientMachine; /* String to store in WM_CLIENT_MACHINE
* property, or NULL. */
int flags; /* Miscellaneous flags, defined below. */
+ int numTransients; /* number of transients on this window */
struct TkWmInfo *nextPtr; /* Next in list of all top-level windows. */
} WmInfo;
@@ -341,6 +342,8 @@
XEvent *eventPtr));
static void WrapperEventProc _ANSI_ARGS_((ClientData clientData,
XEvent *eventPtr));
+static void WmWaitMapProc _ANSI_ARGS_((
+ ClientData clientData, XEvent *eventPtr));
/*
*--------------------------------------------------------------
@@ -431,6 +434,7 @@
wmPtr->winPtr = winPtr;
wmPtr->reparent = None;
wmPtr->masterPtr = NULL;
+ wmPtr->numTransients = 0;
wmPtr->hints.flags = InputHint | StateHint;
wmPtr->hints.input = True;
wmPtr->hints.initial_state = NormalState;
@@ -549,8 +553,17 @@
}
if (wmPtr->masterPtr != NULL) {
- XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
- wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
+ /*
+ * Don't map a transient if the master is not mapped.
+ */
+
+ if (!Tk_IsMapped(wmPtr->masterPtr)) {
+ wmPtr->withdrawn = 1;
+ wmPtr->hints.initial_state = WithdrawnState;
+ } else {
+ XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
+ wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
+ }
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
@@ -743,6 +756,44 @@
if (wmPtr->flags & WM_UPDATE_PENDING) {
Tcl_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
}
+ /*
+ * Reset all transient windows whose master is the dead window.
+ */
+
+ for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
+ wmPtr2 = wmPtr2->nextPtr) {
+ if (wmPtr2->masterPtr == winPtr) {
+ wmPtr->numTransients--;
+ Tk_DeleteEventHandler((Tk_Window) wmPtr2->masterPtr,
+ StructureNotifyMask,
+ WmWaitMapProc, (ClientData) wmPtr2->winPtr);
+ wmPtr2->masterPtr = NULL;
+ if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
+ XSetTransientForHint(wmPtr2->winPtr->display,
+ wmPtr2->wrapperPtr->window, None);
+ /* FIXME: Need a call like Win32's UpdateWrapper() so
+ we can recreate the wrapper and get rid of the
+ transient window decorations. */
+ }
+ }
+ }
+ if (wmPtr->numTransients != 0)
+ panic("numTransients should be 0");
+
+ if (wmPtr->masterPtr != NULL) {
+ wmPtr2 = wmPtr->masterPtr->wmInfoPtr;
+ /*
+ * If we had a master, tell them that we aren't tied
+ * to them anymore
+ */
+ if (wmPtr2 != NULL) {
+ wmPtr2->numTransients--;
+ }
+ Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
+ StructureNotifyMask,
+ WmWaitMapProc, (ClientData) winPtr);
+ wmPtr->masterPtr = NULL;
+ }
ckfree((char *) wmPtr);
winPtr->wmInfoPtr = NULL;
}
@@ -1978,6 +2029,21 @@
return TCL_OK;
}
if (argv[3][0] == '\0') {
+ if (masterPtr != NULL) {
+ /*
+ * If we had a master, tell them that we aren't tied
+ * to them anymore
+ */
+ masterPtr->wmInfoPtr->numTransients--;
+ Tk_DeleteEventHandler((Tk_Window) masterPtr,
+ StructureNotifyMask,
+ WmWaitMapProc, (ClientData) winPtr);
+
+ /* FIXME: Need a call like Win32's UpdateWrapper() so
+ we can recreate the wrapper and get rid of the
+ transient window decorations. */
+ }
+
wmPtr->masterPtr = NULL;
} else {
masterPtr = (TkWindow *) Tk_NameToWindow(interp, argv[3], tkwin);
@@ -2020,14 +2086,41 @@
(char *) NULL);
return TCL_ERROR;
} else if (masterPtr != wmPtr->masterPtr) {
+ /*
+ * Remove old master map/unmap binding before setting
+ * the new master. The event handler will ensure that
+ * transient states reflect the state of the master.
+ */
+
+ if (wmPtr->masterPtr == NULL) {
+ masterPtr->wmInfoPtr->numTransients++;
+ } else {
+ Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
+ StructureNotifyMask,
+ WmWaitMapProc, (ClientData) winPtr);
+ }
+
+ Tk_CreateEventHandler((Tk_Window) masterPtr,
+ StructureNotifyMask,
+ WmWaitMapProc, (ClientData) winPtr);
+
wmPtr->masterPtr = masterPtr;
}
}
if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- Window xwin = (wmPtr->masterPtr == NULL) ? None :
- wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window;
- XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
- xwin);
+ if (wmPtr->masterPtr != NULL && !Tk_IsMapped(wmPtr->masterPtr)) {
+ if (TkpWmSetState(winPtr, WithdrawnState) == 0) {
+ Tcl_SetResult(interp,
+ "couldn't send withdraw message to window manager",
+ TCL_STATIC);
+ return TCL_ERROR;
+ }
+ } else {
+ Window xwin = (wmPtr->masterPtr == NULL) ? None :
+ wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window;
+ XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
+ xwin);
+ }
}
} else if ((c == 'w') && (strncmp(argv[1], "withdraw", length) == 0)
&& (length >= 2)) {
@@ -2067,6 +2160,28 @@
wmPtr->flags |= WM_UPDATE_PENDING;
}
return TCL_OK;
+}
+
+/*
+ * Invoked when a MapNotify or UnmapNotify event is delivered for a
+ * toplevel that is the master of a transient toplevel.
+ */
+static void
+WmWaitMapProc(clientData, eventPtr)
+ ClientData clientData; /* Pointer to window. */
+ XEvent *eventPtr; /* Information about event. */
+{
+ TkWindow *winPtr = (TkWindow *) clientData;
+ TkWindow *masterPtr = winPtr->wmInfoPtr->masterPtr;
+
+ if (masterPtr == NULL)
+ return;
+
+ if (eventPtr->type == MapNotify) {
+ (void) TkpWmSetState(winPtr, NormalState);
+ } else if (eventPtr->type == UnmapNotify) {
+ (void) TkpWmSetState(winPtr, WithdrawnState);
+ }
}
/*
Index: win/tkWinWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinWm.c,v
retrieving revision 1.38
diff -u -r1.38 tkWinWm.c
--- win/tkWinWm.c 27 May 2002 22:54:42 -0000 1.38
+++ win/tkWinWm.c 28 May 2002 21:57:59 -0000
@@ -392,7 +392,7 @@
static void UpdateWrapper _ANSI_ARGS_((TkWindow *winPtr));
static LRESULT CALLBACK WmProc _ANSI_ARGS_((HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam));
-static void WmWaitVisibilityProc _ANSI_ARGS_((
+static void WmWaitVisibilityOrMapProc _ANSI_ARGS_((
ClientData clientData, XEvent *eventPtr));
static BlockOfIconImagesPtr ReadIconFromICOFile _ANSI_ARGS_((
Tcl_Interp *interp, char* fileName));
@@ -1521,10 +1521,10 @@
if (winPtr->flags & TK_EMBEDDED) {
wmPtr->wrapper = (HWND) winPtr->privatePtr;
if (wmPtr->wrapper == NULL) {
- panic("TkWmMapWindow: Cannot find container window");
+ panic("UpdateWrapper: Cannot find container window");
}
if (!IsWindow(wmPtr->wrapper)) {
- panic("TkWmMapWindow: Container was destroyed");
+ panic("UpdateWrapper: Container was destroyed");
}
} else {
@@ -1790,7 +1790,17 @@
InitWm();
}
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
+ if (wmPtr->flags & WM_NEVER_MAPPED) {
+ /*
+ * Don't map a transient if the master is not mapped.
+ */
+
+ if (wmPtr->masterPtr != NULL &&
+ !Tk_IsMapped(wmPtr->masterPtr)) {
+ wmPtr->hints.initial_state = WithdrawnState;
+ return;
+ }
+ } else {
if (wmPtr->hints.initial_state == WithdrawnState) {
return;
}
@@ -1867,8 +1877,7 @@
WmInfo *wmPtr = winPtr->wmInfoPtr;
int cmd;
- if ((wmPtr->flags & WM_NEVER_MAPPED) ||
- (wmPtr->masterPtr && !Tk_IsMapped(wmPtr->masterPtr))) {
+ if (wmPtr->flags & WM_NEVER_MAPPED) {
wmPtr->hints.initial_state = state;
return;
}
@@ -1944,6 +1953,10 @@
for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
wmPtr2 = wmPtr2->nextPtr) {
if (wmPtr2->masterPtr == winPtr) {
+ wmPtr->numTransients--;
+ Tk_DeleteEventHandler((Tk_Window) wmPtr2->masterPtr,
+ VisibilityChangeMask|StructureNotifyMask,
+ WmWaitVisibilityOrMapProc, (ClientData) wmPtr2->winPtr);
wmPtr2->masterPtr = NULL;
if ((wmPtr2->wrapper != None)
&& !(wmPtr2->flags & (WM_NEVER_MAPPED))) {
@@ -1951,6 +1964,8 @@
}
}
}
+ if (wmPtr->numTransients != 0)
+ panic("numTransients should be 0");
if (wmPtr->hints.flags & IconPixmapHint) {
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
@@ -1996,8 +2011,8 @@
wmPtr2->numTransients--;
}
Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
- VisibilityChangeMask,
- WmWaitVisibilityProc, (ClientData) winPtr);
+ VisibilityChangeMask|StructureNotifyMask,
+ WmWaitVisibilityOrMapProc, (ClientData) winPtr);
wmPtr->masterPtr = NULL;
}
@@ -3274,17 +3289,19 @@
}
return TCL_OK;
}
- if (masterPtr != NULL) {
- /*
- * If we had a master, tell them that we aren't tied
- * to them anymore
- */
- masterPtr->wmInfoPtr->numTransients--;
- Tk_DeleteEventHandler((Tk_Window) masterPtr,
- VisibilityChangeMask,
- WmWaitVisibilityProc, (ClientData) winPtr);
- }
if (argv[3][0] == '\0') {
+ if (masterPtr != NULL) {
+ /*
+ * If we had a master, tell them that we aren't tied
+ * to them anymore
+ */
+
+ masterPtr->wmInfoPtr->numTransients--;
+ Tk_DeleteEventHandler((Tk_Window) masterPtr,
+ VisibilityChangeMask|StructureNotifyMask,
+ WmWaitVisibilityOrMapProc, (ClientData) winPtr);
+ }
+
wmPtr->masterPtr = NULL;
} else {
masterPtr = (TkWindow*) Tk_NameToWindow(interp, argv[3], tkwin);
@@ -3324,23 +3341,35 @@
(char *) NULL);
return TCL_ERROR;
} else if (masterPtr != wmPtr->masterPtr) {
- wmPtr->masterPtr = masterPtr;
- masterPtr->wmInfoPtr->numTransients++;
-
/*
- * Bind a visibility event handler to the master window,
- * to ensure that when it is mapped, the children will
- * have their state set properly.
+ * Remove old master map/unmap binding before setting
+ * the new master. The event handler will ensure that
+ * transient states reflect the state of the master.
*/
+ if (wmPtr->masterPtr == NULL) {
+ masterPtr->wmInfoPtr->numTransients++;
+ } else {
+ Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
+ VisibilityChangeMask|StructureNotifyMask,
+ WmWaitVisibilityOrMapProc, (ClientData) winPtr);
+ }
+
Tk_CreateEventHandler((Tk_Window) masterPtr,
- VisibilityChangeMask,
- WmWaitVisibilityProc, (ClientData) winPtr);
+ VisibilityChangeMask|StructureNotifyMask,
+ WmWaitVisibilityOrMapProc, (ClientData) winPtr);
+
+ wmPtr->masterPtr = masterPtr;
}
}
if (!((wmPtr->flags & WM_NEVER_MAPPED)
&& !(winPtr->flags & TK_EMBEDDED))) {
- UpdateWrapper(winPtr);
+ if (wmPtr->masterPtr != NULL &&
+ !Tk_IsMapped(wmPtr->masterPtr)) {
+ TkpWmSetState(winPtr, WithdrawnState);
+ } else {
+ UpdateWrapper(winPtr);
+ }
}
} else if ((c == 'w') && (strncmp(argv[1], "withdraw", length) == 0)) {
if (argc != 3) {
@@ -3377,14 +3406,23 @@
}
/*ARGSUSED*/
static void
-WmWaitVisibilityProc(clientData, eventPtr)
+WmWaitVisibilityOrMapProc(clientData, eventPtr)
ClientData clientData; /* Pointer to window. */
XEvent *eventPtr; /* Information about event. */
{
TkWindow *winPtr = (TkWindow *) clientData;
TkWindow *masterPtr = winPtr->wmInfoPtr->masterPtr;
- if ((eventPtr->type == VisibilityNotify) && (masterPtr != NULL)) {
+ if (masterPtr == NULL)
+ return;
+
+ if (eventPtr->type == MapNotify) {
+ TkpWmSetState(winPtr, NormalState);
+ } else if (eventPtr->type == UnmapNotify) {
+ TkpWmSetState(winPtr, WithdrawnState);
+ }
+
+ if (eventPtr->type == VisibilityNotify) {
int state = masterPtr->wmInfoPtr->hints.initial_state;
if ((state == NormalState) || (state == ZoomState)) {