]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/displayx11.cpp
0a3a132c67353d5b5250a34c9105dba664354629
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"
27 #include "wx/dynarray.h"
28 #include "wx/gdicmn.h"
29 #include "wx/string.h"
31 #endif /* WX_PRECOMP */
35 /* These must be included after the wx files. Otherwise the Data macro in
36 * Xlibint.h conflicts with a function declaration in wx/list.h. */
39 #include <X11/Xlibint.h>
40 #include <X11/extensions/Xinerama.h>
41 #include <X11/extensions/xf86vmode.h>
44 class wxDisplayUnixPriv
51 size_t wxDisplayBase::GetCount()
53 Display
*disp
= (Display
*)wxGetDisplay();
55 if ( XineramaIsActive(disp
) )
57 XineramaScreenInfo
*screenarr
;
59 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
69 int wxDisplayBase::GetFromPoint(const wxPoint
&p
)
71 Display
*disp
= (Display
*)wxGetDisplay();
73 if ( XineramaIsActive(disp
) )
75 int which_screen
= -1;
76 XineramaScreenInfo
*screenarr
;
78 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
81 for (i
= 0; i
< numscreens
; ++i
)
83 if (p
.x
>= screenarr
[i
].x_org
&&
84 p
.x
< screenarr
[i
].x_org
+ screenarr
[i
].width
&&
85 p
.y
>= screenarr
[i
].y_org
&&
86 p
.y
< screenarr
[i
].y_org
+ screenarr
[i
].height
)
97 wxSize size
= wxGetDisplaySize();
99 p
.x
< size
.GetWidth() &&
101 p
.y
< size
.GetHeight())
110 wxDisplay::wxDisplay(size_t index
) : wxDisplayBase ( index
), m_priv( new wxDisplayUnixPriv
)
112 Display
*disp
= (Display
*)wxGetDisplay();
114 if ( XineramaIsActive(disp
) )
116 XineramaScreenInfo
*screenarr
;
118 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 // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
154 // info about xf86 video mode extensions
157 //free private data common to x (usually s3) servers
158 #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
160 //Correct res rate from GLFW, which probably has the perfect license :)
161 #define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f)
162 #define wxCRR(v) wxCRR2(v,v.dotclock)
163 #define wxCVM2(v, dc) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay())), wxCRR2(v,dc))
164 #define wxCVM(v) wxCVM2(v, v.dotclock)
166 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
169 Display
* pDisplay
= (Display
*) wxGetDisplay(); //default display
170 int nScreen
= DefaultScreen(pDisplay
); //default screen of (default) display...
173 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
174 int nNumModes
; //Number of modes enumerated....
176 wxArrayVideoModes Modes
; //modes to return...
178 if (XF86VidModeGetAllModeLines(pDisplay
, nScreen
, &nNumModes
, &ppXModes
) == TRUE
)
180 for (int i
= 0; i
< nNumModes
; ++i
)
182 if (mode
== wxDefaultVideoMode
|| //According to display.h All modes valid if dafault mode...
183 mode
.Matches(wxCVM((*ppXModes
[i
]))) ) //...?
185 Modes
.Add(wxCVM((*ppXModes
[i
])));
187 wxClearXVM((*ppXModes
[i
]));
188 // XFree(ppXModes[i]); //supposed to free?
194 wxLogSysError("XF86VidModeGetAllModeLines Failed in wxX11Display::GetModes()!");
200 wxVideoMode
wxDisplay::GetCurrentMode() const
202 XF86VidModeModeLine VM
;
204 XF86VidModeGetModeLine((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
207 return wxCVM2(VM
, nDotClock
);
210 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
212 //This gets kind of tricky AND complicated :) :\ :( :)
216 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
217 int nNumModes
; //Number of modes enumerated....
219 if(XF86VidModeGetAllModeLines((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()), &nNumModes
, &ppXModes
) == TRUE
)
221 if (mode
== wxDefaultVideoMode
)
223 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
224 ppXModes
[0]) == TRUE
;
226 for (int i
= 0; i
< nNumModes
; ++i
)
228 wxClearXVM((*ppXModes
[i
]));
229 // XFree(ppXModes[i]); //supposed to free?
235 for (int i
= 0; i
< nNumModes
; ++i
)
238 ppXModes
[i
]->hdisplay
== mode
.w
&&
239 ppXModes
[i
]->vdisplay
== mode
.h
&&
240 wxCRR((*ppXModes
[i
])) == mode
.refresh
)
243 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
244 ppXModes
[i
]) == TRUE
;
246 wxClearXVM((*ppXModes
[i
]));
247 // XFree(ppXModes[i]); //supposed to free?
255 wxLogSysError("XF86VidModeGetAllModeLines Failed in wxX11Display::ChangeMode()!");
260 //Brian Victor's patch (X11 can't change bit depth yet), here for reference
261 Display *disp = (Display*)wxGetDisplay();
263 int* depths = XListDepths(disp, 0, &count_return);
264 wxArrayVideoModes modes;
268 for (x = 0; x < count_return; ++x)
270 modes.Add(wxVideoMode(m_priv->m_rect.GetWidth(), m_priv->m_rect.GetHeight(), depths[x]));
277 #endif /* wxUSE_DISPLAY */