diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ScreenInfo.cc | 235 | ||||
-rw-r--r-- | src/ScreenInfo.hh | 84 |
2 files changed, 319 insertions, 0 deletions
diff --git a/src/ScreenInfo.cc b/src/ScreenInfo.cc new file mode 100644 index 0000000..8e46bcf --- /dev/null +++ b/src/ScreenInfo.cc | |||
@@ -0,0 +1,235 @@ | |||
1 | // ScreenInfo.cc for fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen<at>users.sourceforge.net) | ||
3 | // | ||
4 | // from BaseDisplay.cc in Blackbox 0.61.1 | ||
5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) | ||
6 | // | ||
7 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | // copy of this software and associated documentation files (the "Software"), | ||
9 | // to deal in the Software without restriction, including without limitation | ||
10 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | // and/or sell copies of the Software, and to permit persons to whom the | ||
12 | // Software is furnished to do so, subject to the following conditions: | ||
13 | // | ||
14 | // The above copyright notice and this permission notice shall be included in | ||
15 | // all copies or substantial portions of the Software. | ||
16 | // | ||
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
20 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | // DEALINGS IN THE SOFTWARE. | ||
24 | |||
25 | // $Id: ScreenInfo.cc,v 1.1 2003/05/10 13:54:29 fluxgen Exp $ | ||
26 | |||
27 | #include "ScreenInfo.hh" | ||
28 | |||
29 | #include "App.hh" | ||
30 | |||
31 | #include <X11/Xutil.h> | ||
32 | |||
33 | ScreenInfo::ScreenInfo(int num) { | ||
34 | |||
35 | Display * const disp = FbTk::App::instance()->display(); | ||
36 | screen_number = num; | ||
37 | |||
38 | root_window = RootWindow(disp, screen_number); | ||
39 | depth = DefaultDepth(disp, screen_number); | ||
40 | |||
41 | width = | ||
42 | WidthOfScreen(ScreenOfDisplay(disp, screen_number)); | ||
43 | height = | ||
44 | HeightOfScreen(ScreenOfDisplay(disp, screen_number)); | ||
45 | |||
46 | // search for a TrueColor Visual... if we can't find one... we will use the | ||
47 | // default visual for the screen | ||
48 | XVisualInfo vinfo_template, *vinfo_return; | ||
49 | int vinfo_nitems; | ||
50 | |||
51 | vinfo_template.screen = screen_number; | ||
52 | vinfo_template.c_class = TrueColor; | ||
53 | |||
54 | visual = (Visual *) 0; | ||
55 | |||
56 | if ((vinfo_return = XGetVisualInfo(disp, | ||
57 | VisualScreenMask | VisualClassMask, | ||
58 | &vinfo_template, &vinfo_nitems)) && | ||
59 | vinfo_nitems > 0) { | ||
60 | |||
61 | for (int i = 0; i < vinfo_nitems; i++) { | ||
62 | if (depth < (vinfo_return + i)->depth) { | ||
63 | depth = (vinfo_return + i)->depth; | ||
64 | visual = (vinfo_return + i)->visual; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | XFree(vinfo_return); | ||
69 | } | ||
70 | |||
71 | if (visual) { | ||
72 | m_colormap = XCreateColormap(disp, root_window, | ||
73 | visual, AllocNone); | ||
74 | } else { | ||
75 | visual = DefaultVisual(disp, screen_number); | ||
76 | m_colormap = DefaultColormap(disp, screen_number); | ||
77 | } | ||
78 | |||
79 | #ifdef XINERAMA | ||
80 | // check if we have Xinerama extension enabled | ||
81 | if (XineramaIsActive(disp)) { | ||
82 | m_hasXinerama = true; | ||
83 | xineramaLastHead = 0; | ||
84 | xineramaInfos = | ||
85 | XineramaQueryScreens(disp, &xineramaNumHeads); | ||
86 | } else { | ||
87 | m_hasXinerama = false; | ||
88 | xineramaInfos = 0; // make sure we don't point anywhere we shouldn't | ||
89 | } | ||
90 | #endif // XINERAMA | ||
91 | } | ||
92 | |||
93 | ScreenInfo::~ScreenInfo() { | ||
94 | #ifdef XINERAMA | ||
95 | if (m_hasXinerama) { // only free if we first had it | ||
96 | XFree(xineramaInfos); | ||
97 | xineramaInfos = 0; | ||
98 | } | ||
99 | #endif // XINERAMA | ||
100 | } | ||
101 | |||
102 | #ifdef XINERAMA | ||
103 | |||
104 | /** | ||
105 | Searches for the head at the coordinates | ||
106 | x,y. If it fails or Xinerama isn't | ||
107 | activated it'll return head nr 0 | ||
108 | */ | ||
109 | unsigned int ScreenInfo::getHead(int x, int y) const { | ||
110 | |||
111 | // is Xinerama extensions enabled? | ||
112 | if (hasXinerama()) { | ||
113 | // check if last head is still active | ||
114 | /* if ((xineramaInfos[xineramaLastHead].x_org <= x) && | ||
115 | ((xineramaInfos[xineramaLastHead].x_org + | ||
116 | xineramaInfos[xineramaLastHead].width) > x) && | ||
117 | (xineramaInfos[xineramaLastHead].y_org <= y) && | ||
118 | ((xineramaInfos[xineramaLastHead].y_org + | ||
119 | xineramaInfos[xineramaLastHead].height) > y)) { | ||
120 | return xineramaLastHead; | ||
121 | } else { */ | ||
122 | // go trough all the heads, and search | ||
123 | for (int i = 0; (signed) i < xineramaNumHeads; i++) { | ||
124 | if (xineramaInfos[i].x_org <= x && | ||
125 | (xineramaInfos[i].x_org + xineramaInfos[i].width) > x && | ||
126 | xineramaInfos[i].y_org <= y && | ||
127 | (xineramaInfos[i].y_org + xineramaInfos[i].height) > y) | ||
128 | // return (xineramaLastHead = i); | ||
129 | return i; | ||
130 | } | ||
131 | // } | ||
132 | } | ||
133 | |||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | Searches for the head that the pointer | ||
139 | currently is on, if it isn't found | ||
140 | the first one is returned | ||
141 | */ | ||
142 | unsigned int ScreenInfo::getCurrHead(void) const { | ||
143 | |||
144 | // is Xinerama extensions enabled? | ||
145 | if (hasXinerama()) { | ||
146 | int x, y, wX, wY; | ||
147 | unsigned int mask; | ||
148 | Window rRoot, rChild; | ||
149 | // get pointer cordinates | ||
150 | if ( (XQueryPointer(basedisplay->getXDisplay(), root_window, | ||
151 | &rRoot, &rChild, &x, &y, &wX, &wY, &mask)) != 0 ) { | ||
152 | return getHead(x, y); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | @return the width of head | ||
161 | */ | ||
162 | unsigned int ScreenInfo::getHeadWidth(unsigned int head) const { | ||
163 | |||
164 | if (hasXinerama()) { | ||
165 | if ((signed) head >= xineramaNumHeads) { | ||
166 | #ifdef DEBUG | ||
167 | cerr << __FILE__ << ":" <<__LINE__ << ": " << | ||
168 | "Head: " << head << " doesn't exist!" << endl; | ||
169 | #endif // DEBUG | ||
170 | return xineramaInfos[xineramaNumHeads - 1].width; | ||
171 | } else | ||
172 | return xineramaInfos[head].width; | ||
173 | } | ||
174 | |||
175 | return getWidth(); | ||
176 | |||
177 | } | ||
178 | |||
179 | /** | ||
180 | @return the heigt of head | ||
181 | */ | ||
182 | unsigned int ScreenInfo::getHeadHeight(unsigned int head) const { | ||
183 | |||
184 | if (hasXinerama()) { | ||
185 | if ((signed) head >= xineramaNumHeads) { | ||
186 | #ifdef DEBUG | ||
187 | cerr << __FILE__ << ":" <<__LINE__ << ": " << | ||
188 | "Head: " << head << " doesn't exist!" << endl; | ||
189 | #endif // DEBUG | ||
190 | return xineramaInfos[xineramaNumHeads - 1].height; | ||
191 | } else | ||
192 | return xineramaInfos[head].height; | ||
193 | } | ||
194 | |||
195 | return getHeight(); | ||
196 | } | ||
197 | |||
198 | |||
199 | /** | ||
200 | @return the X start of head nr head | ||
201 | */ | ||
202 | int ScreenInfo::getHeadX(unsigned int head) const { | ||
203 | if (hasXinerama()) { | ||
204 | if ((signed) head >= xineramaNumHeads) { | ||
205 | #ifdef DEBUG | ||
206 | cerr << __FILE__ << ":" <<__LINE__ << ": " << | ||
207 | "Head: " << head << " doesn't exist!" << endl; | ||
208 | #endif // DEBUG | ||
209 | return xineramaInfos[head = xineramaNumHeads - 1].x_org; | ||
210 | } else | ||
211 | return xineramaInfos[head].x_org; | ||
212 | } | ||
213 | |||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | @return the Y start of head | ||
219 | */ | ||
220 | int ScreenInfo::getHeadY(unsigned int head) const { | ||
221 | if (hasXinerama()) { | ||
222 | if ((signed) head >= xineramaNumHeads) { | ||
223 | #ifdef DEBUG | ||
224 | cerr << __FILE__ << ":" <<__LINE__ << ": " << | ||
225 | "Head: " << head << " doesn't exist!" << endl; | ||
226 | #endif // DEBUG | ||
227 | return xineramaInfos[xineramaNumHeads - 1].y_org; | ||
228 | } else | ||
229 | return xineramaInfos[head].y_org; | ||
230 | } | ||
231 | |||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | #endif // XINERAMA | ||
diff --git a/src/ScreenInfo.hh b/src/ScreenInfo.hh new file mode 100644 index 0000000..b167d47 --- /dev/null +++ b/src/ScreenInfo.hh | |||
@@ -0,0 +1,84 @@ | |||
1 | // ScreenInfo.hh for fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen<at>users.sourceforge.net) | ||
3 | // | ||
4 | // from BaseDisplay.hh in Blackbox 0.61.1 | ||
5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) | ||
6 | // | ||
7 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | // copy of this software and associated documentation files (the "Software"), | ||
9 | // to deal in the Software without restriction, including without limitation | ||
10 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | // and/or sell copies of the Software, and to permit persons to whom the | ||
12 | // Software is furnished to do so, subject to the following conditions: | ||
13 | // | ||
14 | // The above copyright notice and this permission notice shall be included in | ||
15 | // all copies or substantial portions of the Software. | ||
16 | // | ||
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
20 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | // DEALINGS IN THE SOFTWARE. | ||
24 | |||
25 | // $Id: ScreenInfo.hh,v 1.1 2003/05/10 13:54:29 fluxgen Exp $ | ||
26 | |||
27 | #ifndef SCREENINFO_HH | ||
28 | #define SCREENINFO_HH | ||
29 | |||
30 | #include <X11/Xlib.h> | ||
31 | |||
32 | #ifdef HAVE_CONFIG_H | ||
33 | #include "config.h" | ||
34 | #endif // HAVE_CONFIG_H | ||
35 | |||
36 | #ifdef XINERAMA | ||
37 | extern "C" { | ||
38 | #include <X11/extensions/Xinerama.h> | ||
39 | } | ||
40 | #endif // XINERAMA | ||
41 | |||
42 | /// holds information about a screen | ||
43 | class ScreenInfo { | ||
44 | public: | ||
45 | explicit ScreenInfo(int screen_num); | ||
46 | ~ScreenInfo(); | ||
47 | |||
48 | inline Visual *getVisual() const { return visual; } | ||
49 | inline Window getRootWindow() const { return root_window; } | ||
50 | inline Colormap colormap() const { return m_colormap; } | ||
51 | |||
52 | inline int getDepth() const { return depth; } | ||
53 | inline int getScreenNumber() const { return screen_number; } | ||
54 | |||
55 | inline unsigned int getWidth() const { return width; } | ||
56 | inline unsigned int getHeight() const { return height; } | ||
57 | |||
58 | #ifdef XINERAMA | ||
59 | inline bool hasXinerama() const { return m_hasXinerama; } | ||
60 | inline int getNumHeads() const { return xineramaNumHeads; } | ||
61 | unsigned int getHead(int x, int y) const; | ||
62 | unsigned int getCurrHead() const; | ||
63 | unsigned int getHeadWidth(unsigned int head) const; | ||
64 | unsigned int getHeadHeight(unsigned int head) const; | ||
65 | int getHeadX(unsigned int head) const; | ||
66 | int getHeadY(unsigned int head) const; | ||
67 | #endif // XINERAMA | ||
68 | |||
69 | private: | ||
70 | Visual *visual; | ||
71 | Window root_window; | ||
72 | Colormap m_colormap; | ||
73 | |||
74 | int depth, screen_number; | ||
75 | unsigned int width, height; | ||
76 | #ifdef XINERAMA | ||
77 | bool m_hasXinerama; | ||
78 | int xineramaMajor, xineramaMinor, xineramaNumHeads, xineramaLastHead; | ||
79 | XineramaScreenInfo *xineramaInfos; | ||
80 | #endif // XINERAMA | ||
81 | |||
82 | }; | ||
83 | |||
84 | #endif // SCREENINFO_HH | ||