--- old/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java 2012-03-02 18:15:18.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java 2012-03-02 18:15:18.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-03-02 18:15:20.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2012-03-02 18:15:20.000000000 +0400 @@ -89,6 +89,7 @@ public static final String WINDOW_FADE_IN = "apple.awt._windowFadeIn"; public static final String WINDOW_FADE_OUT = "apple.awt._windowFadeOut"; public static final String WINDOW_FULLSCREENABLE = "apple.awt.fullscreenable"; + public static final String WINDOW_MENU_VISIBLE_IN_FULLSCREEN = "apple.awt.menuVisibleInFullscreen"; // Yeah, I know. But it's easier to deal with ints from JNI @@ -192,12 +193,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; @@ -381,12 +385,6 @@ nativeSetNSWindowStyleBits(getNSWindowPtr(), mask, value ? mask : 0); } - private native void _toggleFullScreenMode(final long model); - - public void toggleFullScreen() { - _toggleFullScreenMode(getNSWindowPtr()); - } - @Override // PlatformWindow public void setMenuBar(MenuBar mb) { final long nsWindowPtr = getNSWindowPtr(); @@ -654,16 +652,67 @@ } } + 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); + } + } + + // Used from com.apple.eawt.Application.requestToggleFullScreen() + public void toggleFullScreen() { + synchronized (LOCK) { + if (isFullScreenMode) { + enterFullScreenMode(); + } else { + exitFullScreenMode(); + } + } + } + @Override public void enterFullScreenMode() { - isFullScreenMode = true; - contentView.enterFullScreenMode(getNSWindowPtr()); + synchronized (LOCK) { + if (!isFullScreenMode) { + isFullScreenMode = true; + boolean hideMenuBar = true; + + if (target instanceof javax.swing.RootPaneContainer) { + javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane(); + Object prop = rootpane.getClientProperty(WINDOW_MENU_VISIBLE_IN_FULLSCREEN); + if (prop != null) { + if (Boolean.parseBoolean(prop.toString())) { + hideMenuBar = false; + } + } + } + + if (hideMenuBar) { + 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 +812,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-03-02 18:15:21.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CWrapper.java 2012-03-02 18:15:21.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:i] retain]. */ + public static native long screens(int i); + } + + public static final class NSMenu { + public static native void setMenuBarVisible(boolean visible); } public static final class NSColor { --- old/src/macosx/native/sun/awt/AWTWindow.m 2012-03-02 18:15:23.000000000 +0400 +++ new/src/macosx/native/sun/awt/AWTWindow.m 2012-03-02 18:15:22.000000000 +0400 @@ -1008,27 +1008,6 @@ } -/* - * Class: sun_lwawt_macosx_CPlatformWindow - * Method: _toggleFullScreenMode - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode -(JNIEnv *env, jobject peer, jlong windowPtr) -{ -JNF_COCOA_ENTER(env); - - AWTWindow *window = OBJC(windowPtr); - SEL toggleFullScreenSelector = @selector(toggleFullScreen:); - if (![window respondsToSelector:toggleFullScreenSelector]) return; - - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ - [window performSelector:toggleFullScreenSelector withObject:nil]; - }]; - -JNF_COCOA_EXIT(env); -} - JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse (JNIEnv *env, jclass clazz, jlong windowPtr) { --- old/src/macosx/native/sun/awt/CWrapper.m 2012-03-02 18:15:24.000000000 +0400 +++ new/src/macosx/native/sun/awt/CWrapper.m 2012-03-02 18:15:24.000000000 +0400 @@ -482,6 +482,32 @@ } /* + * 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); + SEL toggleFullScreenSelector = @selector(toggleFullScreen:); + + if ([window respondsToSelector:toggleFullScreenSelector]) { + id sender = (id)jlong_to_ptr(senderPtr); + + [JNFRunLoop performOnMainThread:toggleFullScreenSelector + on:window + withObject:sender + waitUntilDone:NO]; + } + +JNF_COCOA_EXIT(env); +} + +/* * Class: sun_lwawt_macosx_CWrapper$NSView * Method: addSubview * Signature: (JJ)V @@ -569,46 +595,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 +702,46 @@ } /* + * Class: sun_lwawt_macosx_CWrapper$NSScreen + * Method: screens + * Signature: (I)J + */ +JNIEXPORT jlong JNICALL +Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screens +(JNIEnv *env, jclass cls, jint i) +{ + __block jlong screenPtr = 0L; + +JNF_COCOA_ENTER(env); + + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + screenPtr = ptr_to_jlong([[[NSScreen screens] objectAtIndex:i] 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