scott@graft.Berkeley.EDU (Scott Silvey) (01/15/91)
How does one respond to the WM_SAVEYOURSELF protocol message?
From ICCM, it seems to me that all I have to do is update the WM_COMMAND
property on my window (to nothing) within the window manager timeout
limit. However, this doesn't seem to work. My application window get's
unmapped immediately and then after the WM_SAVEYOURSELF reply routine
returns, the X connection gets closed.
I am using Motif1.1 with mwm. I force the message by selecting the "Close" item
from the mwm client menu on the titlebar.
Here is the callback for the WM_WAVEYOURSELF protocol. It does in fact get
called, so I assume I am installing it properly:
---------------------------------------------------------------------------------
#define SAVE_YOURSELF_ATOM(shell) XInternAtom(XtDisplay(shell), \
"WM_SAVE_YOURSELF", \
FALSE);
#define COMMAND_ATOM(shell) XInternAtom(XtDisplay(shell), \
"WM_COMMAND", \
FALSE);
main()
{
...
/* Remove DELETE protocol from shell so SAVE_YOURSELF won't be ignored. */
XmDeactivateWMProtocol(toplevel, delete_atom);
/* Mark shell as responding to WM_SAVE_YOURSELF protocol message. */
XmActivateWMProtocol(toplevel,
save_yourself_atom);
/* Install the callback to respond to the WM_SAVE_YOURSELF message. */
XmAddWMProtocolCallback(toplevel,
save_yourself_atom,
save_yourself_callback,
toplevel);
...
}
/* ACTUAL CALLBACK. */
save_yourself_callback(w, shell)
Widget w, shell;
{
int i;
char foo[64];
Atom command_atom = COMMAND_ATOM(shell);
strcpy(foo, "");
/*
* OR:
* strcpy(foo, "bar");
*/
fputs("Before XChangeProperty()\n", stderr);
XChangeProperty(XtDisplay(shell),
XtWindow(shell),
command_atom,
XA_STRING,
8,
PropModeReplace,
(unsigned char *) foo,
strlen(foo));
XSync(XtDisplay(shell), 0);
fputs("After XChangeProperty()\n", stderr);
/* Do some work beyond window manager timeout limit. */
for (i=5; i>0; i--) {
fprintf(stderr, "%d!\n", i);
sleep(1);
}
fprintf(stderr, "save_yourself_callback(): SAVE_YOURSELF!\n");
}
---------------------------------------------------------------------------------
END OF CODE
Here is the output from the save_yourself_callback:
<APPLICATION WINDOW GETS UNMAPPED AT THIS POINT>
Before XChangeProperty()
After XChangeProperty()
5!
4!
3!
2!
1!
save_yourself_callback(): SAVE_YOURSELF!
XIO: fatal IO error 54 (Connection reset by peer) on X server "graft:0.0"
after 176 requests (175 known processed) with 0 events remaining.
/-----------------------------------------------------------------------------\
| Scott Silvey | Ronald Reagan on Pac Man: |
| scott@xcf.berkeley.edu | "Someone told me it was a round thing that gobbles |
| Flames to /dev/null. | up money, but I thought that was Tip O'Neill." |
\-----------------------------------------------------------------------------/