Skip to content
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

Custom title bar on macOS #32

Closed
weisJ opened this issue Feb 15, 2020 · 7 comments · Fixed by #54
Closed

Custom title bar on macOS #32

weisJ opened this issue Feb 15, 2020 · 7 comments · Fixed by #54
Labels
enhancement New feature or request help wanted Extra attention is needed macOS Related to the macOS operating system

Comments

@weisJ
Copy link
Owner

weisJ commented Feb 15, 2020

This relates to #2 .

Provide a custom title bar on macOS. After doing some research, this could be done by setting
the properties
fullsizecontentview and ]titlebarappearstransparent of the underlying NSWindow. (see https://stackoverflow.com/questions/54353576/colorizing-the-titlebar-in-macos-with-multiple-colors).

Communication with java would happen as in the windows version through JNI passing the request to a C++ function which in turn calls the objective-c code, that is able to set those properties.

If working the LaF should add a custom title bar (without window buttons, as those should still be present).

As I don't have access to macOS platform I can't do this myself, so help would be highly appreciated.

@weisJ weisJ added enhancement New feature or request help wanted Extra attention is needed labels Feb 15, 2020
@weisJ weisJ added the macOS Related to the macOS operating system label Feb 19, 2020
@vlsi
Copy link
Contributor

vlsi commented Feb 19, 2020

Is it different from Frame#setUndecorated(true) ?

Снимок экрана 2020-02-20 в 1 00 30

@weisJ
Copy link
Owner Author

weisJ commented Feb 19, 2020

Yes this keeps the window buttons and title text.

@vlsi
Copy link
Contributor

vlsi commented Feb 19, 2020

https://bugs.openjdk.java.net/browse/JDK-8212549 which indeed works in Java 13.

JFrame frame = new JFrame();
final JRootPane rootPane = frame.getRootPane();
rootPane.putClientProperty("apple.awt.fullWindowContent", true);
rootPane.putClientProperty("apple.awt.transparentTitleBar", true);

Снимок экрана 2020-02-20 в 2 00 59

@weisJ
Copy link
Owner Author

weisJ commented Feb 19, 2020

Great. At least for java version >= 12 this is a solution. Does moving the window work?

For java version below 12 there should still be a possibility to achieve this. Gladly because the jdk implementation also just sets those corresponding properties on the NSWindow the swing code can be reused and just the method of setting the window property still needs to be implemented natively.

Based on the jdk implementation it could look like this JNIDecorations.m:

#include "package_path_class.h"
#import <Cocoa/Cocoa.h>

#define OBJC(jl) ((id)jlong_to_ptr(jl))
#define FULL_WINDOW_CONTENT 1 << 14
#define TRANSPARENT_TITLE_BAR 1 << 18

JNIEXPORT void JNICALL 
package_path_class_installDecorations(JNIEnv *env, jclass obj, jlong windowPtr)
{
    NSWindow *nsWindow = OBJC(windowPtr);
    window.styleMask |= FULL_WINDOW_CONTENT | TRANSPARENT_TITLE_BAR;
}

To get hold of the window pointer Pointer.nativeValue(Native.getComponentPointer(component)) should still work on macOS.

@vlsi
Copy link
Contributor

vlsi commented Feb 20, 2020

What do you think of setAccessible(true)-driven sun.lwawt.macosx.CPlatformWindow#setStyleBits(int mask, boolean value) for pre Java 12?

@weisJ
Copy link
Owner Author

weisJ commented Feb 20, 2020

Theoretically a good approach. The instance of the underlying CPlatformWindow can be optained as follows:

WindowPeer peer = (WindowPeer)window.getPeer();
CPlatformWindow platformWindow = (CPlatformWindow)((LWWindowPeer)peer).getPlatformWindow();

Neither CPlatformWindw nor LWWindowPeer are visible (or included) in non macOS jdk version.
All of this would need to happen through reflection or otherwise this can't be build.

@weisJ
Copy link
Owner Author

weisJ commented Feb 21, 2020

@vlsi could you tell me if #54 works for your? At least for the part of actually calling setStyleBits on CPlatformWindow.

@weisJ weisJ linked a pull request Feb 24, 2020 that will close this issue
@weisJ weisJ closed this as completed in #54 Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed macOS Related to the macOS operating system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants