Skip to content

Commit 99afd10

Browse files
committed
Update readme
1 parent 853e207 commit 99afd10

1 file changed

Lines changed: 38 additions & 6 deletions

File tree

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ This library is based on Michael Labbe's Native File Dialog ([mlabbe/nativefiled
1010
Features:
1111

1212
- Lean C API, static library — no C++/ObjC runtime needed
13-
- Supports Windows (MSVC, MinGW, Clang), macOS (Clang), and Linux (GTK, portal) (GCC, Clang)
13+
- Support for Windows (MSVC, MinGW, Clang), macOS (Clang), and Linux (GTK, portal) (GCC, Clang)
1414
- Zlib licensed
1515
- Friendly names for filters (e.g. `C/C++ Source files (*.c;*.cpp)` instead of `(*.c;*.cpp)`) on platforms that support it
1616
- Automatically append file extension on platforms where users expect it
1717
- Support for setting a default folder path
1818
- Support for setting a default file name (e.g. `Untitled.c`)
19+
- Support for setting a parent window handle so that the dialog stays on top
1920
- Consistent UTF-8 support on all platforms
2021
- Native character set (UTF-16 `wchar_t`) support on Windows
2122
- Initialization and de-initialization of platform library (e.g. COM (Windows) / GTK (Linux GTK) / D-Bus (Linux portal)) decoupled from dialog functions, so applications can choose when to initialize/de-initialize
22-
- Multiple selection support (for file open and folder select dialogs)
23+
- Support for multiple selection (for file open and folder select dialogs)
2324
- Support for Vista's modern `IFileDialog` on Windows
2425
- No third party dependencies
2526
- Modern CMake build system
26-
- Works alongside [SDL2](http://www.libsdl.org) on all platforms
27+
- Works alongside [SDL](http://www.libsdl.org), [GLFW](https://www.glfw.org/), and [ImGui](https://github.com/ocornut/imgui) on all platforms
2728
- Optional C++ wrapper with `unique_ptr` auto-freeing semantics and optional parameters, for those using this library from C++
2829

2930
**Comparison with original Native File Dialog:**
@@ -35,6 +36,7 @@ Features added in Native File Dialog Extended:
3536
- Friendly names for filters
3637
- Automatically appending file extensions
3738
- Support for setting a default file name
39+
- Support for setting a parent window handle so that the dialog stays on top
3840
- Native character set (UTF-16 `wchar_t`) support on Windows
3941
- xdg-desktop-portal support on Linux that opens the "native" file chooser (see "Usage" section below)
4042
- Multiple folder selection support
@@ -300,24 +302,50 @@ NFDe is known to work with SDL2 and GLFW, and should also work with other platfo
300302
301303
The `parentWindow` argument allows the user to give the dialog a parent.
302304
303-
If using SDL2, include `<nfd_sdl2.h>` and call the following function to set the parent window handle:
305+
Win32 (Windows), Cocoa (macOS), X11 (Linux), and Wayland (Linux) windows are supported. Wayland support requires you to tell NFDe the `wl_display` that owns the windows in your application.
306+
307+
#### SDL2
308+
309+
If using SDL2, include `<nfd_sdl2.h>` and do the following:
310+
311+
Call the following function once, after you create your first SDL2 window (usually with `SDL_CreateWindow()`) but before opening any file dialogs, to tell NFDe the `wl_display` your application is using (this is a no-op if your application isn't using Wayland):
312+
```C
313+
NFD_SetDisplayPropertiesFromSDLWindow(sdlWindow /* SDL_Window* */);
314+
```
315+
316+
Each time you want to show a dialog, call the following function to retrieve the parent window handle and set the corresponding argument:
304317
```C
305318
NFD_GetNativeWindowFromSDLWindow(sdlWindow /* SDL_Window* */, &args.parentWindow);
306319
```
307320
321+
See `test_sdl.c` for an example.
322+
323+
#### GLFW3
324+
308325
If using GLFW3, define the appropriate `GLFW_EXPOSE_NATIVE_*` macros described on the [GLFW native access page](https://www.glfw.org/docs/latest/group__native.html), and then include `<nfd_glfw3.h>` and call the following function to set the parent window handle:
309326
```C
310327
NFD_GetNativeWindowFromGLFWWindow(glfwWindow /* GLFWwindow* */, &args.parentWindow);
311328
```
312329

313-
If you are using another platform abstraction framework, or not using any such framework, you can set `args.parentWindow` manually.
330+
#### Others
314331

315-
Win32 (Windows), Cocoa (macOS), and X11 (Linux) windows are supported. Passing a Wayland (Linux) window currently does nothing (i.e. the dialog acts as if it has no parent), but support is likely to be added in the future.
332+
If you are using another platform abstraction framework, or not using any such framework, you can do the following:
333+
334+
If you are using Wayland, call the following function once, after connecting to the Wayland compositor (thereby obtaining a `wl_display*`) but before opening any file dialogs:
335+
```C
336+
NFD_SetWaylandDisplay(display /* wl_display* */);
337+
```
338+
339+
Then, each time you want to show a dialog, set `args.parentWindow` manually.
316340
317341
#### Why pass a parent window handle?
318342
319343
To make a window (in this case the file dialog) stay above another window, we need to declare the bottom window as the parent of the top window. This keeps the dialog window from disappearing behind the parent window if the user clicks on the parent window while the dialog is open. Keeping the dialog above the window that invoked it is the expected behaviour on all supported operating systems, and so passing the parent window handle is recommended if possible.
320344
345+
#### Why is Wayland special?
346+
347+
Linux has two differences when compared with Windows and macOS: Linux applications open a connection with a display server (X11 or Wayland) to show their windows, and windows are owned by this connection. It is possible to open multiple connections at the same time (including multiple connections to the same display server), and windows are not shared between those connections. GTK needs to use a connection opened by itself, and so it opens a new connection if it hasn't previously opened a connection (which will be the case if your application doesn't create its own GTK windows). Using portals essentially causes the file dialog to be shown by a separate helper process, which also opens its own connection. In either case, the window handle needs to be passed to a different connection. On X11, window handles are global identifiers that can be used as-is by another connection, but on Wayland, the handles need to be _exported_ to a string and then _imported_ by the receiving connection, and performing the export operation requires the owner's Wayland display handle.
348+
321349
### Initialization order
322350
323351
You should initialize NFDe _after_ initializing the framework, and probably should deinitialize NFDe _before_ deinitializing the framework. This is because some frameworks expect to be initialized on a "clean slate", and they may configure the system in a different way from NFDe. `NFD_Init` is generally very careful not to disrupt the existing configuration unless necessary, and `NFD_Quit` restores the configuration back exactly to what it was before initialization.
@@ -370,6 +398,10 @@ Flatpak was introduced in 2015, and with it came a standardized interface to ope
370398
371399
- If the macOS deployment target is ≥ 11.0, the [allowedContentTypes](https://developer.apple.com/documentation/appkit/nssavepanel/3566857-allowedcontenttypes?language=objc) property of NSSavePanel is used instead of the deprecated [allowedFileTypes](https://developer.apple.com/documentation/appkit/nssavepanel/1534419-allowedfiletypes?language=objc) property for file filters. Thus, if you are filtering by a custom file extension specific to your application, you will need to define the data type in your `Info.plist` file as per the [Apple documentation](https://developer.apple.com/documentation/uniformtypeidentifiers/defining_file_and_data_types_for_your_app). (It is possible to force NFDe to use allowedFileTypes by adding `-DNFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE=OFF` to your CMake build command, but this is not recommended. If you need to support older macOS versions, you should be setting the correct deployment target instead.)
372400
401+
### Linux
402+
403+
- Window parenting does not work on XWayland. Dialogs behave as if the parent window handle was not given, and there does not seem to be any way to make this work.
404+
373405
# Known Limitations #
374406
375407
- No support for Windows XP's legacy dialogs such as `GetOpenFileName`. (There are no plans to support this; you shouldn't be still using Windows XP anyway.)

0 commit comments

Comments
 (0)