⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch60.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:
		<TD ALIGN="LEFT">16-color server</TD>



		<TD ALIGN="LEFT"><TT>XF86VGA16Server</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT">Monochrome server</TD>



		<TD ALIGN="LEFT"><TT>XF86MonoServer</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT">S3 server</TD>



		<TD ALIGN="LEFT"><TT>XF86S3Server</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT">Mach8 server</TD>



		<TD ALIGN="LEFT"><TT>XF86Mach8Server</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT">Mach32 server</TD>



		<TD ALIGN="LEFT"><TT>XF86Mach32Server</TT></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT">IBM 8514/A server</TD>



		<TD ALIGN="LEFT"><TT>XF86I8514Server</TT></TD>



	</TR>



</TABLE>



</P>



</CENTER>



<P>In the sample <TT>site.def</TT> in Listing 60.1, I have set only the 256-color



SVGA server to be built. All other servers will not be built.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading10<FONT COLOR="#000077"><B>NOTE: </B></FONT>The PEX extensions



	you have do not support the Monochrome server. 



<HR>







</DL>







<P>The <TT>Drivers</TT> 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 <TT>generic</TT> driver should



be the last one included in the monochrome and 16-color servers because its probe



always succeeds.</P>



<P>The <TT>generic_s3</TT> driver should be the last one included in the S3 servers



for similar reasons.</P>



<P>After you have edited the <TT>site.def</TT> file, you must create the <TT>Makefile</TT>.</P>



<P>To build the <TT>Makefile</TT>, run this command:</P>



<PRE><FONT COLOR="#0066FF"># ./mkmf



</FONT></PRE>



<P>Then, run make to link the servers that you have configured in the <TT>site.def</TT>



file. This command takes a while. After this command is done, run the <TT>make install</TT>



command to install the new servers:</P>



<PRE><FONT COLOR="#0066FF">#  make install



</FONT></PRE>







<DL>



	<DT><FONT COLOR="#0066FF"></FONT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading11<FONT COLOR="#000077"><B>TIP: </B></FONT>Run <TT>make</TT>



	<TT>clean</TT> to remove the files that were created by this procedure. This frees



	the directory structures of any unnecessary files, which is important because disk



	space is at a premium under Linux. 



<HR>







</DL>







<P>Now start X, run the window manager, and in an <TT>xterm</TT> use the <TT>xdpyinfo</TT>



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 <TT>-showconfig</TT>



flag.



<CENTER>



<H4><A NAME="Heading12<FONT COLOR="#000077">Writing Your Own Driver</FONT></H4>



</CENTER>



<P>If you are including a driver that it not part of the standard distribution, make



a directory in <TT>drivers/vga256</TT> (<TT>drivers/vga2</TT> if it is for the monochrome



server; <TT>drivers/vga16</TT> if it is for the 16-color server; or <TT>drivers/bdm2</TT>



if it is for the bdm2 monochrome server's bdm2 screen). Copy either the source or



the <TT>.o</TT> file, and a suitable <TT>Imakefile</TT>, 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 <TT>./renderers</TT>. Look at the



<TT>VGADriver.Doc</TT> file for more details.



<CENTER>



<H3><A NAME="Heading13<FONT COLOR="#000077">Getting PEX</FONT></H3>



</CENTER>



<P>You have PEX files on the CD-ROM at the back of this book.</P>



<P>There are several examples of PEX code available on the Internet. One sample library



can be found at the site <TT>export.lcs.mit.edu</TT> in the <TT>/R5contrib/R5contrib-fixes</TT>



directory as the file <TT>PEX.examples.tar.Z</TT>.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading14<FONT COLOR="#000077"><B>NOTE:</B> </FONT>For Tk and Tcl



	users, PEXtk is available directly from <TT>export.mit.lcs.edu</TT>, and is located



	in <TT>/contrib</TT>. The files are <TT>pextk.PS.tar.Z</TT>, <TT>pextk.README</TT>,



	and <TT>pextk.tar.Z</TT>. PEXtk uses X as its windowing system, so the UI is X-based.



	



<HR>







</DL>







<CENTER>



<H3><A NAME="Heading15<FONT COLOR="#000077">Sample PEX Source File</FONT></H3>



</CENTER>



<P>Let's look at an example of a simple PEX program that prints the line <TT>Howdy



World</TT>. (<TT>Hello World</TT> is a bit overused.) The following is the listing



for printing this line:</P>



<PRE><FONT COLOR="#0066FF">#include &quot;phigs/phigs.h&quot;



#include &quot;X11/Xlib.h&quot;



#include &quot;X11/Xatom.h&quot;



#include &quot;strings.h&quot;







char windowName[] = &quot;PEX in Linux&quot;;



char HelloStr[] = &quot;Howdy World&quot;;







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, &amp;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( &amp;text_pt, HelloStr, strlen(HelloStr)): 



      pclose_struct( );







      ppost_struct( 1, 1, 1.0 );







      printf(&quot;Hit return to exit&quot;);



      getchar();







      pclose_ws( 1 );



      pclose_phigs( );



</FONT></PRE>



<PRE><FONT COLOR="#0066FF">}



</FONT></PRE>



<P>The first executable line in this file opens a connection to the PEX server with



a call to <TT>popen_phigs(NULL,0)</TT>. The <TT>NULL</TT> parameter sets the error



filename to nothing, and the <TT>0</TT> sets the default memory size to 0.</P>



<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



<TT>XCreateSimpleWindow</TT> 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.</P>



<P>The <TT>XChangeProperty</TT> function call sets the window name to the one desired.



The display and window ID (<TT>connid.drawable_id</TT>) are set to that of the root



window of the application.</P>



<P>The <TT>XMapWindow</TT> function maps your display to the current window ID.</P>



<P>The <TT>popen_ws()</TT> call opens the workspace for the display for you to be



able to draw on. You then set the test position for the <TT>Howdy World</TT> string.



Then, open a structure for writing with PEX primitives to set the <TT>text_pt</TT>



structure with the text. It is necessary to call the <TT>pclose_struct()</TT> function



when done with the drawing area buffer. Lastly, post the structure to <TT>ppost_struct</TT>.</P>



<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 <TT>pclose_ws( 1 )</TT> for closing the workspace; the other is a call to



<TT>pclose_phigs( )</TT> for shutting down the PEX server.



<CENTER>



<H3><A NAME="Heading16<FONT COLOR="#000077">PEXlib and Motif</FONT></H3>



</CENTER>



<P>In the previous example, the drawable was used to create the drawing patterns



on a drawing area widget. <TT>PEXlib</TT> by itself is intended to be an interface



into the lower-level Xlib. <TT>PEXlib</TT> gives you the capability to do 3-D mappings,



shading, and so on, along with other geometric transformations.</P>



<P>This section covers the basic act of combining <TT>PEXlib</TT> 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. Here are the steps to combine Motif and <TT>PEXlib</TT>:







<UL>



	<LI>Initialize an X Window, and get the best visual you can for PEX.



	<P>



	<LI>Initialize PEX with a call to <TT>PEXInitialize</TT>.



	<P>



	<LI>Create a top-level shell.



	<P>



	<LI>Create a drawing area interface for PEX.



	<P>



	<LI>Map the drawing area to the screen.



	<P>



	<LI>Create a PEX renderer (just like the GC) for this drawing area.



	<P>



	<LI>Draw to your heart's delight.



</UL>







<CENTER>



<H4><A NAME="Heading17<FONT COLOR="#000077">Initializing the Toolkit</FONT></H4>



</CENTER>



<P>For initializing the toolkit, you must use a long method instead of <TT>XtAppInitialize</TT>.



This long method enables you to select the best visual you can get for PEX. The following



code segment will suffice:</P>



<PRE><FONT COLOR="#0066FF">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],



            &quot;pEX&quot;, /* Class Name */



            NULL, 0, /* no resource options */



            &amp;argc, argv);



     



if (display == (Display *) NULL)







      abort(&quot;Unable to open display&quot;);



</FONT></PRE>



<P>You are making a copy of <TT>argc</TT> and <TT>argv</TT> to preserve their values,



because the call to <TT>XtOpenDisplay()</TT> mangles these original values. It's



necessary to check whether the display pointer is set to a valid value when you return



from <TT>XtOpenDisplay()</TT> because the display may not have been opened for various



reasons, and you do not want to work a <TT>NULL</TT> pointer for the display.</P>



<P>Initialize the <TT>PEXlib</TT> functions with a call to the function <TT>PEXInitialize()</TT>.



The syntax for this call is as follows:</P>



<PRE><FONT COLOR="#0066FF">#include &lt;X11/PEX5/PEXlib.h&gt;







int PEXInitialize(Display *dp,



      PEXExtensionInfo *info_ptr,



      int message_length,



      char *msg);



</FONT></PRE>



<P>The <TT>PEXExtensionInfo</TT> 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:







<UL>



	<LI><TT>PEXBadExtension</TT> if the X server does not support PEX



	<P>



	<LI><TT>PEXBadProtocolVersion</TT> if your X server and the PEXlib you are using



	are of different versions



	<P>



	<LI><TT>PEXBadLocalAlloc</TT> if you are out of memory



	<P>



	<LI><TT><BR>



	PEXBadFloatConversio</TT> if the X server does not support the PEX floating point



</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.</P>



<P>The returned <TT>PEXExtensionInfo</TT> structure is of the following form:</P>



<PRE><FONT COLOR="#0066FF">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: 



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>PEXImmediateMode</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Enables drawing primitives that are sent directly to the display.</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>PEXWorkstationOnly</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Enables workstation resources.</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>PEXStructureMode</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Enables drawing primitives to be stored in a structure before being sent to the display.</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT" VALIGN="TOP"><TT>PEXCompeleteImplementation</TT></TD>



		<TD ALIGN="LEFT" VALIGN="TOP">Enables all of these functions.</TD>



	</TR>



</TABLE>



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.



<CENTER>



<H4><A NAME="Heading18<FONT COLOR="#000077">Creating the Window</FONT></H4>



</CENTER>



<P>Now create the window with the <TT>colormap</TT> and the best visual for PEX.



The way to do this is as follows:</P>



<PRE><FONT COLOR="#0066FF">XStandardColormap       colormap;



Colormap    PEX_colormap;



     



/* open display as before */



     



screen = DefaultScreen(display);



visual = DefaultVisual(display,screen); 



depth  = DefaultDepth(display,screen); 



status = GetStdColormap(display, screen,



            visual, depth,



            &amp;colormap);



if (status == True)



      PEX_colormap = colormap;











blue = AllocNamedColor(display, PEX_colormap,



      &quot;Blue&quot;, 0L);





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -