]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/displayx11.cpp
1 ///////////////////////////////////////////////////////////////////////////
2 // Name: displayx11.cpp
3 // Purpose: Unix/X11 implementation of wxDisplay class
4 // Author: Brian Victor
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/display.h"
24 #include "wx/dynarray.h"
25 #include "wx/gdicmn.h"
26 #include "wx/string.h"
28 #endif /* WX_PRECOMP */
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. */
36 #include <X11/Xlibint.h>
37 #include <X11/extensions/Xinerama.h>
38 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
39 #include <X11/extensions/xf86vmode.h>
43 class wxDisplayUnixPriv
50 size_t wxDisplayBase::GetCount()
52 Display
*disp
= (Display
*)wxGetDisplay();
54 if ( XineramaIsActive(disp
) )
56 XineramaScreenInfo
*screenarr
;
58 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
68 int wxDisplayBase::GetFromPoint(const wxPoint
&p
)
70 Display
*disp
= (Display
*)wxGetDisplay();
72 if ( XineramaIsActive(disp
) )
74 int which_screen
= -1;
75 XineramaScreenInfo
*screenarr
;
77 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
80 for (i
= 0; i
< numscreens
; ++i
)
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
)
96 wxSize size
= wxGetDisplaySize();
98 p
.x
< size
.GetWidth() &&
100 p
.y
< size
.GetHeight())
109 wxDisplay::wxDisplay(size_t index
) : wxDisplayBase ( index
), m_priv( new wxDisplayUnixPriv
)
111 Display
*disp
= (Display
*)wxGetDisplay();
113 if ( XineramaIsActive(disp
) )
115 XineramaScreenInfo
*screenarr
;
117 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
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
));
126 wxSize size
= wxGetDisplaySize();
127 m_priv
->m_rect
= wxRect(0, 0, size
.GetWidth(), size
.GetHeight());
128 m_priv
->m_depth
= wxDisplayDepth();
132 wxDisplay::~wxDisplay()
137 wxRect
wxDisplay::GetGeometry() const
139 return m_priv
->m_rect
;
142 int wxDisplay::GetDepth() const
144 return m_priv
->m_depth
;
147 wxString
wxDisplay::GetName() const
149 return wxEmptyString
;
153 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
156 // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
157 // info about xf86 video mode extensions
160 //free private data common to x (usually s3) servers
161 #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
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)
169 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
172 Display
* pDisplay
= (Display
*) wxGetDisplay(); //default display
173 int nScreen
= DefaultScreen(pDisplay
); //default screen of (default) display...
176 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
177 int nNumModes
; //Number of modes enumerated....
179 wxArrayVideoModes Modes
; //modes to return...
181 if (XF86VidModeGetAllModeLines(pDisplay
, nScreen
, &nNumModes
, &ppXModes
) == TRUE
)
183 for (int i
= 0; i
< nNumModes
; ++i
)
185 if (mode
== wxDefaultVideoMode
|| //According to display.h All modes valid if dafault mode...
186 mode
.Matches(wxCVM((*ppXModes
[i
]))) ) //...?
188 Modes
.Add(wxCVM((*ppXModes
[i
])));
190 wxClearXVM((*ppXModes
[i
]));
191 // XFree(ppXModes[i]); //supposed to free?
197 wxLogSysError(_("Failed to enumerate video modes"));
203 wxVideoMode
wxDisplay::GetCurrentMode() const
205 XF86VidModeModeLine VM
;
207 XF86VidModeGetModeLine((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
210 return wxCVM2(VM
, nDotClock
);
213 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
215 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
216 int nNumModes
; //Number of modes enumerated....
218 if( !XF86VidModeGetAllModeLines((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()), &nNumModes
, &ppXModes
) )
220 wxLogSysError(_("Failed to change video mode"));
225 if (mode
== wxDefaultVideoMode
)
227 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
228 ppXModes
[0]) == TRUE
;
230 for (int i
= 0; i
< nNumModes
; ++i
)
232 wxClearXVM((*ppXModes
[i
]));
233 // XFree(ppXModes[i]); //supposed to free?
238 for (int i
= 0; i
< nNumModes
; ++i
)
241 ppXModes
[i
]->hdisplay
== mode
.w
&&
242 ppXModes
[i
]->vdisplay
== mode
.h
&&
243 wxCRR((*ppXModes
[i
])) == mode
.refresh
)
246 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
247 ppXModes
[i
]) == TRUE
;
249 wxClearXVM((*ppXModes
[i
]));
250 // XFree(ppXModes[i]); //supposed to free?
260 #else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
262 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
264 Display
*disp
= (Display
*)wxGetDisplay();
266 int* depths
= XListDepths(disp
, 0, &count_return
);
267 wxArrayVideoModes modes
;
271 for (x
= 0; x
< count_return
; ++x
)
273 modes
.Add(wxVideoMode(m_priv
->m_rect
.GetWidth(), m_priv
->m_rect
.GetHeight(), depths
[x
]));
279 wxVideoMode
wxDisplay::GetCurrentMode() const
282 return wxVideoMode();
285 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
291 #endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H
293 #endif /* wxUSE_DISPLAY */