Site hosted by Angelfire.com: Build your free website today!

Hands-on Projects for the Linux Graphics Subsystem

New book from Christos Karayiannis

Available in Amazon Kindle format at:

amazon.com   amazon.co.uk   amazon.de   amazon.es   amazon.fr   amazon.it

3.2 X Server main() routine

The main() routine for the X Server, or X as is the executable's name for the Xorg distribution is found at main.c. We start discussing next the most important routines of main, which determine the X Server's functionality.

Preliminary functions

Before main() enters into its permanent 'while' loop it calls a number of routines, namely:

These routines are discussed here.

Main's while loop functions

The main while loop starts with some preliminary functions, namely:

These routines are discussed here.

Functions that are called only the first time the while runs

The routines that called for the first time the while runs (variable serverGeneration becomes 1) are found in the following code snippet:

	if(serverGeneration == 1)
	{
	    CreateWellKnownSockets();
	    InitProcVectors();
	    clients = (ClientPtr *)xalloc(MAXCLIENTS * sizeof(ClientPtr));
	    if (!clients)
		FatalError("couldn't create client array");
	    for (i=1; i<MAXCLIENTS; i++) 
		clients[i] = NullClient;
	    serverClient = (ClientPtr)xalloc(sizeof(ClientRec));
	    if (!serverClient)
		FatalError("couldn't create server client");
	    InitClient(serverClient, 0, (pointer)NULL);
	}

CreateWellKnownSockets() creates at initialization the sockets to listen on for new clients. It is described here.

InitProcVectors() mainly fills the empty items of ProcVector[], SwappedProcVector[] with ProcBadRequest.

Next the clients[] array is created and filled with NullClient. The number of the items of clients[] are indicated by MAXCLIENTS (256).

InitClient() is called next to initialize the serverClient's fields. serverClient is the first client (indexed 0) and is called thus because it is the client that owns the root window (see this text).

Functions that are called if it is not the first time the while runs

ResetWellKnownSockets calls _XSERVTransResetListener(), implemented as TRANS(ResetListener), which is we take as example the sockets API, as found in TRANS(SocketTCPFuncs) it has a NULL value.

SetInputCheck() sets checkForInput[0] and checkForInput[1] respectively to first and second arguments it receives. Those values compared and if they are equal this indicates a user event from the hardware. They are discussed latter in Dispatch(), which is an important routine called by main(). See also the ddx text.

Next some screenInfo and WindowTable initialazation takes place.

WindowTable is an array of pointers to "root" windows, one for each screen.

ScreenInfo is a global struct that includes an array of pointers to ScreeRec structs, called screens[]. The elements of screens[] correspond to each screen of the X server.

typedef struct _ScreenInfo {
    int		imageByteOrder;
    int		bitmapScanlineUnit;
    int		bitmapScanlinePad;
    int		bitmapBitOrder;
    int		numPixmapFormats;
    PixmapFormatRec
		formats[MAXFORMATS];
    int		arraySize;
    int		numScreens;
    ScreenPtr	screens[MAXSCREENS];
    int		numVideoScreens;
} ScreenInfo;

arraySize, i.e. ScreenInfo's size, becomes MAXSCREENS , which is 16. numScreens, the number of screens in initialized to 0.

InitOutput()

InitOutput() is a major routine discussed here.