RFR: 8354943: [Linux] Simplify and update glass gtk backend: window sizing, positioning, and state management issues [v71]
Martin Fox
mfox at openjdk.org
Fri Jan 16 20:47:21 UTC 2026
On Thu, 4 Dec 2025 21:00:47 GMT, Thiago Milczarek Sayao <tsayao at openjdk.org> wrote:
>> This is a continuation to [JDK-8236651](https://bugs.openjdk.org/browse/JDK-8236651) and it aims to stabilize the linux glass gtk backend.
>>
>> This is a refactor of the Glass GTK implementation, primarily focused on window size, positioning, and state management to resolve numerous issues.
>>
>> The main change is that GtkWindow (which is a GtkWidget) has been replaced with a direct use of GdkWindow for windows. This makes sense because GTK includes its own rendering pipeline, whereas JavaFX renders directly to the underlying system window (such as the X11 window) via Prism ES2 using GL and GLX. Most GTK window-related calls have equivalent GDK calls. Since GDK serves as an abstraction over the system window and input events, it aligns better with the purposes of Glass. Additionally, using GTK required various workarounds to integrate with Glass, which are no longer necessary when using GDK directly.
>>
>> It uses a simple C++ Observable to notify the Java side about changes. This approach is more straightforward, as notifications occur at many points and the previous implementation was becoming cluttered.
>>
>> Previously, there were three separate context classes, two of which were used for Java Web Start and Applets. These have now been unified, as they are no longer required.
>>
>> Many tests were added to ensure everything is working correctly. I noticed that some tests produced different results depending on the StageStyle, so they now use @ParameterizedTest to vary the StageStyle.
>>
>> A manual test is also provided. I did not use MonkeyTester for this, as it was quicker to simply run and test manually:`java @build/run.args tests/manual/stage/TestStage.java `
>>
>> While this is focused on XWayland, everything works on pure Xorg as well.
>
> Thiago Milczarek Sayao has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 85 commits:
>
> - Merge branch 'master' into 8354943
>
> # Conflicts:
> # tests/system/src/test/java/test/util/Util.java
> - Merge branch 'master' into 8354943
> - Remote assumeTrue for JDK-8364547
> - Merge branch 'master' into 8354943
> - Merge branch 'master' into 8354943
>
> # Conflicts:
> # modules/javafx.graphics/src/main/native-glass/gtk/glass_window_ime.cpp
> - Merge branch 'master' into 8354943
> - Fix copyright header
> - Revert "8367898: Skip StageFocusTest on Linux"
>
> This reverts commit c95cdcdc9cd8b3070e8076ea91234772d6a21331.
> - Merge branch 'master' into 8354943
> - Remove unused imports
> - ... and 75 more: https://git.openjdk.org/jfx/compare/6626e013...7e3c3205
I'm glad to see this code cleaned up and the new tests added. It would be great if this could get integrated into 27 soon so it gets more real-world testing.
I've left comments in the code related to some minor issues, none of them blocking.
modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkWindow.java line 134:
> 132: minimizeImpl(ptr, minimize);
> 133:
> 134: if (!isVisible()) {
This check is new and only happens when minimizing, not maximizing. Under what conditions does this occur?
modules/javafx.graphics/src/main/native-glass/gtk/glass_window.cpp line 190:
> 188:
> 189: window_size.setOnChange([this](const Size& size) {
> 190: notify_window_resize(is_maximized()
There is a very minor bug here that's also present in the master branch. If the size of a window is changed when it's iconified it can't be un-iconified. This notification tells the Java Window that it has been restored even though it's still iconified which confuses the bookkeeping.
This is an old bug so I would be fine if we just enter a bug report and push the fix off to another PR. Unfortunately there's no way to write an automated test. That would require adding a call to query the OS for the window's state so we can compare it with the state the Java Window is tracking.
modules/javafx.graphics/src/main/native-glass/gtk/glass_window.cpp line 822:
> 820:
> 821: void WindowContext::update_initial_state() {
> 822: GdkWindowState state = gdk_window_get_state(gdk_window);
This handles the case where set_maximized, set_minimized, or enter_fullscreen are called after the peer is created but before it's mapped.
Oh no!
This is an ugly part of the code. For one, when these state flags are set on a Java Window before it is shown the code just stashes them away. When the Window is shown the code applies them in a fixed order: fullscreen, iconified, maximized. So if iconified and maximized are both set the window should end up maximized.
For two, the documentation and code treat iconified/maximized/restored as a trio of mutually exclusive states which are entirely separate from fullscreen (which overrides them all). This is probably a relic of the days when fullscreen was implemented using an entirely separate window. In practice the platform code doesn't honor this separation and if you mix fullscreen with iconified or maximized you'll get different results on different platforms (and the Java state is likely to get confused).
The end result is a bit of a mess. The good news is this leads to the sort of spec violations and bugs that no one notices.
TL;DR - I think the correct order to apply these flags is iconified, maximized, and then fullscreen. This is different than the order the core code uses but, again, as far as it's concerned fullscreen overrides maximized and iconified. To honor that it should be applied last.
modules/javafx.graphics/src/main/native-glass/gtk/glass_window.cpp line 1059:
> 1057:
> 1058: void WindowContext::notify_current_sizes() {
> 1059: notify_window_resize(is_maximized()
This should also be checking for is_iconified. Again, unlikely to be introducing a new bug so this fix can be pushed to a separate PR.
-------------
PR Review: https://git.openjdk.org/jfx/pull/1789#pullrequestreview-3672159390
PR Review Comment: https://git.openjdk.org/jfx/pull/1789#discussion_r2699534109
PR Review Comment: https://git.openjdk.org/jfx/pull/1789#discussion_r2699581987
PR Review Comment: https://git.openjdk.org/jfx/pull/1789#discussion_r2699899249
PR Review Comment: https://git.openjdk.org/jfx/pull/1789#discussion_r2699592229
More information about the openjfx-dev
mailing list