]> Dogcows Code - chaz/openbox/blob - otk/screeninfo.cc
689837d0202a969d41e7191d1e803ada401829d8
[chaz/openbox] / otk / screeninfo.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "config.h"
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 }
9
10 #include "screeninfo.hh"
11 #include "display.hh"
12 #include "util.hh"
13
14 using std::string;
15
16 namespace otk {
17
18 ScreenInfo::ScreenInfo(int num) {
19 assert(num >= 0 && num < ScreenCount(**display));
20
21 _screen = num;
22
23 _root_window = RootWindow(**display, _screen);
24
25 _size = Size(WidthOfScreen(ScreenOfDisplay(**display,
26 _screen)),
27 HeightOfScreen(ScreenOfDisplay(**display,
28 _screen)));
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(**display, _screen);
36 _visual = DefaultVisual(**display, _screen);
37 _colormap = DefaultColormap(**display, _screen);
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;
47 vinfo_template.c_class = TrueColor;
48
49 vinfo_return = XGetVisualInfo(**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(**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(**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 itostring(static_cast<unsigned long>(_screen));
83
84 #if 0 //def 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(**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(**display, &num);
105 if (num > 0 && info) {
106 _xinerama_areas.reserve(num);
107 for (int i = 0; i < num; ++i) {
108 _xinerama_areas.push_back(Rect(info[i].x_org, info[i].y_org,
109 info[i].width, info[i].height));
110 }
111 XFree(info);
112
113 // if we can't find any xinerama regions, then we act as if it is not
114 // active, even though it said it was
115 _xinerama_active = true;
116 }
117 }
118 }
119 }
120 #else
121 _xinerama_active = false;
122 #endif // XINERAMA
123 if (!_xinerama_active)
124 _xinerama_areas.push_back(Rect(Point(0, 0), _size));
125 }
126
127 }
This page took 0.04459 seconds and 3 git commands to generate.