diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 9bbe7dc0c..36fd3ba9f 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -24,6 +24,37 @@ #include #else #include + #if defined(OS_WINDOWS) + #define GLFW_EXPOSE_NATIVE_WIN32 + #endif + #if defined(OS_MACOS) + // macOS platform headers can't be compiled with gcc + #define GLFW_NATIVE_INCLUDE_NONE + typedef uint32_t CGDirectDisplayID; + typedef void *id; + typedef void NSWindow; + #define GLFW_EXPOSE_NATIVE_COCOA + #endif + #if defined(OS_LINUX) + #define GLFW_EXPOSE_NATIVE_X11 + #endif + #if defined(OS_LINUX) && defined(GLFW_WAYLAND_APP_ID) + #define GLFW_EXPOSE_NATIVE_WAYLAND + #endif + #include + #if defined(OS_LINUX) && defined(GLFW_WAYLAND_APP_ID) + #undef GLFW_EXPOSE_NATIVE_WAYLAND + #endif + #if defined(OS_LINUX) + #undef GLFW_EXPOSE_NATIVE_X11 + #endif + #if defined(OS_MACOS) + #undef GLFW_EXPOSE_NATIVE_COCOA + #undef GLFW_NATIVE_INCLUDE_NONE + #endif + #if defined(OS_WINDOWS) + #undef GLFW_EXPOSE_NATIVE_WIN32 + #endif #endif #include @@ -233,20 +264,22 @@ namespace hex::fs { NFD::UniquePathU8 outPath; NFD::UniquePathSet outPaths; nfdresult_t result = NFD_ERROR; + nfdwindowhandle_t nativeWindow{}; + NFD_GetNativeWindowFromGLFWWindow(ImHexApi::System::getMainWindowHandle(), &nativeWindow); // Open the correct file dialog based on the mode switch (mode) { case DialogMode::Open: if (multiple) - result = NFD::OpenDialogMultiple(outPaths, validExtensionsNfd.data(), validExtensionsNfd.size(), defaultPath.empty() ? nullptr : defaultPath.c_str()); + result = NFD::OpenDialogMultiple(outPaths, validExtensionsNfd.data(), validExtensionsNfd.size(), defaultPath.empty() ? nullptr : defaultPath.c_str(), nativeWindow); else - result = NFD::OpenDialog(outPath, validExtensionsNfd.data(), validExtensionsNfd.size(), defaultPath.empty() ? nullptr : defaultPath.c_str()); + result = NFD::OpenDialog(outPath, validExtensionsNfd.data(), validExtensionsNfd.size(), defaultPath.empty() ? nullptr : defaultPath.c_str(), nativeWindow); break; case DialogMode::Save: - result = NFD::SaveDialog(outPath, validExtensionsNfd.data(), validExtensionsNfd.size(), defaultPath.empty() ? nullptr : defaultPath.c_str()); + result = NFD::SaveDialog(outPath, validExtensionsNfd.data(), validExtensionsNfd.size(), defaultPath.empty() ? nullptr : defaultPath.c_str(), nullptr, nativeWindow); break; case DialogMode::Folder: - result = NFD::PickFolder(outPath, defaultPath.empty() ? nullptr : defaultPath.c_str()); + result = NFD::PickFolder(outPath, defaultPath.empty() ? nullptr : defaultPath.c_str(), nativeWindow); break; } diff --git a/lib/third_party/nativefiledialog b/lib/third_party/nativefiledialog index 5786fabce..c099aaee9 160000 --- a/lib/third_party/nativefiledialog +++ b/lib/third_party/nativefiledialog @@ -1 +1 @@ -Subproject commit 5786fabceeaee4d892f3c7a16b243796244cdddc +Subproject commit c099aaee9a24a35ad93e06513b41aeb503d848d0