Skip to content

8354943: [Linux] Simplify and update glass gtk backend: window sizing, positioning, and state management issues #1789

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

tsayao
Copy link
Collaborator

@tsayao tsayao commented Apr 22, 2025

This is a continuation to JDK-8236651 and it aims to stabilize the linux glass gtk backend.

Overall, it has been made more robust within its scope, particularly in terms of sizing, positioning, and state management.

List of changes:

  1. It embraces the asynchronous nature of X11 by reporting geometry changes only upon receiving a configure event, rather than immediately as before. This is because it merely requests changes from the window manager, which may or may not honor them. However, it still reports changes immediately in certain special cases, such as when the window has not yet been realized (i.e., when the window has not actually been created yet). One scenario where this behavior is evident is when we request the window to move to position (0, 0), but the window manager instead places it in the top-right corner where panels converge.
  2. FullScreen now keeps track of geometry changes and apply them on restore as documented on Stage.java. No geometry changes affects the FullScreen state;
  3. States (fullscreen, maximized and iconify) are now reported back to Java when it actually happens rather than immediately (except when not realized);
  4. When a window is maximized, it will ignore geometry changes and restore to the geometry it had prior to being maximized. After some testing, I believe this is the best behavior for platform compatibility;
  5. Unifies the WindowContext class: previously, there were three separate classes—two of which (for applets and Java Web Start) were removed, leaving only one. However, the supporting infrastructure was still there partially. Unify WindowContext in glass-gtk
  6. Tests were added and re-enabled to ensure everything works correctly. The stage tests now cover various StageStyle configurations, as I found that DECORATED stages often behave differently from UNDECORATED or UTILITY stages;
  7. Added Logs for debugging. Enable it with -PCONF=DebugNative;
  8. Old work-arounds dating back to Ubuntu 16.04 with Compiz were removed.

A simple manual test is also provided but I would prefer to move it's functionality to monkey tester:
java @build/run.args tests/manual/stage/TestStage.java

List of fixed issues:

  1. [Linux] Stage.setMaximized() before show() does not persist
  2. [Linux] Intermittent test failure in IconifyTest.canIconifyDecoratedStage
  3. [Linux] Initial window position is not centered on Ubuntu 24.04 / Xorg
  4. [Linux] Some of the SizeToSceneTest fail in Ubuntu 24.04
  5. [Linux] View size glitch when resizing past max window size
  6. RestoreSceneSizeTest fails in Ubuntu 24.04
  7. DualWindowTest fails intermittently on Linux

The Xorg-related bugs were not issues within JavaFX itself, so they were addressed through workarounds - such as delaying the initial state and re-checking the geometry when the window is first mapped.

IMPORTANT: While this is open for review, please allow me some time to further polish and test it before final approval. Feedback is welcome—especially regarding any need to disable the new tests on specific platforms, as some of them might fail.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 2 Reviewers)

Issue

  • JDK-8354943: [Linux] Simplify and update glass gtk backend: window sizing, positioning, and state management issues (Task - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1789/head:pull/1789
$ git checkout pull/1789

Update a local copy of the PR:
$ git checkout pull/1789
$ git pull https://git.openjdk.org/jfx.git pull/1789/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1789

View PR using the GUI difftool:
$ git pr show -t 1789

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1789.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 22, 2025

👋 Welcome back tsayao! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 22, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Ready for review label Apr 22, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 22, 2025

@mlbridge
Copy link

mlbridge bot commented Apr 22, 2025

Webrevs

@kevinrushforth
Copy link
Member

/reviewers 2 reviewers

Reviewers: @lukostyra @kevinrushforth

@beldenfox If you have time, your review would be appreciated as well.

@openjdk
Copy link

openjdk bot commented Apr 22, 2025

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

@beldenfox
Copy link
Contributor

Thanks for adding these tests. I'm currently tracking down two bugs on macOS that should have been caught a long time ago. Looks like these tests cover those cases (finally).

I will at least review and run the tests on macOS and report back. I might have time to run the tests on Windows 11. I don't have a Windows 10 box to test one.

@lukostyra
Copy link
Contributor

I'll give this a thorough read and report back.

In the meantime, I recently was tackling JDK-8321624 and i have to wonder if it got fixed in the process of your changes? It is intermittent, I managed to get it to fail locally on my VM and it seemed like a race between window manager showing the window and us wanting to move it. Judging by the list of bugs you fixed this one could maybe also make he list.

Copy link
Contributor

@beldenfox beldenfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a rough pass on macOS and Windows. There's some failures in the StageLocation and StageAttributes tests that I haven't had time to look into.

You might want to consider adding a few delay constants and using them instead of the 500's you've scattered through these tests. There's the delay needed for big state changes (like entering and exiting fullscreen) and that needs to be 500 or more. Then there's the delay for waiting for a layout pulse and I'm assuming that could be significantly shorter.

There seem to be places where you compare an attribute like Stage.getWidth() against a constant using strict equality and other places where you provide a tolerance delta. I suspect you want a delta in more locations but someone else will have to chime in on that. I think this mostly affects Windows machines using fractional scaling.

There was a discussion a while back about naming conventions and I think the consensus was that new tests should not have "test" in the name (so testMinSize should be minSize or minStageSize). But I might be wrong on that and in the end it's a matter of style.

@EnumSource(value = StageStyle.class,
mode = EnumSource.Mode.INCLUDE,
names = {"DECORATED", "UNDECORATED", "TRANSPARENT"})
void testUnFullScreenChangedSize(StageStyle stageStyle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec changes to the size or position of a window while it's in fullscreen mode will be ignored and applied after the window leaves fullscreen mode. That's not how it currently works on macOS or Windows 11. Actually implementing that part of the spec would be complicated and probably not worth the development cycles. I would rather remove that wording and drop the testUnFullScreenChangeSize and Position tests.

I imagine this was easy to implement back when fullscreen was implemented as a separate window. It's not clear this is useful behavior, the spec might just have captured an implementation detail and elevated it to a feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was kind of on the fence with this one. Maybe it’s a case where the docs in Stage.java need fixing — they do also say that width and height should reflect the unfullscreened size. But there are several tests that check the fullscreen size against the screen size, so I opted for notifying the fullscreen sizes.

@EnumSource(value = StageStyle.class,
mode = EnumSource.Mode.INCLUDE,
names = {"DECORATED", "UNDECORATED", "TRANSPARENT"})
void testFullScreenMaxSize(StageStyle stageStyle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're assuming that fullscreen mode should ignore the max size properties. That's not how Windows 11 and macOS work. On macOS the window expands to the max size and is then centered on a black screen. On Windows 11 it ends up in the upper left corner with the desktop showing beneath it. It looks weird but I don't think there's much point to changing the implementation on these two platforms.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m going to remove this test and undo the workaround I added to support it. I initially thought this behavior was consistent with how it works on Windows, but I think I got confused — Windows does allow a fullscreen, unresizable Stage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. But it does bug a little different than windows, it acts like it's fullscreen, but its not.

@EnumSource(value = StageStyle.class,
mode = EnumSource.Mode.INCLUDE,
names = {"DECORATED", "UNDECORATED", "TRANSPARENT"})
void testMaximizeMaxSize(StageStyle stageStyle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes that maximizing a window will ignore the max size settings. That's not how it works on macOS and it would be a bear to try to implement this. I think we should remove this test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually worked around by removing the constraints, maximize and restore back the constraints when unmaximized. Window does allow this. I would prefer to not allow as well and invert the test (or remove it).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

@EnumSource(value = StageStyle.class,
mode = EnumSource.Mode.INCLUDE,
names = {"DECORATED", "UNDECORATED", "TRANSPARENT", "UTILITY"})
void testMinSize(StageStyle stageStyle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes! This test uncovers a long-standing problem and is failing on macOS and Windows. In general glass will only send a resize notification if the window's size actually changes. When you set the width and height here JavaFX records the new values, sends them on to glass, and glass doesn't respond because the window size doesn't change. The property values do not get corrected to reflect the actual window size and the test fails.

(I am not a fan of the JavaFX property-based API for setting window attributes. Basically JavaFX records an attribute change as if it has already happened and THEN sends it on to glass to be acted on. This creates endless complications like this.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to work around this. It's a little worse, because if the Stage is fullscreen and we call setWitdth, for example, JavaFX will imediatelly set the width (but the Stage is fullscreen!).

private static final int TO_X = 500;
private static final int TO_Y = 500;
private static final Color COLOR = Color.RED;
private static final double TOLERANCE = 0.00;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want a non-zero tolerance for color matching.

tsayao added 2 commits April 26, 2025 09:57
…ng when unresizable)

- Improve code on gtk_window.cpp
- Add delta for sizing (as Martin suggested)
- Add constants for wait times (as Martin suggested)
@tsayao
Copy link
Collaborator Author

tsayao commented Apr 26, 2025

I'll give this a thorough read and report back.

In the meantime, I recently was tackling JDK-8321624 and i have to wonder if it got fixed in the process of your changes? It is intermittent, I managed to get it to fail locally on my VM and it seemed like a race between window manager showing the window and us wanting to move it. Judging by the list of bugs you fixed this one could maybe also make he list.

The DualWindow test consistently fails without these changes on my Ubuntu 24.04 test VM, and consistently passes with the changes applied. However, on a physical machine running Ubuntu 24.04, the test passes even without the changes.

Since I changed the positioning code and it does passes the tests, it might be fixed.

@tsayao
Copy link
Collaborator Author

tsayao commented Apr 27, 2025

Please wait a little before reviewing the glass GTK part, as I may have found a way to improve it further

@lukostyra
Copy link
Contributor

The DualWindow test consistently fails without these changes on my Ubuntu 24.04 test VM, and consistently passes with the changes applied. However, on a physical machine running Ubuntu 24.04, the test passes even without the changes.

Since I changed the positioning code and it does passes the tests, it might be fixed.

Good news! Problems were usually on slower environments ex. VMs. I would add this test to the list as well, and I'll verify for its stability during my review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Ready for review
Development

Successfully merging this pull request may close these issues.

4 participants