On Thu, 8 Jan 2026 11:24:20 GMT, Lukasz Kostyra <[email protected]> wrote:

>> Flatpak is a framework for distributing desktop applications across various 
>> Linux distributions, that runs each application into its own sandbox to 
>> limit its access to the host environment to the strict minimum, including 
>> access to the network, HW devices or the host file system.
>> To do so, it provides a specific set of APIs, known as "XDG Desktop Portal " 
>> that the guest application must be aware of to take full advantage of ; 
>> which is not the case for Java/JavaFX based applications.
>> 
>> Fortunately, some level of support for XDG Desktop Portal is baked into 
>> GTK3, which JavaFX could easily take advantage of.
>> One such opportunity is replace explicit uses of GtkFileChooserDialog with 
>> GtkFileChooserNative.
>> 
>> GtkFileChooserNative is an abstraction of a dialog box suitable for use with 
>> "File/Open" or "File/Save as" commands. By default, this just uses a 
>> GtkFileChooserDialog to implement the actual dialog. However, on certain 
>> platforms, such as Windows and macOS, the native platform file chooser is 
>> used instead. 
>> When the application is running in a sandboxed environment without direct 
>> filesystem access (such as Flatpak), GtkFileChooserNative may call the 
>> proper APIs (portals) to let the user choose a file and make it available to 
>> the application.
>
> It's a small change but we'll have to thoroughly test it before integrating. 
> I'll take a look at it, but a second pair of eyes will be needed for 
> verification on Linux.

Thanks for looking into this, @lukostyra 

Here's a thing that I noticed during my own testing that might be of interest: 
I have verified that when running a test app as a standard process, the file 
chooser dialog resulting from calling `GtkFileChooserNative`  is a standard GTK 
dialog that is identical to the one produced via `GtkFileChooserDialog` (and 
when running the test through the XDG portal API, the dialog is indeed a 
"native" dialog that differs depending on when display environment, which is 
the whole point for this change).

There is, however, a visible difference in what is produced by this 
implementation compared to the previous one in JavaFX: the "Open/Save" and 
"Cancel" buttons do not show an icon besides the label:
<img width="1287" height="1021" alt="GtkFileChooser" 
src="https://github.com/user-attachments/assets/61e38ec8-64af-4ff7-8e97-9016b4716f2c";
 />
<img width="1287" height="1021" alt="GtkNativeFileChooser" 
src="https://github.com/user-attachments/assets/f807420f-4b84-4e6a-b318-9fde3e10bb2f";
 />

The reason for that is that `GtkFileChooserNative` does not appear to support 
using `GTK_STOCK_OPEN/CANCEL` that defines both the default (and localized) 
label and icon for these actions: instead it displays the raw string if passed, 
e.g. "gtk-cancel". It is perhaps unsurprising since GTK_STOCK_OPEN et al have 
been deprecated since v3.10[1], while `GtkNativeDialog`  was introduced in 3.20.

I looked, but couldn't find an alternative way to add the icon in the new 
implementation (not that I personally think it is a big loss, but ideally this 
change shouldn't introduce any visual differences when used in the same 
context).

I have, however, verified that passing `NULL` as the buttons' label to use the 
default does result in properly localized labels when switching languages (a 
far more important point, IMO).

[1] https://docs.gtk.org/gtk3/const.STOCK_OPEN.html

-------------

PR Comment: https://git.openjdk.org/jfx/pull/2025#issuecomment-3723665290

Reply via email to