Add functions for determining if GDK3 backend is X11 or Wayland

This commit is contained in:
Paul Cornett
2022-02-10 10:15:08 -08:00
parent eaa769a73a
commit 94868c6f41
12 changed files with 73 additions and 34 deletions

View File

@@ -0,0 +1,14 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/private/backend.h
// Author: Paul Cornett
// Copyright: (c) 2022 Paul Cornett
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __WXGTK3__
namespace wxGTKImpl
{
bool IsWayland(void* instance);
bool IsX11(void* instance);
}
#endif

View File

@@ -16,6 +16,7 @@
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#endif
#include "wx/gtk/private/backend.h"
//-----------------------------------------------------------------------------
// "wxGtkGetIdFromWidget" from widget
@@ -32,19 +33,16 @@ inline gpointer wxGtkGetIdFromWidget(GtkWidget* widget)
GdkWindow* window = gtk_widget_get_window(widget);
wxASSERT(window);
#ifdef __WXGTK3__
const char* name = g_type_name(G_TYPE_FROM_INSTANCE(window));
#endif
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
if (strcmp("GdkX11Window", name) == 0)
if (wxGTKImpl::IsX11(window))
#endif
{
return (gpointer)GDK_WINDOW_XID(window);
}
#endif
#ifdef GDK_WINDOWING_WAYLAND
if (strcmp("GdkWaylandWindow", name) == 0)
if (wxGTKImpl::IsWayland(window))
{
return (gpointer)gdk_wayland_window_get_wl_surface(window);
}

View File

@@ -14,6 +14,7 @@
#endif
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/backend.h"
#ifdef GDK_WINDOWING_X11
#ifndef __WXGTK4__
#include "wx/unix/private/displayx11.h"
@@ -179,7 +180,7 @@ bool wxDisplayImplGTK::ChangeMode(const wxVideoMode& WXUNUSED(mode))
static inline bool wxIsX11GDKScreen(GdkScreen* screen)
{
return strcmp("GdkX11Screen", g_type_name(G_TYPE_FROM_INSTANCE(screen))) == 0;
return wxGTKImpl::IsX11(screen);
}
#else // !__WXGTK3__

View File

@@ -16,6 +16,7 @@
#include "wx/glcanvas.h"
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/backend.h"
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#endif
@@ -169,11 +170,10 @@ static bool IsAvailable()
{
#if defined(__WXGTK3__) && (defined(GDK_WINDOWING_WAYLAND) || defined(GDK_WINDOWING_X11))
GdkDisplay* display = gdk_display_get_default();
const char* displayTypeName = g_type_name(G_TYPE_FROM_INSTANCE(display));
#endif
#ifdef GDK_WINDOWING_WAYLAND
if (strcmp("GdkWaylandDisplay", displayTypeName) == 0)
if (wxGTKImpl::IsWayland(display))
{
#if wxUSE_GLCANVAS_EGL
return true;
@@ -186,7 +186,7 @@ static bool IsAvailable()
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
if (strcmp("GdkX11Display", displayTypeName) == 0)
if (wxGTKImpl::IsX11(display))
#endif
{
return true;

View File

@@ -26,6 +26,7 @@
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/gtk3-compat.h"
#include "wx/gtk/private/backend.h"
//-----------------------------------------------------------------------------
// data
@@ -161,8 +162,7 @@ gtk_window_button_press_callback(GtkWidget* widget, GdkEventButton* gdk_event, w
#ifdef __WXGTK3__
#ifndef __WXGTK4__
GdkDisplay* display = gdk_window_get_display(gdk_event->window);
if (strcmp("GdkWaylandDisplay", g_type_name(G_TYPE_FROM_INSTANCE(display))) == 0)
if (wxGTKImpl::IsWayland(gdk_event->window))
#endif
{
gtk_window_begin_move_drag(GTK_WINDOW(win->m_widget),

View File

@@ -24,6 +24,7 @@
#endif
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/backend.h"
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
@@ -132,8 +133,7 @@ bool wxTaskBarIconBase::IsAvailable()
{
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
GdkDisplay* display = gdk_display_get_default();
if (strcmp("GdkX11Display", g_type_name(G_TYPE_FROM_INSTANCE(display))) != 0)
if (!wxGTKImpl::IsX11(NULL))
return false;
#endif

View File

@@ -37,6 +37,7 @@
#include "wx/gtk/private/gtk3-compat.h"
#include "wx/gtk/private/stylecontext.h"
#include "wx/gtk/private/win_gtk.h"
#include "wx/gtk/private/backend.h"
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
@@ -79,7 +80,7 @@ static bool HasClientDecor(GtkWidget* widget)
GdkDisplay* display = gtk_widget_get_display(widget);
const char* name = g_type_name(G_TYPE_FROM_INSTANCE(display));
has =
strcmp(name, "GdkWaylandDisplay") == 0 ||
wxGTKImpl::IsWayland(display) ||
strcmp(name, "GdkMirDisplay") == 0 ||
strcmp(name, "GdkBroadwayDisplay") == 0;
}
@@ -504,7 +505,7 @@ bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int*
GdkDisplay* display = gdk_window_get_display(window);
#ifdef __WXGTK3__
if (strcmp("GdkX11Display", g_type_name(G_TYPE_FROM_INSTANCE(display))) != 0)
if (!wxGTKImpl::IsX11(display))
return false;
#endif
@@ -771,12 +772,11 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
G_CALLBACK (wxgtk_tlw_key_press_event), NULL);
#ifdef __WXGTK3__
const char* displayTypeName =
g_type_name(G_TYPE_FROM_INSTANCE(gtk_widget_get_display(m_widget)));
GdkDisplay* display = gtk_widget_get_display(m_widget);
#endif
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
if (strcmp("GdkX11Display", displayTypeName) == 0)
if (wxGTKImpl::IsX11(display))
#endif
{
gtk_widget_add_events(m_widget, GDK_PROPERTY_CHANGE_MASK);
@@ -814,7 +814,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
m_gdkDecor |= GDK_DECOR_TITLE;
#if GTK_CHECK_VERSION(3,10,0)
else if (
strcmp("GdkWaylandDisplay", displayTypeName) == 0 &&
wxGTKImpl::IsWayland(display) &&
gtk_check_version(3,10,0) == NULL)
{
gtk_window_set_titlebar(GTK_WINDOW(m_widget), gtk_header_bar_new());
@@ -933,7 +933,7 @@ bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long)
wxX11FullScreenMethod method = wxX11_FS_WMSPEC;
#ifdef __WXGTK3__
if (strcmp("GdkX11Display", g_type_name(G_TYPE_FROM_INSTANCE(display))) == 0)
if (wxGTKImpl::IsX11(display))
#endif
{
xdpy = GDK_DISPLAY_XDISPLAY(display);
@@ -1068,7 +1068,7 @@ bool wxTopLevelWindowGTK::Show( bool show )
gs_requestFrameExtentsStatus != RFE_STATUS_BROKEN &&
!gtk_widget_get_realized(m_widget) &&
#ifdef __WXGTK3__
strcmp("GdkX11Screen", g_type_name(G_TYPE_FROM_INSTANCE(screen))) == 0 &&
wxGTKImpl::IsX11(screen) &&
#endif
g_signal_handler_find(m_widget,
GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),

View File

@@ -26,6 +26,7 @@
#include "wx/evtloop.h"
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/backend.h"
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#endif
@@ -82,14 +83,13 @@ void *wxGetDisplay()
wxDisplayInfo wxGetDisplayInfo()
{
wxDisplayInfo info = { NULL, wxDisplayNone };
#if defined(GDK_WINDOWING_WAYLAND) || defined(GDK_WINDOWING_X11)
GdkDisplay *display = gdk_window_get_display(wxGetTopLevelGDK());
#if defined(__WXGTK3__) && (defined(GDK_WINDOWING_WAYLAND) || defined(GDK_WINDOWING_X11))
const char* displayTypeName = g_type_name(G_TYPE_FROM_INSTANCE(display));
#endif
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
if (strcmp("GdkX11Display", displayTypeName) == 0)
if (wxGTKImpl::IsX11(display))
#endif
{
info.dpy = GDK_DISPLAY_XDISPLAY(display);
@@ -98,7 +98,7 @@ wxDisplayInfo wxGetDisplayInfo()
}
#endif
#ifdef GDK_WINDOWING_WAYLAND
if (strcmp("GdkWaylandDisplay", displayTypeName) == 0)
if (wxGTKImpl::IsWayland(display))
{
info.dpy = gdk_wayland_display_get_wl_display(display);
info.type = wxDisplayWayland;

View File

@@ -42,6 +42,7 @@
#include "wx/gtk/private/gtk3-compat.h"
#include "wx/gtk/private/event.h"
#include "wx/gtk/private/win_gtk.h"
#include "wx/gtk/private/backend.h"
#include "wx/private/textmeasure.h"
using namespace wxGTKImpl;
@@ -395,6 +396,32 @@ PangoContext* wxGetPangoContext()
return context;
}
#ifdef __WXGTK3__
static bool IsBackend(void* instance, const char* string)
{
if (instance == NULL)
instance = wxGetTopLevelGDK();
const char* name = g_type_name(G_TYPE_FROM_INSTANCE(instance));
return strncmp(string, name, strlen(string)) == 0;
}
bool wxGTKImpl::IsWayland(void* instance)
{
static wxByte is = 2;
if (is > 1)
is = IsBackend(instance, "GdkWayland");
return bool(is);
}
bool wxGTKImpl::IsX11(void* instance)
{
static wxByte is = 2;
if (is > 1)
is = IsBackend(instance, "GdkX11");
return bool(is);
}
#endif // __WXGTK3__
//-----------------------------------------------------------------------------
// "expose_event"/"draw" from m_wxwindow
//-----------------------------------------------------------------------------
@@ -1014,7 +1041,7 @@ wxTranslateGTKKeyEventToWx(wxKeyEvent& event,
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
if (strcmp("GdkX11Window", g_type_name(G_TYPE_FROM_INSTANCE(gdk_event->window))) == 0)
if (wxGTKImpl::IsX11(gdk_event->window))
#else
if (true)
#endif

View File

@@ -29,6 +29,7 @@
#include "wx/scopedptr.h"
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/backend.h"
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#include <wayland-egl.h>
@@ -459,9 +460,8 @@ bool wxGLCanvasEGL::CreateSurface()
}
GdkWindow *window = GTKGetDrawingWindow();
const char* name = g_type_name(G_TYPE_FROM_INSTANCE(window));
#ifdef GDK_WINDOWING_X11
if (strcmp("GdkX11Window", name) == 0)
if (wxGTKImpl::IsX11(window))
{
m_xwindow = GDK_WINDOW_XID(window);
m_surface = eglCreatePlatformWindowSurface(m_display, *m_config,
@@ -470,7 +470,7 @@ bool wxGLCanvasEGL::CreateSurface()
}
#endif
#ifdef GDK_WINDOWING_WAYLAND
if (strcmp("GdkWaylandWindow", name) == 0)
if (wxGTKImpl::IsWayland(window))
{
int x, y;
gdk_window_get_origin(window, &x, &y);

View File

@@ -147,7 +147,7 @@ expose_event_callback(GtkWidget* widget, GdkEventExpose* event, wxGStreamerMedia
);
#ifdef __WXGTK3__
GdkWindow* window = gtk_widget_get_window(widget);
if (strcmp("GdkWaylandWindow", g_type_name(G_TYPE_FROM_INSTANCE(window))) == 0)
if (wxGTKImpl::IsWayland(window))
{
// on wayland we need to place the video
int x, y;
@@ -198,7 +198,7 @@ static void realize_callback(GtkWidget* widget, wxGStreamerMediaBackend* be)
);
#ifdef __WXGTK3__
GdkWindow* window = gtk_widget_get_window(widget);
if (strcmp("GdkWaylandWindow", g_type_name(G_TYPE_FROM_INSTANCE(window))) == 0)
if (wxGTKImpl::IsWayland(window))
{
// on wayland we need to place the video
int x, y;

View File

@@ -27,6 +27,7 @@
#ifdef __WXGTK__
#ifdef __WXGTK20__
#include "wx/gtk/private/wrapgtk.h"
#include "wx/gtk/private/backend.h"
#else // GTK+ 1.x
#include <gtk/gtk.h>
#define GDK_WINDOWING_X11
@@ -2640,9 +2641,7 @@ static bool wxGetKeyStateGTK(wxKeyCode key)
bool wxGetKeyState(wxKeyCode key)
{
#ifdef wxHAS_GETKEYSTATE_GTK
GdkDisplay* display = gdk_window_get_display(wxGetTopLevelGDK());
const char* name = g_type_name(G_TYPE_FROM_INSTANCE(display));
if (strcmp(name, "GdkX11Display") != 0)
if (!wxGTKImpl::IsX11(NULL))
{
return wxGetKeyStateGTK(key);
}