System File Chooser: Linux: cross-compile native library for ARM64 on x86_64 Linux

This commit is contained in:
Karl Tauber
2025-01-19 16:11:42 +01:00
parent 0a4c01cd40
commit d524536575
8 changed files with 96 additions and 4 deletions

View File

@@ -49,6 +49,9 @@ public class FlatNativeLinuxLibrary
return SystemInfo.isLinux && FlatNativeLibrary.isLoaded( API_VERSION_LINUX );
}
//---- X Window System ----------------------------------------------------
// direction for _NET_WM_MOVERESIZE message
// see https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html
static final int MOVE = 8;
@@ -118,6 +121,28 @@ public class FlatNativeLinuxLibrary
}
//---- GTK ----------------------------------------------------------------
private static Boolean isGtk3Available;
/**
* Checks whether GTK 3 is available.
* Use this before invoking any native method that uses GTK.
* Otherwise the app may terminate immediately if GTK is not installed.
* <p>
* This works because Java uses {@code dlopen(RTLD_LAZY)} to load JNI libraries,
* which only resolves symbols as the code that references them is executed.
*
* @since 3.6
*/
public static boolean isGtk3Available() {
if( isGtk3Available == null )
isGtk3Available = isLibAvailable( "libgtk-3.so.0" ) || isLibAvailable( "libgtk-3.so" );
return isGtk3Available;
}
private native static boolean isLibAvailable( String libname );
/**
* https://docs.gtk.org/gtk3/iface.FileChooser.html#properties
*

View File

@@ -49,8 +49,8 @@ import com.formdev.flatlaf.ui.FlatNativeWindowsLibrary;
* If there are no compile errors, then there is a good chance that it works without further changes.
* If there are compile errors, then you're using a feature that {@code SystemFileChooser} does not support.
* <p>
* Supported platforms are <b>Windows 10+</b>, <b>macOS 10.14+</b> and <b>Linux GTK 3</b>.
* {@code JFileChooser} is used on unsupported platforms.
* Supported platforms are <b>Windows 10+</b>, <b>macOS 10.14+</b> and <b>Linux with GTK 3</b>.
* {@code JFileChooser} is used on unsupported platforms or if GTK 3 is not installed.
* <p>
* {@code SystemFileChooser} requires FlatLaf native libraries (usually contained in flatlaf.jar).
* If not available or disabled (via {@link FlatSystemProperties#USE_NATIVE_LIBRARY}
@@ -421,7 +421,7 @@ public class SystemFileChooser
return new WindowsFileChooserProvider();
else if( SystemInfo.isMacOS && FlatNativeMacLibrary.isLoaded() )
return new MacFileChooserProvider();
else if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isLoaded() )
else if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isLoaded() && FlatNativeLinuxLibrary.isGtk3Available() )
return new LinuxFileChooserProvider();
else // unknown platform or FlatLaf native library not loaded
return new SwingFileChooserProvider();