|
Next: Limitations Of The Up: Writing An Xlib Previous: Compiling And Linking
An Example ProgramThe example program creates a window, containing a text message, a rectangle and a filled ellipse. It uses expose events to redraw the items in the window and mouse button press events to quit the application. The contents of the text message can be specified by the user, using client resources, as discussed earlier. The program sequence is to attempt to open a connection to a server and select a screen. The routine XOpenDisplay used with the parameter NULL attempts to connect to the server specified by the user's environment variable DISPLAY. The macro DefaultScreen chooses the server's default screen, should it control more than one. The routine XCreateSimpleWindow sets up a window to be drawn on the root window at position (100,200), width 400 pixels, height 300 pixels, border width 1, border colour as defined by the macro BlackPixel, and background as defined by the macro WhitePixel. Next, the expose and mouse button press events are selected, using the routine XSelectInput, to be the only events to be sent to the window, The application routine setUpGCs calls Xlib routines to create two graphics context resources in the server, one to specify certain attributes for the message text and rectangle and one for the ellipse. It also creates a stipple to be used be used as the fill pattern for the ellipse. The data used to define the stipple pixmap, as shown in figure 14, was obtained from the client application bitmap.
Then, the routine XGetDefault attempts to set the message text to that specified by any external client resource setting, such as that shown in figure 15. Failing that, there is an internal, fallback setting. The routine XMapWindow causes only the window to be drawn on the screen.
Finally, the application enters an infinite loop, awaiting the selected events. An expose event causes the message, rectangle and ellipse to be drawn in to the window. The fact that mapping a window causes an expose event to be sent to that window, means that the drawings now appear. A mouse button press event causes program termination. Figure 16 shows the result of running the example program in the presence of the twm window manager. Note twm's addition of a title bar to the top of the application's main window.
Next: Limitations Of The Up: Writing An Xlib Previous: Compiling And Linking
JR Pitchers Wed May 3 16:45:04 BST 1995 |
|||||||||||||||||
With any suggestions or questions please feel free to contact us |