]> Dogcows Code - chaz/openbox/blob - src/XScreen.cc
fix compiling with --disable-nls
[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 <X11/Xutil.h>
23 #include "XScreen.h"
24 #include "XDisplay.h"
25 #include "Geometry.h"
26
27 XScreen::XScreen(const XDisplay *display, const unsigned int number) {
28 _display = display->_display;
29 _number = number;
30
31 _root = RootWindow(_display, _number);
32 _size = Size(WidthOfScreen(ScreenOfDisplay(_display, _number)),
33 HeightOfScreen(ScreenOfDisplay(_display, _number)));
34 setColorData();
35 }
36
37
38 XScreen::~XScreen() {
39 }
40
41
42 /*
43 * This sets up the _depth, _visual, and _colormap properties.
44 */
45 void XScreen::setColorData() {
46 _depth = DefaultDepth(_display, _number);
47 _visual = (Visual *) 0;
48
49 // search for a TrueColor Visual. If we can't find one, use the default
50 // visual for the screen
51 XVisualInfo vinfo_template, *vinfo_return;
52 int vinfo_nitems;
53
54 vinfo_template.screen = _number;
55 vinfo_template.c_class = TrueColor;
56
57 vinfo_return = XGetVisualInfo(_display, VisualScreenMask | VisualClassMask,
58 &vinfo_template, &vinfo_nitems);
59 if (vinfo_return && vinfo_nitems > 0) {
60 for (int i = 0; i < vinfo_nitems; i++)
61 if (_depth < (vinfo_return + i)->depth) {
62 _depth = (vinfo_return + i)->depth;
63 _visual = (vinfo_return + i)->visual;
64 }
65 XFree(vinfo_return);
66 }
67 if (_visual)
68 _colormap = XCreateColormap(_display, _root, _visual, AllocNone);
69 else {
70 _visual = DefaultVisual(_display, _number);
71 _colormap = DefaultColormap(_display, _number);
72 }
73 }
74
75
76 /*
77 * Creates a window on screen.
78 */
79 Window createWindow(Window parent, const Rect &area, int borderw,
80 unsigned int winclass, unsigned long attrib_mask,
81 XSetWindowAttributes *attrib) const {
82 return XCreateWindow(_display, parent,
83 area.x(), area.y(), area.w(), area.h(),
84 borderw, depth(), winclass, visual(),
85 attrib_mask, attrib);
86 }
This page took 0.035299 seconds and 4 git commands to generate.