Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GTK4 support #38

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

# Mac OS X rubbish
.DS_Store

# CMake build directory
/build/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ set (CMAKE_CXX_STANDARD 17)
add_subdirectory(src)

option(NFD_BUILD_TESTS "Build tests for nfd" OFF)
if(${NFD_BUILD_TESTS})
if(NFD_BUILD_TESTS)
add_subdirectory(test)
endif()
30 changes: 26 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@ endif()

if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
message("Using GTK version: ${GTK3_VERSION}")
set(NFD_GTK_VERSION "" CACHE STRING "GTK version for Linux builds ('3' or '4')")
set_property(CACHE NFD_GTK_VERSION PROPERTY STRINGS "" 3 4)
# For Linux, we support both GTK3 and GTK4.
# If NFD_GTK_VERSION is not explicitly set, then we take one that is available.
# Otherwise, we find the version that the user wants.
if(NFD_GTK_VERSION STREQUAL "")
pkg_search_module(GTK REQUIRED gtk+-3.0 gtk4)
if(DEFINED GTK_gtk+-3.0_VERSION)
set(GTK_VERSION ${GTK_gtk+-3.0_VERSION})
elseif(DEFINED GTK_gtk4_VERSION)
set(GTK_VERSION ${GTK_gtk4_VERSION})
endif()
elseif(NFD_GTK_VERSION STREQUAL 3)
pkg_check_modules(GTK REQUIRED gtk+-3.0)
elseif(NFD_GTK_VERSION STREQUAL 4)
pkg_check_modules(GTK REQUIRED gtk4)
else()
message(FATAL_ERROR "Unsupported GTK version: ${NFD_GTK_VERSION}")
endif()

message("Using GTK version: ${GTK_VERSION}")
list(APPEND SOURCE_FILES nfd_gtk.cpp)
endif()

Expand All @@ -32,9 +51,12 @@ target_include_directories(${TARGET_NAME}

if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
target_include_directories(${TARGET_NAME}
PRIVATE ${GTK3_INCLUDE_DIRS})
PRIVATE ${GTK_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME}
PRIVATE ${GTK3_LIBRARIES})
PRIVATE ${GTK_LIBRARIES})
string(REPLACE "." ";" GTK_VERSION_LIST ${GTK_VERSION})
list(GET GTK_VERSION_LIST 0 GTK_VERSION_MAJOR)
target_compile_definitions(${TARGET_NAME} PUBLIC NFD_GTK_VERSION=${GTK_VERSION_MAJOR})
endif()

if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
Expand Down
7 changes: 7 additions & 0 deletions src/include/nfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ typedef char nfdnchar_t;
typedef void nfdpathset_t;
typedef struct {
void* ptr;
#if defined(NFD_GTK_VERSION) && NFD_GTK_VERSION == 4
unsigned int next_index;
#endif
} nfdpathsetenum_t;

typedef unsigned int nfdfiltersize_t;
Expand All @@ -43,6 +46,10 @@ typedef struct {
const nfdnchar_t* spec;
} nfdnfilteritem_t;

/* Conventions:
* Output parameter (typically outPath/outPaths), if any, will not be modified if the function
* returns something other than NFD_OKAY. This applies everywhere, including helper functions. */

/* nfd_<targetplatform>.c */

/* free a file path that was returned by the dialogs */
Expand Down
Loading