From 1d01a01c45c8c1e09138128ea6820e2559543820 Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Mon, 14 Aug 2023 22:38:49 +0300 Subject: [PATCH] feat(nfd) support XDG Desktop Portal backend May optionally be enabled with the new NFD_LINUX_PORTAL configuration option (or -Dorg.lwjgl.nfd.linux.portal=true). Close #893 --- build.xml | 13 +++++++++- config/linux/build.xml | 25 +++++++++++++++++-- doc/notes/3.3.3.md | 1 + .../kotlin/org/lwjgl/generator/Modules.kt | 25 +++++++++++++------ .../java/org/lwjgl/system/Configuration.java | 10 ++++++++ .../java/org/lwjgl/util/nfd/LibNFD.java | 2 +- 6 files changed, 65 insertions(+), 11 deletions(-) diff --git a/build.xml b/build.xml index 5566f94014..c8e12f5858 100644 --- a/build.xml +++ b/build.xml @@ -1672,7 +1672,18 @@ - + + + + + + + + + + + + diff --git a/config/linux/build.xml b/config/linux/build.xml index 4fa90ee28e..d65dacda28 100644 --- a/config/linux/build.xml +++ b/config/linux/build.xml @@ -60,6 +60,7 @@ + @@ -79,12 +80,12 @@ - + - + @@ -282,6 +283,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/doc/notes/3.3.3.md b/doc/notes/3.3.3.md index 8151f9416b..cbb1fd7e2f 100644 --- a/doc/notes/3.3.3.md +++ b/doc/notes/3.3.3.md @@ -8,6 +8,7 @@ This build includes the following changes: - meshoptimizer: Updated to 0.19 (up from 0.18) - NativeFileDialog: Update to 1.1.0 (up from 1.0.2) + * Added `Configuration.NFD_LINUX_PORTAL` which enables the XDG Desktop Portal backend on Linux. (#893) - OpenAL Soft: Updated to 1.23.1 (up from 1.23.0) * Added `AL_SOFT_buffer_length_query` extension. * Added `AL_SOFT_source_start_delay` extension. diff --git a/modules/generator/src/main/kotlin/org/lwjgl/generator/Modules.kt b/modules/generator/src/main/kotlin/org/lwjgl/generator/Modules.kt index ebaa5cc7c9..c4acc53977 100644 --- a/modules/generator/src/main/kotlin/org/lwjgl/generator/Modules.kt +++ b/modules/generator/src/main/kotlin/org/lwjgl/generator/Modules.kt @@ -423,7 +423,11 @@ enum class Module( Contains bindings to ${url("https://github.com/btzy/nativefiledialog-extended", "Native File Dialog Extended")}, a small C library that portably invokes native file open, folder select and file save dialogs. Write dialog code once and have it pop up native dialogs on all supported platforms. """, - library = JNILibrary.create("LibNFD", setupAllocator = true) + library = JNILibrary.create( + "LibNFD", + libraryName = "Platform.get() == Platform.LINUX && Configuration.NFD_LINUX_PORTAL.get(false) ? \"lwjgl_nfd_portal\" : \"lwjgl_nfd\"", + setupAllocator = true + ) ), NUKLEAR( "nuklear", @@ -884,8 +888,14 @@ float h = layout.dimensions(YGDimensionHeight);""")} internal interface JNILibrary { companion object { fun simple(expression: String? = null): JNILibrary = JNILibrarySimple(expression) - fun create(className: String, custom: Boolean = false, setupAllocator: Boolean = false, cpp: Boolean = false): JNILibrary = - JNILibraryWithInit(className, custom, setupAllocator, cpp) + fun create( + className: String, + libraryName: String? = null, + custom: Boolean = false, + setupAllocator: Boolean = false, + cpp: Boolean = false + ): JNILibrary = + JNILibraryWithInit(className, libraryName, custom, setupAllocator, cpp) } fun expression(module: Module): String @@ -902,9 +912,10 @@ private class JNILibrarySimple(private val expression: String?) : JNILibrary { private class JNILibraryWithInit constructor( private val className: String, - private val custom: Boolean = false, - private val setupAllocator: Boolean = false, - private val cpp: Boolean = false + private val libraryName: String?, + private val custom: Boolean, + private val setupAllocator: Boolean, + private val cpp: Boolean ) : JNILibrary { override fun expression(module: Module) = "$className.initialize();" @@ -933,7 +944,7 @@ private class JNILibraryWithInit constructor( """${access.modifier}final class $className { static { - String libName = Platform.mapLibraryNameBundled("lwjgl_${module.key}"); + String libName = Platform.mapLibraryNameBundled(${libraryName ?: "\"lwjgl_${module.key}\""}); Library.loadSystem(System::load, System::loadLibrary, $className.class, "${module.java}", libName);${if (setupAllocator) """ MemoryAllocator allocator = getAllocator(Configuration.DEBUG_MEMORY_ALLOCATOR_INTERNAL.get(true)); diff --git a/modules/lwjgl/core/src/main/java/org/lwjgl/system/Configuration.java b/modules/lwjgl/core/src/main/java/org/lwjgl/system/Configuration.java index 16eb36efe2..7e36d6105d 100644 --- a/modules/lwjgl/core/src/main/java/org/lwjgl/system/Configuration.java +++ b/modules/lwjgl/core/src/main/java/org/lwjgl/system/Configuration.java @@ -517,6 +517,16 @@ public class Configuration { /** Similar to {@link #LIBRARY_NAME} for the LLVM/LTO library (org.lwjgl.llvm.clang.libname). */ public static final Configuration LLVM_LTO_LIBRARY_NAME = new Configuration<>("org.lwjgl.llvm.lto.libname", StateInit.STRING); + // -- NativeFileDialog + /** + * Set to true to enable NativeFileDialog's XDG Desktop Portal backend on Linux. + * + *

+ * Property: org.lwjgl.nfd.linux.portal
+ *    Usage: Static

+ */ + public static final Configuration NFD_LINUX_PORTAL = new Configuration<>("org.lwjgl.nfd.linux.portal", StateInit.BOOLEAN); + // -- ODBC /** Similar to {@link #LIBRARY_NAME} for the ODBC library (org.lwjgl.odbc.libname). */ diff --git a/modules/lwjgl/nfd/src/generated/java/org/lwjgl/util/nfd/LibNFD.java b/modules/lwjgl/nfd/src/generated/java/org/lwjgl/util/nfd/LibNFD.java index b5303ee883..e2904a2155 100644 --- a/modules/lwjgl/nfd/src/generated/java/org/lwjgl/util/nfd/LibNFD.java +++ b/modules/lwjgl/nfd/src/generated/java/org/lwjgl/util/nfd/LibNFD.java @@ -13,7 +13,7 @@ final class LibNFD { static { - String libName = Platform.mapLibraryNameBundled("lwjgl_nfd"); + String libName = Platform.mapLibraryNameBundled(Platform.get() == Platform.LINUX && Configuration.NFD_LINUX_PORTAL.get(false) ? "lwjgl_nfd_portal" : "lwjgl_nfd"); Library.loadSystem(System::load, System::loadLibrary, LibNFD.class, "org.lwjgl.nfd", libName); MemoryAllocator allocator = getAllocator(Configuration.DEBUG_MEMORY_ALLOCATOR_INTERNAL.get(true));