aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ScreenInfo.cc235
-rw-r--r--src/ScreenInfo.hh76
2 files changed, 0 insertions, 311 deletions
diff --git a/src/ScreenInfo.cc b/src/ScreenInfo.cc
deleted file mode 100644
index 8e46bcf..0000000
--- a/src/ScreenInfo.cc
+++ /dev/null
@@ -1,235 +0,0 @@
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
33ScreenInfo::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
93ScreenInfo::~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*/
109unsigned 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*/
142unsigned 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*/
162unsigned 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*/
182unsigned 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*/
202int 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*/
220int 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
deleted file mode 100644
index 4cdd070..0000000
--- a/src/ScreenInfo.hh
+++ /dev/null
@@ -1,76 +0,0 @@
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.2 2003/05/10 23:01:00 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
37extern "C" {
38#include <X11/extensions/Xinerama.h>
39}
40#endif // XINERAMA
41
42/// holds information about a screen
43class ScreenInfo {
44public:
45 explicit ScreenInfo(int screen_num);
46 ~ScreenInfo();
47
48 inline int getScreenNumber() const { return screen_number; }
49
50#ifdef XINERAMA
51 inline bool hasXinerama() const { return m_hasXinerama; }
52 inline int getNumHeads() const { return xineramaNumHeads; }
53 unsigned int getHead(int x, int y) const;
54 unsigned int getCurrHead() const;
55 unsigned int getHeadWidth(unsigned int head) const;
56 unsigned int getHeadHeight(unsigned int head) const;
57 int getHeadX(unsigned int head) const;
58 int getHeadY(unsigned int head) const;
59#endif // XINERAMA
60
61private:
62 Visual *visual;
63 Window root_window;
64 Colormap m_colormap;
65
66 int depth, screen_number;
67 unsigned int width, height;
68#ifdef XINERAMA
69 bool m_hasXinerama;
70 int xineramaMajor, xineramaMinor, xineramaNumHeads, xineramaLastHead;
71 XineramaScreenInfo *xineramaInfos;
72#endif // XINERAMA
73
74};
75
76#endif // SCREENINFO_HH