Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ jobs:

build-ubuntu:

name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.casesensitive.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.wayland.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.casesensitive.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
runs-on: ${{ matrix.os.label }}

strategy:
matrix:
os: [ {label: ubuntu-latest, name: latest}, {label: ubuntu-22.04, name: 22.04} ]
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)
autoappend: [ {flag: OFF, name: NoAppendExtn} ] # By default the NFD_PORTAL mode does not append extensions, because it breaks some features of the portal
wayland: [ {flag: OFF, dep: , name: NoWayland} ]
casesensitive: [ {flag: OFF, name: CaseInsensitive} ] # Case insensitive or case sensitive file filtering
compiler: [ {c: gcc, cpp: g++, name: GCC}, {c: clang, cpp: clang++, name: Clang} ] # The default compiler is gcc/g++
cppstd: [20, 11]
Expand All @@ -53,34 +54,47 @@ jobs:
- os: {label: ubuntu-latest, name: latest}
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
autoappend: {flag: ON, name: AutoAppendExtn}
wayland: {flag: OFF, dep: , name: NoWayland}
casesensitive: {flag: OFF, name: CaseInsensitive}
compiler: {c: gcc, cpp: g++, name: GCC}
cppstd: 11
shared_lib: {flag: OFF, name: Static}
- os: {label: ubuntu-latest, name: latest}
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
autoappend: {flag: ON, name: AutoAppendExtn}
wayland: {flag: OFF, dep: , name: NoWayland}
casesensitive: {flag: OFF, name: CaseInsensitive}
compiler: {c: clang, cpp: clang++, name: Clang}
cppstd: 11
shared_lib: {flag: OFF, name: Static}
- os: {label: ubuntu-latest, name: latest}
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
autoappend: {flag: OFF, name: NoAppendExtn}
wayland: {flag: OFF, dep: , name: NoWayland}
casesensitive: {flag: OFF, name: CaseInsensitive}
compiler: {c: gcc, cpp: g++, name: GCC}
cppstd: 11
shared_lib: {flag: ON, name: Shared}
- os: {label: ubuntu-latest, name: latest}
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
autoappend: {flag: OFF, name: NoAppendExtn}
wayland: {flag: ON, dep: libwayland-dev libwayland-bin, name: Wayland}
casesensitive: {flag: OFF, name: CaseInsensitive}
compiler: {c: gcc, cpp: g++, name: GCC}
cppstd: 11
shared_lib: {flag: ON, name: Static}
- os: {label: ubuntu-latest, name: latest}
portal: {flag: OFF, dep: libgtk-3-dev, name: GTK}
autoappend: {flag: OFF, name: NoAppendExtn}
wayland: {flag: OFF, dep: , name: NoWayland}
casesensitive: {flag: ON, name: CaseSensitive}
compiler: {c: gcc, cpp: g++, name: GCC}
cppstd: 11
shared_lib: {flag: OFF, name: Static}
- os: {label: ubuntu-latest, name: latest}
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
autoappend: {flag: OFF, name: NoAppendExtn}
wayland: {flag: OFF, dep: , name: NoWayland}
casesensitive: {flag: ON, name: CaseSensitive}
compiler: {c: gcc, cpp: g++, name: GCC}
cppstd: 11
Expand All @@ -89,16 +103,18 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }}
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }} ${{ matrix.wayland.dep }}
- name: Configure
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 -Wshadow -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_APPEND_EXTENSION=${{ matrix.autoappend.flag }} -DNFD_CASE_SENSITIVE_FILTER=${{ matrix.casesensitive.flag }} -DBUILD_SHARED_LIBS=${{ matrix.shared_lib.flag }} -DNFD_BUILD_TESTS=ON ..
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 -Wshadow -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_WAYLAND=${{ matrix.wayland.flag }} -DNFD_APPEND_EXTENSION=${{ matrix.autoappend.flag }} -DNFD_CASE_SENSITIVE_FILTER=${{ matrix.casesensitive.flag }} -DBUILD_SHARED_LIBS=${{ matrix.shared_lib.flag }} -DNFD_BUILD_TESTS=ON ..
- name: Build
run: cmake --build build --target install
- name: Upload test binaries
uses: actions/upload-artifact@v4
with:
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.casesensitive.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.wayland.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.casesensitive.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
path: |
build/src/*
build/test/*
Expand Down Expand Up @@ -208,26 +224,29 @@ jobs:

build-ubuntu-sdl2:

name: Ubuntu latest - GCC, ${{ matrix.portal.name }}, Static, SDL2
name: Ubuntu latest - GCC, ${{ matrix.portal.name }}, ${{ matrix.wayland.name }}, Static, SDL2
runs-on: ubuntu-latest

strategy:
matrix:
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)
wayland: [ {flag: OFF, dep: , name: NoWayland}, {flag: ON, dep: libwayland-dev libwayland-bin, name: Wayland} ]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }} libsdl2-dev libsdl2-ttf-dev
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }} ${{ matrix.wayland.dep }} libsdl2-dev libsdl2-ttf-dev
- name: Configure
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_APPEND_EXTENSION=OFF -DNFD_BUILD_TESTS=OFF -DNFD_BUILD_SDL2_TESTS=ON ..
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_WAYLAND=${{ matrix.wayland.flag }} -DNFD_APPEND_EXTENSION=OFF -DNFD_BUILD_TESTS=OFF -DNFD_BUILD_SDL2_TESTS=ON ..
- name: Build
run: cmake --build build --target install
- name: Upload test binaries
uses: actions/upload-artifact@v4
with:
name: Ubuntu latest - GCC, ${{ matrix.portal.name }}, Static, SDL2
name: Ubuntu latest - GCC, ${{ matrix.portal.name }}, ${{ matrix.wayland.name }}, Static, SDL2
path: |
build/src/*
build/test/*
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3ps/wayland-protocols"]
path = 3ps/wayland-protocols
url = https://gitlab.freedesktop.org/wayland/wayland-protocols.git
1 change: 1 addition & 0 deletions 3ps/wayland-protocols
Submodule wayland-protocols added at 122a47
37 changes: 34 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,33 @@ if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
option(NFD_PORTAL "Use xdg-desktop-portal instead of GTK" OFF)
if(NOT NFD_PORTAL)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
message("Using GTK version: ${GTK3_VERSION}")
message(STATUS "Using GTK version: ${GTK3_VERSION}")
list(APPEND SOURCE_FILES nfd_gtk.cpp)
else()
pkg_check_modules(DBUS REQUIRED dbus-1)
message("Using DBUS version: ${DBUS_VERSION}")
message(STATUS "Using D-Bus version: ${DBUS_VERSION}")
list(APPEND SOURCE_FILES nfd_portal.cpp)
endif()

# for Linux, we support X11, Wayland, or both
option(NFD_X11 "Support X11 on Linux" ON)
option(NFD_WAYLAND "Support Wayland on Linux" ON)
if(NFD_WAYLAND)
pkg_check_modules(WAYLAND REQUIRED wayland-client)
message(STATUS "Using Wayland version: ${WAYLAND_VERSION}")
set(NFD_WAYLAND_PROTOCOL_XDG_FOREIGN ${CMAKE_CURRENT_SOURCE_DIR}/../3ps/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v1.xml)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.h
COMMAND wayland-scanner client-header < ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN} > ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.h
MAIN_DEPENDENCY ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN}
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.c
COMMAND wayland-scanner private-code < ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN} > ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.c
MAIN_DEPENDENCY ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN}
)
list(APPEND SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.h ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.c)
endif()
endif()

if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
Expand Down Expand Up @@ -94,10 +114,21 @@ if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
if(NFD_APPEND_EXTENSION)
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_APPEND_EXTENSION)
endif()

option(NFD_CASE_SENSITIVE_FILTER "Make filters case sensitive" OFF)
if(NFD_CASE_SENSITIVE_FILTER)
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_CASE_SENSITIVE_FILTER)
endif()

if(NFD_X11)
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_X11)
endif()
if(NFD_WAYLAND)
target_include_directories(${TARGET_NAME} PRIVATE ${WAYLAND_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} PRIVATE ${WAYLAND_LINK_LIBRARIES})
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_WAYLAND)
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()

if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
Expand All @@ -122,7 +153,7 @@ if(nfd_COMPILER STREQUAL COMPILER_CLANGCL)
endif()

if(nfd_COMPILER STREQUAL COMPILER_GNU)
target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions -fno-rtti)
target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif()

set_target_properties(${TARGET_NAME} PROPERTIES
Expand Down
8 changes: 7 additions & 1 deletion src/include/nfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ enum {
NFD_WINDOW_HANDLE_TYPE_COCOA = 2,
// X11: handle is Window
NFD_WINDOW_HANDLE_TYPE_X11 = 3,
// Wayland support will be implemented separately in the future
// Wayland: handle is wl_surface*
NFD_WINDOW_HANDLE_TYPE_WAYLAND = 4,
};
// The native window handle. If using a platform abstraction framework (e.g. SDL2), this should be
// obtained using the corresponding NFD glue header (e.g. nfd_sdl2.h).
Expand Down Expand Up @@ -190,6 +191,11 @@ NFD_API nfdresult_t NFD_Init(void);
/** Call this to de-initialize NFD, if NFD_Init returned NFD_OKAY. */
NFD_API void NFD_Quit(void);

struct wl_display;
/** Sets or updates the Wayland display used by your application. Use NULL to remove an existing
* display. Only defined on Linux. */
NFD_API nfdresult_t NFD_SetWaylandDisplay(struct wl_display*);

/** Single file open dialog
*
* It's the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns
Expand Down
20 changes: 20 additions & 0 deletions src/include/nfd_sdl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ extern "C" {
#define NFD_INLINE static inline
#endif // __cplusplus

NFD_INLINE bool NFD_SetDisplayPropertiesFromSDLWindow(SDL_Window* sdlWindow) {
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (!SDL_GetWindowWMInfo(sdlWindow, &info) || info.subsystem != SDL_SYSWM_WAYLAND) {
return false;
}
return NFD_SetWaylandDisplay(info.info.wl.display) == NFD_OKAY;
#else
(void)sdlWindow;
return true;
#endif
}

/**
* Converts an SDL window handle to a native window handle that can be passed to NFDe.
* @param sdlWindow The SDL window handle.
Expand Down Expand Up @@ -59,6 +73,12 @@ NFD_INLINE bool NFD_GetNativeWindowFromSDLWindow(SDL_Window* sdlWindow,
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_X11;
nativeWindow->handle = (void*)info.info.x11.window;
return true;
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
case SDL_SYSWM_WAYLAND:
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_WAYLAND;
nativeWindow->handle = (void*)info.info.wl.surface;
return true;
#endif
default:
// Silence the warning in case we are not using a supported backend.
Expand Down
6 changes: 6 additions & 0 deletions src/nfd_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ nfdresult_t NFD_Init(void) {
}
return NFD_OKAY;
}

nfdresult_t NFD_SetWaylandDisplay(wl_display*) {
// TODO do something with the display
return NFD_OKAY;
}

void NFD_Quit(void) {
// do nothing, GTK cannot be de-initialized
}
Expand Down
Loading