rhl55.htm
来自「linux的初学电子书」· HTM 代码 · 共 1,689 行 · 第 1/3 页
HTM
1,689 行
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
XF86MonoServer</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
S3 server
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
XF86S3Server</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Mach8 server
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
XF86Mach8Server</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Mach32 server
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
XF86Mach32Server</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
IBM 8514/A server
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
XF86I8514Server</FONT>
</TABLE><P>In the sample site.def in Listing 55.1, I have set only the 256-color SVGA server to be built. All other servers will not be built.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>The PEX extensions you have do not support the Monochrome server.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The Drivers variables define the video drivers that you want to include in a server. The order of drivers determines the order in which the server probes the video card to determine which driver to use. The generic driver should be the last one included
in the monochrome and 16-color servers because its probe always succeeds.
<BR>
<P>The generic_s3 driver should be the last one included in the S3 servers for similar reasons.
<BR>
<P>After you have edited the site.def file, you must create the Makefile.
<BR>
<P>To build the Makefile, run this command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080"># ./mkmf</FONT></PRE>
<P>Then, run make to link the servers that you have configured in the site.def file. This command takes a while. After this command is done, run the make install command to install the new servers:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080"># make install</FONT></PRE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Run make clean to remove the files that were created by this procedure.
<BR>This frees the directory structures of any unnecessary files, which is important because disk space is at a premium under Linux.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Now start X, run the window manager, and in an xterm use the xdpyinfo command to see whether the PEX extensions are there. It is possible to see which drivers are included in the server by running the X server with the -showconfig flag.
<BR>
<BR>
<A NAME="E69E541"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Writing Your Own Driver</B></FONT></CENTER></H4>
<BR>
<P>If you are including a driver that it not part of the standard distribution, make a directory in drivers/vga256 (drivers/vga2 if it is for the monochrome server; drivers/vga16 if it is for the 16-color server; or drivers/bdm2 if it is for the bdm2
monochrome server's bdm2 screen). Copy either the source or the .o file, and a suitable Imakefile, into that directory. The name of the directory should be the same as the name of the driver. If you are adding an additional font renderer, put the library
in ./renderers. Look at the VGADriver.Doc file for more details.
<BR>
<BR>
<A NAME="E68E423"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Getting PEX</B></FONT></CENTER></H3>
<BR>
<P>You have PEX files on the CD-ROM at the back of this book.
<BR>
<P>There are several examples of PEX code available on the Internet. One sample library can be found at the site export.lcs.mit.edu in the /R5contrib/R5contrib-fixes directory as the file PEX.examples.tar.Z.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>For Tk and Tcl users, PEXtk is available directly from <A HREF="tppmsgs/msgs1.htm#178" tppabs="ftp://export.mit.lcs.edu/">export.mit.lcs.edu</A>, and is located in /contrib. The files are pextk.PS.tar.Z, pextk.README, and pextk.tar.Z. PEXtk uses X as its windowing system, so the UI
is X-based.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E424"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Sample PEX Source File</B></FONT></CENTER></H3>
<BR>
<P>Let's look at an example of a simple PEX program that prints the line Howdy World. (Hello World is a bit overused.) The following is the listing for printing this line:
<BR>
<PRE>
<FONT COLOR="#000080">#include "phigs/phigs.h"
#include "X11/Xlib.h"
#include "X11/Xatom.h"
#include "strings.h"
char windowName[] = "PEX in Linux";
char HelloStr[] = "Howdy World";
main()
{
Pconnid_x_drawable connid;
Display *display;
int screen;
Ppoint text_pt;
popen_phigs(NULL,0); /* open a conn. to PHIGS server */
/*
** Set the error file name to NULL
** Set default memory size to zero
*/
connid.display = display = XOpenDisplay( NULL );
screen = DefaultScreen( display );
connid.drawable_id =
XCreateSimpleWindow( display,
RootWindow( display, screen ),
0, 0, 600, 600, 4,
WhitePixel( display, screen ),
BlackPixel( display, screen ) );
XChangeProperty( display, connid.drawable_id, XA_WM_NAME,
XA_STRING, 8, PropModeReplace,
(unsigned char *) windowName , strlen(windowName) );
XMapWindow( display, connid.drawable_id );
popen_ws( 1, &connid, phigs_ws_type_x_drawable );
popen_struct( 1 );
text_pt.x = 0.2;
text_pt.y = 0.5;
pset_char_ht( 0.05 );
ptext( &text_pt, HelloStr, strlen(HelloStr)):
pclose_struct( );
ppost_struct( 1, 1, 1.0 );
printf("Hit return to exit");
getchar();
pclose_ws( 1 );
pclose_phigs( );
}</FONT></PRE>
<P>The first executable line in this file opens a connection to the PEX server with a call to popen_phigs(NULL,0). The NULL parameter sets the error filename to nothing, and the 0 sets the default memory size to 0.
<BR>
<P>The next lines set the display, screen, and window IDs for this application. The window ID is set to point to the root window for the application with a call to the XCreateSimpleWindow function. The display and screen IDs are set to the defaults. Note
that you are using low-level X Window system function calls to create the root window. This example tells you that it's possible to access all the low-level X Window functions, in addition to the PEX functions.
<BR>
<P>The XChangeProperty function call sets the window name to the one desired. The display and window ID (connid.drawable_id) are set to that of the root window of the application.
<BR>
<P>The XMapWindow function maps your display to the current window ID.
<BR>
<P>The popen_ws() call opens the workspace for the display for you to be able to draw on. You then set the test position for the Howdy World string. Then, open a structure for writing with PEX primitives to set the text_pt structure with the text. It is
necessary to call the pclose_struct() function when done with the drawing area buffer. Lastly, post the structure to ppost_struct.
<BR>
<P>Wait until the user gives the keystroke you want, and then end the application. In this case, you must call two functions before ending the application. One is a call to pclose_ws( 1 ) for closing the workspace, and the other is a call to pclose_phigs(
) for shutting down the PEX server.
<BR>
<BR>
<A NAME="E68E425"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>PEXlib</B><B> and Motif</B></FONT></CENTER></H3>
<BR>
<P>In the previous example, the drawable was used to create the drawing patterns on a drawing area widget. PEXlib by itself is intended to be an interface into the lower-level Xlib. PEXlib gives you the capability to do 3-D mappings, shading, and so on,
along with other geometric transformations.
<BR>
<P>This section covers the basic act of combining PEXlib with Motif. This way, you can get a drawable area under Motif and be able to use PEX functions on it. In addition to this, you still have the Motif framework to add your own menus to it. The steps to
combine Motif and PEXlib are as follows:
<BR>
<UL>
<LI>Initialize an X Window, and get the best visual you can for PEX.
<BR>
<BR>
<LI>Initialize PEX with a call to PEXInitialize.
<BR>
<BR>
<LI>Create a top-level shell.
<BR>
<BR>
<LI>Create a drawing area interface for PEX.
<BR>
<BR>
<LI>Map the drawing area to the screen.
<BR>
<BR>
<LI>Create a PEX renderer (just like the GC) for this drawing area.
<BR>
<BR>
<LI>Draw to your heart's delight.
<BR>
<BR>
</UL>
<BR>
<A NAME="E69E542"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Initializing the Toolkit</B></FONT></CENTER></H4>
<BR>
<P>For initializing the toolkit, you must use a long method instead of XtAppInitialize. This long method enables you to select the best visual you can get for PEX. The following code segment will suffice:
<BR>
<PRE>
<FONT COLOR="#000080">XtToolkitInitialize();
app_context = XtCreateApplicationContext();
cp_argc = argc;
argv_sz = argc * sizeof(char *);
cp_argv = (char **)XtMalloc(argv_sz);
memcpy(cp_argv, argv, argv_sz); /* copy the pointers */
display = XtOpenDisplay(app_context,
argv[0], argv[0],
"pEX", /* Class Name */
NULL, 0, /* no resource options */
&argc, argv);
if (display == (Display *) NULL)
abort("Unable to open display");</FONT></PRE>
<P>You are making a copy of argc and argv to preserve their values, because the call to XtOpenDisplay() mangles these original values. It's necessary to check whether the display pointer is set to a valid value when you return from XtOpenDisplay() because
the display may not have been opened for a variety of reasons, and you do not want to work a NULL pointer for the display.
<BR>
<P>Initialize the PEXlib functions with a call to the function PEXInitialize(). The syntax for this call is as follows:
<BR>
<PRE>
<FONT COLOR="#000080">#include <X11/PEX5/PEXlib.h>
int PEXInitialize(Display *dp,
PEXExtensionInfo *info_ptr,
int message_length,
char *msg);</FONT></PRE>
<P>The PEXExtensionInfo pointer should point to a structure to which you want this function to return information about the PEX server. The message array should be about 80 characters long, and contain the text for any returned error messages. The function
returns 0 if no errors occurred; otherwise, it returns one of the following values:
<BR>
<UL>
<LI>PEXBadExtension if the X server does not support PEX
<BR>
<BR>
<LI>PEXBadProtocolVersion if your X server and the PEXlib you are using are of different versions
<BR>
<BR>
<LI>PEXBadLocalAlloc if you are out of memory
<BR>
<BR>
<LI>PEXBadFloatConversion if the X server does not support the PEX floating point
<BR>
<BR>
</UL>
<P>Also, note that I used PEX5 as the location of the include files. When PEX 6.0 comes along, you may have to change this PEX5 reference to PEX6 in all the code you have to date. A bummer indeed, but necessary for an upgrade.
<BR>
<P>The returned PEXExtensionInfo structure is of the following form:
<BR>
<PRE>
<FONT COLOR="#000080">typedef struct {
unsigned_short major_version;
unsigned_short minor_version;
unsigned long release;
unsigned long subset_info;
char *vendor_name;
int major_opcode;
int first_event;
int first_error;
} PEXExtensionInfo;</FONT></PRE>
<P>The major version is usually 5 or 6, and the minor version either 0 or 1. The vendor name and release are vendor-specific. The subset information contains information about the features in your PEX server, and can have the following values:
<BR>
<UL>
<UL>
<P>PEXImmediateMode Enables drawing primitives that are sent directly to the display.
<BR>
</UL></UL>
<UL>
<UL>
<P>PEXWorkstationOnly Enables workstation resources.
<BR>
</UL></UL>
<UL>
<UL>
<P>PEXStructureMode Enables drawing primitives to be stored in a structure before being sent to the display.
<BR>
</UL></UL>
<UL>
<UL>
<P>PEXCompleteImplementation Enables all of these functions.
<BR>
</UL></UL>
<P>Check this value to see what features your X server supports. If your server does not have either the complete or Immediate mode graphics (the Linux server is and should be complete), you should exit the application with an error message.
<BR>
<BR>
<A NAME="E69E543"></A>
<H4 ALIGN=CENTER>
<CENTER>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?