]> icculus.org git repositories - mikachu/openbox.git/blob - otk/screeninfo.cc
change how the widgets' _dirty flag works so that all inheritence levels of the widge...
[mikachu/openbox.git] / otk / screeninfo.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2
3 #ifdef    HAVE_CONFIG_H
4 #  include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 extern "C" {
8 #include <X11/Xlib.h>
9 #include <X11/Xutil.h>
10 }
11
12 #include "screeninfo.hh"
13 #include "display.hh"
14 #include "util.hh"
15
16 using std::string;
17
18 namespace otk {
19
20 ScreenInfo::ScreenInfo(unsigned int num) {
21   screen_number = num;
22
23   root_window = RootWindow(OBDisplay::display, screen_number);
24
25   rect.setSize(WidthOfScreen(ScreenOfDisplay(OBDisplay::display,
26                                              screen_number)),
27                HeightOfScreen(ScreenOfDisplay(OBDisplay::display,
28                                               screen_number)));
29   /*
30     If the default depth is at least 8 we will use that,
31     otherwise we try to find the largest TrueColor visual.
32     Preference is given to 24 bit over larger depths if 24 bit is an option.
33   */
34
35   depth = DefaultDepth(OBDisplay::display, screen_number);
36   visual = DefaultVisual(OBDisplay::display, screen_number);
37   colormap = DefaultColormap(OBDisplay::display, screen_number);
38   
39   if (depth < 8) {
40     // search for a TrueColor Visual... if we can't find one...
41     // we will use the default visual for the screen
42     XVisualInfo vinfo_template, *vinfo_return;
43     int vinfo_nitems;
44     int best = -1;
45
46     vinfo_template.screen = screen_number;
47     vinfo_template.c_class = TrueColor;
48
49     vinfo_return = XGetVisualInfo(OBDisplay::display,
50                                   VisualScreenMask | VisualClassMask,
51                                   &vinfo_template, &vinfo_nitems);
52     if (vinfo_return) {
53       int max_depth = 1;
54       for (int i = 0; i < vinfo_nitems; ++i) {
55         if (vinfo_return[i].depth > max_depth) {
56           if (max_depth == 24 && vinfo_return[i].depth > 24)
57             break;          // prefer 24 bit over 32
58           max_depth = vinfo_return[i].depth;
59           best = i;
60         }
61       }
62       if (max_depth < depth) best = -1;
63     }
64
65     if (best != -1) {
66       depth = vinfo_return[best].depth;
67       visual = vinfo_return[best].visual;
68       colormap = XCreateColormap(OBDisplay::display, root_window, visual,
69                                  AllocNone);
70     }
71
72     XFree(vinfo_return);
73   }
74
75   // get the default display string and strip the screen number
76   string default_string = DisplayString(OBDisplay::display);
77   const string::size_type pos = default_string.rfind(".");
78   if (pos != string::npos)
79     default_string.resize(pos);
80
81   display_string = string("DISPLAY=") + default_string + '.' +
82     otk::itostring(static_cast<unsigned long>(screen_number));
83   
84 #ifdef    XINERAMA
85   xinerama_active = False;
86
87   if (d->hasXineramaExtensions()) {
88     if (d->getXineramaMajorVersion() == 1) {
89       // we know the version 1(.1?) protocol
90
91       /*
92         in this version of Xinerama, we can't query on a per-screen basis, but
93         in future versions we should be able, so the 'activeness' is checked
94         on a pre-screen basis anyways.
95       */
96       if (XineramaIsActive(OBDisplay::display)) {
97         /*
98           If Xinerama is being used, there there is only going to be one screen
99           present. We still, of course, want to use the screen class, but that
100           is why no screen number is used in this function call. There should
101           never be more than one screen present with Xinerama active.
102         */
103         int num;
104         XineramaScreenInfo *info = XineramaQueryScreens(OBDisplay::display,
105                                                         &num);
106         if (num > 0 && info) {
107           xinerama_areas.reserve(num);
108           for (int i = 0; i < num; ++i) {
109             xinerama_areas.push_back(Rect(info[i].x_org, info[i].y_org,
110                                           info[i].width, info[i].height));
111           }
112           XFree(info);
113
114           // if we can't find any xinerama regions, then we act as if it is not
115           // active, even though it said it was
116           xinerama_active = True;
117         }
118       }
119     }
120   }
121 #endif // XINERAMA
122 }
123
124 }