]> Dogcows Code - chaz/openbox/blob - otk/screeninfo.cc
rm consts that wont compile on some libfreetype's
[chaz/openbox] / otk / screeninfo.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
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 = num;
22
23 _root_window = RootWindow(OBDisplay::display, _screen);
24
25 _rect.setSize(WidthOfScreen(ScreenOfDisplay(OBDisplay::display,
26 _screen)),
27 HeightOfScreen(ScreenOfDisplay(OBDisplay::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(OBDisplay::display, _screen);
36 _visual = DefaultVisual(OBDisplay::display, _screen);
37 _colormap = DefaultColormap(OBDisplay::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(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));
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 }
This page took 0.041162 seconds and 4 git commands to generate.