RFR: 8313424: JavaFX controls in the title bar [v3]
Thiago Milczarek Sayao
tsayao at openjdk.org
Mon Oct 21 10:58:47 UTC 2024
On Sun, 20 Oct 2024 01:23:01 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
>> This PR is a new take on a highly requested feature: JavaFX controls in the header bar (see also #594 for an earlier iteration).
>>
>> This is a feature with many possible ways to skin the cat, and it has taken quite a bit of effort to come up with a good user model. In contrast to the previous iteration, the focus has shifted from providing an entirely undecorated window to providing a window with a user-configurable header bar.
>>
>> The customizable header bar is a new layout container: `javafx.scene.layout.HeaderBar`. It has three areas that accept child nodes: leading, center, and trailing. `HeaderBar` also automatically adjusts for the placement of the default window buttons (minimize, maximize, close) on the left or right side of the window.
>>
>> The customizable header bar is combined with a new `EXTENDED` stage style, which extends the client area into the header bar area. The new extended stage style is supported on Windows, macOS, and Linux. For platforms that don't support this stage style, it automatically downgrades to `DECORATED`.
>>
>> This is how it looks like on each of the three operating systems:
>>
>> 
>>
>> The window buttons (minimize, maximize, close) are provided by JavaFX, not by the application developer. This makes it easier to get basic window functionality without recreating the entirety of the window controls for all platforms.
>>
>> ## Usage
>> This is a minimal example that uses a custom header bar with a `TextField` in the center area. `HeaderBar` is usually placed in the top area of a `BorderPane` root container:
>>
>> public class MyApp extends Application {
>> @Override
>> public void start(Stage stage) {
>> var headerBar = new HeaderBar();
>> headerBar.setCenter(new TextField());
>>
>> var root = new BorderPane();
>> root.setTop(headerBar);
>>
>> stage.setScene(new Scene(root));
>> stage.initStyle(StageStyle.EXTENDED);
>> stage.show();
>> }
>> }
>>
>> To learn more about the details of the API, refer to the documentation of `StageStyle.EXTENDED` and `HeaderBar`.
>>
>> ## Platform integration
>> The implementation varies per platform, and ranges from pretty easy to quite involved:
>> 1. **macOS**: The window buttons are provided by macOS, we just leave an empty area where the window buttons will appear. The client area is extended to cover the entire window by setting the `NSW...
>
> 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 (and also MS Windows? For that to work, `EXTENDED` should be also transparent (or maybe add EXTENDED_TRANSPARENT). 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.
Nice cleanup on `Window.java` . `UndecoratedMoveResizeHelper` was not going to work on Linux anyways.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1605#issuecomment-2426328912
More information about the openjfx-dev
mailing list