Skip to content

Commit 1e20206

Browse files
authored
New feature: Accept native parent window handle (#136)
This is necessary for platforms to present the dialog properly, e.g. ensuring that the dialog never goes behind the parent window.
1 parent ec07834 commit 1e20206

File tree

14 files changed

+1111
-127
lines changed

14 files changed

+1111
-127
lines changed

.github/workflows/cmake.yml

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@v2
32-
- name: Installing Dependencies
32+
- name: Install Dependencies
3333
run: sudo apt-get update && sudo apt-get install dos2unix
3434
- name: Convert to Unix line endings
3535
run: dos2unix */*
@@ -72,7 +72,7 @@ jobs:
7272
steps:
7373
- name: Checkout
7474
uses: actions/checkout@v2
75-
- name: Installing Dependencies
75+
- name: Install Dependencies
7676
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }}
7777
- name: Configure
7878
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${{ matrix.compiler.c }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} -DCMAKE_CXX_STANDARD=${{ matrix.cppstd }} -DCMAKE_C_FLAGS="-Wall -Wextra -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_APPEND_EXTENSION=${{ matrix.autoappend.flag }} -DBUILD_SHARED_LIBS=${{ matrix.shared_lib.flag }} -DNFD_BUILD_TESTS=ON ..
@@ -189,3 +189,75 @@ jobs:
189189
path: |
190190
build/src/*
191191
build/test/*
192+
193+
build-ubuntu-sdl2:
194+
195+
name: Ubuntu latest - GCC, ${{ matrix.portal.name }}, Static, SDL2
196+
runs-on: ubuntu-latest
197+
198+
strategy:
199+
matrix:
200+
portal: [ {flag: OFF, dep: libgtk-3-dev, name: GTK}, {flag: ON, dep: libdbus-1-dev, name: Portal} ] # The NFD_PORTAL setting defaults to OFF (i.e. uses GTK)
201+
202+
steps:
203+
- name: Checkout
204+
uses: actions/checkout@v2
205+
- name: Install Dependencies
206+
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }} libsdl2-dev libsdl2-ttf-dev
207+
- name: Configure
208+
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-Wall -Wextra -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_APPEND_EXTENSION=OFF -DNFD_BUILD_TESTS=OFF -DNFD_BUILD_SDL2_TESTS=ON ..
209+
- name: Build
210+
run: cmake --build build --target install
211+
- name: Upload test binaries
212+
uses: actions/upload-artifact@v2
213+
with:
214+
name: Ubuntu latest - GCC, ${{ matrix.portal.name }}, Static, SDL2
215+
path: |
216+
build/src/*
217+
build/test/*
218+
219+
build-macos-sdl2:
220+
221+
name: MacOS latest - Clang, Static, SDL2
222+
runs-on: macos-latest
223+
224+
steps:
225+
- name: Checkout
226+
uses: actions/checkout@v2
227+
- name: Install Dependencies
228+
run: brew install sdl2 sdl2_ttf
229+
- name: Configure
230+
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-Wall -Wextra -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -pedantic" -DNFD_BUILD_TESTS=OFF -DNFD_BUILD_SDL2_TESTS=ON ..
231+
- name: Build
232+
run: cmake --build build --target install
233+
- name: Upload test binaries
234+
uses: actions/upload-artifact@v2
235+
with:
236+
name: MacOS latest - Clang, Static, SDL2
237+
path: |
238+
build/src/*
239+
build/test/*
240+
241+
build-windows-sdl2:
242+
243+
name: Windows latest - MSVC, Static, SDL2
244+
runs-on: windows-latest
245+
246+
steps:
247+
- name: Checkout
248+
uses: actions/checkout@v2
249+
- name: Install pkgconfiglite
250+
run: choco install pkgconfiglite
251+
- name: Install Dependencies
252+
run: vcpkg integrate install && vcpkg install sdl2 sdl2-ttf --triplet=x64-windows-release
253+
- name: Configure
254+
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET="x64-windows-release" -DNFD_BUILD_TESTS=OFF -DNFD_BUILD_SDL2_TESTS=ON ..
255+
- name: Build
256+
run: cmake --build build --target install --config Release
257+
- name: Upload test binaries
258+
uses: actions/upload-artifact@v2
259+
with:
260+
name: Windows latest - MSVC, Static, SDL2
261+
path: |
262+
build/src/Release/*
263+
build/test/Release/*

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif ()
88

99
option(BUILD_SHARED_LIBS "Build a shared library instead of static" OFF)
1010
option(NFD_BUILD_TESTS "Build tests for nfd" ${nfd_ROOT_PROJECT})
11+
option(NFD_BUILD_SDL2_TESTS "Build SDL2 tests for nfd" OFF)
1112
option(NFD_INSTALL "Generate install target for nfd" ${nfd_ROOT_PROJECT})
1213

1314
set(nfd_PLATFORM Undefined)
@@ -48,6 +49,6 @@ endif()
4849

4950
add_subdirectory(src)
5051

51-
if(${NFD_BUILD_TESTS})
52+
if(${NFD_BUILD_TESTS} OR ${NFD_BUILD_SDL2_TESTS})
5253
add_subdirectory(test)
5354
endif()

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ set(TARGET_NAME nfd)
22

33
set(PUBLIC_HEADER_FILES
44
include/nfd.h
5-
include/nfd.hpp)
5+
include/nfd.hpp
6+
include/nfd_sdl2.h
7+
include/nfd_glfw3.h)
68

79
set(SOURCE_FILES ${PUBLIC_HEADER_FILES})
810

src/include/nfd.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,39 @@ typedef struct {
9696
typedef nfdu8filteritem_t nfdnfilteritem_t;
9797
#endif // _WIN32
9898

99+
// The native window handle type.
100+
enum {
101+
NFD_WINDOW_HANDLE_TYPE_UNSET = 0,
102+
// Windows: handle is HWND (the Windows API typedefs this to void*)
103+
NFD_WINDOW_HANDLE_TYPE_WINDOWS = 1,
104+
// Cocoa: handle is NSWindow*
105+
NFD_WINDOW_HANDLE_TYPE_COCOA = 2,
106+
// X11: handle is Window
107+
NFD_WINDOW_HANDLE_TYPE_X11 = 3,
108+
// Wayland support will be implemented separately in the future
109+
};
110+
// The native window handle. If using a platform abstraction framework (e.g. SDL2), this should be
111+
// obtained using the corresponding NFD glue header (e.g. nfd_sdl2.h).
112+
typedef struct {
113+
size_t type; // this is one of the values of the enum above
114+
void* handle;
115+
} nfdwindowhandle_t;
116+
99117
typedef size_t nfdversion_t;
100118

101119
typedef struct {
102120
const nfdu8filteritem_t* filterList;
103121
nfdfiltersize_t filterCount;
104122
const nfdu8char_t* defaultPath;
123+
nfdwindowhandle_t parentWindow;
105124
} nfdopendialogu8args_t;
106125

107126
#ifdef _WIN32
108127
typedef struct {
109128
const nfdnfilteritem_t* filterList;
110129
nfdfiltersize_t filterCount;
111130
const nfdnchar_t* defaultPath;
131+
nfdwindowhandle_t parentWindow;
112132
} nfdopendialognargs_t;
113133
#else
114134
typedef nfdopendialogu8args_t nfdopendialognargs_t;
@@ -119,6 +139,7 @@ typedef struct {
119139
nfdfiltersize_t filterCount;
120140
const nfdu8char_t* defaultPath;
121141
const nfdu8char_t* defaultName;
142+
nfdwindowhandle_t parentWindow;
122143
} nfdsavedialogu8args_t;
123144

124145
#ifdef _WIN32
@@ -127,18 +148,21 @@ typedef struct {
127148
nfdfiltersize_t filterCount;
128149
const nfdnchar_t* defaultPath;
129150
const nfdnchar_t* defaultName;
151+
nfdwindowhandle_t parentWindow;
130152
} nfdsavedialognargs_t;
131153
#else
132154
typedef nfdsavedialogu8args_t nfdsavedialognargs_t;
133155
#endif // _WIN32
134156

135157
typedef struct {
136158
const nfdu8char_t* defaultPath;
159+
nfdwindowhandle_t parentWindow;
137160
} nfdpickfolderu8args_t;
138161

139162
#ifdef _WIN32
140163
typedef struct {
141164
const nfdnchar_t* defaultPath;
165+
nfdwindowhandle_t parentWindow;
142166
} nfdpickfoldernargs_t;
143167
#else
144168
typedef nfdpickfolderu8args_t nfdpickfoldernargs_t;

0 commit comments

Comments
 (0)