Skip to content

Commit

Permalink
Add Mac bringToFront with NSApp activateIgnoringOtherApps
Browse files Browse the repository at this point in the history
Also implement IsFront with NSWindow isMainWindow
  • Loading branch information
Quezion committed Jun 26, 2023
1 parent 5885f78 commit e266088
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 13 additions & 1 deletion macos/cc/WindowMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,20 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
[nsWindow makeKeyAndOrderFront:nil];
}

extern "C" JNIEXPORT jint JNICALL Java_io_github_humbleui_jwm_WindowMac__1nGetZOrder
extern "C" JNIEXPORT bool JNICALL Java_io_github_humbleui_jwm_WindowMac__1nIsFront
(JNIEnv* env, jobject obj) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
NSWindow* nsWindow = instance->fNSWindow;
return [nsWindow isMainWindow];
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowMac__1nBringToFront
(JNIEnv* env, jobject obj) {
[NSApp activateIgnoringOtherApps:YES];
}

extern "C" JNIEXPORT jint JNICALL Java_io_github_humbleui_jwm_WindowMac__1nGetZOrder
(JNIEnv* env, jobject obj) {
jwm::WindowMac* instance = reinterpret_cast<jwm::WindowMac*>(jwm::classes::Native::fromJava(env, obj));
NSWindow* nsWindow = instance->fNSWindow;
NSWindowLevel level = [nsWindow level];
Expand Down
7 changes: 4 additions & 3 deletions macos/java/WindowMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,14 @@ public Window focus() {
@Override
public Window bringToFront() {
assert _onUIThread() : "Should be run on UI thread";
// TODO: impl me
_nBringToFront();
return this;
}

@Override
public boolean isFront() {
assert _onUIThread() : "Should be run on UI thread";
// TODO: impl me
return false;
return _nIsFront();
}

@Override
Expand Down Expand Up @@ -315,6 +314,8 @@ public void close() {
@ApiStatus.Internal public native void _nHideMouseCursorUntilMoved(boolean value);
@ApiStatus.Internal public native void _nLockMouseCursor(boolean value);
@ApiStatus.Internal public native void _nSetVisible(boolean value);
@ApiStatus.Internal public native boolean _nIsFront();
@ApiStatus.Internal public native void _nBringToFront();
@ApiStatus.Internal public native Screen _nGetScreen();
@ApiStatus.Internal public native void _nRequestFrame();
@ApiStatus.Internal public native void _nMinimize();
Expand Down

0 comments on commit e266088

Please sign in to comment.