Doxygen Source Code Documentation
        
Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search   
layerutil.c
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include "layerutil.h"
00013 
00014 Bool layersRead = False;
00015 OverlayInfo **overlayInfoPerScreen;
00016 unsigned long *numOverlaysPerScreen;
00017 
00018 void
00019 findServerOverlayVisualsInfo(Display * dpy)
00020 {
00021   static Atom overlayVisualsAtom;
00022   Atom actualType;
00023   Status status;
00024   unsigned long sizeData, bytesLeft;
00025   Window root;
00026   int actualFormat, numScreens, i;
00027 
00028   if (layersRead == False) {
00029     overlayVisualsAtom = XInternAtom(dpy,
00030       "SERVER_OVERLAY_VISUALS", True);
00031     if (overlayVisualsAtom != None) {
00032       numScreens = ScreenCount(dpy);
00033       overlayInfoPerScreen = (OverlayInfo **)
00034         malloc(numScreens * sizeof(OverlayInfo *));
00035       numOverlaysPerScreen = (unsigned long *)
00036         malloc(numScreens * sizeof(unsigned long));
00037       if (overlayInfoPerScreen != NULL &&
00038         numOverlaysPerScreen != NULL) {
00039         for (i = 0; i < numScreens; i++) {
00040           root = RootWindow(dpy, i);
00041           status = XGetWindowProperty(dpy, root,
00042             overlayVisualsAtom, 0L, (long) 10000, False,
00043             overlayVisualsAtom, &actualType, &actualFormat,
00044             &sizeData, &bytesLeft,
00045             (unsigned char **) &overlayInfoPerScreen[i]);
00046           if (status != Success ||
00047             actualType != overlayVisualsAtom ||
00048             actualFormat != 32 || sizeData < 4)
00049             numOverlaysPerScreen[i] = 0;
00050           else
00051             
00052 
00053             numOverlaysPerScreen[i] = sizeData / 4;
00054         }
00055         layersRead = True;
00056       } else {
00057         if (overlayInfoPerScreen != NULL)
00058           free(overlayInfoPerScreen);
00059         if (numOverlaysPerScreen != NULL)
00060           free(numOverlaysPerScreen);
00061       }
00062     }
00063   }
00064 }
00065 
00066 int
00067 __glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
00068 {
00069   int i, screen = vinfo->screen;
00070   OverlayInfo *overlayInfo;
00071 
00072   findServerOverlayVisualsInfo(dpy);
00073   if (layersRead) {
00074     for (i = 0; i < numOverlaysPerScreen[screen]; i++) {
00075       overlayInfo = &overlayInfoPerScreen[screen][i];
00076       if (vinfo->visualid == overlayInfo->overlay_visual) {
00077         if (overlayInfo->transparent_type == TransparentPixel) {
00078           return (int) overlayInfo->value;
00079         } else {
00080           return -1;
00081         }
00082       }
00083     }
00084   }
00085   return -1;
00086 }
00087 
00088 XLayerVisualInfo *
00089 __glutXGetLayerVisualInfo(Display * dpy, long lvinfo_mask,
00090   XLayerVisualInfo * lvinfo_template, int *nitems_return)
00091 {
00092   XVisualInfo *vinfo;
00093   XLayerVisualInfo *layerInfo;
00094   int numVisuals, count, i, j;
00095 
00096   vinfo = XGetVisualInfo(dpy, lvinfo_mask & VisualAllMask,
00097     &lvinfo_template->vinfo, nitems_return);
00098   if (vinfo == NULL)
00099     return NULL;
00100   numVisuals = *nitems_return;
00101   findServerOverlayVisualsInfo(dpy);
00102   layerInfo = (XLayerVisualInfo *)
00103     malloc(numVisuals * sizeof(XLayerVisualInfo));
00104   if (layerInfo == NULL) {
00105     XFree(vinfo);
00106     return NULL;
00107   }
00108   count = 0;
00109   for (i = 0; i < numVisuals; i++) {
00110     XVisualInfo *pVinfo = &vinfo[i];
00111     int screen = pVinfo->screen;
00112     OverlayInfo *overlayInfo = NULL;
00113 
00114     overlayInfo = NULL;
00115     if (layersRead) {
00116       for (j = 0; j < numOverlaysPerScreen[screen]; j++)
00117         if (pVinfo->visualid ==
00118           overlayInfoPerScreen[screen][j].overlay_visual) {
00119           overlayInfo = &overlayInfoPerScreen[screen][j];
00120           break;
00121         }
00122     }
00123     if (lvinfo_mask & VisualLayerMask)
00124       if (overlayInfo == NULL) {
00125         if (lvinfo_template->layer != 0)
00126           continue;
00127       } else if (lvinfo_template->layer != overlayInfo->layer)
00128         continue;
00129     if (lvinfo_mask & VisualTransparentType)
00130       if (overlayInfo == NULL) {
00131         if (lvinfo_template->type != None)
00132           continue;
00133       } else if (lvinfo_template->type !=
00134         overlayInfo->transparent_type)
00135         continue;
00136     if (lvinfo_mask & VisualTransparentValue)
00137       if (overlayInfo == NULL)
00138         
00139 
00140         continue;
00141       else if (lvinfo_template->value != overlayInfo->value)
00142         continue;
00143     layerInfo[count].vinfo = *pVinfo;
00144     if (overlayInfo == NULL) {
00145       layerInfo[count].layer = 0;
00146       layerInfo[count].type = None;
00147       layerInfo[count].value = 0;  
00148     } else {
00149       layerInfo[count].layer = overlayInfo->layer;
00150       layerInfo[count].type = overlayInfo->transparent_type;
00151       layerInfo[count].value = overlayInfo->value;
00152     }
00153     count++;
00154   }
00155   XFree(vinfo);
00156   *nitems_return = count;
00157   if (count == 0) {
00158     XFree(layerInfo);
00159     return NULL;
00160   } else
00161     return layerInfo;
00162 }
00163 
00164 #if 0                   
00165 Status
00166 __glutXMatchLayerVisualInfo(Display * dpy, int screen,
00167   int depth, int class, int layer,
00168   XLayerVisualInfo * lvinfo_return)
00169 {
00170   XLayerVisualInfo *lvinfo;
00171   XLayerVisualInfo lvinfoTemplate;
00172   int nitems;
00173 
00174   lvinfoTemplate.vinfo.screen = screen;
00175   lvinfoTemplate.vinfo.depth = depth;
00176   lvinfoTemplate.vinfo.class = class;
00177   lvinfoTemplate.layer = layer;
00178   lvinfo = __glutXGetLayerVisualInfo(dpy,
00179     VisualScreenMask | VisualDepthMask |
00180     VisualClassMask | VisualLayerMask,
00181     &lvinfoTemplate, &nitems);
00182   if (lvinfo != NULL && nitems > 0) {
00183     *lvinfo_return = *lvinfo;
00184     return 1;
00185   } else
00186     return 0;
00187 }
00188 #endif