changeset 7833:71c7b518c853

RT-38338: [Glass, Mac] While a stage is in fullscreen mode you cannot open another stage on top of the fullscreen stage Summary: Use the modern OS X 10.7+ full screen mode Reviewed-by: snorthov
author Anthony Petrov <anthony.petrov@oracle.com>
date Thu, 28 Aug 2014 11:22:16 +0400
parents 9bcafd4e5543
children 12525821c845
files modules/graphics/src/main/native-glass/mac/GlassFullscreenWindow.h modules/graphics/src/main/native-glass/mac/GlassFullscreenWindow.m modules/graphics/src/main/native-glass/mac/GlassViewDelegate.h modules/graphics/src/main/native-glass/mac/GlassViewDelegate.m modules/graphics/src/main/native-glass/mac/GlassWindow+Overrides.m
diffstat 5 files changed, 22 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/mac/GlassFullscreenWindow.h	Thu Aug 28 09:06:13 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassFullscreenWindow.h	Thu Aug 28 11:22:16 2014 +0400
@@ -26,22 +26,9 @@
 #import <Cocoa/Cocoa.h>
 #import <jni.h>
 
-// used during fullscreen animation for fading in/out the screen
-@interface GlassBackgroundWindow : NSWindow
-{
-        NSWindow                                *trackWindow;
-        CGFloat                                        startingTrackingSize;
-}
-
-- (id)initWithWindow:(NSWindow *)window;
-
-@end
-
 @interface GlassFullscreenWindow : NSWindow
 {
         NSPoint                                        point;
-@public
-        CGDirectDisplayID                displayID;
 }
 
 - (id)initWithContentRect:(NSRect)contentRect withHostView:(NSView *)hostView withView:(NSView *)view withScreen:(NSScreen *)screen withPoint:(NSPoint)point;
--- a/modules/graphics/src/main/native-glass/mac/GlassFullscreenWindow.m	Thu Aug 28 09:06:13 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassFullscreenWindow.m	Thu Aug 28 11:22:16 2014 +0400
@@ -25,102 +25,11 @@
 
 #import "GlassFullscreenWindow.h"
 
-@implementation GlassBackgroundWindow : NSWindow
-
-- (id)initWithWindow:(NSWindow *)window
-{
-    self = [super initWithContentRect:[[window screen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO screen:[window screen]];
-    if (self != nil)
-    {
-        self->trackWindow = [window retain];
-        //[self->trackWindow setDelegate:self];
-        [self setAlphaValue:0.0f];
-        
-        CGFloat ratioWidth = ([self->trackWindow frame].size.width/[[self->trackWindow screen] frame].size.width);
-        CGFloat ratioHeight = ([self->trackWindow frame].size.height/[[self->trackWindow screen] frame].size.height);
-        if (ratioWidth > ratioHeight)
-        {
-            self->startingTrackingSize = [window frame].size.width;
-        }
-        else
-        {
-            self->startingTrackingSize = [window frame].size.height;
-        }
-        
-        [self useOptimizedDrawing:NO];
-    }
-    return self;
-}
-
-- (void)dealloc
-{
-    [self->trackWindow release];
-    
-    [super dealloc];
-}
-
-- (void)windowDidResize:(NSNotification *)notification
-{
-    CGFloat alpha = 0.0f;
-    
-    CGFloat ratioWidth = ([self->trackWindow frame].size.width/[[self->trackWindow screen] frame].size.width);
-    CGFloat ratioHeight = ([self->trackWindow frame].size.height/[[self->trackWindow screen] frame].size.height);
-    if (ratioWidth > ratioHeight)
-    {
-        CGFloat currentTrackingWindowSize = [self->trackWindow frame].size.width - self->startingTrackingSize;
-        alpha = (currentTrackingWindowSize / ([[self->trackWindow screen] frame].size.width - self->startingTrackingSize));
-    }
-    else
-    {
-        CGFloat currentTrackingWindowSize = [self->trackWindow frame].size.height - self->startingTrackingSize;
-        alpha = (currentTrackingWindowSize / ([[self->trackWindow screen] frame].size.height - self->startingTrackingSize));
-    }
-    
-    [self setAlphaValue:(alpha*alpha)]; // linear
-}
-
-- (BOOL)isReleasedWhenClosed
-{
-    return YES;
-}
-
-- (BOOL)isOpaque
-{
-    return NO;
-}
-
-- (BOOL)hasShadow
-{
-    return NO;
-}
-
-- (BOOL)canBecomeMainWindow
-{
-    return NO;
-}
-
-- (BOOL)canBecomeKeyWindow
-{
-    return NO;
-}
-
-- (BOOL)showsResizeIndicator
-{
-    return NO;
-}
-
-- (NSColor *)backgroundColor
-{
-    return [NSColor blackColor];
-}
-
-@end
-
 @implementation GlassFullscreenWindow : NSWindow
 
 - (id)initWithContentRect:(NSRect)contentRect withHostView:(NSView *)hostView withView:(NSView *)view withScreen:(NSScreen *)screen withPoint:(NSPoint)p
 {
-    self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO screen:screen];
+    self = [super initWithContentRect:contentRect styleMask:(NSBorderlessWindowMask|NSResizableWindowMask) backing:NSBackingStoreBuffered defer:NO screen:screen];
     if (self != nil)
     {
         self->point = p;
@@ -129,7 +38,7 @@
         [self setContentView:hostView];
         [self setInitialFirstResponder:view];
         [self makeFirstResponder:view];
-        [self setLevel:NSScreenSaverWindowLevel];
+        [self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
         
         [self setBackgroundColor:[NSColor colorWithCalibratedRed:0.0f green:0.0f blue:0.0f alpha:0.0f]];
         
@@ -168,11 +77,6 @@
     return YES;
 }
 
-- (BOOL)showsResizeIndicator
-{
-    return NO;
-}
-
 - (NSPoint)point
 {
     return self->point;        
--- a/modules/graphics/src/main/native-glass/mac/GlassViewDelegate.h	Thu Aug 28 09:06:13 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassViewDelegate.h	Thu Aug 28 11:22:16 2014 +0400
@@ -44,8 +44,7 @@
     CGFloat                 parentWindowAlpha;
     
     GlassHostView           *fullscreenHost;
-    GlassBackgroundWindow   *backgroundWindow;
-    // not nil when the FX mode is initiated with the OS X 10.7 widget
+    // not nil when the FS mode is initiated with the OS X 10.7 widget
     NSWindow*               nativeFullScreenModeWindow;
     
     BOOL                    mouseIsDown;
@@ -59,6 +58,7 @@
     NSInteger               lastTrackingNumber;
     
 @public
+    // not nil when we create a new FS window ourselves
     GlassFullscreenWindow   *fullscreenWindow;
 }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassViewDelegate.m	Thu Aug 28 09:06:13 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassViewDelegate.m	Thu Aug 28 11:22:16 2014 +0400
@@ -1060,6 +1060,14 @@
 - (void)enterFullscreenWithAnimate:(BOOL)animate withKeepRatio:(BOOL)keepRatio withHideCursor:(BOOL)hideCursor
 {
     LOG("GlassViewDelegate enterFullscreenWithAnimate:%d withKeepRatio:%d withHideCursor:%d", animate, keepRatio, hideCursor);
+
+    if ([[self->nsView window] isKindOfClass:[GlassEmbeddedWindow class]] == NO)
+    {
+        [[self->nsView window] toggleFullScreen:self];
+        // wait until the operation is complete
+        [GlassApplication enterFullScreenExitingLoop];
+        return;
+    }
     
     NSScreen *screen = [[self->nsView window] screen];
 
@@ -1087,7 +1095,6 @@
                                                                           withPoint:pointInPrimaryScreenCoords];
         
         // 3.
-        self->backgroundWindow = [[GlassBackgroundWindow alloc] initWithWindow:self->fullscreenWindow];
         
         [self->parentWindow disableFlushWindow];
         {
@@ -1115,12 +1122,17 @@
             // 5.
             [self->fullscreenWindow setInitialFirstResponder:self->nsView];
             [self->fullscreenWindow makeFirstResponder:self->nsView];
+
+            // This trick allows an applet to display a focused window. This is harmless otherwise.
+            // If we don't do this, we end up with a literally empty full screen background and no content shown whatsoever.
+            [[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows)];
+
             [self->fullscreenWindow makeKeyAndOrderFront:self->nsView];
+            [self->fullscreenWindow orderFrontRegardless];
             [self->fullscreenWindow makeMainWindow];
         }
         
         // 6.
-        [self->fullscreenWindow addChildWindow:self->backgroundWindow ordered:NSWindowBelow];
         
         NSRect screenFrame = [screen frame];
         NSRect fullscreenFrame = [screen frame];
@@ -1144,11 +1156,10 @@
         
         // 7.
         //[self->fullscreenWindow setBackgroundColor:[NSColor whiteColor]]; // debug
-        [self->fullscreenWindow setFrame:fullscreenFrame display:YES animate:animate];
+        [self->fullscreenWindow setFrame:frameInWindowScreenCoords display:YES animate:animate];
         
         // 8.
-        //[self enterFullScreenMode:[self->fullscreenWindow screen] withOptions:nil];
-        self->fullscreenWindow->displayID = [screen enterFullscreenAndHideCursor:hideCursor];
+        [self->fullscreenWindow toggleFullScreen:self->fullscreenWindow];
     }
     @catch (NSException *e)
     {
@@ -1172,7 +1183,7 @@
             return;
         }
         
-        [[self->fullscreenWindow screen] exitFullscreen:self->fullscreenWindow->displayID];
+        [self->fullscreenWindow toggleFullScreen:self->fullscreenWindow];
         
         NSRect frame = [self->parentHost bounds];
         frame.origin = [self->fullscreenWindow point];
@@ -1210,10 +1221,6 @@
         [self->fullscreenWindow close];
         self->fullscreenWindow = nil;
         
-        [self->backgroundWindow orderOut:nil];
-        [self->backgroundWindow close];
-        self->backgroundWindow = nil;
-
         // It was retained upon entering the FS mode
         [self->nsView release];
     }
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow+Overrides.m	Thu Aug 28 09:06:13 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow+Overrides.m	Thu Aug 28 11:22:16 2014 +0400
@@ -190,6 +190,7 @@
 {
     //NSLog(@"windowDidEnterFullScreen");
     [(GlassViewDelegate*)[self->view delegate] sendJavaFullScreenEvent:YES withNativeWidget:YES];
+    [GlassApplication leaveFullScreenExitingLoopIfNeeded];
 }
 
 - (void)windowWillExitFullScreen:(NSNotification *)notification