]> Dogcows Code - chaz/openbox/blob - src/XScreen.cc
adding new X base classes which encapsulate all X server interation
[chaz/openbox] / src / XScreen.cc
1 // XScreen.cc for Openbox
2 // Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22 #include "XScreen.h"
23 #include "Geometry.h"
24
25 XScreen::XScreen(const Display *display, const unsigned int number) {
26 _display = display;
27 _number = number;
28
29 _root = RootWindow(_display, _number);
30 _size = Size(WidthOfScreen(ScreenOfDisplay(_display, _number)),
31 HeightOfScreen(ScreenOfDisplay(_display, _number)));
32 setColorData();
33 }
34
35
36 /*
37 * This sets up the _depth, _visual, and _colormap properties.
38 */
39 void XScreen::setColorData() {
40 _depth = DefaultDepth(_display, _number);
41 _visual = (Visual *) 0;
42
43 // search for a TrueColor Visual. If we can't find one, use the default
44 // visual for the screen
45 XVisualInfo vinfo_template, *vinfo_return;
46 int vinfo_nitems;
47
48 vinfo_template.screen = _number;
49 vinfo_template.c_class = TrueColor;
50
51 vinfo_return = XGetVisualInfo(_display, VisualScreenMask | VisualClassMask,
52 &vinfo_template, &vinfo_nitems);
53 if (vinfo_return && vinfo_nitems > 0) {
54 for (int i = 0; i < vinfo_nitems; i++)
55 if (_depth < (vinfo_return + i)->depth) {
56 _depth = (vinfo_return + i)->depth;
57 _visual = (vinfo_return + i)->visual;
58 }
59 XFree(vinfo_return);
60 }
61 if (visual)
62 _colormap = XCreateColormap(_display, _root, _visual, AllocNone);
63 else {
64 _visual = DefaultVisual(_display, _number);
65 _colormap = DefaultColormap(_display, _number);
66 }
67 }
This page took 0.035002 seconds and 4 git commands to generate.