1 // FbRootWindow.cc
2 // Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
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 "FbRootWindow.hh"
23 
24 #include "FbTk/App.hh"
25 #include <X11/Xutil.h>
26 
FbRootWindow(int screen_num)27 FbRootWindow::FbRootWindow(int screen_num):
28     FbTk::FbWindow(RootWindow(FbTk::App::instance()->display(), screen_num)),
29     m_visual(0),
30     m_colormap(0),
31     m_decorationDepth(0),
32     m_decorationVisual(0),
33     m_decorationColormap(0),
34     m_maxDepth(depth()) {
35 
36     Display *disp = FbTk::App::instance()->display();
37 
38     m_visual = DefaultVisual(disp, screen_num);
39     m_colormap = DefaultColormap(disp, screen_num);
40 
41     m_decorationDepth = DefaultDepth(disp, screen_num);
42     m_decorationVisual = DefaultVisual(disp, screen_num);
43     m_decorationColormap = DefaultColormap(disp, screen_num);
44 
45     // search for a TrueColor Visual... if we can't find one... we will use the
46     // default visual for the screen
47     XVisualInfo vinfo_template, *vinfo_return;
48     int vinfo_nitems;
49 
50     vinfo_template.screen = screen_num;
51     vinfo_template.c_class = TrueColor;
52     if ((vinfo_return = XGetVisualInfo(disp,
53                                        VisualScreenMask | VisualClassMask,
54                                        &vinfo_template, &vinfo_nitems)) &&
55         vinfo_nitems > 0) {
56 
57         for (int i = 0; i < vinfo_nitems; i++) {
58             if ((DefaultDepth(disp, screen_num) < vinfo_return[i].depth)
59                     && (m_maxDepth < vinfo_return[i].depth)){
60                 m_visual = vinfo_return[i].visual;
61                 m_maxDepth = vinfo_return[i].depth;
62             }
63 
64             if((m_decorationDepth < vinfo_return[i].depth)
65                     && (vinfo_return[i].depth != 32)) {
66                 m_decorationVisual = vinfo_return[i].visual;
67                 m_decorationDepth = vinfo_return[i].depth;
68             }
69         }
70 
71         XFree(vinfo_return);
72     }
73 
74     if (m_visual != DefaultVisual(disp, screen_num)) {
75         m_colormap = XCreateColormap(disp, window(), m_visual, AllocNone);
76     }
77     if (m_decorationVisual != DefaultVisual(disp, screen_num)) {
78         m_decorationColormap = XCreateColormap(disp, window(), m_decorationVisual, AllocNone);
79     }
80 }
81