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