This is the mail archive of the
xconq7@sources.redhat.com
mailing list for the Xconq project.
[Patch] BadWindow/BadDrawable Fix
On Fri, 27 Jun 2003, Hans Ronne wrote:
> >Or it can be done in tkmain.c with:
>
> The second solution seems to be the best way if it works.
OK, here is pretty much everything. I still need to think about dealing with
the error and warning dialogs because they use tk_messageBox, but this should
fix (at least it does on my machine) the BadWindow/BadDrawable errors for:
.newgame, .prefs, .find, .contour, .research, .gameover, .meridian, .help,
.scores, .design, and .agreements (even though I know this last window is
currently unused).
I also did a few cosmetic brushups to the Tcl code for the research dialog
since it appeared to be overindented in my editor.
And included is the small patch to tkmap.c that I sent to the list a few days
ago. It never made it into CVS. All it does is remove a compile-time warning.
--- orig-tkconq.h Fri Jun 27 21:44:21 2003
+++ tkconq.h Fri Jun 27 21:47:32 2003
@@ -315,6 +315,8 @@
extern void init_x_signal_handlers(void); /* Lives in xconq.c. */
+extern int withdraw_window (const char *, Tcl_Interp *);
+
extern void initial_ui_init(void);
extern void init_display(void);
extern void init_redraws(void);
--- orig-tkmain.c Fri Jun 27 20:22:38 2003
+++ tkmain.c Fri Jun 27 23:09:09 2003
@@ -195,6 +195,8 @@
TclCmdFn mapw_cmd;
TclCmdFn imfsample_cmd;
+TclCmdFn tk_withdraw_window;
+
void update_mouseover(Map *map, int rawx, int rawy);
/* Declarations of local functions. */
@@ -346,6 +348,7 @@
tcl_cmd("get_scores", tk_get_scores);
tcl_cmd("reset_popup_flag", tk_reset_popup_flag);
tcl_cmd("exit_xconq", tk_exit_xconq);
+ tcl_cmd("withdraw_window", tk_withdraw_window);
tkwin = Tk_MainWindow(interp);
@@ -4255,4 +4258,52 @@
void
end_printing_forms(void)
{
+}
+
+int
+tk_withdraw_window( \
+ ClientData cldata, Tcl_Interp *interp, int argc, char *argv[])
+{
+ if (2 > argc){
+ /* TODO: How should we report the error? */
+ return TCL_ERROR;
+ }
+ return withdraw_window(argv[1], interp);
+}
+
+/*
+ * Does the equivalent of "wm withdraw" in Tcl/Tk with the additional
+ * step of destroying the window on X11 to get rid of the BadWindow messages.
+ */
+int
+withdraw_window (const char * windowpath, Tcl_Interp * interp)
+{
+
+ Tk_Window tkwin = NULL;
+#ifdef UNIX
+ Window xid = 0;
+#endif
+
+ tkwin = Tk_NameToWindow(interp, (char *)windowpath, Tk_MainWindow(interp));
+ if (NULL == tkwin){
+ /* Assume that the user may have closed the window.
+ ...for now, anyway...
+ We may get smarter about this someday.
+ */
+ Dprintf("Could not find window %s.\n", windowpath);
+ }
+ else{
+#ifdef UNIX
+ xid = Tk_WindowId(tkwin);
+#endif
+ Tk_UnmapWindow(tkwin);
+#ifdef UNIX
+ Tk_DestroyWindow(tkwin);
+ Dprintf("Unmapped window %s with XID %x.\n", windowpath, (unsigned)xid);
+#else
+ Dprintf("Unmapped window %s.\n", windowpath);
+#endif
+ }
+ return TCL_OK;
+
}
--- orig-tkconq.tcl Fri Jun 27 21:48:30 2003
+++ tkconq.tcl Fri Jun 27 23:41:09 2003
@@ -1424,7 +1424,7 @@
}
launch_game
# Once the game is underway, we can make this dialog go away.
- wm withdraw .newgame
+ withdraw_window ".newgame"
}
set indepside_up 0
@@ -2928,7 +2928,7 @@
-bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
-fg $fgcolor -activeforeground $afcolor -width 8
button .contour.bottom.cancel -text "Cancel" \
- -command { wm withdraw .contour } \
+ -command { withdraw_window ".contour" } \
-bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
-fg $fgcolor -activeforeground $afcolor -width 8
grid .contour.bottom.cancel .contour.bottom.ok -sticky ew -padx 8 -pady 4
@@ -2936,7 +2936,7 @@
bind .contour <Key> {
if {"%K" == "Escape"} {
.contour.bottom.cancel flash
- wm withdraw .contour
+ withdraw_window ".contour"
} elseif {"%K" == "Return"} {
.contour.bottom.ok flash
ok_contour_interval
@@ -2952,7 +2952,7 @@
execute_long_command $map_number($contour_interval_map) \
"map contour-interval=$contour_interval"
- wm withdraw .contour
+ withdraw_window ".contour"
}
set new_meridian_interval 0
@@ -2994,7 +2994,7 @@
-bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
-fg $fgcolor -activeforeground $afcolor -width 8
button .meridian.bottom.cancel -text "Cancel" \
- -command { wm withdraw .meridian } \
+ -command { withdraw_window ".meridian" } \
-bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
-fg $fgcolor -activeforeground $afcolor -width 8
grid .meridian.bottom.cancel .meridian.bottom.ok -sticky ew -padx 8 -pady 4
@@ -3002,7 +3002,7 @@
bind .meridian <Key> {
if {"%K" == "Escape"} {
.meridian.bottom.cancel flash
- wm withdraw .meridian
+ withdraw_window ".meridian"
} elseif {"%K" == "Return"} {
.meridian.bottom.ok flash
ok_meridian_interval
@@ -3018,7 +3018,7 @@
set default_map_options(meridian_interval) $new_meridian_interval
set_map_view_option .m1 meridian_interval
- wm withdraw .meridian
+ withdraw_window ".meridian"
}
# Given a map window, set up all of its standard event bindings.
@@ -3690,7 +3690,7 @@
}
proc ask_bool_done { mapn } {
- wm withdraw .bool
+ wm withdraw .bool
destroy .bool
}
@@ -3877,7 +3877,8 @@
button .find.bottom.find -text "Find" -command ok_find -default active \
-bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
-fg $fgcolor -activeforeground $afcolor -width 8
- button .find.bottom.cancel -text "Cancel" -command { wm withdraw .find } \
+ button .find.bottom.cancel -text "Cancel" \
+ -command { withdraw_window ".find" } \
-bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
-fg $fgcolor -activeforeground $afcolor -width 8
grid .find.bottom.cancel .find.bottom.find -sticky ew -padx 8 -pady 4
@@ -3885,7 +3886,7 @@
bind .find <Key> {
if {"%K" == "Escape"} {
.find.bottom.cancel flash
- wm withdraw .find
+ withdraw_window ".find"
} elseif {"%K" == "Return"} {
.find.bottom.find flash
ok_find
@@ -3907,7 +3908,7 @@
if { $rslt == 0 } {
bell
} else {
- wm withdraw .find
+ withdraw_window ".find"
}
}
@@ -3946,16 +3947,17 @@
frame .research.bottom -bg $bgcolor
pack .research.bottom -side bottom -fill x
button .research.bottom.ok -text "Research" -command ok_research \
- -bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
- -fg $fgcolor -activeforeground $afcolor
+ -bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
+ -fg $fgcolor -activeforeground $afcolor
pack .research.bottom.ok -side left -padx 5 -pady 5
button .research.bottom.rest -text "Rest" -command rest_research \
- -bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
- -fg $fgcolor -activeforeground $afcolor
+ -bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
+ -fg $fgcolor -activeforeground $afcolor
pack .research.bottom.rest -side left -padx 5 -pady 5
- button .research.bottom.cancel -text "Close" -command { wm withdraw .research } \
- -bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
- -fg $fgcolor -activeforeground $afcolor
+ button .research.bottom.cancel -text "Close" \
+ -command { withdraw_window ".research" } \
+ -bg $bgcolor -highlightbackground $hbcolor -activebackground $abcolor \
+ -fg $fgcolor -activeforeground $afcolor
pack .research.bottom.cancel -side left -padx 5 -pady 5
listbox .research.topics -selectmode browse -width 25 \
@@ -4005,12 +4007,12 @@
return
}
set_side_research $i
- wm withdraw .research
+ withdraw_window ".research"
}
proc rest_research {} {
set_side_research nothing
- wm withdraw .research
+ withdraw_window ".research"
}
# Create and popup an agreement editing window.
@@ -4131,7 +4133,7 @@
}
proc close_agreements_window {} {
- wm withdraw .agreements
+ withdraw_window ".agreements"
}
proc update_agreement_display {} {
@@ -4205,7 +4207,7 @@
}
proc dismiss_scores {} {
- wm withdraw .scores
+ withdraw_window ".scores"
}
# Create and popup the preferences dialog.
@@ -4275,7 +4277,7 @@
bind .prefs <Key> {
if {"%K" == "Escape"} {
.prefs.bot.cancel flash
- wm withdraw .prefs
+ withdraw_window ".prefs"
} elseif {"%K" == "Return"} {
.prefs.bot.ok flash
ok_preferences
@@ -4728,7 +4730,7 @@
# Make the dialog go away, without altering any preferences.
proc dismiss_preferences_dialog {} {
- wm withdraw .prefs
+ withdraw_window ".prefs"
}
# Create and popup the help window.
@@ -4994,7 +4996,7 @@
# Make the dialog go away.
proc dismiss_help_dialog {} {
- wm withdraw .help
+ withdraw_window ".help"
}
# Game save dialog.
@@ -5108,7 +5110,7 @@
}
proc dismiss_game_over_dialog {} {
- wm withdraw .gameover
+ withdraw_window ".gameover"
}
proc disable_move_mode {} {
@@ -5980,7 +5982,7 @@
proc dismiss_design_palette {} {
if { "[ winfo exists .design ]" } {
- wm withdraw .design
+ withdraw_window ".design"
}
}
--- orig-tkmap.c Fri Jun 27 23:48:29 2003
+++ tkmap.c Fri Jun 27 23:49:29 2003
@@ -4230,7 +4230,7 @@
the interface freeze. */
XDrawLines(dpy, d, gc, points, 5, CoordModeOrigin);
}
-#endif MAC
+#endif /* MAC */
XFlush(dpy);
XSetFunction(dpy, gc, GXcopy);