00001
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
00031
00032
00033
00034
00035 _depth = DefaultDepth(**display, _screen);
00036 _visual = DefaultVisual(**display, _screen);
00037 _colormap = DefaultColormap(**display, _screen);
00038
00039 if (_depth < 8) {
00040
00041
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;
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
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
00090
00091
00092
00093
00094
00095
00096 if (XineramaIsActive(**display)) {
00097
00098
00099
00100
00101
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
00114
00115 _xinerama_active = True;
00116 }
00117 }
00118 }
00119 }
00120 #endif // XINERAMA
00121 }
00122
00123 }