]>
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. */
37 #include <X11/Xlibint.h>
38 # include <X11/extensions/Xinerama.h>
39 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
40 #include <X11/extensions/xf86vmode.h>
45 class wxDisplayUnixPriv
52 size_t wxDisplayBase::GetCount()
54 Display
*disp
= (Display
*)wxGetDisplay();
57 if ( XineramaIsActive(disp
) )
59 XineramaScreenInfo
*screenarr
;
61 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
72 int wxDisplayBase::GetFromPoint(const wxPoint
&p
)
74 Display
*disp
= (Display
*)wxGetDisplay();
77 if ( XineramaIsActive(disp
) )
79 int which_screen
= -1;
80 XineramaScreenInfo
*screenarr
;
82 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
85 for (i
= 0; i
< numscreens
; ++i
)
87 if (p
.x
>= screenarr
[i
].x_org
&&
88 p
.x
< screenarr
[i
].x_org
+ screenarr
[i
].width
&&
89 p
.y
>= screenarr
[i
].y_org
&&
90 p
.y
< screenarr
[i
].y_org
+ screenarr
[i
].height
)
102 wxSize size
= wxGetDisplaySize();
104 p
.x
< size
.GetWidth() &&
106 p
.y
< size
.GetHeight())
115 wxDisplay::wxDisplay(size_t index
) : wxDisplayBase ( index
), m_priv( new wxDisplayUnixPriv
)
117 Display
*disp
= (Display
*)wxGetDisplay();
120 if ( XineramaIsActive(disp
) )
122 XineramaScreenInfo
*screenarr
;
124 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
126 m_priv
->m_rect
= wxRect(screenarr
[index
].x_org
, screenarr
[index
].y_org
,
127 screenarr
[index
].width
, screenarr
[index
].height
);
128 m_priv
->m_depth
= DefaultDepth(disp
, DefaultScreen(disp
));
134 wxSize size
= wxGetDisplaySize();
135 m_priv
->m_rect
= wxRect(0, 0, size
.GetWidth(), size
.GetHeight());
136 m_priv
->m_depth
= wxDisplayDepth();
140 wxDisplay::~wxDisplay()
145 wxRect
wxDisplay::GetGeometry() const
147 return m_priv
->m_rect
;
150 int wxDisplay::GetDepth() const
152 return m_priv
->m_depth
;
155 wxString
wxDisplay::GetName() const
157 return wxEmptyString
;
161 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
164 // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
165 // info about xf86 video mode extensions
168 //free private data common to x (usually s3) servers
169 #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
171 // Correct res rate from GLFW
172 #define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f)
173 #define wxCRR(v) wxCRR2(v,v.dotclock)
174 #define wxCVM2(v, dc) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay())), wxCRR2(v,dc))
175 #define wxCVM(v) wxCVM2(v, v.dotclock)
177 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
180 Display
* pDisplay
= (Display
*) wxGetDisplay(); //default display
181 int nScreen
= DefaultScreen(pDisplay
); //default screen of (default) display...
184 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
185 int nNumModes
; //Number of modes enumerated....
187 wxArrayVideoModes Modes
; //modes to return...
189 if (XF86VidModeGetAllModeLines(pDisplay
, nScreen
, &nNumModes
, &ppXModes
) == TRUE
)
191 for (int i
= 0; i
< nNumModes
; ++i
)
193 if (mode
== wxDefaultVideoMode
|| //According to display.h All modes valid if dafault mode...
194 mode
.Matches(wxCVM((*ppXModes
[i
]))) ) //...?
196 Modes
.Add(wxCVM((*ppXModes
[i
])));
198 wxClearXVM((*ppXModes
[i
]));
199 // XFree(ppXModes[i]); //supposed to free?
205 wxLogSysError(_("Failed to enumerate video modes"));
211 wxVideoMode
wxDisplay::GetCurrentMode() const
213 XF86VidModeModeLine VM
;
215 XF86VidModeGetModeLine((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
218 return wxCVM2(VM
, nDotClock
);
221 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
223 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
224 int nNumModes
; //Number of modes enumerated....
226 if( !XF86VidModeGetAllModeLines((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()), &nNumModes
, &ppXModes
) )
228 wxLogSysError(_("Failed to change video mode"));
233 if (mode
== wxDefaultVideoMode
)
235 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
236 ppXModes
[0]) == TRUE
;
238 for (int i
= 0; i
< nNumModes
; ++i
)
240 wxClearXVM((*ppXModes
[i
]));
241 // XFree(ppXModes[i]); //supposed to free?
246 for (int i
= 0; i
< nNumModes
; ++i
)
249 ppXModes
[i
]->hdisplay
== mode
.w
&&
250 ppXModes
[i
]->vdisplay
== mode
.h
&&
251 wxCRR((*ppXModes
[i
])) == mode
.refresh
)
254 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
255 ppXModes
[i
]) == TRUE
;
257 wxClearXVM((*ppXModes
[i
]));
258 // XFree(ppXModes[i]); //supposed to free?
268 #else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
270 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
272 Display
*disp
= (Display
*)wxGetDisplay();
274 int* depths
= XListDepths(disp
, 0, &count_return
);
275 wxArrayVideoModes modes
;
279 for (x
= 0; x
< count_return
; ++x
)
281 modes
.Add(wxVideoMode(m_priv
->m_rect
.GetWidth(), m_priv
->m_rect
.GetHeight(), depths
[x
]));
287 wxVideoMode
wxDisplay::GetCurrentMode() const
290 return wxVideoMode();
293 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
299 #endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H
301 #endif /* wxUSE_DISPLAY */