Xmsgtrace |
Home | Features | Examples | FAQ | Download | Links |
You probably won't find this example program in an X programming book because nothing is displayed on the screen. But, it is a valid program. It makes a connection with the X server by calling the Xlib funtion XOpenDisplay() and then immediately exits which breaks the connection.
The Xmsgtrace recording shows the protocol produced when XOpenDisplay() is called. Other X programs will get a similar recording when a connection is made. (Descriptions of the different requests, replies, events, and their associated parameters can be found in the X Window System Protocol document referenced on the links page.)
The first piece of information sent to the client program from the X server is the connection setup reply as shown in lines 8-9. This tells the client program how to talk to the X server, such as the byte-order to be used to exchange data, what color visuals are available, the screen size, etc. Details of all the fields are described in the X Window System Protocol document. Note that Xmsgtrace doesn't record all these fields because they are the same for each connection and simply take up space in the log file. The data that are not recorded can be obtained by executing the xdpyinfo program.
Finally, XOpenDisplay() completes the initialization of the program by generating protocol requests in lines 10-21 to check if various extensions are availabe for use as well as other things.
Normally, the programmer has no interest in this part of the recording. It's just a standard preamble sent by the X server each time a connection is made. The important point here is to recognize this part of the Xmsgtrace recording as being produced by the XOpenDisplay() call.
The next example (Example 5) is an X recording from a program that does create a window on the display and draws a figure on the window.
/* * example1.c */ #include <stdio.h> #include <X11/Xlib.h> #include <X11/Xutil.h> main(argc,argv) int argc; char **argv; { Display *dpy; /* X server connection */ /* * Open the display using the $DISPLAY environment variable to locate * the X server. */ if ((dpy = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "%s: can't open %s\n", argv[0], XDisplayName(NULL)); exit(1); } exit(1); }
1 ########################################################################################## 2 xmsgtrace.log (version 1.0) 3 Sun Jan 6 22:45:52 2002 4 5 XRecordStartOfData 6 7 ***************Client=17, Name=Unknown************************************************************************************************** 8 >>>>> Client 17 Connection Setup Reply: swapped=FALSE, protocol-major-version=11, protocol-minor-version=0, resource-id-base=0x2200000 9 release_number=4003, resource-id-mask=0x1FFFFF 10 Request(CreateGC[55]): client=17, seq=1, cid=0x2200000, drawable=0x2B, value-mask=0x8 11 background:0xFFFF 12 Request(QueryExtension[98]): client=17, seq=2, name=BIG-REQUESTS 13 Reply(QueryExtension[98]): client=17, seq=2, present=TRUE, major_opcode=134, first_event=0, first_error=0 14 Request(GetProperty[20]): client=17, seq=3, delete==0, Window=0x2B, property=23, type=31, long-offset=0, long-offset=100000000 15 Reply(GetProperty[20]): client=17, seq=3, format=0, atom=0(0x0), bytes-after=0, format_units=0 16 Request(BIG-REQUESTS extension): client=17, seq=4 17 Reply(BIG-REQUESTS extension): client=17, seq=4, max_request_length(in 4-byte units)=1048575 18 Request(InternAtom[16]): client=17, seq=5, only-if-exists=FALSE, name=Compose 19 Reply(InternAtom[16]): seq=5, atom=198(0xC6) 20 Request(QueryExtension[98]): client=17, seq=6, name=XKEYBOARD 21 Reply(QueryExtension[98]): client=17, seq=6, present=TRUE, major_opcode=140, first_event=92, first_error=161 22 >>>>> Client 17 died 23 XRecordEndOfData