ryan@sjuvax.UUCP (P. Ryan) (07/13/89)
being new to the world of windows programming, i am having some difficulty figuring out how to manipulate the events queues to my advantage. i have a program that calls a number of window at various times. because memory is a little tight on the particular machine i'm working on, i limit the number of windows that the program can have active at once. my question is this: if the user closes one of the program's windows with the mouse (i.e. clicks on the 'Close' option of the window's menu), what, if any, signal is generated? i am trying to manage the program's resources and i can't figure out how to get the program to realize that a window has been closed and the memory the window used can be reallocated. thanks, pat p.s. please mail responses. danke. /patrick/ryan /nasa/ goddard space flight center /crustal dynamics project /mail code 626.9, greenbelt, maryland 20770, usa /net pmr@bootes.gsfc.nasa.gov, pmr@gemini.gsfc.nasa.gov -- /patrick/ryan st. joseph's university, philadelphia, pennsylvania uucp { bpa | burdvax | drexel | princeton} !sjuvax!ryan arpa/cs/bitnet ryan@sjuvax.sju.edu, ryan%sjuvax.sju.edu@relay.cs.net
rws@EXPO.LCS.MIT.EDU (07/19/89)
if the user closes one of the program's windows with the mouse (i.e. clicks on the 'Close' option of the window's menu), what, if any, signal is generated? If by 'Close' you mean "Iconify", your window will be unmapped (if the window manager conforms to the ICCCM). You can select for StructureNotify on your window to receive the UnmapNotify event. If by 'Close' you mean "Destroy", your window will be destroyed (and unmapped as well, if it was mapped). You can select for StructureNotify on your window to receive the DestroyNotify event.
pmr@BOOTES.GSFC.NASA.GOV (Pat Ryan) (07/20/89)
> >> if the user closes one >> of the program's windows with the mouse (i.e. clicks on the 'Close' >> option of the window's menu), what, if any, signal is generated? >> >If by 'Close' you mean "Iconify", your window will be unmapped (if the >window manager conforms to the ICCCM). You can select for StructureNotify >on your window to receive the UnmapNotify event. > >If by 'Close' you mean "Destroy", your window will be destroyed (and >unmapped as well, if it was mapped). You can select for StructureNotify >on your window to receive the DestroyNotify event. By 'Close' I mean the user clicks the mouse on the top-left corner of the window and then clicks the 'Close' option. I have selected 'StructureNotifyMask' for XCheckWindowEvent and then loop around until either I come upon a DestroyNotify event or I run out of StructureNotify events. For some reason, no DestroyNotify event seems to be appearing. I have included the suspect code below. There are arrays of the data structures used by XWindows and there is an array called 'used' that is set to TRUE when the window is created. If you have the tim to look at it, I would be most appreciative. Pat ------------------------------------------------------------------ #include <X11/X.h> #include <X11/Xos.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include "skw_defs.h" #include "xdefs.h" #include "xstruct.h" #define CLASS extern #include "xglobal.h" int update_alloc() /* * 'update_alloc' is called before a new batch of windows is * processed. It traverses the usage array and if a window is * said to be in use, it will look at the event queue for that * particular window and see if it has been closed by the user * since the last time windows were plotted. * * right now, this does not work. * * 890701 PMR created */ { int i, stop; XEvent report; /* * traverse the usage array looking for used windows */ for (i = 0; i < MAX_WIN; ++i) /* * if it is in use, check to see if it has been destroyed * since the last time windows were plotted */ if (used[i]) { stop = FALSE; while ((!stop) && (XCheckWindowEvent(display[i],win[i], StructureNotifyMask, &report))) /* * if it has been destroyed, free the graphics context, * close the display, and reset the usage flag. */ if (report.type == DestroyNotify) { XFreeGC(display[i], gc[i]); XCloseDisplay(display[i]); used[i]= FALSE; stop = TRUE; printf("reallocated window %d\n",i); } } return(OK); }
rws@EXPO.LCS.MIT.EDU (07/20/89)
By 'Close' I mean the user clicks the mouse on the top-left corner of the window and then clicks the 'Close' option. Since I have no idea what window manager you're using, I have no idea what 'Close' really does, and this doesn't tell me. I assume from your comments that it kills the application. Your code fragment is not enough (for me) to deduce what or where the problem is.