]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/displayx11.cpp
93e52b192d86da24d77c352893c51aa2b6357198
1 ///////////////////////////////////////////////////////////////////////////
2 // Name: displayx11.cpp
3 // Purpose: Unix/X11 implementation of wxDisplay class
4 // Author: Brian Victor
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "display.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/display.h"
28 #include "wx/dynarray.h"
29 #include "wx/gdicmn.h"
30 #include "wx/string.h"
32 #endif /* WX_PRECOMP */
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. */
40 #include <X11/Xlibint.h>
41 #include <X11/extensions/Xinerama.h>
42 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
43 #include <X11/extensions/xf86vmode.h>
47 class wxDisplayUnixPriv
54 size_t wxDisplayBase::GetCount()
56 Display
*disp
= (Display
*)wxGetDisplay();
58 if ( XineramaIsActive(disp
) )
60 XineramaScreenInfo
*screenarr
;
62 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
72 int wxDisplayBase::GetFromPoint(const wxPoint
&p
)
74 Display
*disp
= (Display
*)wxGetDisplay();
76 if ( XineramaIsActive(disp
) )
78 int which_screen
= -1;
79 XineramaScreenInfo
*screenarr
;
81 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
84 for (i
= 0; i
< numscreens
; ++i
)
86 if (p
.x
>= screenarr
[i
].x_org
&&
87 p
.x
< screenarr
[i
].x_org
+ screenarr
[i
].width
&&
88 p
.y
>= screenarr
[i
].y_org
&&
89 p
.y
< screenarr
[i
].y_org
+ screenarr
[i
].height
)
100 wxSize size
= wxGetDisplaySize();
102 p
.x
< size
.GetWidth() &&
104 p
.y
< size
.GetHeight())
113 wxDisplay::wxDisplay(size_t index
) : wxDisplayBase ( index
), m_priv( new wxDisplayUnixPriv
)
115 Display
*disp
= (Display
*)wxGetDisplay();
117 if ( XineramaIsActive(disp
) )
119 XineramaScreenInfo
*screenarr
;
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
));
129 wxSize size
= wxGetDisplaySize();
130 m_priv
->m_rect
= wxRect(0, 0, size
.GetWidth(), size
.GetHeight());
131 m_priv
->m_depth
= wxDisplayDepth();
135 wxDisplay::~wxDisplay()
140 wxRect
wxDisplay::GetGeometry() const
142 return m_priv
->m_rect
;
145 int wxDisplay::GetDepth() const
147 return m_priv
->m_depth
;
150 wxString
wxDisplay::GetName() const
152 return wxEmptyString
;
156 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
159 // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
160 // info about xf86 video mode extensions
163 //free private data common to x (usually s3) servers
164 #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
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)
172 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
175 Display
* pDisplay
= (Display
*) wxGetDisplay(); //default display
176 int nScreen
= DefaultScreen(pDisplay
); //default screen of (default) display...
179 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
180 int nNumModes
; //Number of modes enumerated....
182 wxArrayVideoModes Modes
; //modes to return...
184 if (XF86VidModeGetAllModeLines(pDisplay
, nScreen
, &nNumModes
, &ppXModes
) == TRUE
)
186 for (int i
= 0; i
< nNumModes
; ++i
)
188 if (mode
== wxDefaultVideoMode
|| //According to display.h All modes valid if dafault mode...
189 mode
.Matches(wxCVM((*ppXModes
[i
]))) ) //...?
191 Modes
.Add(wxCVM((*ppXModes
[i
])));
193 wxClearXVM((*ppXModes
[i
]));
194 // XFree(ppXModes[i]); //supposed to free?
200 wxLogSysError(_("Failed to enumerate video modes"));
206 wxVideoMode
wxDisplay::GetCurrentMode() const
208 XF86VidModeModeLine VM
;
210 XF86VidModeGetModeLine((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
213 return wxCVM2(VM
, nDotClock
);
216 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
218 //This gets kind of tricky AND complicated :) :\ :( :)
222 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
223 int nNumModes
; //Number of modes enumerated....
225 if(XF86VidModeGetAllModeLines((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()), &nNumModes
, &ppXModes
) == TRUE
)
227 if (mode
== wxDefaultVideoMode
)
229 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
230 ppXModes
[0]) == TRUE
;
232 for (int i
= 0; i
< nNumModes
; ++i
)
234 wxClearXVM((*ppXModes
[i
]));
235 // XFree(ppXModes[i]); //supposed to free?
241 for (int i
= 0; i
< nNumModes
; ++i
)
244 ppXModes
[i
]->hdisplay
== mode
.w
&&
245 ppXModes
[i
]->vdisplay
== mode
.h
&&
246 wxCRR((*ppXModes
[i
])) == mode
.refresh
)
249 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
250 ppXModes
[i
]) == TRUE
;
252 wxClearXVM((*ppXModes
[i
]));
253 // XFree(ppXModes[i]); //supposed to free?
261 wxLogSysError(_("Failed to change video mode"));
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 */