-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: Accept native parent window handle
This is necessary for platforms to present the dialog properly, e.g. ensuring that the dialog never goes behind the parent window.
- Loading branch information
Showing
11 changed files
with
773 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Native File Dialog Extended | ||
Repository: https://github.com/btzy/nativefiledialog-extended | ||
License: Zlib | ||
Authors: Bernard Teo | ||
This header contains a function to convert a GLFW window handle to a native window handle for | ||
passing to NFDe. | ||
*/ | ||
|
||
#ifndef _NFD_GLFW_H | ||
#define _NFD_GLFW_H | ||
|
||
#include <GLFW/glfw3native.h> | ||
#include <nfd.h> | ||
#include <stdbool.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
/** | ||
* Converts a GLFW window handle to a native window handle that can be passed to NFDe. | ||
* @param sdlWindow The GLFW window handle. | ||
* @param[out] nativeWindow The output native window handle, populated if and only if this function | ||
* returns true. | ||
* @return Either true to indicate success, or false to indicate failure. It is intended that | ||
* users ignore the error and simply pass a value-initialized nfdwindowhandle_t to NFDe if this | ||
* function fails. */ | ||
inline bool NFD_GetNativeWindowFromGLFWWindow(GLFWwindow* glfwWindow, | ||
nfdwindowhandle_t* nativeWindow) { | ||
GLFWerrorfun* oldCallback = glfwSetErrorCallback(NULL); | ||
bool success = false; | ||
#if defined(GLFW_EXPOSE_NATIVE_WIN32) | ||
if (!success) { | ||
const HWND hwnd = glfwGetWin32Window(glfwWindow); | ||
if (hwnd) { | ||
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_WINDOWS; | ||
nativeWindow->handle = (void*)hwnd; | ||
success = true; | ||
} | ||
} | ||
#endif | ||
#if defined(GLFW_EXPOSE_NATIVE_COCOA) | ||
if (!success) { | ||
NSWindow* const cocoa_window = glfwGetCocoaWindow(glfwWindow); | ||
if (cocoa_window) { | ||
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_COCOA; | ||
nativeWindow->handle = (void*)cocoa_window; | ||
success = true; | ||
} | ||
} | ||
#endif | ||
#if defined(NFD_WINDOW_HANDLE_TYPE_X11) | ||
if (!success) { | ||
const Window x11_window = glfwGetX11Window(glfwWindow); | ||
if (x11_window != None) { | ||
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_X11; | ||
nativeWindow->handle = (void*)x11_window; | ||
success = true; | ||
} | ||
} | ||
#endif | ||
glfwSetErrorCallback(oldCallback); | ||
return success; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus | ||
|
||
#endif // _NFD_GLFW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Native File Dialog Extended | ||
Repository: https://github.com/btzy/nativefiledialog-extended | ||
License: Zlib | ||
Authors: Bernard Teo | ||
This header contains a function to convert an SDL window handle to a native window handle for | ||
passing to NFDe. | ||
This is meant to be used with SDL2, but if there are incompatibilities with future SDL versions, | ||
we can conditionally compile based on SDL_MAJOR_VERSION. | ||
*/ | ||
|
||
#ifndef _NFD_SDL_H | ||
#define _NFD_SDL_H | ||
|
||
#include <SDL_error.h> | ||
#include <SDL_syswm.h> | ||
#include <nfd.h> | ||
#include <stdbool.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
/** | ||
* Converts an SDL window handle to a native window handle that can be passed to NFDe. | ||
* @param sdlWindow The SDL window handle. | ||
* @param[out] nativeWindow The output native window handle, populated if and only if this function | ||
* returns true. | ||
* @return Either true to indicate success, or false to indicate failure. If false is returned, | ||
* you can call SDL_GetError() for more information. However, it is intended that users ignore the | ||
* error and simply pass a value-initialized nfdwindowhandle_t to NFDe if this function fails. */ | ||
inline bool NFD_GetNativeWindowFromSDLWindow(SDL_Window* sdlWindow, | ||
nfdwindowhandle_t* nativeWindow) { | ||
SDL_SysWMinfo info; | ||
SDL_VERSION(&info.version); | ||
if (SDL_GetWindowWMInfo(sdlWindow, &info)) { | ||
return false; | ||
} | ||
switch (info.subsystem) { | ||
#if defined(SDL_VIDEO_DRIVER_WINDOWS) | ||
case SDL_SYSWM_WINDOWS: | ||
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_WINDOWS; | ||
nativeWindow->handle = (void*)info.info.win.window; | ||
return true; | ||
#endif | ||
#if defined(SDL_VIDEO_DRIVER_COCOA) | ||
case SDL_SYSWM_COCOA: | ||
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_COCOA; | ||
nativeWindow->handle = (void*)info.info.cocoa.window; | ||
return true; | ||
#endif | ||
#if defined(SDL_VIDEO_DRIVER_X11) | ||
case SDL_SYSWM_X11: | ||
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_X11; | ||
nativeWindow->handle = (void*)info.info.x11.window; | ||
return true; | ||
#endif | ||
default: | ||
SDL_SetError("Unsupported native window type."); | ||
return false; | ||
} | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus | ||
|
||
#endif // _NFD_SDL_H |
Oops, something went wrong.