From 462c96fd4c8c378b3ee5dce8c4999d76d268dff8 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Mon, 11 Sep 2023 00:18:13 +0000 Subject: [PATCH] Launch on xwayland under Wayland if no EGL On initialization, if wxWidgets was compiled without EGL support, check in environment variables if running under Wayland and if so tell GDK to prefer using an X11 backend, causing the program to launch under xwayland. Fix #1028 Signed-off-by: Rafael Kitover --- src/wx/wxvbam.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 80491060..63421882 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -47,6 +47,10 @@ #include "widgets/user-input-ctrl.h" #include "wxhead.h" +#ifdef __WXGTK__ +#include +#endif + namespace { // Resets the accelerator text for `menu_item` to the first keyboard input. @@ -136,6 +140,15 @@ int main(int argc, char** argv) { wxLog::SetLogLevel(wxLOG_Info); #endif // DEBUG + // Launch under xwayland on Wayland if EGL is not available. +#if defined(__WXGTK__) && !defined(HAVE_WAYLAND_EGL) + wxString xdg_session_type = wxGetenv("XDG_SESSION_TYPE"); + wxString wayland_display = wxGetenv("WAYLAND_DISPLAY"); + + if (xdg_session_type == "wayland" || wayland_display.Contains("wayland")) + gdk_set_allowed_backends("x11,*"); +#endif + // This will be freed on wxEntry exit. wxApp::SetInstance(new wxvbamApp()); return wxEntry(argc, argv);