Site hosted by Build your free website today!

Hands-on Projects for the Linux Graphics Subsystem

New book from Christos Karayiannis

Available in Amazon Kindle format at:

Screen Matching

We continue in InitOutput() with the following part of code:

     * Match up the screens found by the probes against those specified
     * in the config file.  Remove the ones that won't be used.  Sort
     * them in the order specified.

     * What is the best way to do this?
     * For now, go through the screens allocated by the probes, and
     * look for screen config entry which refers to the same device
     * section as picked out by the probe.

    for (i = 0; i < xf86NumScreens; i++) {
      for (layout = xf86ConfigLayout.screens; layout->screen != NULL;
	   layout++) {
	  Bool found = FALSE;
	  for (j = 0; j < xf86Screens[i]->numEntities; j++) {
	      GDevPtr dev =

	      if (dev == layout->screen->device) {
		  /* A match has been found */ 
		  xf86Screens[i]->confScreen = layout->screen;
		  found = TRUE;
	  if (found) break;
      if (layout->screen == NULL) {
	/* No match found */
	    "Screen %d deleted because of no matching config section.\n", i);
        xf86DeleteScreen(i--, 0);

     * If no screens left, return now.

    if (xf86NumScreens == 0) {
	      "Device(s) detected, but none match those in the config file.\n");


     * Sort the drivers to match the requested ording.  Using a slow
     * bubble sort.
    for (j = 0; j < xf86NumScreens - 1; j++) {
	for (i = 0; i < xf86NumScreens - j - 1; i++) {
	    if (xf86Screens[i + 1]->confScreen->screennum <
		xf86Screens[i]->confScreen->screennum) {
		ScrnInfoPtr tmpScrn = xf86Screens[i + 1];
		xf86Screens[i + 1] = xf86Screens[i];
		xf86Screens[i] = tmpScrn;
    /* Fix up the indexes */
    for (i = 0; i < xf86NumScreens; i++) {
	xf86Screens[i]->scrnIndex = i;

As we previously saw xf86NumScreens increased each time a new ScrnInfoRec was allocated in xf86Screens[]. Also xf86ConfigLayout describes the active layout of xorg.conf (see section The code scans the devices of all screens of the xf86ConfigLayout (until the NULL terminating in the list is found) and compares each with the ones resulted from the probe and stored now at the xf86Screens[] fields. If a match is found the xf86Screens[i] confScreen field is filled with the specific confScreenRec value. confScreen is of type confScreenPtr which we find in section, defined as:

typedef struct _confscreenrec {
    char *		id;
    int			screennum;
    int			defaultdepth;
    int			defaultbpp;
    int			defaultfbbpp;
    MonPtr		monitor;
    GDevPtr		device;
    int			numdisplays;
    DispPtr		displays;
    int			numxvadaptors;
    confXvAdaptorPtr	xvadaptors;
    pointer		options;
} confScreenRec, *confScreenPtr;

The two confScreenPtr that are resulted from the this case study xorg.conf fill each confScreen field of the two ScrnInfoRec formed in the example of section

xf86GetDevFromEntity() is implemented as:

xf86GetDevFromEntity(int entityIndex, int instance)
    int i;
    /* We might not use AddDevtoEntity */
    if ( (!xf86Entities[entityIndex]->devices) ||
         (!xf86Entities[entityIndex]->devices[0]) ) 
	return NULL;

    if (entityIndex >= xf86NumEntities ||
	instance >= xf86Entities[entityIndex]->numInstances)
	return NULL;
    for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++)
	if (xf86Entities[entityIndex]->devices[i]->screen == instance)
    return xf86Entities[entityIndex]->devices[i];

The global array xf86Screens[], the array of all ScrnInfoRec is sorted according to the screen number of the xorg.conf file.


Blue colored text indicates that a value is assigned to a ScrnInfoRec field.