📄 appc
字号:
.IP \(bu 5A Boolean that indicates whether.PN _XReply is to discard any additional bytesbeyond those it was told to read<P>Because most reply structures are 32 bytes long, the third argument is usually 0. The only core protocol exceptions are the replies to .PN GetWindowAttributes , .PN QueryFont , .PN QueryKeymap , and .PN GetKeyboardControl ,which have longer replies.<P>The last argument should be .PN False if the reply structure is followedby additional variable length data (such as a list or string). It should be .PN True if there is not any variable length data..NTThis last argument is provided for upward-compatibility reasonsto allow a client to communicate properly with a hypothetical laterversion of the server that sends more data than the client expected.For example, some later version of .PN GetWindowAttributes might use alarger, but compatible, .PN xGetWindowAttributesReply that contains additional attribute data at the end..NE.PN _XReply returns .PN Trueif it received a reply successfully or .PN False if it received any sort of error. <P>For a request with a reply that is not followed by variable lengthdata, you write something like:<P>.Ds .R_XReply(display, (xReply *)&rep, 0, True);*ret1 = rep.ret1;*ret2 = rep.ret2;*ret3 = rep.ret3;...UnlockDisplay(dpy);SyncHandle();return (rep.ret4);}.DeIf there is variable length data after the reply, change the .PN True to .PN False , and use the appropriate.PN _XRead function to read the variable length data.<P>.sM.FD 0_XRead(\fIdisplay\fP, \fIdata_return\fP, \fInbytes\fP) Display *\fIdisplay\fP; char *\fIdata_return\fP; long \fInbytes\fP; .FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fIdata_return\fP 1iSpecifies the buffer..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThe.PN _XReadfunction reads the specified number of bytes into data_return.<P>.sM.FD 0_XRead16(\fIdisplay\fP, \fIdata_return\fP, \fInbytes\fP) Display *\fIdisplay\fP; short *\fIdata_return\fP; long \fInbytes\fP;.FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fIdata_return\fP 1iSpecifies the buffer..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThe.PN _XRead16function reads the specified number of bytes,unpacking them as 16-bit quantities,into the specified array as shorts.<P>.sM.FD 0_XRead32(\fIdisplay\fP, \fIdata_return\fP, \fInbytes\fP) Display *\fIdisplay\fP; long *\fIdata_return\fP; long \fInbytes\fP;.FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fIdata_return\fP 1iSpecifies the buffer..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThe.PN _XRead32function reads the specified number of bytes,unpacking them as 32-bit quantities,into the specified array as longs.<P>.sM.FD 0_XRead16Pad(\fIdisplay\fP, \fIdata_return\fP, \fInbytes\fP) Display *\fIdisplay\fP; short *\fIdata_return\fP; long \fInbytes\fP; .FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fIdata_return\fP 1iSpecifies the buffer..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThe.PN _XRead16Padfunction reads the specified number of bytes,unpacking them as 16-bit quantities,into the specified array as shorts.If the number of bytes is not a multiple of four,.PN _XRead16Padreads and discards up to two additional pad bytes.<P>.sM.FD 0_XReadPad(\fIdisplay\fP, \fIdata_return\fP, \fInbytes\fP) Display *\fIdisplay\fP; char *\fIdata_return\fP; long \fInbytes\fP; .FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fIdata_return\fP 1iSpecifies the buffer..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThe.PN _XReadPadfunction reads the specified number of bytes into data_return.If the number of bytes is not a multiple of four,.PN _XReadPadreads and discards up to three additional pad bytes.<P>Each protocol request is a little different. For further information,see the Xlib sources for examples..SHSynchronous Calling<P>Each procedure should have a call, just before returning to the user, to a macro called.PN SyncHandle .If synchronous mode is enabled (see .PN XSynchronize ), the request is sent immediately.The library, however, waits until any error the procedure could generateat the server has been handled..SHAllocating and Deallocating Memory<P>To support the possible reentry of these procedures, you must observe several conventions when allocating and deallocating memory,most often done when returning data to the user from the windowsystem of a size the caller could not know in advance(for example, a list of fonts or a list of extensions).The standard C library functions on many systemsare not protected against signals or other multithreaded uses.The following analogies to standard I/O library functionshave been defined:.TSl l.T{.PN Xmalloc ()T} T{Replaces .PN malloc ()T}T{.PN XFree ()T} T{Replaces .PN free ()T}T{.PN Xcalloc ()T} T{Replaces .PN calloc ()T}.TE<P>These should be used in place of any calls you would make to the normalC library functions.<P>If you need a single scratch buffer inside a critical section (for example, to pack and unpack data to and from the wire protocol),the general memory allocators may be too expensive to use(particularly in output functions, which are performance critical). The following function returns a scratch buffer for use within acritical section:<!.IN "_XAllocScratch" "" "@DEF@">.sM.FD 0char *_XAllocScratch(\fIdisplay\fP, \fInbytes\fP).br Display *\fIdisplay\fP;.br unsigned long \fInbytes\fP;.FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThis storage must only be used inside of a critical section of yourstub. The returned pointer cannot be assumed valid after any callthat might permit another thread to execute inside Xlib. For example,the pointer cannot be assumed valid after any use of the.PN GetReqor.PN Datafamilies of macros,after any use of.PN _XReply ,or after any use of the.PN _XSendor.PN _XReadfamilies of functions.<P>.spThe following function returns a scratch buffer for use acrosscritical sections:<!.IN "_XAllocTemp" "" "@DEF@">.sM.FD 0char *_XAllocTemp(\fIdisplay\fP, \fInbytes\fP).br Display *\fIdisplay\fP;.br unsigned long \fInbytes\fP;.FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fInbytes\fP 1iSpecifies the number of bytes required.<P>.eMThis storage can be used across calls that might permit another thread toexecute inside Xlib. The storage must be explicitly returned to Xlib.The following function returns the storage:<!.IN "_XFreeTemp" "" "@DEF@">.sM.FD 0void _XFreeTemp(\fIdisplay\fP, \fIbuf\fP, \fInbytes\fP).br Display *\fIdisplay\fP;.br char *\fIbuf\fP;.br unsigned long \fInbytes\fP;.FN.IP \fIdisplay\fP 1iSpecifies the connection to the X server..IP \fIbuf\fP 1iSpecifies the buffer to return..IP \fInbytes\fP 1iSpecifies the size of the buffer.<P>.eMYou must pass back the same pointer and size that were returned by.PN _XAllocTemp ..SHPortability Considerations<P>Many machine architectures, including many of the more recent RISC architectures, do not correctly access data at unaligned locations; their compilers pad out structures to preserve this characteristic.Many other machines capable of unaligned references pad inside of structuresas well to preserve alignment, because accessing aligned data isusually much faster.Because the library and the server use structures to access data atarbitrary points in a byte stream,all data in request and reply packets \fImust\fP be naturally aligned;that is, 16-bit data starts on 16-bit boundaries in the requestand 32-bit data on 32-bit boundaries.All requests \fImust\fP be a multiple of 32 bits in length to preservethe natural alignment in the data stream.You must pad structures out to 32-bit boundaries.Pad information does not have to be zeroed unless you want topreserve such fields for future use in your protocol requests.Floating point varies radically between machines and should beavoided completely if at all possible.<P>This code may run on machines with 16-bit ints. So, if any integer argument, variable, or return value either can take only nonnegative values or is declared as a.PN CARD16in the protocol, be sure to declare it as.PN unsigned.PN intand not as.PN int .(This, of course, does not apply to Booleans or enumerations.)<P>Similarly, if any integer argument or return value is declared.PN CARD32in the protocol, declare it as an.PN unsigned.PN longand not as.PN intor.PN long .This also goes for any internal variables that maytake on values larger than the maximum 16-bit.PN unsigned.PN int .<P>The library currently assumes that a.PN charis 8 bits, a.PN shortis 16 bits, an.PN intis 16 or 32 bits, and a.PN longis 32 bits. The .PN PackData macro is a half-hearted attempt to deal with the possibility of 32 bit shorts. However, much more work is needed to make this work properly..SHDeriving the Correct Extension Opcode<P>The remaining problem a writer of an extension stub procedure faces thatthe core protocol does not face is to map from the call to the propermajor and minor opcodes. While there are a number of strategies, the simplest and fastest is outlined below..IP 1. 5Declare an array of pointers, _NFILE long (this is normally foundin <B><TT>stdio.h</TT></B>and is the number of file descriptors supported on the system)of type .PN XExtCodes .Make sure these are all initialized to NULL..IP 2. 5When your stub is entered, your initialization test is just to usethe display pointer passed in to access the file descriptor and an indexinto the array. If the entry is NULL, then this is the first time youare entering the procedure for this display. Call your initialization procedure and pass to it the display pointer..IP 3. 5Once in your initialization procedure, call .PN XInitExtension ;if it succeeds, store the pointer returned into this array. Make sure to establish a close display handler to allow you to zero the entry.Do whatever other initialization your extension requires.(For example, install event handlers and so on.)Your initialization procedure would normally return a pointer to the.PN XExtCodes structure for this extension, which is what would normallybe found in your array of pointers..IP 4. 5After returning from your initialization procedure, the stub can now continue normally, because it has its major opcode safely in its hand in the .PN XExtCodes structure..bp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -