Extract X11 functions used by wxGTK in a separate header

This makes src/unix/displayx11.cpp almost readable as it's not littered
by "#ifndef __WXGTK20__" checks everywhere any more -- instead this file
is just not compiled as part of wxGTK2 at all any longer (it is still
included in wxGTK1 as well as wxX11 itself and wxMotif).

wxGTK code also can just include the new wx/unix/private/displayx11.h
instead of having to declare all the X11 functions it uses manually.

There should be no changes in behaviour, this is just a clean up.
This commit is contained in:
Vadim Zeitlin
2018-10-04 17:07:11 +02:00
parent c38a8f960e
commit e0ba727dec
7 changed files with 284 additions and 365 deletions

View File

@@ -29,17 +29,8 @@
#include "wx/log.h"
#endif /* WX_PRECOMP */
#ifdef __WXGTK20__
#include <gdk/gdk.h> // GDK_WINDOWING_X11
#endif
#if !defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#include "wx/private/display.h"
#ifndef __WXGTK20__
#include "wx/unix/private/displayx11.h"
static wxRect wxGetMainScreenWorkArea();
@@ -70,12 +61,8 @@ protected:
}
};
#endif // !__WXGTK20__
#if wxUSE_DISPLAY
#ifndef __WXGTK20__
#include <X11/extensions/Xinerama.h>
typedef XineramaScreenInfo ScreenInfo;
@@ -189,118 +176,13 @@ wxDisplayImpl *wxDisplayFactoryX11::CreateDisplay(unsigned n)
return n < screens.GetCount() ? new wxDisplayImplX11(n, screens[n]) : NULL;
}
#endif // !__WXGTK20__
// ============================================================================
// wxDisplayImplX11 implementation
// ============================================================================
#if !defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)
#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
#include <X11/extensions/xf86vmode.h>
//
// See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
// info about xf86 video mode extensions
//
//free private data common to x (usually s3) servers
#define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
// Correct res rate from GLFW
#define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f)
#define wxCRR(v) wxCRR2(v,v.dotclock)
#define wxCVM2(v, dc, display, nScreen) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth(display, nScreen), wxCRR2(v,dc))
#define wxCVM(v, display, nScreen) wxCVM2(v, v.dotclock, display, nScreen)
wxArrayVideoModes wxXF86VidMode_GetModes(const wxVideoMode& mode, Display* display, int nScreen)
{
XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :))
int nNumModes; //Number of modes enumerated....
wxArrayVideoModes Modes; //modes to return...
if (XF86VidModeGetAllModeLines(display, nScreen, &nNumModes, &ppXModes))
{
for (int i = 0; i < nNumModes; ++i)
{
XF86VidModeModeInfo& info = *ppXModes[i];
const wxVideoMode vm = wxCVM(info, display, nScreen);
if (vm.Matches(mode))
{
Modes.Add(vm);
}
wxClearXVM(info);
// XFree(ppXModes[i]); //supposed to free?
}
XFree(ppXModes);
}
else //OOPS!
{
wxLogSysError(_("Failed to enumerate video modes"));
}
return Modes;
}
wxVideoMode wxXF86VidMode_GetCurrentMode(Display* display, int nScreen)
{
XF86VidModeModeLine VM;
int nDotClock;
if ( !XF86VidModeGetModeLine(display, nScreen, &nDotClock, &VM) )
return wxVideoMode();
wxClearXVM(VM);
return wxCVM2(VM, nDotClock, display, nScreen);
}
bool wxXF86VidMode_ChangeMode(const wxVideoMode& mode, Display* display, int nScreen)
{
XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :))
int nNumModes; //Number of modes enumerated....
if(!XF86VidModeGetAllModeLines(display, nScreen, &nNumModes, &ppXModes))
{
wxLogSysError(_("Failed to change video mode"));
return false;
}
bool bRet = false;
if (mode == wxDefaultVideoMode)
{
bRet = XF86VidModeSwitchToMode(display, nScreen, ppXModes[0]) != 0;
for (int i = 0; i < nNumModes; ++i)
{
wxClearXVM((*ppXModes[i]));
// XFree(ppXModes[i]); //supposed to free?
}
}
else
{
for (int i = 0; i < nNumModes; ++i)
{
if (!bRet &&
ppXModes[i]->hdisplay == mode.GetWidth() &&
ppXModes[i]->vdisplay == mode.GetHeight() &&
wxCRR((*ppXModes[i])) == mode.GetRefresh())
{
//switch!
bRet = XF86VidModeSwitchToMode(display, nScreen, ppXModes[i]) != 0;
}
wxClearXVM((*ppXModes[i]));
// XFree(ppXModes[i]); //supposed to free?
}
}
XFree(ppXModes);
return bRet;
}
#ifndef __WXGTK20__
wxArrayVideoModes wxDisplayImplX11::GetModes(const wxVideoMode& modeMatch) const
{
Display* display = static_cast<Display*>(wxGetDisplay());
@@ -321,33 +203,9 @@ bool wxDisplayImplX11::ChangeMode(const wxVideoMode& mode)
int nScreen = DefaultScreen(display);
return wxXF86VidMode_ChangeMode(mode, display, nScreen);
}
#endif // !__WXGTK20__
#else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
wxArrayVideoModes wxX11_GetModes(const wxDisplayImpl* impl, const wxVideoMode& modeMatch, Display* display)
{
int count_return;
int* depths = XListDepths(display, 0, &count_return);
wxArrayVideoModes modes;
if ( depths )
{
const wxRect rect = impl->GetGeometry();
for ( int x = 0; x < count_return; ++x )
{
wxVideoMode mode(rect.width, rect.height, depths[x]);
if ( mode.Matches(modeMatch) )
{
modes.Add(mode);
}
}
XFree(depths);
}
return modes;
}
#ifndef __WXGTK20__
wxArrayVideoModes wxDisplayImplX11::GetModes(const wxVideoMode& modeMatch) const
{
Display* display = static_cast<Display*>(wxGetDisplay());
@@ -365,16 +223,15 @@ bool wxDisplayImplX11::ChangeMode(const wxVideoMode& WXUNUSED(mode))
// Not implemented
return false;
}
#endif // !__WXGTK20__
#endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H
#endif // !defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)
#endif // wxUSE_DISPLAY
// ============================================================================
// wxDisplay::CreateFactory()
// ============================================================================
#ifndef __WXGTK20__
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{
#if wxUSE_DISPLAY
@@ -384,40 +241,6 @@ bool wxDisplayImplX11::ChangeMode(const wxVideoMode& WXUNUSED(mode))
return new wxDisplayFactorySingleX11;
}
#endif
#if !defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)
void wxGetWorkAreaX11(Screen* screen, int& x, int& y, int& width, int& height)
{
Display* display = DisplayOfScreen(screen);
Atom property = XInternAtom(display, "_NET_WORKAREA", true);
if (property)
{
Atom actual_type;
int actual_format;
unsigned long nitems;
unsigned long bytes_after;
unsigned char* data = NULL;
Status status = XGetWindowProperty(
display, RootWindowOfScreen(screen), property,
0, 4, false, XA_CARDINAL,
&actual_type, &actual_format, &nitems, &bytes_after, &data);
if (status == Success && actual_type == XA_CARDINAL &&
actual_format == 32 && nitems == 4)
{
const long* p = (long*)data;
x = p[0];
y = p[1];
width = p[2];
height = p[3];
}
if (data)
XFree(data);
}
}
#endif // !defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)
#ifndef __WXGTK20__
wxRect wxGetMainScreenWorkArea()
{
@@ -447,5 +270,3 @@ wxRect wxGetMainScreenWorkArea()
return rect;
}
#endif // !__WXGTK20__