XEvent event = new XEvent();
event.type = X11.ClientMessage;
// Select the proper union structure for the event type and populate it
event.setType(XClientMessageEvent.class);
event.xclient.type = X11.ClientMessage;
event.xclient.serial = new NativeLong(0L);
event.xclient.send_event = TRUE;
event.xclient.message_type = x.XInternAtom(display, msg, false);
event.xclient.window = new com.sun.jna.platform.unix.X11.Window(wid);
event.xclient.format = 32;
// Select the proper union structure for the event data and populate it
event.xclient.data.setType(NativeLong[].class);
event.xclient.data.l[0] = data0;
event.xclient.data.l[1] = data1;
event.xclient.data.l[2] = new NativeLong(0L);
event.xclient.data.l[3] = new NativeLong(0L);
event.xclient.data.l[4] = new NativeLong(0L);
// Send the event
NativeLong mask = new NativeLong(X11.SubstructureRedirectMask | X11.SubstructureNotifyMask);
int result = x.XSendEvent(display, x.XDefaultRootWindow(display), 0, mask, event);
// Flush, since we're not processing an X event loop
x.XFlush(display);
// Finally, return the result of sending the event
return result;