1 // -*- mode: C++; indent-tabs-mode: nil; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "screeninfo.hh"
14 ScreenInfo::ScreenInfo(unsigned int num
) {
17 root_window
= RootWindow(ob::OBDisplay::display
, screen_number
);
19 rect
.setSize(WidthOfScreen(ScreenOfDisplay(OBDisplay::display
,
21 HeightOfScreen(ScreenOfDisplay(OBDisplay::display
,
24 If the default depth is at least 8 we will use that,
25 otherwise we try to find the largest TrueColor visual.
26 Preference is given to 24 bit over larger depths if 24 bit is an option.
29 depth
= DefaultDepth(OBDisplay::display
, screen_number
);
30 visual
= DefaultVisual(OBDisplay::display
, screen_number
);
31 colormap
= DefaultColormap(OBDisplay::display
, screen_number
);
34 // search for a TrueColor Visual... if we can't find one...
35 // we will use the default visual for the screen
36 XVisualInfo vinfo_template
, *vinfo_return
;
40 vinfo_template
.screen
= screen_number
;
41 vinfo_template
.c_class
= TrueColor
;
43 vinfo_return
= XGetVisualInfo(OBDisplay::display
,
44 VisualScreenMask
| VisualClassMask
,
45 &vinfo_template
, &vinfo_nitems
);
48 for (int i
= 0; i
< vinfo_nitems
; ++i
) {
49 if (vinfo_return
[i
].depth
> max_depth
) {
50 if (max_depth
== 24 && vinfo_return
[i
].depth
> 24)
51 break; // prefer 24 bit over 32
52 max_depth
= vinfo_return
[i
].depth
;
56 if (max_depth
< depth
) best
= -1;
60 depth
= vinfo_return
[best
].depth
;
61 visual
= vinfo_return
[best
].visual
;
62 colormap
= XCreateColormap(OBDisplay::display
, root_window
, visual
,
69 // get the default display string and strip the screen number
70 string default_string
= DisplayString(OBDisplay::display
);
71 const string::size_type pos
= default_string
.rfind(".");
72 if (pos
!= string::npos
)
73 default_string
.resize(pos
);
75 display_string
= string("DISPLAY=") + default_string
+ '.' +
76 itostring(static_cast<unsigned long>(screen_number
));
79 xinerama_active
= False
;
81 if (d
->hasXineramaExtensions()) {
82 if (d
->getXineramaMajorVersion() == 1) {
83 // we know the version 1(.1?) protocol
86 in this version of Xinerama, we can't query on a per-screen basis, but
87 in future versions we should be able, so the 'activeness' is checked
88 on a pre-screen basis anyways.
90 if (XineramaIsActive(OBDisplay::display
)) {
92 If Xinerama is being used, there there is only going to be one screen
93 present. We still, of course, want to use the screen class, but that
94 is why no screen number is used in this function call. There should
95 never be more than one screen present with Xinerama active.
98 XineramaScreenInfo
*info
= XineramaQueryScreens(OBDisplay::display
,
100 if (num
> 0 && info
) {
101 xinerama_areas
.reserve(num
);
102 for (int i
= 0; i
< num
; ++i
) {
103 xinerama_areas
.push_back(Rect(info
[i
].x_org
, info
[i
].y_org
,
104 info
[i
].width
, info
[i
].height
));
108 // if we can't find any xinerama regions, then we act as if it is not
109 // active, even though it said it was
110 xinerama_active
= True
;