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

Java Swing applications (SWT) lack Desktop integration #15

Open
nbenitez opened this issue Jan 16, 2021 · 7 comments
Open

Java Swing applications (SWT) lack Desktop integration #15

nbenitez opened this issue Jan 16, 2021 · 7 comments

Comments

@nbenitez
Copy link

nbenitez commented Jan 16, 2021

I've been packaging Java GUI applications in flathub recently, they usually are multiplaform apps (Windows, Mac and Linux) which use Java Swing interface. And most of them fail to open url links from their dialogs or menu items (eg. to visit their project page or issue tracker, or to show their online documentation), another one also failed to launch file browser (eg. Nautilus) to show a local directory.

These apps all use a Java api for Desktop integration, which is the following Desktop class:
https://docs.oracle.com/javase/9/docs/api/java/awt/Desktop.html

Unfortunately, the linux desktop integration in java is very old and outdated, it uses the gnome_url_show() call which is provided by deprecated library libgnome which is not even present in modern linux distros. See below how gnome_url_show() is used in the Java source code:
https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/java.desktop/unix/classes/sun/awt/X11/XDesktopPeer.java#l119

So, in order for Java Swing applications to work well in their Desktop integration I propose to add a small patch to openjdk extension to replace the gnome_url_show() call for one of xdg-open so it works perfectly fine under flatpak when the app manifest also includes the flatpak-xdg-utils module.

Related issue: flatpak/xdg-desktop-portal#519

nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 17, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
@nbenitez
Copy link
Author

Well, diving a bit more in the Java source, gnome_url_show() is called when libgnome is found, but it also checks whether gtk3 and gtk2 is installed, and calls gtk_show_uri() in that case. Links to that java source:
https://hg.openjdk.java.net/jdk/jdk15/file/0dabbdfd97e6/src/java.desktop/unix/native/libawt_xawt/xawt/awt_Desktop.c#l78
https://hg.openjdk.java.net/jdk/jdk15/file/0dabbdfd97e6/src/java.desktop/unix/native/libawt_xawt/awt/gtk_interface.c#l46

I just sent PR #16 to replace those with a call to xdg-open which will work in any desktop not just GTK/Gnome and will also work in the minimal Freedesktop runtime which many Java apps are built upon in flathub.

nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 17, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 17, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 17, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 18, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 18, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 19, 2021
even when there's no GTK installed, by replacing
gnome_url_show() (which also may call gtk_show_uri())
by 'xdg-open' command, which will work in any desktop
and not only GTK/Gnome.

It also works when using the minimal Freedesktop
runtime, which many Java apps are built upon.

flathub#15
nbenitez added a commit to nbenitez/org.freedesktop.Sdk.Extension.openjdk11 that referenced this issue Jan 20, 2021
by replacing gnome_url_show() call (it may also
call gtk_show_uri()) by a 'xdg-open' command,
which will work inside the flatpak sandbox, and
for any desktop environment not just GTK/Gnome.

Many Java apps in flathub are SWT apps which are
built upon the minimal Freedesktop runtime, and
they are currently broken with respect to launch
web links or open local files, this commit patches
the Desktop class so it can work under the sandbox.

flathub#15
@12people
Copy link

Opening URLs is not the only problem here — file chooser dialogs are as well. It'd be great if that was added too. Or, alternatively, if a new Java package was created that developers could use to easily integrate xdg-desktop-portal into Java apps.

@nbenitez
Copy link
Author

nbenitez commented Jan 21, 2021

Opening URLs is not the only problem here — file chooser dialogs are as well. It'd be great if that was added too. Or, alternatively, if a new Java package was created that developers could use to easily integrate xdg-desktop-portal into Java apps.

That would be cool, but I see that more as an enhancement, first we need to handle the issue here which is more of a bug, where many java apps are currently buggy in that they cannot open links or local files/directories (those which are allowed by --filesystem flag).

But in your line, I think other buggy behaviours of java apps that may be patched further (after this gets accepted):

  • Setting JVM default temp dir to be ~/.var/$APP_ID/cache/tmp so people can stop adding -Djava.io.tmpdir=bla in their java launch scripts. This is for java apps that create temp files, using the java api CreateTempFile() which would fail if not setting the aforementioned hack, as JVM hardcodes /tmp as default temp dir on unix/linux.
  • Automatically supporting HiDPI in java swing apps. Currently I add that HiDPI support in the bash launch script for every java app I package, but there are lot of java apps in flathub that don't have it and display very tiny in HiDPI displays.

@12people
Copy link

@nbenitez What license is your HiDPI support script? I'd like to use it in my own Flathub project — FOSStriangulator

@nbenitez
Copy link
Author

@nbenitez What license is your HiDPI support script? I'd like to use it in my own Flathub project — FOSStriangulator

Public domain, no license.

@12people
Copy link

Wonderful, thank you!

@mbooth101
Copy link
Collaborator

mbooth101 commented Sep 22, 2021

Opening URLs is not the only problem here — file chooser dialogs are as well. It'd be great if that was added too. Or, alternatively, if a new Java package was created that developers could use to easily integrate xdg-desktop-portal into Java apps.

FWIW the Java UI framework SWT has full portal integration because it is built on GTK3 and uses all native chooser dialogs. This is how Eclipse (a large Java application) got full desktop portal integration -- it just inherits it from GTK3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants