Skip to content

Commit

Permalink
implement WindowMac setTitlebarStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Jan 11, 2022
1 parent 4626ebc commit 2ffa983
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/dashboard/java/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public Example() {
}

// window.setTitlebarVisible(true);
((WindowMac) window).setFullSizeContentView(true);
// ((WindowMac) window).setTitleVisible(true);
((WindowMac) window).setTitlebarStyle(WindowMacTitlebarStyle.UNIFIED_SMALL);
// ((WindowMac) window).setFullSizeContentView(true);

window.setVisible(true);
initialized = true;
Expand Down
46 changes: 46 additions & 0 deletions macos/cc/WindowMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "WindowDelegate.hh"
#include "Util.hh"
#include "ZOrder.hh"
#include "WindowMacTitlebarStyle.hh"

namespace jwm {
NSArray* kCursorCache;
Expand Down Expand Up @@ -260,6 +261,18 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
}
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowMac__1nSetSubtitle
(JNIEnv* env, jobject obj, jstring subtitleStr) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
jsize len = env->GetStringLength(subtitleStr);
const jchar* chars = env->GetStringCritical(subtitleStr, nullptr);
NSString* subtitle = [[NSString alloc] initWithCharacters:chars length:len];
env->ReleaseStringCritical(subtitleStr, chars);
instance->fNSWindow.subtitle = subtitle;
[instance->fNSWindow setTitleVisibility:NSWindowTitleVisible];
[subtitle release];
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowMac__1nSetIcon
(JNIEnv* env, jobject obj, jstring pathStr) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
Expand Down Expand Up @@ -306,6 +319,39 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
[nsWindow setTitlebarAppearsTransparent:value];
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowMac__1nSetTitlebarStyle
(JNIEnv* env, jobject obj, jint titlebarStyle) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
NSWindow* nsWindow = instance->fNSWindow;

NSToolbar* toolbar = nullptr;
NSWindowToolbarStyle toolbarStyle = NSWindowToolbarStyleAutomatic;
switch (static_cast<jwm::WindowMacTitlebarStyle>(titlebarStyle)) {
case jwm::WindowMacTitlebarStyle::DEFAULT:
// Just set the toolbar to null
break;
case jwm::WindowMacTitlebarStyle::UNIFIED_SMALL:
toolbar = [[NSToolbar alloc] init];
toolbarStyle = NSWindowToolbarStyleUnifiedCompact;
break;
case jwm::WindowMacTitlebarStyle::UNIFIED_LARGE:
toolbar = [[NSToolbar alloc] init];
toolbarStyle = NSWindowToolbarStyleUnified;
break;
}
[nsWindow setToolbar:toolbar];
[nsWindow setToolbarStyle:toolbarStyle];
[toolbar release];
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowMac__1nSetTrafficLightPosition
(JNIEnv* env, jobject obj, jint left, jint top) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
NSWindow* nsWindow = instance->fNSWindow;

//todo
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowMac__1nSetMouseCursor
(JNIEnv* env, jobject obj, jint cursorIdx) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
Expand Down
10 changes: 10 additions & 0 deletions macos/cc/WindowMacTitlebarStyle.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace jwm {
// must be kept in sync with WindowMacTitlebarStyle.java
enum class WindowMacTitlebarStyle {
DEFAULT,
UNIFIED_SMALL,
UNIFIED_LARGE,
};
}
24 changes: 24 additions & 0 deletions macos/java/WindowMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public Window setTitle(String title) {
return this;
}

@NotNull @Contract("-> this")
public Window setSubtitle(@NotNull String title) {
assert _onUIThread();
_nSetSubtitle(title);
return this;
}

@Override
public Window setIcon(File icon) {
assert _onUIThread();
Expand All @@ -88,6 +95,20 @@ public WindowMac setFullSizeContentView(boolean isFullSizeContentView) {
return this;
}

@NotNull @Contract("-> this")
public WindowMac setTitlebarStyle(WindowMacTitlebarStyle titlebarStyle) {
assert _onUIThread();
_nSetTitlebarStyle(titlebarStyle.ordinal());
return this;
}

@NotNull @Contract("-> this")
public WindowMac setTrafficLightPosition(int left, int top) {
assert _onUIThread();
_nSetTrafficLightPosition(left, top);
return this;
}


@ApiStatus.Internal @Override
public native void _nSetMouseCursor(int cursorIdx);
Expand Down Expand Up @@ -169,9 +190,12 @@ public void close() {
@ApiStatus.Internal public native void _nSetWindowSize(int width, int height);
@ApiStatus.Internal public native void _nSetContentSize(int width, int height);
@ApiStatus.Internal public native void _nSetTitle(String title);
@ApiStatus.Internal public native void _nSetSubtitle(String title);
@ApiStatus.Internal public native void _nSetIcon(String path);
@ApiStatus.Internal public native void _nSetTitlebarVisible(boolean value);
@ApiStatus.Internal public native void _nSetFullSizeContentView(boolean value);
@ApiStatus.Internal public native void _nSetTitlebarStyle(int titlebarStyle);
@ApiStatus.Internal public native void _nSetTrafficLightPosition(int left, int top);
@ApiStatus.Internal public native void _nSetVisible(boolean value);
@ApiStatus.Internal public native Screen _nGetScreen();
@ApiStatus.Internal public native void _nRequestFrame();
Expand Down
7 changes: 7 additions & 0 deletions macos/java/WindowMacTitlebarStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.humbleui.jwm;

public enum WindowMacTitlebarStyle {
DEFAULT,
UNIFIED_SMALL,
UNIFIED_LARGE
}

0 comments on commit 2ffa983

Please sign in to comment.