ec013c8
From 76c393b8bd1968dcf18e2c93f1c37d1c58215d4f Mon Sep 17 00:00:00 2001
ec013c8
From: Scott Talbert <swt@techie.net>
ec013c8
Date: Wed, 1 Aug 2018 20:52:11 -0700
ec013c8
Subject: [PATCH] Give an error when trying to use wxGLCanvas on non-X11
ec013c8
 display
ec013c8
ec013c8
Currently, wxGLCanvas on wxGTK is only supported on X11 displays.  If a
ec013c8
user attempts to use wxGLCanvas on Wayland, for example, the application
ec013c8
will core dump.  This change adds an error message and a suggested
ec013c8
workaround until wxGLCanvas is supported on Wayland.
ec013c8
See #17702
ec013c8
See https://github.com/wxWidgets/wxWidgets/pull/871
ec013c8
ec013c8
(backport of 95857a1f71bd0c19e3059ebf0eea28e9bb8b7602)
ec013c8
---
ec013c8
 src/gtk/glcanvas.cpp | 16 ++++++++++++++++
ec013c8
 1 file changed, 16 insertions(+)
ec013c8
ec013c8
diff --git a/src/gtk/glcanvas.cpp b/src/gtk/glcanvas.cpp
ec013c8
index d4acb9c8c2a..0953be61807 100644
ec013c8
--- a/src/gtk/glcanvas.cpp
ec013c8
+++ b/src/gtk/glcanvas.cpp
ec013c8
@@ -208,6 +208,19 @@ wxGLCanvas::wxGLCanvas(wxWindow *parent,
ec013c8
 
ec013c8
 #endif // WXWIN_COMPATIBILITY_2_8
ec013c8
 
ec013c8
+static bool IsAvailable()
ec013c8
+{
ec013c8
+#ifdef GDK_WINDOWING_X11
ec013c8
+    if ( !GDK_IS_X11_DISPLAY(gdk_display_get_default()) )
ec013c8
+#endif
ec013c8
+    {
ec013c8
+        wxSafeShowMessage(_("Fatal Error"), _("wxGLCanvas is only supported on X11 currently.  You may be able to\nwork around this by setting environment variable GDK_BACKEND=x11 before starting\nyour program."));
ec013c8
+        return false;
ec013c8
+    }
ec013c8
+
ec013c8
+    return true;
ec013c8
+}
ec013c8
+
ec013c8
 bool wxGLCanvas::Create(wxWindow *parent,
ec013c8
                         wxWindowID id,
ec013c8
                         const wxPoint& pos,
ec013c8
@@ -217,6 +230,9 @@ bool wxGLCanvas::Create(wxWindow *parent,
ec013c8
                         const int *attribList,
ec013c8
                         const wxPalette& palette)
ec013c8
 {
ec013c8
+    if ( !IsAvailable() )
ec013c8
+        return false;
ec013c8
+
ec013c8
 #if wxUSE_PALETTE
ec013c8
     wxASSERT_MSG( !palette.IsOk(), wxT("palettes not supported") );
ec013c8
 #endif // wxUSE_PALETTE