From: matt@kvamdata.no (Matthew Kerr)
Subject: XSendEvent()...Friend or Foe?
Organization: Kvam data as
Date: Thu, 05 Nov 1992 21:56:46 GMT


(code included below -- just add water)

I'm trying to send myself a ClientMessage (via XSendEvent())
from my XmPushButton's activate Callback  :-)

***** Question? *****
This code works runs on NCD (2.4) and ODT (1.0) servers (from various boxes),
but when running under my PC X Servers (XVision for Windows3.1 and
PMX(?) for OS2 1.3) I get this:

	X Error of failed request:  BadValue (integer parameter out of range for operation)
	  Major opcode of failed request:  25 (X_SendEvent)
	  Minor opcode of failed request:  0
	  Resource id in failed request:  0xffffffff
	  Serial number of failed request:  72
	  Current serial number in output stream:  72

(i.e. BadNews Deluxe...)

This code is TRIVIAL!  What am I doing wrong????
(I've even (more or less) copied this code from Young's book pg. 305)

I'm _lost_ !!!

thanks,
matt

fyi...
==============================================================================
 Matthew Kerr                   Kvam data as
 matt@kvamdata.no               Nikkelveien 14, N-4300 Sandnes, Norway
                                Tel: + 47 4 62 37 66
 (woof)                         Fax: + 47 4 62 39 85
==============================================================================

/* ----------- 8<   Snipity, Snip, Snip...   8< ---------------------------- */
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <stdio.h>

/*********************************************************************/
void SendEventCB (NotUsed, Shell)
	Widget NotUsed;
	Widget Shell;
{
	XClientMessageEvent tCMevent;
/*
** WHAT'S WRONG HERE?...
*/
	tCMevent.type	 = ClientMessage;
	tCMevent.display = XtDisplay (Shell);
	tCMevent.window	 = XtWindow (Shell);
	tCMevent.format	 = 8;			/* does this matter ??? */
	printf ("SendEventCB: calling XSendEvent()\n"); fflush (stdout);
/*
** ...BECAUSE THIS GETS XError()???
*/
	if (!XSendEvent(
		XtDisplay (Shell),
		XtWindow (Shell),
		True,
		XtAllEvents,
		(XEvent *) &tCMevent))
	{
		exit (-27);
	}
}

/*********************************************************************/
XtCallbackProc ClientMsgCB (NotUsed1, NotUsed2, event)
	Widget NotUsed1;
	caddr_t NotUsed2;
	XEvent *event;
{
	if (event->type == ClientMessage)
		printf ("received ClientMessage  :-)\n");
	else
		printf ("received type=%d  :-?\n", event->type);
	fflush (stdout);
}

/*********************************************************************/
main (argc, argv)
	Cardinal argc;
	char *argv[];
{
	XtAppContext AppContext;
	Display *MyDisp;
	Widget AppShell, Button;
	Arg args[10];
	Cardinal n;

/* Initialize Stuff... */
		     XtToolkitInitialize();
	AppContext = XtCreateApplicationContext();
	MyDisp	   = XtOpenDisplay(
				AppContext, 
				NULL,
				"AppName",
				"AppClass",
				NULL, 0,
				&argc, argv);

/* Create Shell... */
	n = 0;
	XtSetArg (args[n], XmNwidth,  250); n++;
	XtSetArg (args[n], XmNheight, 100); n++;
	AppShell = XtAppCreateShell(
			"AppName",
			"AppClass",
			applicationShellWidgetClass,
			MyDisp,
			args, n);
	XtRealizeWidget	(AppShell);
	XtAddEventHandler (AppShell, NoEventMask, True, ClientMsgCB, NULL);

/* Create Button... */
	Button = XmCreatePushButton(
				AppShell,
				"SendEvent()...",
				NULL, 0);
	XtManageChild (Button);
	XtAddCallback (Button, XmNactivateCallback, SendEventCB, AppShell);

/* Loop... */
	XtAppMainLoop(AppContext);
}