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(unsigned int num
) {
23 _root_window
= RootWindow(Display::display
, _screen
);
25 _rect
.setSize(WidthOfScreen(ScreenOfDisplay(Display::display
,
27 HeightOfScreen(ScreenOfDisplay(Display::display
,
30 If the default depth is at least 8 we will use that,
31 otherwise we try to find the largest TrueColor visual.
32 Preference is given to 24 bit over larger depths if 24 bit is an option.
35 _depth
= DefaultDepth(Display::display
, _screen
);
36 _visual
= DefaultVisual(Display::display
, _screen
);
37 _colormap
= DefaultColormap(Display::display
, _screen
);
40 // search for a TrueColor Visual... if we can't find one...
41 // we will use the default visual for the screen
42 XVisualInfo vinfo_template
, *vinfo_return
;
46 vinfo_template
.screen
= _screen
;
47 vinfo_template
.c_class
= TrueColor
;
49 vinfo_return
= XGetVisualInfo(Display::display
,
50 VisualScreenMask
| VisualClassMask
,
51 &vinfo_template
, &vinfo_nitems
);
54 for (int i
= 0; i
< vinfo_nitems
; ++i
) {
55 if (vinfo_return
[i
].depth
> max_depth
) {
56 if (max_depth
== 24 && vinfo_return
[i
].depth
> 24)
57 break; // prefer 24 bit over 32
58 max_depth
= vinfo_return
[i
].depth
;
62 if (max_depth
< _depth
) best
= -1;
66 _depth
= vinfo_return
[best
].depth
;
67 _visual
= vinfo_return
[best
].visual
;
68 _colormap
= XCreateColormap(Display::display
, _root_window
, _visual
,
75 // get the default display string and strip the screen number
76 string default_string
= DisplayString(Display::display
);
77 const string::size_type pos
= default_string
.rfind(".");
78 if (pos
!= string::npos
)
79 default_string
.resize(pos
);
81 _display_string
= string("DISPLAY=") + default_string
+ '.' +
82 itostring(static_cast<unsigned long>(_screen
));
85 _xinerama_active
= False
;
87 if (d
->hasXineramaExtensions()) {
88 if (d
->getXineramaMajorVersion() == 1) {
89 // we know the version 1(.1?) protocol
92 in this version of Xinerama, we can't query on a per-screen basis, but
93 in future versions we should be able, so the 'activeness' is checked
94 on a pre-screen basis anyways.
96 if (XineramaIsActive(Display::display
)) {
98 If Xinerama is being used, there there is only going to be one screen
99 present. We still, of course, want to use the screen class, but that
100 is why no screen number is used in this function call. There should
101 never be more than one screen present with Xinerama active.
104 XineramaScreenInfo
*info
= XineramaQueryScreens(Display::display
,
106 if (num
> 0 && info
) {
107 _xinerama_areas
.reserve(num
);
108 for (int i
= 0; i
< num
; ++i
) {
109 _xinerama_areas
.push_back(Rect(info
[i
].x_org
, info
[i
].y_org
,
110 info
[i
].width
, info
[i
].height
));
114 // if we can't find any xinerama regions, then we act as if it is not
115 // active, even though it said it was
116 _xinerama_active
= True
;