]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/displayx11.cpp
c19c2c2f60d4aea265dd7b038e3c1718357386ea
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 #include <X11/extensions/xf86vmode.h>
45 class wxDisplayUnixPriv
52 size_t wxDisplayBase::GetCount()
54 Display
*disp
= (Display
*)wxGetDisplay();
56 if ( XineramaIsActive(disp
) )
58 XineramaScreenInfo
*screenarr
;
60 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
70 int wxDisplayBase::GetFromPoint(const wxPoint
&p
)
72 Display
*disp
= (Display
*)wxGetDisplay();
74 if ( XineramaIsActive(disp
) )
76 int which_screen
= -1;
77 XineramaScreenInfo
*screenarr
;
79 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
82 for (i
= 0; i
< numscreens
; ++i
)
84 if (p
.x
>= screenarr
[i
].x_org
&&
85 p
.x
< screenarr
[i
].x_org
+ screenarr
[i
].width
&&
86 p
.y
>= screenarr
[i
].y_org
&&
87 p
.y
< screenarr
[i
].y_org
+ screenarr
[i
].height
)
98 wxSize size
= wxGetDisplaySize();
100 p
.x
< size
.GetWidth() &&
102 p
.y
< size
.GetHeight())
111 wxDisplay::wxDisplay(size_t index
) : wxDisplayBase ( index
), m_priv( new wxDisplayUnixPriv
)
113 Display
*disp
= (Display
*)wxGetDisplay();
115 if ( XineramaIsActive(disp
) )
117 XineramaScreenInfo
*screenarr
;
119 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
120 m_priv
->m_rect
= wxRect(screenarr
[index
].x_org
, screenarr
[index
].y_org
,
121 screenarr
[index
].width
, screenarr
[index
].height
);
122 m_priv
->m_depth
= DefaultDepth(disp
, DefaultScreen(disp
));
127 wxSize size
= wxGetDisplaySize();
128 m_priv
->m_rect
= wxRect(0, 0, size
.GetWidth(), size
.GetHeight());
129 m_priv
->m_depth
= wxDisplayDepth();
133 wxDisplay::~wxDisplay()
138 wxRect
wxDisplay::GetGeometry() const
140 return m_priv
->m_rect
;
143 int wxDisplay::GetDepth() const
145 return m_priv
->m_depth
;
148 wxString
wxDisplay::GetName() const
150 return wxEmptyString
;
154 // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
155 // info about xf86 video mode extensions
158 //free private data common to x (usually s3) servers
159 #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
161 //Correct res rate from GLFW, which probably has the perfect license :)
162 #define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f)
163 #define wxCRR(v) wxCRR2(v,v.dotclock)
164 #define wxCVM2(v, dc) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth((Display*)wxGetDisplay(), DefaultScreen((Display*)wxGetDisplay())), wxCRR2(v,dc))
165 #define wxCVM(v) wxCVM2(v, v.dotclock)
167 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
170 Display
* pDisplay
= (Display
*) wxGetDisplay(); //default display
171 int nScreen
= DefaultScreen(pDisplay
); //default screen of (default) display...
174 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
175 int nNumModes
; //Number of modes enumerated....
177 wxArrayVideoModes Modes
; //modes to return...
179 if (XF86VidModeGetAllModeLines(pDisplay
, nScreen
, &nNumModes
, &ppXModes
) == TRUE
)
181 for (int i
= 0; i
< nNumModes
; ++i
)
183 if (mode
== wxDefaultVideoMode
|| //According to display.h All modes valid if dafault mode...
184 mode
.Matches(wxCVM((*ppXModes
[i
]))) ) //...?
186 Modes
.Add(wxCVM((*ppXModes
[i
])));
188 wxClearXVM((*ppXModes
[i
]));
189 // XFree(ppXModes[i]); //supposed to free?
195 wxLogSysError(_("Failed to enumerate video modes"));
201 wxVideoMode
wxDisplay::GetCurrentMode() const
203 XF86VidModeModeLine VM
;
205 XF86VidModeGetModeLine((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
208 return wxCVM2(VM
, nDotClock
);
211 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
213 //This gets kind of tricky AND complicated :) :\ :( :)
217 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
218 int nNumModes
; //Number of modes enumerated....
220 if(XF86VidModeGetAllModeLines((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()), &nNumModes
, &ppXModes
) == TRUE
)
222 if (mode
== wxDefaultVideoMode
)
224 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
225 ppXModes
[0]) == TRUE
;
227 for (int i
= 0; i
< nNumModes
; ++i
)
229 wxClearXVM((*ppXModes
[i
]));
230 // XFree(ppXModes[i]); //supposed to free?
236 for (int i
= 0; i
< nNumModes
; ++i
)
239 ppXModes
[i
]->hdisplay
== mode
.w
&&
240 ppXModes
[i
]->vdisplay
== mode
.h
&&
241 wxCRR((*ppXModes
[i
])) == mode
.refresh
)
244 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
245 ppXModes
[i
]) == TRUE
;
247 wxClearXVM((*ppXModes
[i
]));
248 // XFree(ppXModes[i]); //supposed to free?
256 wxLogSysError(_("Failed to change video mode"));
261 //Brian Victor's patch (X11 can't change bit depth yet), here for reference
262 Display *disp = (Display*)wxGetDisplay();
264 int* depths = XListDepths(disp, 0, &count_return);
265 wxArrayVideoModes modes;
269 for (x = 0; x < count_return; ++x)
271 modes.Add(wxVideoMode(m_priv->m_rect.GetWidth(), m_priv->m_rect.GetHeight(), depths[x]));
278 #endif /* wxUSE_DISPLAY */