| Ticket UUID: | 233150 | |||
| Title: | window flashes on screen when withdrawn/deiconified | |||
| Type: | Bug | Version: | ||
| Submitter: | mdejong | Created on: | 2001-02-19 22:32:13 | |
| Subsystem: | 68. Win Window Operations | Assigned To: | hobbs | |
| Priority: | 5 Medium | Severity: | ||
| Status: | Closed | Last Modified: | 2002-06-25 03:35:21 | |
| Resolution: | Accepted | Closed By: | mdejong | |
| Closed on: | 2002-06-24 20:35:21 | |||
| Description: |
This problem only seems to show up under Windows.
The bug exists in Tk 8.3.2, I assume it shows
up in 8.4, but I have not tested that under Windows.
This bug actually has two parts. You can sort of
work around the problem by adding calls to update
and update idletasks, but that also causes problems.
Here is a bit of code that brings up a window
after a delay. Try it out and you will notice
that the window is initially mapped with a
geom of 1000x1000, it is then resized down
to the reqwidth and reqheight of the button.
if 1 {
set t [toplevel .t -width 1000 -height 1000 -bg black]
wm withdraw $t
update
pack [button $t.b -text AREALLYLONGSTRING]
after 4000
#update idletasks
wm deiconify $t
}
This problem can be "fixed" by uncommenting the
"update idletasks" call. You might be wondering,
why is the first call to update in there? Well
that is because the Window appears on the screen
for a split second even though it has been withdrawn.
So, the first call to update keeps the window from
appearing for a split second initially, but it
causes another problem. When the window is mapped,
it shows up at 1000x1000 for a split second and
then it gets resized to the reqwidth and reqheight
of the button.
This second problem can be worked around by
the "update idletasks", kind of ugly eh?
What is really odd about this bug is that if
you don't call update at all (the way it really
should work) then the window is mapped correctly
(even though it still flashed before being
put away).
| |||
| User Comments: |
mdejong added on 2002-06-25 03:16:10:
Logged In: YES user_id=90858 I am going to check this one in. The log indicates that this fix has been in queue for more than a year so it is about time it got integrated. It fits the beta terms since it is a criticl bug fix. hobbs added on 2002-06-24 10:05:25: Logged In: YES user_id=72656 The last "On Windows" part quoted by Mo from the man page is something that I'm fairly sure I added in 8.3 when fixing some other bugs, FWIW. mdejong added on 2002-06-24 09:31:29: Logged In: YES user_id=90858 Further proof of how the deiconify command should work can be found in the man page. wm deiconify window Arrange for window to be displayed in normal (non- iconified) form. This is done by mapping the win dow. If the window has never been mapped then this command will not map the window, but it will ensure that when the window is first mapped it will be displayed in de-iconified form. On Windows, a deiconified window will also be raised and be given the focus (made the active window). Returns an empty string. mdejong added on 2002-06-23 05:30:34: Logged In: YES user_id=90858 This patch has nothing to do with bug 571600 which seems to have been introduced by the patch for TIP 47. This patch only deals with the problem of "flashy windows" described above. hobbs added on 2002-06-22 08:54:34: Logged In: YES user_id=72656 Does this fix the initial 'wm geometry' problem? (Tk bug 571600)? This is very easy to reproduce on Windows: toplevel .t; wm geometry .t +200+200 In 8.3 -> 8.4a5 (up to 2 weeks ago), this would place the window at x=200,y=200 on the screen. Now it pops up in the top lefthand corner instead. mdejong added on 2002-06-22 08:46:18: Logged In: YES user_id=90858 So, any objections to adding this patch before the beta? If not I will check it in. mdejong added on 2002-06-14 15:27:56:
File Deleted - 10573:
File Added - 25090: toplevel_map.patch2
Logged In: YES
user_id=90858
The first thing to watch out for when talking about the
deiconify command is that it is almost the same as
the [wm state $t normal] command. In this case, things
are fine because the state command deals with the
WM_NEVER_MAPPED case (inside TkpWmSetState).
TkpWmSetState(winPtr, NormalState);
/*
* This varies from 'wm deiconify' because it does not
* force the window to be raised and receive focus
*/
Since the impl explicitly states that the two
commands will act differently, I ignored it.
Now lets take a look at the update idle block in the
current win32 deiconify implementation.
/*
* If WM_UPDATE_PENDING is true, a pending
UpdateGeometryInfo may
* need to be called first to update a withdrew
toplevel's geometry
* before it is deiconified by TkpWmSetState.
* Don't bother if we've never been mapped.
*/
if ((wmPtr->flags & WM_UPDATE_PENDING)) {
Tcl_CancelIdleCall(UpdateGeometryInfo,
(ClientData) winPtr);
UpdateGeometryInfo((ClientData) winPtr);
}
The first thing you might notice is the following comment:
"Don't bother if we've never been mapped."
That seems a little off since the block of code does not
seem
to explicitly do anything to deal with the WM_NEVER_MAPPED
case.
A look at revision 1.25 shows what happened here.
The code before revision 1.25 looked like so:
if ((wmPtr->flags & WM_UPDATE_PENDING) &&
!(wmPtr->flags & WM_NEVER_MAPPED)) {
The 1.25 revision reverted changes related to making the
map, raise, and focus commands happen at idle time. After
reverting the changes, the code looked like so:
if ((wmPtr->flags & WM_UPDATE_PENDING)) {
Reverting the idle callback changes was the right
thing to do, but the WM_NEVER_MAPPED flag was not
related to the idle callback implementation so it
should not have been reverted. Still, this does not
matter since it is not possible to have both
the WM_UPDATE_PENDING and WM_NEVER_MAPPED
flags set at the same time. Every location in
the code where WM_UPDATE_PENDING is set is
protected by a check like so:
if (!(wmPtr->flags &
(WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData)
winPtr);
wmPtr->flags |= WM_UPDATE_PENDING;
}
Well, there is one exception. The ConfigureTopLevel function
does not have such a check but it does not need one since it
is only called by Windows for a Window that has been mapped.
While the WM_NEVER_MAPPED flag does not change any of the
functionality in this case, I added it back so that
things are clear to the next person that looks at this.
The rest of the current implementation looks like this:
if (wmPtr->hints.initial_state == ZoomState) {
TkpWmSetState(winPtr, ZoomState);
} else {
TkpWmSetState(winPtr, NormalState);
}
/*
* Follow Windows-like style here, raising the
window to the top.
*/
TkWmRestackToplevel(winPtr, Above, NULL);
if (!(Tk_Attributes((Tk_Window)
winPtr)->override_redirect)) {
TkSetFocusWin(winPtr, 1);
}
The meat of my patch is the following:
--- win/tkWinWm.c12 Jun 2002 19:02:50 -00001.39
+++ win/tkWinWm.c14 Jun 2002 07:28:11 -0000
@@ -2366,6 +2367,15 @@
TkpWmSetState(winPtr, ZoomState);
} else {
TkpWmSetState(winPtr, NormalState);
+}
+
+/*
+ * An unmapped window will be mapped at idle time
+ * by a call to MapFrame. That calls CreateWrapper
+ * which sets the focus and raises the window.
+ */
+if (wmPtr->flags & WM_NEVER_MAPPED) {
+ return TCL_OK;
}
/*
And here is a test case for the change:
test wm-deiconify-2.1 {a window that has never been mapped
should not be mapped by a call to deiconify} {
destroy .t
toplevel .t
wm deiconify .t
winfo ismapped .t
} 0
This test case would fail with the current CVS
version under Win32, but it passes with my patch
and with X (Mac should pass too).
Above, I talked about why the deiconify command would
never invoke UpdateGeometryInfo() in the case of
a WM_NEVER_MAPPED toplevel. So what does happen
without the patch? The call to TkWmRestackToplevel
wants to raise the toplevel, but it does not actually
exist yet so it gets created with the req width
and req height. The toplevel is put at the top of
the display and assigned the focus. Then at idle
time the call to MapFrame that was supposed to
map the frame gets run. The MapFrame function
will get the requested sizes from the layout
manager and then resize the toplevel.
This out of order processing results in a toplevel that
flashes on the screen for a second before it gets
resized to the proper size. So, now that we know
what the problem is, what is the fix?
Fixing the problem was actually rather easy, but lots
of additional checking was required to make sure that
it did not break anything. We just need to check for
the WM_NEVER_MAPPED flag and then avoid calling
TkWmRestackToplevel and TkSetFocusWin in this one case.
A newely mapped window will still appear on the top
of the display and have the focus assigned to it.
I added two test cases to winWm.test to double
check this. Both tests pass before and after the
patch.
An toplevel that has already been mapped will still
get to the TkWmRestackToplevel and TkSetFocusWin
calls, so there is no functional change for that
code path.
I was unable to find a workaround for this problem
in pure Tcl code. It turned out to be a *very*
serious issue for end users. They felt that the
"flashed windows" gave the Windows version of
Source-Navigator a unprofessional appearance.
mdejong added on 2002-06-14 02:35:51: File Added - 25053: deiconify_history Logged In: YES user_id=90858 I have attached a file that tracks the history of changes in the wm deiconify implementation under Windows. I am working on a more detailed patch and test cases as well as a writeup that will ref this history. hobbs added on 2001-09-11 08:15:25: Logged In: YES user_id=72656 Please look in the Tk ChangeLogs for other changes to tkWinWm.c. The forced mapping was done intentionally to get around other bugs and make this work. We'd have to track down (through changed DB numbers) exactly what problem was fixed before to make sure we aren't going to reintroduce something. The attached patch may be correct, but this was definitely a tricky problem before. mdejong added on 2001-09-10 06:49:47: Logged In: YES user_id=90858 Jeff, I am assigning this bug to you since I think this fix is ready to go into 8.4. I am not able to access tcltk.com to find out who the maintainer for this area is, I hope that is ok. Also, this patch just grabs a block of code from the Unix impl of Tk_WmCmd in case you are wondering where the logic came from. mdejong added on 2001-09-10 06:43:44: File Added - 10573: win_wm.patch Logged In: YES user_id=90858 After looking at this problem some more, I think my earlier patch was in error. I have attached a patch that seems to fix the problem without creating any new ones. I also added two test cases to make sure things work the same way under Windows as they do under Unix. nobody added on 2001-09-09 08:32:13: Logged In: NO
I took another look at this problem and it
seems to be caused by the call to TkWmRestackToplevel
in Tk_WmCmd from tkWinWm.c. When "wm deiconify" is
called the Window is mapped even though it should
not be mapped until idle. The following patch
seems to fix the problem by moving the call to
raise and focus in on the toplevel to a point
after it has been mapped in the idle callback.
This is Windows only code so there should be no
danger to the Unix or Mac ports. I am not sure
about the correctness of this patch so if someone
could take a look and give me some feedback that
would be great.
Index: win/tkWinWm.c
============================================================
=======
RCS file: /cvsroot/tktoolkit/tk/win/tkWinWm.c,v
retrieving revision 1.29
diff -u -r1.29 tkWinWm.c
--- win/tkWinWm.c2001/03/30 21:52:561.29
+++ win/tkWinWm.c2001/09/09 01:21:13
@@ -1773,6 +1773,16 @@
wmPtr->titleUid = winPtr->nameUid;
}
UpdateWrapper(winPtr);
+
+ /*
+ * Follow Windows-like style here.
+ * Raise the window and give it the focus.
+ */
+
+ TkWmRestackToplevel(winPtr, Above, NULL);
+ if (!(Tk_Attributes((Tk_Window) winPtr)-
>override_redirect)) {
+TkSetFocusWin(winPtr, 1);
+ }
}
/*
@@ -2313,13 +2323,6 @@
TkpWmSetState(winPtr, NormalState);
}
-/*
- * Follow Windows-like style here, raising the
window to the top.
- */
-TkWmRestackToplevel(winPtr, Above, NULL);
-if (!(Tk_Attributes((Tk_Window) winPtr)-
>override_redirect)) {
- TkSetFocusWin(winPtr, 1);
-}
} else if ((c == 'f') && (strncmp(argv
[1], "focusmodel", length) == 0)
&& (length >= 2)) {
if ((argc != 3) && (argc != 4)) {
| |||
Attachments:
- toplevel_map.patch2 [download] added by mdejong on 2002-06-14 15:27:56. [details]
- deiconify_history [download] added by mdejong on 2002-06-14 02:35:51. [details]
