]> Dogcows Code - chaz/openbox/blob - otk/screeninfo.cc
signed ints instead of unsigned ints again. less pain. pain bad.
[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(int num) {
21 assert(num >= 0 && num < ScreenCount(**display));
22
23 _screen = num;
24
25 _root_window = RootWindow(**display, _screen);
26
27 _size = Size(WidthOfScreen(ScreenOfDisplay(**display,
28 _screen)),
29 HeightOfScreen(ScreenOfDisplay(**display,
30 _screen)));
31 /*
32 If the default depth is at least 8 we will use that,
33 otherwise we try to find the largest TrueColor visual.
34 Preference is given to 24 bit over larger depths if 24 bit is an option.
35 */
36
37 _depth = DefaultDepth(**display, _screen);
38 _visual = DefaultVisual(**display, _screen);
39 _colormap = DefaultColormap(**display, _screen);
40
41 if (_depth < 8) {
42 // search for a TrueColor Visual... if we can't find one...
43 // we will use the default visual for the screen
44 XVisualInfo vinfo_template, *vinfo_return;
45 int vinfo_nitems;
46 int best = -1;
47
48 vinfo_template.screen = _screen;
49 vinfo_template.c_class = TrueColor;
50
51 vinfo_return = XGetVisualInfo(**display,
52 VisualScreenMask | VisualClassMask,
53 &vinfo_template, &vinfo_nitems);
54 if (vinfo_return) {
55 int max_depth = 1;
56 for (int i = 0; i < vinfo_nitems; ++i) {
57 if (vinfo_return[i].depth > max_depth) {
58 if (max_depth == 24 && vinfo_return[i].depth > 24)
59 break; // prefer 24 bit over 32
60 max_depth = vinfo_return[i].depth;
61 best = i;
62 }
63 }
64 if (max_depth < _depth) best = -1;
65 }
66
67 if (best != -1) {
68 _depth = vinfo_return[best].depth;
69 _visual = vinfo_return[best].visual;
70 _colormap = XCreateColormap(**display, _root_window, _visual,
71 AllocNone);
72 }
73
74 XFree(vinfo_return);
75 }
76
77 // get the default display string and strip the screen number
78 string default_string = DisplayString(**display);
79 const string::size_type pos = default_string.rfind(".");
80 if (pos != string::npos)
81 default_string.resize(pos);
82
83 _display_string = string("DISPLAY=") + default_string + '.' +
84 itostring(static_cast<unsigned long>(_screen));
85
86 #if 0 //def XINERAMA
87 _xinerama_active = False;
88
89 if (d->hasXineramaExtensions()) {
90 if (d->getXineramaMajorVersion() == 1) {
91 // we know the version 1(.1?) protocol
92
93 /*
94 in this version of Xinerama, we can't query on a per-screen basis, but
95 in future versions we should be able, so the 'activeness' is checked
96 on a pre-screen basis anyways.
97 */
98 if (XineramaIsActive(**display)) {
99 /*
100 If Xinerama is being used, there there is only going to be one screen
101 present. We still, of course, want to use the screen class, but that
102 is why no screen number is used in this function call. There should
103 never be more than one screen present with Xinerama active.
104 */
105 int num;
106 XineramaScreenInfo *info = XineramaQueryScreens(**display, &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.038518 seconds and 5 git commands to generate.