RFR: 8313424: JavaFX controls in the title bar [v3]

Michael Strauß mstrauss at openjdk.org
Mon Oct 21 23:24:09 UTC 2024


On Mon, 21 Oct 2024 10:55:53 GMT, Thiago Milczarek Sayao <tsayao at openjdk.org> wrote:

>> Michael Strauß has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   revert unintended change
>
> A few points observed on Linux:
> 1) It's possible to resize it to 1px using the provided functionality with `gtk_window_begin_resize_drag`. An then it's not possible to resize back. The Headerbar should block resizing to the size of window controls.
> 2) It's not possible to move the window if the cursor is over a control. Maybe you should just  `gtk_window_begin_move_drag`  when a drag is detected, not on click. That would be on `WindowContextBase::process_mouse_motion`;
> 3) The application is closing if the click happens on the top right corner (that's because it's triggering the close button instead of resizing (I think  2 should solve it as well). It closes with:
> `(java:16179): Gtk-CRITICAL **: 07:34:26.721: gtk_window_begin_resize_drag: assertion 'gtk_widget_get_visible (widget)' failed`
> 4) Alt + F8 is working (it's a desktop shortcut for resizing the window) - just pointing out to include in manual testing;
> 5) I think rounded edges should be supported on the HeaderBar, since it's the default on gnome. For that to work, `EXTENDED` should be also transparent on Linux. It would loose the window drop shadow which can be added on the JavaFX side. `gdk_window_set_shadow_width` should be called with the drop shadow size, so the desktop will know the correct window bounds.
> 
> Added later:
> 6) It should have a "focused" state/pseudo class because on gnome (maybe others) the focused window has a different background on the HeaderBar which is darker.
> 7) Suggestion: Maybe make window states stylable on the HeaderBar with pseudo-classes like `:maximized`, `:fullscreen`, `:focused`, `:solid` (when it does not have rounded corners). Then it would be possible to CSS style it.
> 8) Maybe integrate with platform preferences and provide a way to CSS style it when it's Light or Dark?
> 
> 
> Nice cleanup on `Window.java` . `UndecoratedMoveResizeHelper` was not going to work on Linux anyways.

@tsayao Thanks for the comments. I'll have a look at the bugs that you found.

> 2. It's not possible to move the window if the cursor is over a control. Maybe you should just  `gtk_window_begin_move_drag`  when a drag is detected, not on click. That would be on `WindowContextBase::process_mouse_motion`;

I know that dragging on interactive controls is a thing on Linux, but I don't think that we should be doing that. JavaFX applications are multi-platform apps, which means that their behavior should be consistent across platforms. Stealing mouse interactions on interactive controls is not a thing on Windows and macOS, and this has the potential to cause problems for application developers.

If you want, you can declare any node in the header bar to be draggable on all platforms with `HeaderBar.setDraggable(Node, boolean)`.

> 5. I think rounded edges should be supported on the HeaderBar, since it's the default on gnome. For that to work, `EXTENDED` should be also transparent on Linux. It would loose the window drop shadow which can be added on the JavaFX side. `gdk_window_set_shadow_width` should be called with the drop shadow size, so the desktop will know the correct window bounds.

I'll have to look into that, but in general an `EXTENDED` window should work out of the box for all platforms, without platform-specific changes on the JavaFX side.

> Added later: 6) It should have a "focused" state/pseudo class because on gnome (maybe others) the focused window has a different background on the HeaderBar which is darker. 7) Suggestion: Maybe make window states stylable on the HeaderBar with pseudo-classes like `:maximized`, `:fullscreen`, `:focused`, `:solid` (when it does not have rounded corners). Then it would be possible to CSS style it. 8) Maybe integrate with platform preferences and provide a way to CSS style it when it's Light or Dark?

While that sounds useful at first, I don't think it carries its own weight. Many platforms use different styling for windows that are focused vs. windows that are not. This not only includes the header bar, but many other parts of the user interface as well. I don't think that we should be adding what would essentially be ad-hoc pseudo-classes _only_ to HeaderBar.

In addition to that, it is extremely easy for an application to do this by adding a listener to `Stage.focused` and then toggling pseudo-classes on all relevant controls.

We should _definitely_ not do pseudo-classes for light vs. dark mode. The correct way to solve this problem is with media queries ([prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme)).

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

PR Comment: https://git.openjdk.org/jfx/pull/1605#issuecomment-2427910290


More information about the openjfx-dev mailing list