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