Add a separate GTK-specific wxDisplay implementation.
This separates the GTK implementation from Unix/X11, except for the wxVideoMode stuff, and _NET_WORKAREA when GTK < 3.4. wxDisplay and wxClientDisplayRect() should now work as well as they can with Wayland. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76365 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -23,55 +23,35 @@
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
|
||||
#include "wx/display.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/intl.h"
|
||||
#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
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
|
||||
#include "wx/display.h"
|
||||
#include "wx/display_impl.h"
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
// define the struct with the same fields as XineramaScreenInfo (except for
|
||||
// screen number which we don't need) but which we can use without
|
||||
// including Xinerama headers
|
||||
struct ScreenInfo
|
||||
{
|
||||
short x_org;
|
||||
short y_org;
|
||||
short width;
|
||||
short height;
|
||||
};
|
||||
#else // use raw Xinerama functions
|
||||
/* These must be included after the wx files. Otherwise the Data macro in
|
||||
* Xlibint.h conflicts with a function declaration in wx/list.h. */
|
||||
extern "C"
|
||||
{
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xlibint.h>
|
||||
#ifndef __WXGTK20__
|
||||
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
}
|
||||
|
||||
typedef XineramaScreenInfo ScreenInfo;
|
||||
#endif // GTK+/Xinerama
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper class storing information about all screens
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// the base class provides access to ScreenInfo array, derived class
|
||||
// initializes it using either GTK+ or Xinerama functions
|
||||
class ScreensInfoBase
|
||||
{
|
||||
public:
|
||||
@@ -84,36 +64,6 @@ protected:
|
||||
int m_num;
|
||||
};
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
|
||||
class ScreensInfo : public ScreensInfoBase
|
||||
{
|
||||
public:
|
||||
ScreensInfo()
|
||||
{
|
||||
GdkScreen * const screen = gdk_screen_get_default();
|
||||
|
||||
m_num = gdk_screen_get_n_monitors(screen);
|
||||
m_screens = new ScreenInfo[m_num];
|
||||
for ( int i = 0; i < m_num; i++ )
|
||||
{
|
||||
GdkRectangle rect;
|
||||
gdk_screen_get_monitor_geometry(screen, i, &rect);
|
||||
m_screens[i].x_org = rect.x;
|
||||
m_screens[i].y_org = rect.y;
|
||||
m_screens[i].width = rect.width;
|
||||
m_screens[i].height = rect.height;
|
||||
}
|
||||
}
|
||||
|
||||
~ScreensInfo()
|
||||
{
|
||||
delete [] m_screens;
|
||||
}
|
||||
};
|
||||
|
||||
#else // Xinerama
|
||||
|
||||
class ScreensInfo : public ScreensInfoBase
|
||||
{
|
||||
public:
|
||||
@@ -128,8 +78,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif // GTK+/Xinerama
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// display and display factory classes
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -211,11 +159,14 @@ 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>
|
||||
@@ -234,13 +185,8 @@ wxDisplayImpl *wxDisplayFactoryX11::CreateDisplay(unsigned n)
|
||||
#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 wxDisplayImplX11::GetModes(const wxVideoMode& mode) const
|
||||
wxArrayVideoModes wxXF86VidMode_GetModes(const wxVideoMode& mode, Display* display, int nScreen)
|
||||
{
|
||||
//Convenience...
|
||||
Display* display = (Display*) wxGetDisplay(); //default display
|
||||
int nScreen = DefaultScreen(display); //default screen of (default) display...
|
||||
|
||||
//Some variables..
|
||||
XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :))
|
||||
int nNumModes; //Number of modes enumerated....
|
||||
|
||||
@@ -269,10 +215,8 @@ wxArrayVideoModes wxDisplayImplX11::GetModes(const wxVideoMode& mode) const
|
||||
return Modes;
|
||||
}
|
||||
|
||||
wxVideoMode wxDisplayImplX11::GetCurrentMode() const
|
||||
wxVideoMode wxXF86VidMode_GetCurrentMode(Display* display, int nScreen)
|
||||
{
|
||||
Display* display = static_cast<Display*>(wxGetDisplay());
|
||||
int nScreen = DefaultScreen(display);
|
||||
XF86VidModeModeLine VM;
|
||||
int nDotClock;
|
||||
XF86VidModeGetModeLine(display, nScreen, &nDotClock, &VM);
|
||||
@@ -280,10 +224,8 @@ wxVideoMode wxDisplayImplX11::GetCurrentMode() const
|
||||
return wxCVM2(VM, nDotClock, display, nScreen);
|
||||
}
|
||||
|
||||
bool wxDisplayImplX11::ChangeMode(const wxVideoMode& mode)
|
||||
bool wxXF86VidMode_ChangeMode(const wxVideoMode& mode, Display* display, int nScreen)
|
||||
{
|
||||
Display* display = static_cast<Display*>(wxGetDisplay());
|
||||
int nScreen = DefaultScreen(display);
|
||||
XF86VidModeModeInfo** ppXModes; //Enumerated Modes (Don't forget XFree() :))
|
||||
int nNumModes; //Number of modes enumerated....
|
||||
|
||||
@@ -326,18 +268,42 @@ bool wxDisplayImplX11::ChangeMode(const wxVideoMode& mode)
|
||||
return bRet;
|
||||
}
|
||||
|
||||
#else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
|
||||
|
||||
#ifndef __WXGTK20__
|
||||
wxArrayVideoModes wxDisplayImplX11::GetModes(const wxVideoMode& modeMatch) const
|
||||
{
|
||||
Display* display = static_cast<Display*>(wxGetDisplay());
|
||||
int nScreen = DefaultScreen(display);
|
||||
return wxXF86VidMode_GetModes(modeMatch, display, nScreen);
|
||||
}
|
||||
|
||||
wxVideoMode wxDisplayImplX11::GetCurrentMode() const
|
||||
{
|
||||
Display* display = static_cast<Display*>(wxGetDisplay());
|
||||
int nScreen = DefaultScreen(display);
|
||||
return wxXF86VidMode_GetCurrentMode(display, nScreen);
|
||||
}
|
||||
|
||||
bool wxDisplayImplX11::ChangeMode(const wxVideoMode& mode)
|
||||
{
|
||||
Display* display = static_cast<Display*>(wxGetDisplay());
|
||||
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*)wxGetDisplay(), 0, &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(m_rect.GetWidth(), m_rect.GetHeight(), depths[x]);
|
||||
wxVideoMode mode(rect.width, rect.height, depths[x]);
|
||||
if ( mode.Matches(modeMatch) )
|
||||
{
|
||||
modes.Add(mode);
|
||||
@@ -349,6 +315,13 @@ wxArrayVideoModes wxDisplayImplX11::GetModes(const wxVideoMode& modeMatch) const
|
||||
return modes;
|
||||
}
|
||||
|
||||
#ifndef __WXGTK20__
|
||||
wxArrayVideoModes wxDisplayImplX11::GetModes(const wxVideoMode& modeMatch) const
|
||||
{
|
||||
Display* display = static_cast<Display*>(wxGetDisplay());
|
||||
return wxX11_GetModes(this, modeMatch, display);
|
||||
}
|
||||
|
||||
wxVideoMode wxDisplayImplX11::GetCurrentMode() const
|
||||
{
|
||||
// Not implemented
|
||||
@@ -360,118 +333,67 @@ 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)
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplay::CreateFactory()
|
||||
// ============================================================================
|
||||
|
||||
#ifndef __WXGTK20__
|
||||
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
|
||||
{
|
||||
// GTK+ screen functions are always available, no need to check for them
|
||||
#ifndef __WXGTK20__
|
||||
if ( !XineramaIsActive((Display*)wxGetDisplay()) )
|
||||
return new wxDisplayFactorySingle;
|
||||
#endif
|
||||
|
||||
return new wxDisplayFactoryX11;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* wxUSE_DISPLAY */
|
||||
|
||||
#include "wx/utils.h"
|
||||
#ifdef __WXGTK20__
|
||||
#include <gdk/gdk.h> // for GDK_WINDOWING_X11
|
||||
#endif
|
||||
|
||||
#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 || !defined(GDK_WINDOWING_X11)
|
||||
|
||||
void wxClientDisplayRect(int *x, int *y, int *width, int *height)
|
||||
#if !defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)
|
||||
void wxGetWorkAreaX11(Screen* screen, int& x, int& y, int& width, int& height)
|
||||
{
|
||||
// TODO: don't hardcode display size
|
||||
if ( x )
|
||||
*x = 0;
|
||||
if ( y )
|
||||
*y = 0;
|
||||
if ( width )
|
||||
*width = 672;
|
||||
if ( height )
|
||||
*height = 396;
|
||||
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)
|
||||
|
||||
#else // !wxUSE_LIBHILDON || !wxUSE_LIBHILDON2
|
||||
#ifndef __WXGTK20__
|
||||
|
||||
#include "wx/log.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
// TODO: make this a full-fledged class and move to a public header
|
||||
class wxX11Ptr
|
||||
{
|
||||
public:
|
||||
wxX11Ptr(void *ptr = NULL) : m_ptr(ptr) { }
|
||||
~wxX11Ptr() { if ( m_ptr ) XFree(m_ptr); }
|
||||
|
||||
private:
|
||||
void *m_ptr;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxX11Ptr);
|
||||
};
|
||||
|
||||
// NB: this function is implemented using X11 and not GDK calls as it's shared
|
||||
// by wxGTK[12], wxX11 and wxMotif ports
|
||||
void wxClientDisplayRect(int *x, int *y, int *width, int *height)
|
||||
{
|
||||
Display * const dpy = wxGetX11Display();
|
||||
wxCHECK_RET( dpy, wxT("can't be called before initializing the GUI") );
|
||||
|
||||
wxRect rectClient;
|
||||
|
||||
const Atom atomWorkArea = XInternAtom(dpy, "_NET_WORKAREA", True);
|
||||
if ( atomWorkArea )
|
||||
{
|
||||
long *workareas = NULL;
|
||||
unsigned long numItems;
|
||||
unsigned long bytesRemaining;
|
||||
Atom actualType;
|
||||
int format;
|
||||
|
||||
if ( XGetWindowProperty
|
||||
(
|
||||
dpy,
|
||||
XDefaultRootWindow(dpy),
|
||||
atomWorkArea,
|
||||
0, // offset of data to retrieve
|
||||
4, // number of items to retrieve
|
||||
False, // don't delete property
|
||||
XA_CARDINAL, // type of the items to get
|
||||
&actualType,
|
||||
&format,
|
||||
&numItems,
|
||||
&bytesRemaining,
|
||||
(unsigned char **)&workareas
|
||||
) == Success && workareas )
|
||||
{
|
||||
wxX11Ptr x11ptr(workareas); // ensure it will be freed
|
||||
|
||||
// check that we retrieved the property of the expected type and
|
||||
// that we did get back 4 longs (32 is the format for long), as
|
||||
// requested
|
||||
if ( actualType != XA_CARDINAL ||
|
||||
format != 32 ||
|
||||
numItems != 4 )
|
||||
{
|
||||
wxLogDebug(wxT("XGetWindowProperty(\"_NET_WORKAREA\") failed"));
|
||||
}
|
||||
else
|
||||
{
|
||||
rectClient = wxRect(workareas[0], workareas[1],
|
||||
workareas[2], workareas[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
wxGetWorkAreaX11(DefaultScreenOfDisplay(dpy),
|
||||
rectClient.x, rectClient.y, rectClient.width, rectClient.height);
|
||||
|
||||
// Although _NET_WORKAREA is supposed to return the client size of the
|
||||
// screen, not all implementations are conforming, apparently, see #14419,
|
||||
@@ -505,5 +427,4 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height)
|
||||
if ( height )
|
||||
*height = rectClient.height;
|
||||
}
|
||||
|
||||
#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
|
||||
#endif // !__WXGTK20__
|
||||
|
Reference in New Issue
Block a user