next up previous index
Next: Predefined Predicates Up: Using Xlib Primitives Previous: Using Xlib Primitives

Initialisation

The ProTcXl interface to Xlib is loaded separately by calling

lib('tk/xlib')
after the tk library has been loaded.

The next step is to create and display in the final size the window(s) which will be used to display Xlib primitives. It is quite important to wait until the window is already displayed, otherwise the X server raises an error.   Then, the predicate

tk_xlib_init(WindowName, XID)
is used to create a handle XID for this window. This ID stores all data which Xlib functions need to access the corresponding window. The predicate
tk_xlib_id(XID, Display, Window, GC)
takes an Xlib ID and returns the corresponding display, window ( drawable) and graphics context,     which can then be used in explicit Xlib calls.

Tk itself offers a number of low-level functions which access and modify Xlib data and which are easier to use than the Xlib functions. These Tk functions usually require the Tk_Window structure and sometimes the interpreter. The former can be extracted from a given XID using the predicate

 

xlib_tkwin(XID, Tk_Window)
and the latter with
tcl_interp(Interp).

Many of the Xlib functions have integer arguments whose values are predefined X11 macros defined in the X11 include file X.h   They have names like KeyPress, CWBorderPixmap or GXand. To make the interface easier to use, ProTcXl defines an ECLiPSe macro for each of the macros defined in this file. The ECLiPSe macro has the same name as the C macro with an x prefix, so that e.g. Prolog atoms xKeyPress, xCWBorderPixmap and xGXand are transformed into integers which correspond to the values of the above C macros.

It might be interesting for the reader to know how these macros are defined in ProTcXl . First I thought that I will have to define each of them by hand, taking each macro from the X.h file and writing an ECLiPSe macro with the appropriate name and value (there is about 350 of them and e.g. the XWIP package has done this).   Then I have realised that Prolog is the language preferably used for parsing and I have written a subset of the C grammar which is necessary to parse the X.h file and a few predicates to create the macros. Not surprisingly, it worked and the whole process was much faster and it was certainly more fun than handcoding all the macros, not even mentioning that there are no problems with future modifications of the X.h include file.


next up previous index
Next: Predefined Predicates Up: Using Xlib Primitives Previous: Using Xlib Primitives



Micha Meier
Tue Jul 2 09:49:39 MET DST 1996