1 // XScreen.cc for Openbox
2 // Copyright (c) 2002 - 2002 Ben Janens (ben at orodu.net)
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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.
22 #include <X11/Xutil.h>
27 XScreen::XScreen(const XDisplay
*display
, const unsigned int number
) {
28 _display
= display
->_display
;
31 _root
= RootWindow(_display
, _number
);
32 _size
= Size(WidthOfScreen(ScreenOfDisplay(_display
, _number
)),
33 HeightOfScreen(ScreenOfDisplay(_display
, _number
)));
43 * This sets up the _depth, _visual, and _colormap properties.
45 void XScreen::setColorData() {
46 _depth
= DefaultDepth(_display
, _number
);
47 _visual
= (Visual
*) 0;
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
;
54 vinfo_template
.screen
= _number
;
55 vinfo_template
.c_class
= TrueColor
;
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
;
68 _colormap
= XCreateColormap(_display
, _root
, _visual
, AllocNone
);
70 _visual
= DefaultVisual(_display
, _number
);
71 _colormap
= DefaultColormap(_display
, _number
);
77 * Creates a window on screen.
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(),