-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
macOS: window title bar close/minimize/zoom buttons spacing #779
Conversation
Tested macOS 14.2 JDK 17 no problems though not able to comment on signing question. I am looking for something similar to |
I've tested latest changes, excellent with large size. I wasn't using a JToolBar, when I do, JToggleButtons have same background as the panel and I can find no property related to this. |
Good news. Found a way to make the space around the traffic lights even larger 😄 Updated main post. Note that client property has changed. @ctipper something like JetBrains |
I was testing full screen behaviour I noticed a couple of things.
Thinking about it I would like to handle the left inset programmatically, it is nice for setting this up, but it's just as easy to add a horizontal strut and this would work in full screen also |
I realised the macOS popup PR was included in the latest build, that's pretty cool too. All my reasons to use JetBrainsRuntime have now been met, and I don't have to use it, the next release of this library looks like it's going to be good. |
This is looking very good! I just tested on a macbook air M1, MacOS 13.4.1, OpenJDK 19.0.1 (Adoptium) and the traffic lights and rounded popups are working great. It's already mentioned that the traffic lights can be seen moving when exiting full screen, for me this is totally acceptable, what I did in my own experiments was hide them during the transition, I also tried to postpone the update of the toolbar margins after the transition but I could net get this to work reliable, but when it did work this was the best looking workaround in my opinion. I did not get any gatekeeper warnings that I did not expect, just the normal warnings about unknown developer. I noticed that my default JDK on this laptop is still a jetbrains 17.0.2 runtime, while I was testing the full screen behaviour in the FlatLaf demo app I noticed that if I click the theme combobox in the upper right corner after this the main window content is no longer resized when going to full screen, this was also happening without the new MacOS native features so I am pretty sure it is unrelated, but I thought you might like to know. Next weekend I will also be able to test on an older Intel macbook. |
@duhiqc you need to setup FlatLaf. E.g. using |
|
Have you setup FlatLaf before creating the frame? |
yes |
Code? |
|
You're setting up FlatLaf after creating the frame! |
You're still setting up FlatLaf after creating the frame! (hint class |
Wait, just got it wrong, But FlatLightLaf.setup();
|
I am curious I have always installed look and feel before calling setup, as in
|
@duhiqc you're setting the wrong client property. The key of the client property is |
@DevCharly JBR actually has this API, hopefully it won't conflict with this PR:
|
I've been following JBR and my understanding is that they subsequently removed this property following attempts to fix this issue (my own PR) JBR-4875 |
Try this: JBR.getWindowDecorations().setCustomTitleBar(window, JBR.getWindowDecorations().createCustomTitleBar().also { customTitleBar ->
customTitleBar.height = topBarHeight // !!!
}) Tip: The way to obtain jbr-api-17.1.7.0-sources.jar: First, build IntelliJ IDEA Community Edition, and then you can find the source code of JBR, which will be in the local maven directory. |
@DevCharly Looks and works great! Any chance this will be supported for the JIDE |
- uses height of macOS window title bar - adds left insets for close/minimize/zoom buttons (except if full screen, where those buttons are hidden)
… becomes full screen
…COS_LARGE_WINDOW_TITLE_BAR` (or `"FlatLaf.macOS.largeWindowTitleBar"`)
…set after leaving full screen
…ilaible since macOS 11+; standard in macOS Finder, etc) to allow even larger space around close/minimize/zoom buttons
…or easier testing
d63400c
to
f68a871
Compare
- added title bar buttons placeholder - added client property to root pane that contains title bar buttons bounds - undone toolbar extensions from commit ea2447d
- renamed client property `MACOS_WINDOW_BUTTON_STYLE` to `MACOS_WINDOW_BUTTONS_SPACING` - no longer allow value `true` for that client property - enable using `MACOS_WINDOW_BUTTONS_SPACING` without `apple.awt.fullWindowContent` - remove client property `FULL_WINDOW_CONTENT_BUTTONS_BOUNDS` when `apple.awt.fullWindowContent` is set to false or null - added placeholder options `zeroInFullScreen`, `leftToRight` and `rightToLeft` - hide close/min/max buttons during the transition from full-screen to non-full-screen to avoid that they "jump" when the nsToolbar is made visible - fixed: full-screen listeners where added multiple times - updated macOS native libraries - added `FlatMacOSTest`
Thanks for the feedback 👍 There are some (breaking) changes in recent commits. See initial post for updates. |
@rogerbj I've removed that "feature" again from toolbar and replaced it with "buttons placeholder". See initial post. This should also work for JIDE |
@ctipper fixed
@ctipper you can do that now with following placeholder: JPanel placeholder = new JPanel();
placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac zeroInFullScreen" ); |
@remcopoelstra thanks for that idea. That works fine. 👍 |
@drakeet as long as you do not enable both, it should not conflict 😉 |
Your latest commits are good, my application works quite well. I don't have any suggestions for the code itself but I don't know whether you should keep the instructions for a placeholder panel, much simpler to use a JPanel on its own and use `add(Box.createHorizontalStrut(90))'. Personally I don't really like what happens whilst cycling to full screen content when the horizontal spacing shrinks to zero, much better in my opinion to have a fixed offset which is easily added by using a horizontal strut. |
If you don't like it, don't use it 😉
But this is how native macOS applications work. |
I take your point but I have my own opinion. But I am going to stick with a fixed offset there's a lot of animation going on. |
- uninstall when switching from FlatLaf to another Laf - install when switching from another Laf to FlatLaf (for PR #779)
@DevCharly While trying out the new traffic-light spacing in our app I run into a problem. At first display of the JFrame, the spacing looks perfect but at some point during initialization, the spacing is lost. The height of the placeholder panel is also decreased to its default. I've tried a lot to find out what Swing/AWT calls that restores the spacing and location of the traffic-light icons but fail. As far as I can see in the FlatLaf code, the icons are positioned natively which makes me even more frustrated what in Swing/AWT that effects it. For clarity we're using the JIDE application framework which do not interact with any native code. What I've tried in a test app is to reproduce the exact same scenario. There are buttons in the JToolBar to call various Swing methods (listed below) that potentially could have an effect on the traffic-light icons, but no matter which of these are called, the spacing stays intact.
None of the above changes the position or size of the traffic-light icons pane. Would be awesome if you have any ideas or pointers what calls in Swing/AWT that potentially may result that the size of the traffic-light pane is reset. |
@rogerbj that's strange. What Java version do you use? Are you using the latest FlatLaf code from branch Have you checked whether FlatLaf itself resets the traffic light spacing?
|
@DevCharly Problem solved! I updated my fork and now it works perfect. Previously I used one of the snapshot releases. Thanks! |
If using full window content mode on macOS, this PR enables using larger window title bar, which adds more empty space around the close/minimize/zoom buttons (traffic lights). (issues #769 and #562)
This feature requires Java 17+ and macOS 10.14+.
Default:
Medium:
Large (requires macOS 11+):
Note that the traffic lights have moved, the "main" toolbar has larger left insets and larger height, which horizontally aligns traffic lights and toolbar buttons.
Besides enabling full window content, transparent title bar and hide window title, it is also necessary to set client property
FlatClientProperties.MACOS_WINDOW_BUTTONS_SPACING
(or"FlatLaf.macOS.windowButtonsSpacing"
) to:FlatClientProperties.MACOS_WINDOW_BUTTONS_SPACING_LARGE
or"large"
: recommended since native macOS apps like Finder also use this styleFlatClientProperties.MACOS_WINDOW_BUTTONS_SPACING_MEDIUM
or"medium"
E.g.:
Update 2024-01-22
MACOS_WINDOW_BUTTON_STYLE
toMACOS_WINDOW_BUTTONS_SPACING
true
for that client propertyFULL_WINDOW_CONTENT_BUTTONS_BOUNDS
to root pane that contains title bar buttons boundsButtons placeholder
To avoid that your components are overlapped by the close/minimize/zoom buttons, you need to add some placeholder component to the layout of your application. For macOS in the top-left corner. A buttons placeholder is a
JPanel
that has client propertyFlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER
set.Note that FlatLaf controls the preferred size of the placeholder panel. If fullWindowContent mode is enabled, it gets the size of the buttons area. Otherwise, the preferred size is
0, 0
, which hides the placeholder.If you have a toolbar at top of your frame, use an additional panel that contains placeholder at WEST and toolbar in CENTER:
See FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER javadoc for details.
For testing, you can make the placeholder "visible" with:
"main" toolbarremoved in commit 28278a7; use buttons placeholder instead
If there is aJToolBar
at the top of the window, at location0, 0
, then FlatLaf automatically increases the left inset (to avoid overlapping with traffic lights) and the preferred toolbar height (for horizontal alignment) of that toolbar.Otherwise you have to take care yourself to avoid overlapping with traffic lights.Feedback wanted
I've tested this only on macOS 10.14 (Intel) and on 13.3 (M1).
Would be great to get some feedback whether this works without problems on other macOS versions.
I'm also interested whether macOS Gatekeeper makes problems, because there are two new native libraries (dylib), which are extracted from flatlaf.jar to a temporary directory and loaded from there. The dylibs are signed with "FormDev Software" code signing certificate, but this is not (yet) an Apple certificate. So if you ship a signed application, it may be possible that Gatekeeper pops up. (I don't know yet).