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