]>
Commit | Line | Data |
---|---|---|
b1b3ddd8 JS |
1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Name: displayx11.cpp | |
3 | // Purpose: Unix/X11 implementation of wxDisplay class | |
4 | // Author: Brian Victor | |
5 | // Modified by: | |
6 | // Created: 12/05/02 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
b1b3ddd8 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
b1b3ddd8 JS |
13 | #pragma implementation "display.h" |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #include "wx/display.h" | |
428b6942 | 24 | #include "wx/intl.h" |
73b89f70 | 25 | #include "wx/log.h" |
b1b3ddd8 JS |
26 | |
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/dynarray.h" | |
29 | #include "wx/gdicmn.h" | |
30 | #include "wx/string.h" | |
31 | #include "wx/utils.h" | |
32 | #endif /* WX_PRECOMP */ | |
33 | ||
34 | #if wxUSE_DISPLAY | |
35 | ||
36 | /* These must be included after the wx files. Otherwise the Data macro in | |
37 | * Xlibint.h conflicts with a function declaration in wx/list.h. */ | |
38 | extern "C" { | |
39 | #include <X11/Xlib.h> | |
40 | #include <X11/Xlibint.h> | |
41 | #include <X11/extensions/Xinerama.h> | |
505c8ccd | 42 | #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H |
73b89f70 | 43 | #include <X11/extensions/xf86vmode.h> |
505c8ccd | 44 | #endif |
b1b3ddd8 JS |
45 | } |
46 | ||
47 | class wxDisplayUnixPriv | |
48 | { | |
49 | public: | |
50 | wxRect m_rect; | |
51 | int m_depth; | |
52 | }; | |
53 | ||
54 | size_t wxDisplayBase::GetCount() | |
55 | { | |
56 | Display *disp = (Display*)wxGetDisplay(); | |
57 | ||
58 | if ( XineramaIsActive(disp) ) | |
59 | { | |
60 | XineramaScreenInfo *screenarr; | |
61 | int numscreens; | |
62 | screenarr = XineramaQueryScreens(disp, &numscreens); | |
63 | XFree(screenarr); | |
64 | return numscreens; | |
65 | } | |
66 | else | |
67 | { | |
68 | return 1; | |
69 | } | |
70 | } | |
71 | ||
72 | int wxDisplayBase::GetFromPoint(const wxPoint &p) | |
73 | { | |
74 | Display *disp = (Display*)wxGetDisplay(); | |
75 | ||
76 | if ( XineramaIsActive(disp) ) | |
77 | { | |
78 | int which_screen = -1; | |
79 | XineramaScreenInfo *screenarr; | |
80 | int numscreens; | |
81 | screenarr = XineramaQueryScreens(disp, &numscreens); | |
82 | ||
83 | int i; | |
84 | for (i = 0; i < numscreens; ++i) | |
85 | { | |
86 | if (p.x >= screenarr[i].x_org && | |
f2ebd959 | 87 | p.x < screenarr[i].x_org + screenarr[i].width && |
b1b3ddd8 | 88 | p.y >= screenarr[i].y_org && |
f2ebd959 | 89 | p.y < screenarr[i].y_org + screenarr[i].height) |
b1b3ddd8 JS |
90 | { |
91 | which_screen = i; | |
92 | } | |
93 | } | |
94 | ||
95 | XFree(screenarr); | |
96 | return which_screen; | |
97 | } | |
98 | else | |
99 | { | |
3cb98121 VZ |
100 | wxSize size = wxGetDisplaySize(); |
101 | if (p.x >= 0 && | |
f2ebd959 RN |
102 | p.x < size.GetWidth() && |
103 | p.y >= 0 && | |
104 | p.y < size.GetHeight()) | |
3cb98121 VZ |
105 | { |
106 | return 0; | |
107 | } | |
108 | ||
e07d33e7 | 109 | return -1; |
b1b3ddd8 JS |
110 | } |
111 | } | |
112 | ||
113 | wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ), m_priv( new wxDisplayUnixPriv ) | |
114 | { | |
115 | Display *disp = (Display*)wxGetDisplay(); | |
116 | ||
117 | if ( XineramaIsActive(disp) ) | |
118 | { | |
119 | XineramaScreenInfo *screenarr; | |
120 | int numscreens; | |
121 | screenarr = XineramaQueryScreens(disp, &numscreens); | |
6f070389 | 122 | |
b1b3ddd8 JS |
123 | m_priv->m_rect = wxRect(screenarr[index].x_org, screenarr[index].y_org, |
124 | screenarr[index].width, screenarr[index].height); | |
125 | m_priv->m_depth = DefaultDepth(disp, DefaultScreen(disp)); | |
126 | XFree(screenarr); | |
127 | } | |
128 | else | |
129 | { | |
130 | wxSize size = wxGetDisplaySize(); | |
131 | m_priv->m_rect = wxRect(0, 0, size.GetWidth(), size.GetHeight()); | |
132 | m_priv->m_depth = wxDisplayDepth(); | |
133 | } | |
134 | } | |
135 | ||
136 | wxDisplay::~wxDisplay() | |
137 | { | |
138 | delete m_priv; | |
139 | } | |
140 | ||
141 | wxRect wxDisplay::GetGeometry() const | |
142 | { | |
143 | return m_priv->m_rect; | |
144 | } | |
145 | ||
146 | int wxDisplay::GetDepth() const | |
147 | { | |
148 | return m_priv->m_depth; | |
149 | } | |
150 | ||
151 | wxString wxDisplay::GetName() const | |
152 | { | |
32e2c761 | 153 | return wxEmptyString; |
b1b3ddd8 JS |
154 | } |
155 | ||
505c8ccd VS |
156 | |
157 | #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H | |
158 | ||
73b89f70 RN |
159 | // |
160 | // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more | |
161 | // info about xf86 video mode extensions | |
162 | // | |
163 | ||
2980fc88 RN |
164 | //free private data common to x (usually s3) servers |
165 | #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private) | |
166 | ||
a90bf709 | 167 | // Correct res rate from GLFW |
2980fc88 RN |
168 | #define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f) |
169 | #define wxCRR(v) wxCRR2(v,v.dotclock) | |
170 | #define wxCVM2(v, dc) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay())), wxCRR2(v,dc)) | |
171 | #define wxCVM(v) wxCVM2(v, v.dotclock) | |
73b89f70 RN |
172 | |
173 | wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const | |
e07d33e7 | 174 | { |
73b89f70 RN |
175 | //Convenience... |
176 | Display* pDisplay = (Display*) wxGetDisplay(); //default display | |
177 | int nScreen = DefaultScreen(pDisplay); //default screen of (default) display... | |
178 | ||
179 | //Some variables.. | |
180 | XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :)) | |
181 | int nNumModes; //Number of modes enumerated.... | |
182 | ||
183 | wxArrayVideoModes Modes; //modes to return... | |
184 | ||
185 | if (XF86VidModeGetAllModeLines(pDisplay, nScreen, &nNumModes, &ppXModes) == TRUE) | |
186 | { | |
187 | for (int i = 0; i < nNumModes; ++i) | |
188 | { | |
189 | if (mode == wxDefaultVideoMode || //According to display.h All modes valid if dafault mode... | |
2980fc88 | 190 | mode.Matches(wxCVM((*ppXModes[i]))) ) //...? |
73b89f70 | 191 | { |
2980fc88 | 192 | Modes.Add(wxCVM((*ppXModes[i]))); |
73b89f70 RN |
193 | } |
194 | wxClearXVM((*ppXModes[i])); | |
195 | // XFree(ppXModes[i]); //supposed to free? | |
196 | } | |
197 | XFree(ppXModes); | |
198 | } | |
199 | else //OOPS! | |
200 | { | |
428b6942 | 201 | wxLogSysError(_("Failed to enumerate video modes")); |
73b89f70 RN |
202 | } |
203 | ||
204 | return Modes; | |
e07d33e7 RN |
205 | } |
206 | ||
207 | wxVideoMode wxDisplay::GetCurrentMode() const | |
208 | { | |
2980fc88 RN |
209 | XF86VidModeModeLine VM; |
210 | int nDotClock; | |
211 | XF86VidModeGetModeLine((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()), | |
212 | &nDotClock, &VM); | |
213 | wxClearXVM(VM); | |
214 | return wxCVM2(VM, nDotClock); | |
e07d33e7 RN |
215 | } |
216 | ||
217 | bool wxDisplay::ChangeMode(const wxVideoMode& mode) | |
218 | { | |
a90bf709 VZ |
219 | XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :)) |
220 | int nNumModes; //Number of modes enumerated.... | |
221 | ||
222 | if( !XF86VidModeGetAllModeLines((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()), &nNumModes, &ppXModes) ) | |
73b89f70 | 223 | { |
a90bf709 VZ |
224 | wxLogSysError(_("Failed to change video mode")); |
225 | return false; | |
226 | } | |
73b89f70 | 227 | |
a90bf709 VZ |
228 | bool bRet = false; |
229 | if (mode == wxDefaultVideoMode) | |
230 | { | |
231 | bRet = XF86VidModeSwitchToMode((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()), | |
232 | ppXModes[0]) == TRUE; | |
233 | ||
234 | for (int i = 0; i < nNumModes; ++i) | |
73b89f70 | 235 | { |
a90bf709 VZ |
236 | wxClearXVM((*ppXModes[i])); |
237 | // XFree(ppXModes[i]); //supposed to free? | |
238 | } | |
239 | } | |
240 | else | |
241 | { | |
242 | for (int i = 0; i < nNumModes; ++i) | |
243 | { | |
244 | if (!bRet && | |
245 | ppXModes[i]->hdisplay == mode.w && | |
246 | ppXModes[i]->vdisplay == mode.h && | |
247 | wxCRR((*ppXModes[i])) == mode.refresh) | |
2980fc88 | 248 | { |
a90bf709 | 249 | //switch! |
2980fc88 | 250 | bRet = XF86VidModeSwitchToMode((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()), |
a90bf709 | 251 | ppXModes[i]) == TRUE; |
2980fc88 | 252 | } |
a90bf709 VZ |
253 | wxClearXVM((*ppXModes[i])); |
254 | // XFree(ppXModes[i]); //supposed to free? | |
73b89f70 RN |
255 | } |
256 | } | |
a90bf709 VZ |
257 | |
258 | XFree(ppXModes); | |
259 | ||
260 | return bRet; | |
e5804ce7 RN |
261 | } |
262 | ||
263 | ||
264 | #else // !HAVE_X11_EXTENSIONS_XF86VMODE_H | |
265 | ||
266 | wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const | |
267 | { | |
f2ebd959 RN |
268 | Display *disp = (Display*)wxGetDisplay(); |
269 | int count_return; | |
270 | int* depths = XListDepths(disp, 0, &count_return); | |
271 | wxArrayVideoModes modes; | |
272 | if (depths) | |
273 | { | |
274 | int x; | |
275 | for (x = 0; x < count_return; ++x) | |
276 | { | |
277 | modes.Add(wxVideoMode(m_priv->m_rect.GetWidth(), m_priv->m_rect.GetHeight(), depths[x])); | |
278 | } | |
279 | } | |
280 | return modes; | |
505c8ccd VS |
281 | } |
282 | ||
283 | wxVideoMode wxDisplay::GetCurrentMode() const | |
284 | { | |
285 | // Not implemented | |
286 | return wxVideoMode(); | |
287 | } | |
288 | ||
289 | bool wxDisplay::ChangeMode(const wxVideoMode& mode) | |
290 | { | |
291 | // Not implemented | |
292 | return false; | |
293 | } | |
294 | ||
295 | #endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H | |
296 | ||
297 | #endif /* wxUSE_DISPLAY */ |