--- old/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java 2012-02-29 18:46:54.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java 2012-02-29 18:46:54.000000000 +0400 @@ -84,35 +84,6 @@ return peer; } - public void enterFullScreenMode(final long nsWindowPtr) { - CWrapper.NSView.enterFullScreenMode(ptr); - - // REMIND: CGLSurfaceData expects top-level's size - // and therefore we need to account insets before - // recreating the surface data - Insets insets = peer.getInsets(); - - Rectangle screenBounds; - final long screenPtr = CWrapper.NSWindow.screen(nsWindowPtr); - try { - screenBounds = CWrapper.NSScreen.frame(screenPtr).getBounds(); - } finally { - CWrapper.NSObject.release(screenPtr); - } - - // the move/size notification from the underlying system comes - // but it contains a bounds smaller than the whole screen - // and therefore we need to create the synthetic notifications - peer.notifyReshape(screenBounds.x - insets.left, - screenBounds.y - insets.bottom, - screenBounds.width + insets.left + insets.right, - screenBounds.height + insets.top + insets.bottom); - } - - public void exitFullScreenMode() { - CWrapper.NSView.exitFullScreenMode(ptr); - } - // ---------------------------------------------------------------------- // PAINTING METHODS // ---------------------------------------------------------------------- --- old/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2012-02-29 18:46:56.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2012-02-29 18:46:56.000000000 +0400 @@ -192,12 +192,15 @@ } }; + private final Object LOCK = new Object(){}; + // Bounds of the native widget but in the Java coordinate system. // In order to keep it up-to-date we will update them on // 1) setting native bounds via nativeSetBounds() call // 2) getting notification from the native level via deliverMoveResizeEvent() private Rectangle nativeBounds; - private volatile boolean isFullScreenMode = false; + + private boolean isFullScreenMode = false; // synchronized on the LOCK private Window target; private LWWindowPeer peer; @@ -654,16 +657,42 @@ } } + private void setMenuBarVisibleIfOnPrimaryScreen(boolean visible) { + long screen = CWrapper.NSWindow.screen(getNSWindowPtr()); + try { + long primaryScreen = CWrapper.NSScreen.screens_0(); + try { + if (primaryScreen == screen) { + CWrapper.NSMenu.setMenuBarVisible(visible); + } + } finally { + CWrapper.NSObject.release(primaryScreen); + } + } finally { + CWrapper.NSObject.release(screen); + } + } + @Override public void enterFullScreenMode() { - isFullScreenMode = true; - contentView.enterFullScreenMode(getNSWindowPtr()); + synchronized (LOCK) { + if (!isFullScreenMode) { + isFullScreenMode = true; + setMenuBarVisibleIfOnPrimaryScreen(false); + CWrapper.NSWindow.toggleFullScreen(getNSWindowPtr(), 0L); + } + } } @Override public void exitFullScreenMode() { - contentView.exitFullScreenMode(); - isFullScreenMode = false; + synchronized (LOCK) { + if (isFullScreenMode) { + CWrapper.NSWindow.toggleFullScreen(getNSWindowPtr(), 0L); + setMenuBarVisibleIfOnPrimaryScreen(true); + isFullScreenMode = false; + } + } } @Override @@ -763,12 +792,6 @@ } private void deliverMoveResizeEvent(int x, int y, int width, int height) { - // when the content view enters the full-screen mode, the native - // move/resize notifications contain a bounds smaller than - // the whole screen and therefore we ignore the native notifications - // and the content view itself creates correct synthetic notifications - if (isFullScreenMode) return; - nativeBounds = new Rectangle(x, y, width, height); peer.notifyReshape(x, y, width, height); //TODO validateSurface already called from notifyReshape --- old/src/macosx/classes/sun/lwawt/macosx/CWrapper.java 2012-02-29 18:46:58.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CWrapper.java 2012-02-29 18:46:57.000000000 +0400 @@ -72,6 +72,8 @@ public static native void makeFirstResponder(long window, long responder); public static native long screen(long window); + + public static native void toggleFullScreen(long window, long sender); } public static final class NSView { @@ -81,9 +83,6 @@ public static native void setFrame(long view, int x, int y, int w, int h); public static native Rectangle2D frame(long view); public static native long window(long view); - - public static native void enterFullScreenMode(long view); - public static native void exitFullScreenMode(long view); } public static final class NSObject { @@ -94,6 +93,13 @@ public static native Rectangle2D frame(long screen); public static native Rectangle2D visibleFrame(long screen); public static native long screenByDisplayId(int displayID); + + /** [[[NSScreen screens] objectAtIndex:0] retain]. */ + public static native long screens_0(); + } + + public static final class NSMenu { + public static native void setMenuBarVisible(boolean visible); } public static final class NSColor { --- old/src/macosx/native/sun/awt/CWrapper.m 2012-02-29 18:46:59.000000000 +0400 +++ new/src/macosx/native/sun/awt/CWrapper.m 2012-02-29 18:46:59.000000000 +0400 @@ -482,6 +482,27 @@ } /* + * Class: sun_lwawt_macosx_CWrapper$NSWindow + * Method: toggleFullScreen + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_sun_lwawt_macosx_CWrapper_00024NSWindow_toggleFullScreen +(JNIEnv *env, jclass cls, jlong windowPtr, jlong senderPtr) +{ +JNF_COCOA_ENTER(env); + + NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); + id sender = (id)jlong_to_ptr(senderPtr); + [JNFRunLoop performOnMainThread:@selector(toggleFullScreen:) + on:window + withObject:sender + waitUntilDone:NO]; + +JNF_COCOA_EXIT(env); +} + +/* * Class: sun_lwawt_macosx_CWrapper$NSView * Method: addSubview * Signature: (JJ)V @@ -569,46 +590,6 @@ /* * Class: sun_lwawt_macosx_CWrapper$NSView - * Method: enterFullScreenMode - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_sun_lwawt_macosx_CWrapper_00024NSView_enterFullScreenMode -(JNIEnv *env, jclass cls, jlong viewPtr) -{ -JNF_COCOA_ENTER(env); - - NSView *view = (NSView *)jlong_to_ptr(viewPtr); - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ - NSScreen *screen = [[view window] screen]; - NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], NSFullScreenModeAllScreens, nil]; - [view enterFullScreenMode:screen withOptions:opts]; - }]; - -JNF_COCOA_EXIT(env); -} - -/* - * Class: sun_lwawt_macosx_CWrapper$NSView - * Method: exitFullScreenMode - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_sun_lwawt_macosx_CWrapper_00024NSView_exitFullScreenMode -(JNIEnv *env, jclass cls, jlong viewPtr) -{ -JNF_COCOA_ENTER(env); - - NSView *view = (NSView *)jlong_to_ptr(viewPtr); - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ - [view exitFullScreenModeWithOptions:nil]; - }]; - -JNF_COCOA_EXIT(env); -} - -/* - * Class: sun_lwawt_macosx_CWrapper$NSView * Method: window * Signature: (J)J */ @@ -716,6 +697,46 @@ } /* + * Class: sun_lwawt_macosx_CWrapper$NSScreen + * Method: screens_0 + * Signature: ()J + */ +JNIEXPORT jlong JNICALL +Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screens_10 +(JNIEnv *env, jclass cls) +{ + __block jlong screenPtr = 0L; + +JNF_COCOA_ENTER(env); + + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + screenPtr = ptr_to_jlong([[[NSScreen screens] objectAtIndex:0] retain]); + }]; + +JNF_COCOA_EXIT(env); + + return screenPtr; +} + +/* + * Class: sun_lwawt_macosx_CWrapper$NSMenu + * Method: setMenuBarVisible + * Signature: (Z)V + */ +JNIEXPORT jlong JNICALL +Java_sun_lwawt_macosx_CWrapper_00024NSMenu_setMenuBarVisible +(JNIEnv *env, jclass cls, jboolean visible) +{ +JNF_COCOA_ENTER(env); + + [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + [NSMenu setMenuBarVisible: visible]; + }]; + +JNF_COCOA_EXIT(env); +} + +/* * Class: sun_lwawt_macosx_CWrapper$NSColor * Method: clearColor * Signature: ()J