Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: File dialogs on Linux causing a crash on systems where GTK uses Wayland but GLFW uses X11 #1834

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/libimhex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ else()
target_compile_definitions(libimhex PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}")
endif()

if (UNIX AND NOT APPLE)
# For Linux, we need to figure out whether our GLFW is built for X11, Wayland, or both
INCLUDE(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${GLFW_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES})
check_cxx_source_compiles("
#define GLFW_EXPOSE_NATIVE_X11
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
Window test(GLFWwindow* w) { return glfwGetX11Window(w); }
int main() {}
" GLFW_HAS_X11)
check_cxx_source_compiles("
#define GLFW_EXPOSE_NATIVE_WAYLAND
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
wl_surface* test(GLFWwindow* w) { return glfwGetWaylandWindow(w); }
int main() {}
" GLFW_HAS_WAYLAND)
if (GLFW_HAS_X11)
target_compile_definitions(libimhex PRIVATE GLFW_BACKEND_X11)
endif()
if (GLFW_HAS_WAYLAND)
target_compile_definitions(libimhex PRIVATE GLFW_BACKEND_WAYLAND)
endif()
endif()


if (DEFINED IMHEX_COMMIT_HASH_LONG AND DEFINED IMHEX_COMMIT_BRANCH)
set(GIT_COMMIT_HASH_LONG "${IMHEX_COMMIT_HASH_LONG}")
Expand Down
24 changes: 10 additions & 14 deletions lib/libimhex/source/helpers/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#if defined(OS_WEB)
#include <emscripten.h>
#else
#include <GLFW/glfw3.h>
#include <nfd.hpp>
#if defined(OS_WINDOWS)
#define GLFW_EXPOSE_NATIVE_WIN32
Expand All @@ -36,21 +35,18 @@
typedef void NSWindow;
#define GLFW_EXPOSE_NATIVE_COCOA
#endif
#if defined(OS_LINUX)
#if GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4
#define GLFW_EXPOSE_NATIVE_X11
#endif
#if defined(OS_LINUX) && defined(GLFW_BACKEND_X11)
#define GLFW_EXPOSE_NATIVE_X11
#endif
#if defined(OS_LINUX) && defined(GLFW_BACKEND_WAYLAND)
#define GLFW_EXPOSE_NATIVE_WAYLAND
#endif

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <nfd_glfw3.h>
#pragma GCC diagnostic pop

#if defined(OS_LINUX) && GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4
#if GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4
#undef GLFW_EXPOSE_NATIVE_X11
#endif
#if defined(OS_LINUX) && defined(GLFW_BACKEND_WAYLAND)
#undef GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#if defined(OS_LINUX) && defined(GLFW_BACKEND_X11)
#undef GLFW_EXPOSE_NATIVE_X11
#endif
#if defined(OS_MACOS)
#undef GLFW_EXPOSE_NATIVE_COCOA
Expand Down
2 changes: 1 addition & 1 deletion lib/third_party/nativefiledialog
Loading