Skip to content

Commit

Permalink
feat(nfd) support XDG Desktop Portal backend
Browse files Browse the repository at this point in the history
May optionally be enabled with the new NFD_LINUX_PORTAL configuration
option (or -Dorg.lwjgl.nfd.linux.portal=true).

Close #893
  • Loading branch information
Spasi committed Aug 14, 2023
1 parent 698db42 commit 1d01a01
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
13 changes: 12 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,18 @@
<release-module name="nanovg" native-library="lwjgl_nanovg" title="NanoVG" if:true="${binding.nanovg}"/>

<!-- Native File Dialog -->
<release-module name="nfd" native-library="lwjgl_nfd" title="Native File Dialog" if:true="${binding.nfd}"/>
<release-module name="nfd" native-library="lwjgl_nfd" title="Native File Dialog" if:true="${binding.nfd}">
<natives>
<get-release platform="linux" arch="x64" file="liblwjgl_nfd_portal.so"/>
<get-release platform="linux" arch="x64" file="liblwjgl_nfd_portal.so.git"/>

<get-release platform="linux" arch="arm64" file="liblwjgl_nfd_portal.so"/>
<get-release platform="linux" arch="arm64" file="liblwjgl_nfd_portal.so.git"/>

<get-release platform="linux" arch="arm32" file="liblwjgl_nfd_portal.so"/>
<get-release platform="linux" arch="arm32" file="liblwjgl_nfd_portal.so.git"/>
</natives>
</release-module>

<!-- Nuklear -->
<release-module name="nuklear" native-library="lwjgl_nuklear" title="Nuklear" if:true="${binding.nuklear}"/>
Expand Down
25 changes: 23 additions & 2 deletions config/linux/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

<macrodef name="build">
<attribute name="module"/>
<attribute name="suffix" default=""/>
<attribute name="linker" default="gcc"/>
<attribute name="lang" default="c"/>
<attribute name="gcc.exec" default="${gcc.prefix}gcc${gcc.suffix}"/>
Expand All @@ -79,12 +80,12 @@
<property name="src.generated" location="${module.lwjgl}/@{module}/src/generated/c" relative="true"/>

<local name="name"/>
<condition property="name" value="lwjgl" else="lwjgl_@{module}">
<condition property="name" value="lwjgl" else="lwjgl_@{module}@{suffix}">
<equals arg1="@{module}" arg2="core"/>
</condition>

<local name="dest"/>
<property name="dest" value="${bin.native}/@{module}"/>
<property name="dest" value="${bin.native}/@{module}@{suffix}"/>

<beforeCompile/>
<compile lang="@{lang}" gcc.exec="@{gcc.exec}" gpp.exec="@{gpp.exec}" flags="@{flags}" simple="@{simple}">
Expand Down Expand Up @@ -282,6 +283,26 @@
<arg value="-lgdk-3"/>
</link>
</build>
<build module="nfd" suffix="_portal" simple="true" linker="g++" if:true="${binding.nfd}">
<beforeCompile>
<local name="linux.triplet"/>
<condition property="linux.triplet" value="x86_64-linux-gnu"><not><isset property="build.arch.arm"/></not></condition>
<condition property="linux.triplet" value="arm-linux-gnueabihf"><isset property="build.arch.arm32"/></condition>
<condition property="linux.triplet" value="aarch64-linux-gnu"><isset property="build.arch.arm64"/></condition>

<compile lang="c++">
<arg line="-I/usr/include/dbus-1.0 -I/usr/lib/${linux.triplet}/dbus-1.0/include"/>
<arg value="-I${src.main.rel}/include"/>
<fileset dir="." includes="${src.main}/nfd_portal.cpp"/>
</compile>
</beforeCompile>
<source>
<arg value="-I${src.main.rel}/include"/>
</source>
<link>
<arg value="-ldbus-1"/>
</link>
</build>

<!-- Nuklear -->
<build simple="true" module="nuklear">
Expand Down
1 change: 1 addition & 0 deletions doc/notes/3.3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 18 additions & 7 deletions modules/generator/src/main/kotlin/org/lwjgl/generator/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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();"
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,16 @@ public class Configuration<T> {
/** Similar to {@link #LIBRARY_NAME} for the LLVM/LTO library (<b>org.lwjgl.llvm.clang.libname</b>). */
public static final Configuration<String> 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.
*
* <p style="font-family: monospace">
* Property: <b>org.lwjgl.nfd.linux.portal</b><br>
* &nbsp; &nbsp;Usage: Static</p>
*/
public static final Configuration<Boolean> NFD_LINUX_PORTAL = new Configuration<>("org.lwjgl.nfd.linux.portal", StateInit.BOOLEAN);

// -- ODBC

/** Similar to {@link #LIBRARY_NAME} for the ODBC library (<b>org.lwjgl.odbc.libname</b>). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1d01a01

Please sign in to comment.