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