]> git.saurik.com Git - wxWidgets.git/blame - src/unix/displayx11.cpp
Added an extra c header for memcmp and stuff...
[wxWidgets.git] / src / unix / displayx11.cpp
CommitLineData
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. */
38extern "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
47class wxDisplayUnixPriv
48{
49 public:
50 wxRect m_rect;
51 int m_depth;
52};
53
54size_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
72int 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
113wxDisplay::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);
122 m_priv->m_rect = wxRect(screenarr[index].x_org, screenarr[index].y_org,
123 screenarr[index].width, screenarr[index].height);
124 m_priv->m_depth = DefaultDepth(disp, DefaultScreen(disp));
125 XFree(screenarr);
126 }
127 else
128 {
129 wxSize size = wxGetDisplaySize();
130 m_priv->m_rect = wxRect(0, 0, size.GetWidth(), size.GetHeight());
131 m_priv->m_depth = wxDisplayDepth();
132 }
133}
134
135wxDisplay::~wxDisplay()
136{
137 delete m_priv;
138}
139
140wxRect wxDisplay::GetGeometry() const
141{
142 return m_priv->m_rect;
143}
144
145int wxDisplay::GetDepth() const
146{
147 return m_priv->m_depth;
148}
149
150wxString wxDisplay::GetName() const
151{
32e2c761 152 return wxEmptyString;
b1b3ddd8
JS
153}
154
505c8ccd
VS
155
156#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
157
73b89f70
RN
158//
159// See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
160// info about xf86 video mode extensions
161//
162
2980fc88
RN
163//free private data common to x (usually s3) servers
164#define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
165
166//Correct res rate from GLFW, which probably has the perfect license :)
167#define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f)
168#define wxCRR(v) wxCRR2(v,v.dotclock)
169#define wxCVM2(v, dc) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay())), wxCRR2(v,dc))
170#define wxCVM(v) wxCVM2(v, v.dotclock)
73b89f70
RN
171
172wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
e07d33e7 173{
73b89f70
RN
174 //Convenience...
175 Display* pDisplay = (Display*) wxGetDisplay(); //default display
176 int nScreen = DefaultScreen(pDisplay); //default screen of (default) display...
177
178 //Some variables..
179 XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :))
180 int nNumModes; //Number of modes enumerated....
181
182 wxArrayVideoModes Modes; //modes to return...
183
184 if (XF86VidModeGetAllModeLines(pDisplay, nScreen, &nNumModes, &ppXModes) == TRUE)
185 {
186 for (int i = 0; i < nNumModes; ++i)
187 {
188 if (mode == wxDefaultVideoMode || //According to display.h All modes valid if dafault mode...
2980fc88 189 mode.Matches(wxCVM((*ppXModes[i]))) ) //...?
73b89f70 190 {
2980fc88 191 Modes.Add(wxCVM((*ppXModes[i])));
73b89f70
RN
192 }
193 wxClearXVM((*ppXModes[i]));
194 // XFree(ppXModes[i]); //supposed to free?
195 }
196 XFree(ppXModes);
197 }
198 else //OOPS!
199 {
428b6942 200 wxLogSysError(_("Failed to enumerate video modes"));
73b89f70
RN
201 }
202
203 return Modes;
e07d33e7
RN
204}
205
206wxVideoMode wxDisplay::GetCurrentMode() const
207{
2980fc88
RN
208 XF86VidModeModeLine VM;
209 int nDotClock;
210 XF86VidModeGetModeLine((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()),
211 &nDotClock, &VM);
212 wxClearXVM(VM);
213 return wxCVM2(VM, nDotClock);
e07d33e7
RN
214}
215
216bool wxDisplay::ChangeMode(const wxVideoMode& mode)
217{
2980fc88 218 //This gets kind of tricky AND complicated :) :\ :( :)
73b89f70
RN
219 {
220 bool bRet = false;
221 //Some variables..
222 XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :))
223 int nNumModes; //Number of modes enumerated....
224
225 if(XF86VidModeGetAllModeLines((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()), &nNumModes, &ppXModes) == TRUE)
226 {
2980fc88
RN
227 if (mode == wxDefaultVideoMode)
228 {
229 bRet = XF86VidModeSwitchToMode((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()),
230 ppXModes[0]) == TRUE;
231
232 for (int i = 0; i < nNumModes; ++i)
233 {
234 wxClearXVM((*ppXModes[i]));
235 // XFree(ppXModes[i]); //supposed to free?
236 }
237 XFree(ppXModes);
238
239 return bRet;
240 }
73b89f70
RN
241 for (int i = 0; i < nNumModes; ++i)
242 {
243 if (!bRet &&
244 ppXModes[i]->hdisplay == mode.w &&
245 ppXModes[i]->vdisplay == mode.h &&
2980fc88 246 wxCRR((*ppXModes[i])) == mode.refresh)
73b89f70
RN
247 {
248 //switch!
249 bRet = XF86VidModeSwitchToMode((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()),
250 ppXModes[i]) == TRUE;
251 }
252 wxClearXVM((*ppXModes[i]));
253 // XFree(ppXModes[i]); //supposed to free?
254 }
255 XFree(ppXModes);
256
257 return bRet;
258 }
259 else //OOPS!
260 {
428b6942 261 wxLogSysError(_("Failed to change video mode"));
73b89f70
RN
262 return false;
263 }
264 }
e5804ce7
RN
265}
266
267
268#else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
269
270wxArrayVideoModes 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
287wxVideoMode wxDisplay::GetCurrentMode() const
288{
289 // Not implemented
290 return wxVideoMode();
291}
292
293bool 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 */