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