1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
5 # include "../config.h"
6 #endif // HAVE_CONFIG_H
10 #include <X11/Xutil.h>
13 #include "screeninfo.hh"
21 ScreenInfo::ScreenInfo(unsigned int num
) {
24 _root_window
= RootWindow(Display::display
, _screen
);
26 _rect
.setSize(WidthOfScreen(ScreenOfDisplay(Display::display
,
28 HeightOfScreen(ScreenOfDisplay(Display::display
,
31 If the default depth is at least 8 we will use that,
32 otherwise we try to find the largest TrueColor visual.
33 Preference is given to 24 bit over larger depths if 24 bit is an option.
36 _depth
= DefaultDepth(Display::display
, _screen
);
37 _visual
= DefaultVisual(Display::display
, _screen
);
38 _colormap
= DefaultColormap(Display::display
, _screen
);
41 // search for a TrueColor Visual... if we can't find one...
42 // we will use the default visual for the screen
43 XVisualInfo vinfo_template
, *vinfo_return
;
47 vinfo_template
.screen
= _screen
;
48 vinfo_template
.c_class
= TrueColor
;
50 vinfo_return
= XGetVisualInfo(Display::display
,
51 VisualScreenMask
| VisualClassMask
,
52 &vinfo_template
, &vinfo_nitems
);
55 for (int i
= 0; i
< vinfo_nitems
; ++i
) {
56 if (vinfo_return
[i
].depth
> max_depth
) {
57 if (max_depth
== 24 && vinfo_return
[i
].depth
> 24)
58 break; // prefer 24 bit over 32
59 max_depth
= vinfo_return
[i
].depth
;
63 if (max_depth
< _depth
) best
= -1;
67 _depth
= vinfo_return
[best
].depth
;
68 _visual
= vinfo_return
[best
].visual
;
69 _colormap
= XCreateColormap(Display::display
, _root_window
, _visual
,
76 // get the default display string and strip the screen number
77 string default_string
= DisplayString(Display::display
);
78 const string::size_type pos
= default_string
.rfind(".");
79 if (pos
!= string::npos
)
80 default_string
.resize(pos
);
82 _display_string
= string("DISPLAY=") + default_string
+ '.' +
83 itostring(static_cast<unsigned long>(_screen
));
86 _xinerama_active
= False
;
88 if (d
->hasXineramaExtensions()) {
89 if (d
->getXineramaMajorVersion() == 1) {
90 // we know the version 1(.1?) protocol
93 in this version of Xinerama, we can't query on a per-screen basis, but
94 in future versions we should be able, so the 'activeness' is checked
95 on a pre-screen basis anyways.
97 if (XineramaIsActive(Display::display
)) {
99 If Xinerama is being used, there there is only going to be one screen
100 present. We still, of course, want to use the screen class, but that
101 is why no screen number is used in this function call. There should
102 never be more than one screen present with Xinerama active.
105 XineramaScreenInfo
*info
= XineramaQueryScreens(Display::display
,
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
));
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
;