Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!hp-pcd!hpcvlx!dex From: dex@hpcvlx.cv.hp.com (Dex Smith) Newsgroups: comp.windows.x Subject: Re: WM_SAVE_YOURSELF Message-ID: <100920280@hpcvlx.cv.hp.com> Date: 25 Jan 91 00:48:29 GMT References: <1991Jan22.064227.4656@agate.berkeley.edu> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 75 In your first message, you mention that you are testing your "save yourself" callback by choosing the Close command in the window menu. The "save yourself" protocol described in ICCCM is intended for use with session managers, and is not related to the Close button. So, there are really two questions here: FIRST QUESTION: * What should an application do to support session management? 1. Create (intern) a "save yourself" atom. Be sure you call XInternAtom() after realizing your top-level shell. saveYourselfAtom = XInternAtom(XtDisplay(top_level), "WM_SAVE_YOURSELF", False); Where saveYourselfAtom is declared as type "Atom." 2. Add a "save session" callback routine. This function should save whatever application-specific data is necessary to fully restore the application to its current state (just as though it was never killed). Within the "save session" callback, your application should set the WM_COMMAND property. Session managers watch for this to know when your application is done saving itself. (There is some timeout period, I believe, for applications that don't respond.) You can set this property with the XSetCommand() function. 3. Add a protocol callback that invokes the "save session" callback routine. Something like this: XmAddWMProtocolCallback (top_level, saveYourselfAtom, SaveSessionCB, NULL); Where SaveSessionCB() is the routine written in step 2. Now, whenever a session manager sets the "save yourself" property, your application will save its session information. SECOND QUESTION: * How can an application respond to the window manager's Close command? The idea is that the Close command should work just like the Exit command in your File menu (if you have one). Refer to the OSF/Motif style guide for more information on the File menu. For example, if you File menu's Exit command displays a confirmation dialog, so should the Close command in the window menu. So, how does your appliation know when the user has chosen Close? Like this: 1. Create a "delete window" atom. Something like this: delWinAtom = XInternAtom(XtDisplay(top_level), "WM_DELETE_WINDOW", False); 2. Set the XmNdeleteResponse resource (for your top-level shell) to XmDO_NOTHING. This prevents the window from being automatically destroyed by the Close command (ie. the behavior you described). 3. Add a protocol callback that calls the same routine that the Exit button in your File menu calls (ExitCB(), in this example). XmAddWMProtocolCallback (top_level, delWinAtom, ExitCB, NULL); I hope this is what you are looking for. - Dex Smith Hewlett-Packard Company Corvallis, Oregon dex@hpcvlx.hp.com