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 //free private data common to x (usually s3) servers
45 #define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
46 class wxDisplayUnixPriv
51 XF86VidModeModeInfo m_DefaultVidMode
;
54 wxClearXVM(m_DefaultVidMode
);
58 size_t wxDisplayBase::GetCount()
60 Display
*disp
= (Display
*)wxGetDisplay();
62 if ( XineramaIsActive(disp
) )
64 XineramaScreenInfo
*screenarr
;
66 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
76 int wxDisplayBase::GetFromPoint(const wxPoint
&p
)
78 Display
*disp
= (Display
*)wxGetDisplay();
80 if ( XineramaIsActive(disp
) )
82 int which_screen
= -1;
83 XineramaScreenInfo
*screenarr
;
85 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
88 for (i
= 0; i
< numscreens
; ++i
)
90 if (p
.x
>= screenarr
[i
].x_org
&&
91 p
.x
<= screenarr
[i
].x_org
+ screenarr
[i
].width
&&
92 p
.y
>= screenarr
[i
].y_org
&&
93 p
.y
<= screenarr
[i
].y_org
+ screenarr
[i
].height
)
104 wxSize size
= wxGetDisplaySize();
106 p
.x
<= size
.GetWidth() &&
108 p
.y
<= size
.GetHeight())
118 wxDisplay::wxDisplay(size_t index
) : wxDisplayBase ( index
), m_priv( new wxDisplayUnixPriv
)
120 Display
*disp
= (Display
*)wxGetDisplay();
122 if ( XineramaIsActive(disp
) )
124 XineramaScreenInfo
*screenarr
;
126 screenarr
= XineramaQueryScreens(disp
, &numscreens
);
127 m_priv
->m_rect
= wxRect(screenarr
[index
].x_org
, screenarr
[index
].y_org
,
128 screenarr
[index
].width
, screenarr
[index
].height
);
129 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 XF86VidModeModeLine VM
;
143 XF86VidModeGetModeLine((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
146 //A XF86VidModeModeLine is a XF86ModeModeInfo without the dotclock
147 //field. It would be nice to mayby use a memcpy() here instead of
149 m_priv
->m_DefaultVidMode
.dotclock
= nDotClock
;
150 m_priv
->m_DefaultVidMode
.hdisplay
= VM
.hdisplay
;
151 m_priv
->m_DefaultVidMode
.hsyncstart
= VM
.hsyncstart
;
152 m_priv
->m_DefaultVidMode
.hsyncend
= VM
.hsyncend
;
153 m_priv
->m_DefaultVidMode
.htotal
= VM
.htotal
;
154 m_priv
->m_DefaultVidMode
.hskew
= VM
.hskew
;
155 m_priv
->m_DefaultVidMode
.vdisplay
= VM
.vdisplay
;
156 m_priv
->m_DefaultVidMode
.vsyncstart
= VM
.vsyncstart
;
157 m_priv
->m_DefaultVidMode
.vsyncend
= VM
.vsyncend
;
158 m_priv
->m_DefaultVidMode
.vtotal
= VM
.vtotal
;
159 m_priv
->m_DefaultVidMode
.flags
= VM
.flags
;
160 m_priv
->m_DefaultVidMode
.privsize
= VM
.privsize
;
161 m_priv
->m_DefaultVidMode
.c_private
= VM
.c_private
;
164 wxDisplay::~wxDisplay()
169 wxRect
wxDisplay::GetGeometry() const
171 return m_priv
->m_rect
;
174 int wxDisplay::GetDepth() const
176 return m_priv
->m_depth
;
179 wxString
wxDisplay::GetName() const
181 return wxEmptyString
;
185 // See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
186 // info about xf86 video mode extensions
189 #define wxCVM(v) wxVideoMode(v.hdisplay, v.vdisplay, v.dotclock /*BPP in X? */,((v.hsyncstart + v.vsyncstart) / 2) )
190 #define wxCVM2(v) wxVideoMode(v.hdisplay, v.vdisplay, 0 /*BPP in X? */,((v.hsyncstart + v.vsyncstart) / 2) )
192 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
195 Display
* pDisplay
= (Display
*) wxGetDisplay(); //default display
196 int nScreen
= DefaultScreen(pDisplay
); //default screen of (default) display...
199 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
200 int nNumModes
; //Number of modes enumerated....
202 wxArrayVideoModes Modes
; //modes to return...
204 if (XF86VidModeGetAllModeLines(pDisplay
, nScreen
, &nNumModes
, &ppXModes
) == TRUE
)
206 for (int i
= 0; i
< nNumModes
; ++i
)
208 if (mode
== wxDefaultVideoMode
|| //According to display.h All modes valid if dafault mode...
209 mode
.Matches(wxCVM2((*ppXModes
[i
]))) ) //...?
211 Modes
.Add(wxCVM2((*ppXModes
[i
])));
213 wxClearXVM((*ppXModes
[i
]));
214 // XFree(ppXModes[i]); //supposed to free?
220 wxLogSysError("XF86VidModeGetAllModeLines Failed in wxX11Display::GetModes()!");
226 wxVideoMode
wxDisplay::GetCurrentMode() const
228 return wxCVM2(m_priv
->m_DefaultVidMode
);
231 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
233 if (mode
== wxDefaultVideoMode
)
235 return XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
236 &m_priv
->m_DefaultVidMode
) == TRUE
;
238 else //This gets kind of tricky AND complicated :) :\ :( :)
242 XF86VidModeModeInfo
** ppXModes
; //Enumerated Modes (Don't forget XFree() :))
243 int nNumModes
; //Number of modes enumerated....
245 if(XF86VidModeGetAllModeLines((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()), &nNumModes
, &ppXModes
) == TRUE
)
247 for (int i
= 0; i
< nNumModes
; ++i
)
250 ppXModes
[i
]->hdisplay
== mode
.w
&&
251 ppXModes
[i
]->vdisplay
== mode
.h
&&
252 ((ppXModes
[i
]->hsyncstart
+ ppXModes
[i
]->vsyncstart
) / 2) == mode
.refresh
)
255 bRet
= XF86VidModeSwitchToMode((Display
*)wxGetDisplay(), DefaultScreen((Display
*)wxGetDisplay()),
256 ppXModes
[i
]) == TRUE
;
258 wxClearXVM((*ppXModes
[i
]));
259 // XFree(ppXModes[i]); //supposed to free?
267 wxLogSysError("XF86VidModeGetAllModeLines Failed in wxX11Display::ChangeMode()!");
273 #endif /* wxUSE_DISPLAY */