[comp.windows.x] EventMask for XSendEvent

carroll@m.cs.uiuc.edu (05/09/90)

I'm having problems with Client Messages and XSendEvent. The code works on a
SysV 11R3 system, but not on Sun-3's or Sparcs with SunOS4.0.3 & 11R4.

In R3, the following sends off the Client Message:
	XSendEvent(xr->dpy,xr->id,False,(unsigned long)~0L,&ev); 
Under R4, neither that nor
	XSendEvent(xr->dpy,xr->id,False,(unsigned long)-1L,&ev); 
send the message out. XSendEvent reports True as a result, but the clients
on the other end never receive the events, even though I've verified that
they receive other clients events. In desperation, I tried the following:
	XSendEvent(xr->dpy,xr->id,False,
		SubstructureNotifyMask | SubstructureRedirectMask,
		,&ev); 
That works, but only for messages to the window manager, not for a
general Client Message receiver (which does not have either of those events
selected). What I want to know is why I can't send it with _all_ the event
mask bits set? Was something changed here from R3 to R4? Thanks!

Alan M. Carroll                Barbara/Marilyn in '92 :
carroll@cs.uiuc.edu            + This time, why not choose the better halves?
Epoch Development Team         
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!cs.uiuc.edu!carroll

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (05/09/90)

Please remember that detailed context is usually important ...

    In R3, the following sends off the Client Message:
	XSendEvent(xr->dpy,xr->id,False,(unsigned long)~0L,&ev); 
    Under R4, neither that nor
	XSendEvent(xr->dpy,xr->id,False,(unsigned long)-1L,&ev); 

Without knowing the structure of the receiver (what the window hierarchy
is and what clients are selecting for what events), it's really hard to
know what the problem is.  I note in passing that the R4 Xt uses the
first form of XSendEvent noted above for selections, and it works fine.

	XSendEvent(xr->dpy,xr->id,False,
		SubstructureNotifyMask | SubstructureRedirectMask,
		,&ev); 
    That works, but only for messages to the window manager, not for a
    general Client Message receiver (which does not have either of those events
    selected).

Sounds like you are sending to the wrong window, sending to the window manager's
frame rather than the true client window.  Perhaps part of your confusion is
that you moved from uwm in R3 to twm (or some other reparenting WM) in R4.
Given a top-level window, try using XmuClientWindow to find the real window to
send to.

    What I want to know is why I can't send it with _all_ the event
    mask bits set? Was something changed here from R3 to R4?

Yes, the server was made to obey the protocol here.  You can't use all ones
because that includes some illegal bits, which should result in the server
generating a protocol error.

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (05/09/90)

            XSendEvent(xr->dpy,xr->id,False,(unsigned long)~0L,&ev); 

        I note in passing that the R4 Xt uses the first form

    Why doesn't the selection code for Xt generate protocol errors,
    if it uses ~0L as the event mask?

Sorry, I misread the line, Xt uses 0, not ~0.

rlh2@ukc.ac.uk (R.L.Hesketh) (05/10/90)

In article <26900116@m.cs.uiuc.edu> carroll@m.cs.uiuc.edu writes:
>I'm having problems with Client Messages and XSendEvent. The code works on a
>SysV 11R3 system, but not on Sun-3's or Sparcs with SunOS4.0.3 & 11R4.

Ahh, that little nut.  I think this one is getting popular enough to
become a "common asked question about X11".

>In desperation, I tried the following:
>	XSendEvent(xr->dpy,xr->id,False,
>		SubstructureNotifyMask | SubstructureRedirectMask,
>		,&ev); 

Try ..

	XSendEvent(xr->dpy, xr->id, False, 0L, &ev);

(ie. a null event mask)

Xlib manual (section 8.10):

"If the event_mask is the empty set, the event is sent to the client
 that created the destination window.  If that client no longer exists,
 no event is sent."

>What I want to know is why I can't send it with _all_ the event
>mask bits set?

The ClientMessage event is non-maskable and does not have an event mask.

>               Was something changed here from R3 to R4? Thanks!

Yup, the MIT Server is stricter about obeying the protocol.

carroll@m.cs.uiuc.edu (05/10/90)

Thanks to RWS I now have a better handle on the problem. Here is the back
ground information:
I'm working on Epoch 3.2 (GNUemacs with extensions for X windows), and I'm
trying to get epoch::send-client-message to work. Because of other
improvments, send-client-message can now send client messages to any other
X window. One thing that would be nice would be to be able to send WM
client messages, such as "Iconify Window". However, I can't see how to be
able to do this _and_ send "normal" client messages. I'm running on a
'386 386/ix box (R3) and a Sparc OS4.0.3 (R4), both running GWM 1.6

The problem is the EventMask for the XSendEvent. If I use 0, then "normal"
client messages work - I can send client messages from Epoch to itself.
However, sending ICCCM messages to the root window doesn't work. If I change
the EventMask to
	(SubstructureNotifyMask|SubstructureRedirectMask)
as specified in the ICCCM docs, sending WM messages works, but sending
"normal" ones doesn't. Under R3 I can reconcile these by using an EventMask
of ~0. However, RWS informs me that that will generate protocol errors under R4.
What is the preferred solution to this? I want to avoid either having the
Elisp programmer specify the EventMask, or having two calls for the two cases.

Alan M. Carroll                Barbara/Marilyn in '92 :
carroll@cs.uiuc.edu            + This time, why not choose the better halves?
Epoch Development Team         
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!cs.uiuc.edu!carroll