File PrusaSlicer-2.9.1-pr14214-egl-support.patch of Package PrusaSlicer

From 1dc697c0cb86dc3799b52c4318e01ba84fe1e527 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Sat, 1 Mar 2025 10:14:57 +0100
Subject: [PATCH] Allow to build PrusaSlicer with EGL support

A lot of Linux distribution don't build wxWidgets with EGL support yet.
This is why by default this option is set to OFF. If a Linux
distribution has built wxWidgets and GLEW with EGL support, you should
turn that on!
---
 CMakeLists.txt                  |  4 ++++
 deps/+wxWidgets/wxWidgets.cmake |  2 +-
 src/CLI/GuiParams.cpp           |  9 ++++++---
 src/CLI/Setup.cpp               | 10 ++++++----
 src/CMakeLists.txt              |  4 ++++
 5 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e37bb3f55..4fc18db26 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,10 @@ endif()
 
 option(SLIC3R_STATIC 			"Compile PrusaSlicer with static libraries (Boost, TBB)" ${SLIC3R_STATIC_INITIAL})
 option(SLIC3R_GUI    			"Compile PrusaSlicer with GUI components (OpenGL, wxWidgets)" 1)
+# A lot of Linux distribution don't build wxWidgets with EGL support yet. This
+# is why by default this option is set to OFF. If a Linux distribution has
+# built wxWidgets EGL support, you should turn that on!
+option(SLIC3R_EGL               "Compile PrusaSlicer with Wayland (EGL) support" OFF)
 option(SLIC3R_FHS               "Assume PrusaSlicer is to be installed in a FHS directory structure" 0)
 option(SLIC3R_PCH               "Use precompiled headers" 1)
 option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)
diff --git a/deps/+wxWidgets/wxWidgets.cmake b/deps/+wxWidgets/wxWidgets.cmake
index 5537ff8b5..95f1cd21b 100644
--- a/deps/+wxWidgets/wxWidgets.cmake
+++ b/deps/+wxWidgets/wxWidgets.cmake
@@ -51,7 +51,7 @@ add_cmake_project(wxWidgets
         -DwxUSE_EXPAT=sys
         -DwxUSE_LIBSDL=OFF
         -DwxUSE_XTEST=OFF
-        -DwxUSE_GLCANVAS_EGL=OFF
+        -DwxUSE_GLCANVAS_EGL=${SLIC3R_EGL}
         -DwxUSE_WEBREQUEST=OFF
         ${_wx_webview}
         ${_wx_secretstore}
diff --git a/src/CLI/GuiParams.cpp b/src/CLI/GuiParams.cpp
index f44b91651..db746ce6a 100644
--- a/src/CLI/GuiParams.cpp
+++ b/src/CLI/GuiParams.cpp
@@ -107,9 +107,12 @@ int start_gui_with_params(GUI::GUI_InitParams& params)
 #if !defined(_WIN32) && !defined(__APPLE__)
     // likely some linux / unix system
     const char* display = boost::nowide::getenv("DISPLAY");
-    // const char *wayland_display = boost::nowide::getenv("WAYLAND_DISPLAY");
-    //if (! ((display && *display) || (wayland_display && *wayland_display))) {
+#ifdef SLIC3R_EGL
+    const char *wayland_display = boost::nowide::getenv("WAYLAND_DISPLAY");
+    if (! ((display && *display) || (wayland_display && *wayland_display))) {
+#else // SLIC3R_EGL
     if (!(display && *display)) {
+#endif // SLIC3R_EGL
         // DISPLAY not set.
         boost::nowide::cerr << "DISPLAY not set, GUI mode not available." << std::endl << std::endl;
         print_help(false);
@@ -141,4 +144,4 @@ int start_as_gcode_viewer(GUI::GUI_InitParams& gui_params)
 }
 #else // SLIC3R_GUI
     // If there is no GUI, we shall ignore the parameters. Remove them from the list.
-#endif // SLIC3R_GUI
\ No newline at end of file
+#endif // SLIC3R_GUI
diff --git a/src/CLI/Setup.cpp b/src/CLI/Setup.cpp
index 82e03d466..d04ecfa98 100644
--- a/src/CLI/Setup.cpp
+++ b/src/CLI/Setup.cpp
@@ -212,10 +212,12 @@ static bool setup_common()
     save_main_thread_id();
 
 #ifdef __WXGTK__
-    // On Linux, wxGTK has no support for Wayland, and the app crashes on
-    // startup if gtk3 is used. This env var has to be set explicitly to
-    // instruct the window manager to fall back to X server mode.
+#ifndef SLIC3R_EGL
+    // On a lot of Linux distributions, wxWidgets isn't compiled with EGL
+    // support. In order to avoid crashes force the X11 backend. If Wayland is
+    // running this will fallback to XWayland.
     ::setenv("GDK_BACKEND", "x11", /* replace */ true);
+#endif // SLIC3R_EGL
 
     // https://github.com/prusa3d/PrusaSlicer/issues/12969
     ::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "1", /* replace */ false);
@@ -338,4 +340,4 @@ bool setup(Data& cli, int argc, char** argv)
     return true;
 }
 
-}
\ No newline at end of file
+}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c6ddf2e1d..44612b102 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -140,6 +140,10 @@ if (NOT WIN32 AND NOT APPLE)
     set_target_properties(PrusaSlicer PROPERTIES OUTPUT_NAME "prusa-slicer")
 endif ()
 
+if (SLIC3R_EGL)
+    target_compile_options(PrusaSlicer PRIVATE -DSLIC3R_EGL=1)
+endif()
+
 
 target_link_libraries(PrusaSlicer PRIVATE libslic3r libcereal slic3r-arrange-wrapper libseqarrange stb_image)
 
-- 
2.49.0

openSUSE Build Service is sponsored by