You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-6Lines changed: 38 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,20 +10,21 @@ This library is based on Michael Labbe's Native File Dialog ([mlabbe/nativefiled
10
10
Features:
11
11
12
12
- 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)
14
14
- Zlib licensed
15
15
- Friendly names for filters (e.g. `C/C++ Source files (*.c;*.cpp)` instead of `(*.c;*.cpp)`) on platforms that support it
16
16
- Automatically append file extension on platforms where users expect it
17
17
- Support for setting a default folder path
18
18
- 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
19
20
- Consistent UTF-8 support on all platforms
20
21
- Native character set (UTF-16 `wchar_t`) support on Windows
21
22
- 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)
23
24
- Support for Vista's modern `IFileDialog` on Windows
24
25
- No third party dependencies
25
26
- 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
27
28
- Optional C++ wrapper with `unique_ptr` auto-freeing semantics and optional parameters, for those using this library from C++
28
29
29
30
**Comparison with original Native File Dialog:**
@@ -35,6 +36,7 @@ Features added in Native File Dialog Extended:
35
36
- Friendly names for filters
36
37
- Automatically appending file extensions
37
38
- Support for setting a default file name
39
+
- Support for setting a parent window handle so that the dialog stays on top
38
40
- Native character set (UTF-16 `wchar_t`) support on Windows
39
41
- xdg-desktop-portal support on Linux that opens the "native" file chooser (see "Usage" section below)
40
42
- Multiple folder selection support
@@ -300,24 +302,50 @@ NFDe is known to work with SDL2 and GLFW, and should also work with other platfo
300
302
301
303
The `parentWindow` argument allows the user to give the dialog a parent.
302
304
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):
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:
If you are using another platform abstraction framework, or not using any such framework, you can set `args.parentWindow` manually.
330
+
#### Others
314
331
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.
316
340
317
341
#### Why pass a parent window handle?
318
342
319
343
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.
320
344
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
+
321
349
### Initialization order
322
350
323
351
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
370
398
371
399
- 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.)
372
400
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
+
373
405
# Known Limitations #
374
406
375
407
- 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