Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/otk/screeninfo.cc

Go to the documentation of this file.
00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
00002 
00003 #ifdef    HAVE_CONFIG_H
00004 #  include "../config.h"
00005 #endif // HAVE_CONFIG_H
00006 
00007 extern "C" {
00008 #include <X11/Xlib.h>
00009 #include <X11/Xutil.h>
00010 }
00011 
00012 #include "screeninfo.hh"
00013 #include "display.hh"
00014 #include "util.hh"
00015 
00016 using std::string;
00017 
00018 namespace otk {
00019 
00020 ScreenInfo::ScreenInfo(unsigned int num) {
00021   _screen = num;
00022 
00023   _root_window = RootWindow(**display, _screen);
00024 
00025   _rect.setSize(WidthOfScreen(ScreenOfDisplay(**display,
00026                                               _screen)),
00027                HeightOfScreen(ScreenOfDisplay(**display,
00028                                               _screen)));
00029   /*
00030     If the default depth is at least 8 we will use that,
00031     otherwise we try to find the largest TrueColor visual.
00032     Preference is given to 24 bit over larger depths if 24 bit is an option.
00033   */
00034 
00035   _depth = DefaultDepth(**display, _screen);
00036   _visual = DefaultVisual(**display, _screen);
00037   _colormap = DefaultColormap(**display, _screen);
00038   
00039   if (_depth < 8) {
00040     // search for a TrueColor Visual... if we can't find one...
00041     // we will use the default visual for the screen
00042     XVisualInfo vinfo_template, *vinfo_return;
00043     int vinfo_nitems;
00044     int best = -1;
00045 
00046     vinfo_template.screen = _screen;
00047     vinfo_template.c_class = TrueColor;
00048 
00049     vinfo_return = XGetVisualInfo(**display,
00050                                   VisualScreenMask | VisualClassMask,
00051                                   &vinfo_template, &vinfo_nitems);
00052     if (vinfo_return) {
00053       int max_depth = 1;
00054       for (int i = 0; i < vinfo_nitems; ++i) {
00055         if (vinfo_return[i].depth > max_depth) {
00056           if (max_depth == 24 && vinfo_return[i].depth > 24)
00057             break;          // prefer 24 bit over 32
00058           max_depth = vinfo_return[i].depth;
00059           best = i;
00060         }
00061       }
00062       if (max_depth < _depth) best = -1;
00063     }
00064 
00065     if (best != -1) {
00066       _depth = vinfo_return[best].depth;
00067       _visual = vinfo_return[best].visual;
00068       _colormap = XCreateColormap(**display, _root_window, _visual,
00069                                   AllocNone);
00070     }
00071 
00072     XFree(vinfo_return);
00073   }
00074 
00075   // get the default display string and strip the screen number
00076   string default_string = DisplayString(**display);
00077   const string::size_type pos = default_string.rfind(".");
00078   if (pos != string::npos)
00079     default_string.resize(pos);
00080 
00081   _display_string = string("DISPLAY=") + default_string + '.' +
00082     itostring(static_cast<unsigned long>(_screen));
00083   
00084 #if 0 //def    XINERAMA
00085   _xinerama_active = False;
00086 
00087   if (d->hasXineramaExtensions()) {
00088     if (d->getXineramaMajorVersion() == 1) {
00089       // we know the version 1(.1?) protocol
00090 
00091       /*
00092         in this version of Xinerama, we can't query on a per-screen basis, but
00093         in future versions we should be able, so the 'activeness' is checked
00094         on a pre-screen basis anyways.
00095       */
00096       if (XineramaIsActive(**display)) {
00097         /*
00098           If Xinerama is being used, there there is only going to be one screen
00099           present. We still, of course, want to use the screen class, but that
00100           is why no screen number is used in this function call. There should
00101           never be more than one screen present with Xinerama active.
00102         */
00103         int num;
00104         XineramaScreenInfo *info = XineramaQueryScreens(**display, &num);
00105         if (num > 0 && info) {
00106           _xinerama_areas.reserve(num);
00107           for (int i = 0; i < num; ++i) {
00108             _xinerama_areas.push_back(Rect(info[i].x_org, info[i].y_org,
00109                                            info[i].width, info[i].height));
00110           }
00111           XFree(info);
00112 
00113           // if we can't find any xinerama regions, then we act as if it is not
00114           // active, even though it said it was
00115           _xinerama_active = True;
00116         }
00117       }
00118     }
00119   }
00120 #endif // XINERAMA
00121 }
00122 
00123 }

Generated on Tue Feb 4 22:58:56 2003 for Openbox by doxygen1.3-rc2