]> git.saurik.com Git - wxWidgets.git/blame - src/unix/displayx11.cpp
fixed warnings about truncating 64 bit integers
[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$
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. */
34extern "C" {
35 #include <X11/Xlib.h>
36 #include <X11/Xlibint.h>
37 #include <X11/extensions/Xinerama.h>
505c8ccd 38#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
73b89f70 39 #include <X11/extensions/xf86vmode.h>
505c8ccd 40#endif
b1b3ddd8
JS
41}
42
43class wxDisplayUnixPriv
44{
45 public:
46 wxRect m_rect;
47 int m_depth;
48};
49
50size_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
68int 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 &&
f2ebd959 83 p.x < screenarr[i].x_org + screenarr[i].width &&
b1b3ddd8 84 p.y >= screenarr[i].y_org &&
f2ebd959 85 p.y < screenarr[i].y_org + screenarr[i].height)
b1b3ddd8
JS
86 {
87 which_screen = i;
88 }
89 }
90
91 XFree(screenarr);
92 return which_screen;
93 }
94 else
95 {
3cb98121
VZ
96 wxSize size = wxGetDisplaySize();
97 if (p.x >= 0 &&
f2ebd959
RN
98 p.x < size.GetWidth() &&
99 p.y >= 0 &&
100 p.y < size.GetHeight())
3cb98121
VZ
101 {
102 return 0;
103 }
104
e07d33e7 105 return -1;
b1b3ddd8
JS
106 }
107}
108
109wxDisplay::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);
6f070389 118
b1b3ddd8
JS
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
132wxDisplay::~wxDisplay()
133{
134 delete m_priv;
135}
136
137wxRect wxDisplay::GetGeometry() const
138{
139 return m_priv->m_rect;
140}
141
142int wxDisplay::GetDepth() const
143{
144 return m_priv->m_depth;
145}
146
147wxString wxDisplay::GetName() const
148{
32e2c761 149 return wxEmptyString;
b1b3ddd8
JS
150}
151
505c8ccd
VS
152
153#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
154
73b89f70
RN
155//
156// See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
157// info about xf86 video mode extensions
158//
159
2980fc88
RN
160//free private data common to x (usually s3) servers
161#define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
162
a90bf709 163// Correct res rate from GLFW
2980fc88
RN
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)
73b89f70
RN
168
169wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
e07d33e7 170{
73b89f70
RN
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...
2980fc88 186 mode.Matches(wxCVM((*ppXModes[i]))) ) //...?
73b89f70 187 {
2980fc88 188 Modes.Add(wxCVM((*ppXModes[i])));
73b89f70
RN
189 }
190 wxClearXVM((*ppXModes[i]));
191 // XFree(ppXModes[i]); //supposed to free?
192 }
193 XFree(ppXModes);
194 }
195 else //OOPS!
196 {
428b6942 197 wxLogSysError(_("Failed to enumerate video modes"));
73b89f70
RN
198 }
199
200 return Modes;
e07d33e7
RN
201}
202
203wxVideoMode wxDisplay::GetCurrentMode() const
204{
2980fc88
RN
205 XF86VidModeModeLine VM;
206 int nDotClock;
207 XF86VidModeGetModeLine((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()),
208 &nDotClock, &VM);
209 wxClearXVM(VM);
210 return wxCVM2(VM, nDotClock);
e07d33e7
RN
211}
212
213bool wxDisplay::ChangeMode(const wxVideoMode& mode)
214{
a90bf709
VZ
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) )
73b89f70 219 {
a90bf709
VZ
220 wxLogSysError(_("Failed to change video mode"));
221 return false;
222 }
73b89f70 223
a90bf709
VZ
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)
73b89f70 231 {
a90bf709
VZ
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)
2980fc88 244 {
a90bf709 245 //switch!
2980fc88 246 bRet = XF86VidModeSwitchToMode((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay()),
a90bf709 247 ppXModes[i]) == TRUE;
2980fc88 248 }
a90bf709
VZ
249 wxClearXVM((*ppXModes[i]));
250 // XFree(ppXModes[i]); //supposed to free?
73b89f70
RN
251 }
252 }
a90bf709
VZ
253
254 XFree(ppXModes);
255
256 return bRet;
e5804ce7
RN
257}
258
259
260#else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
261
262wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
263{
f2ebd959
RN
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;
505c8ccd
VS
277}
278
279wxVideoMode wxDisplay::GetCurrentMode() const
280{
281 // Not implemented
282 return wxVideoMode();
283}
284
285bool 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 */