[comp.windows.x] XSendEvent

jre@vax135.UUCP (Bob Ensor) (09/09/87)

I would like to use a window to intercept input from a display
and then give some of the input to other windows.
Apparently, Version 11 offers the operation "XSendEvent"
for this use.  However, I am unable to get XSendEvent to
do this for me.  Regardless of the values I pass to the 
operation as window and event-mask arguments, it posts
an event on the request queue with unexpected values for
these event attributes.

I would appreciate very much an explanation of this operation
and its use if anyone can provide it.

Thank you for your help.

Bob Ensor
AT&T Bell Laboratories
4F-607
Holmdel, NJ  07733
(201) 949-2979

P.S. I'm running X11-beta3 on a Sun 3/160.

sanjeev@psuvax1.cs.psu.edu (Sanjeev Y. Dharap) (08/07/89)

I need some help with XSendEvent. What I am doing is the following.

I want to unmap a window on a KeyPress event, so I dont look at the
rest of the event structure. I want this event to be generated by
another client, so I call XSendEvent with

send_event.xany.window = window;
send_event.xany.display = display;
send_event.xany.type = KeyPress;
XSendEvent(display,window,False,KeyPress,&send_event);

I am trying this first by making the client send a KeyPress event to
itself. The call to XSendEvent returns 1, but no event is sent.

I am printing the event type immediately after the XNextEvent.

The questions are;

a. Must the window be either of PointerWindow or InputFocus?

b. Does the server look at the event structure in the call?

c. What is a clean way to communicate to the other client, the display
and window parameters? I am using sockets.

d. Possible solutions to my problem?

thanx in advance,

sanjeev.

rws@EXPO.LCS.MIT.EDU (08/07/89)

    a. Must the window be either of PointerWindow or InputFocus?

No.

    b. Does the server look at the event structure in the call?

No.

    c. What is a clean way to communicate to the other client, the display
    and window parameters? I am using sockets.

I don't understand the question.

    d. Possible solutions to my problem?

Try using KeyPressMask instead of KeyPress in you call:

    XSendEvent(display,window,False,KeyPress,&send_event);

sanjeev@psuvax1.cs.psu.edu (Sanjeev Y. Dharap) (08/14/89)

Is there anyone out there who has actually used XSendEvent
effectively?

I have been trying to use it without results. If a client sends an
event to itself, using XSendEvent, it works perfectly. On the other
hand, if I do something like this...

<global display, window>

<Open display, create window, etc.>

if(fork()==0)
	child();

<stuff>

...

and child() contains

child(){
   XEvent send_event;
   int k;

   send_event.type = KeyPress;
   do{
      sleep(5);
      printf("Sending..");
      k = XSendEvent(display,window,False,KeyPressMask,&send_event);
      printf(".returns %d\n",k);
   }while(1);

}/* end child */

then this bombs. The child process keeps printing the messages, but
sends no event. (I print out the events in the parent.)

Can someone help me? There's very little documentation on XSendEvent.

Any hints, pointers will be greatly appreciated.

Thanx.

sanjeev.

sanjeev@psuvax1.cs.psu.edu

rws@EXPO.LCS.MIT.EDU (08/14/89)

   do{
      sleep(5);
      printf("Sending..");
      k = XSendEvent(display,window,False,KeyPressMask,&send_event);
      printf(".returns %d\n",k);
   }while(1);

It kinda looks like you are never forcing buffered output to be sent ...
It might work better if you added an XFlush(display).

But, if you are sharing the display connection between parent and child,
expect all kinds of bad things to happen to you.

dsseewe@SUPER.ORG (Daniel Seewer) (10/05/89)

How about helping me out with XSendEvent().  I am a little confussed as to when
it is appropriate to use this call.   Currently I am using it to do the 
following:

		* User generates a pixmap to look at
		* The user can scroll through the pixmap
		* I have a button that the user can press to autoscroll until
			pressed again.
		* This button merely sends Events to the scrollbar widget 
			Button press and Button release events.
		* Actually an alarm (SIGALRM) is set to trigger the continual
			sending of events.

Was this the intended usage of XSendEvent()????  I ocassionally get the following
error:

		X Protocol error: BadRequest, invalid request code or no such
			operation
		Major opcode of failed request: 0()
		Minor			      : 0

dsseewe@super.ORG (Daniel Seewer) (10/05/89)

Sorry but I cut myself off.  My request is could someone give me a proper
example of how and when to use XSendEvent()!!!!  THANKS IN ADVANCE!


			Seewer
			(dsseewe@super.org)

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (10/05/89)

	* This button merely sends Events to the scrollbar widget 
		Button press and Button release events.

	Was this the intended usage of XSendEvent()????

If the button is in the same client as the scrollbar, no.

SendEvent is primarily for inter-client communication, e.g. as described
in the Inter-Client Communication Conventions Manual (ICCCM).

klee@gilroy.pa.dec.com (Ken Lee) (10/05/89)

In article <8910050100.AA21383@metropolis.super.org>, dsseewe@SUPER.ORG
(Daniel Seewer) writes:
> 		* This button merely sends Events to the scrollbar widget 
> 			Button press and Button release events.

While XSendEvent certainly could be used for communication within a
client, I think the overhead of doing this is much to high for most
applications.  XSendEvent is better used for communicating between
separate clients.  Examples are selection notification, window manager
synthetic events, and client message events.

Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@decwrl.dec.com
uucp: uunet!decwrl!klee

abmg@cathedral.cerc.wvu.wvnet.edu (Aliasghar Babadi) (02/17/90)

Hi,

	I like to know more about XSendEvent:
where does the events sent by XSendEvent go? if queued, which queue?
can the window which receives these events, access them by XNextEvent?
can somebody send me a simple example showing sending and receiving events
by XSendEvent?

	Thank You very much for sharing your experience with me.

klee@wsl.dec.com (Ken Lee) (02/21/90)

In article <390@cerc.wvu.wvnet.edu.edu>,
abmg@cathedral.cerc.wvu.wvnet.edu (Aliasghar Babadi) writes:
> 	I like to know more about XSendEvent:
> where does the events sent by XSendEvent go? if queued, which queue?
> can the window which receives these events, access them by XNextEvent?

XSendEvent sends an event to a window.  Any client selecting that event
from that window will receive that event through normal event
processing (e.g., XNextEvent).  Most window managers in X11R4 use this
for ICCCM stuff.

Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee

marbru@auto-trol.UUCP (Martin Brunecky) (09/02/90)

I need to use XSendEvent in a widget which moves the pointer
on the screen and simulates button events based on input from
a digitizer (digitizer running on a different machine, served
by the lobotomized X Server).

As the description of XSendEvent is somewhat sketchy, I would
like to know more about:

 1) How is the "propagate" supposed to work with button
    event. My coding/testing shows that the event is
    delivered to the window specified in the call, and
    I have to simulate "propagate" by doing a lookup
    for a window which understands button events myself.

 2) How are handled any redirect windows (in particular,
    window manager input redirection).

 Thanx in advance ...
 


-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                   marbru@auto-trol.COM
(303) 252-2499                    {...}ncar!ico!auto-trol!marbru
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404