Browse Source

fix: simpleFullscreen window should be on top of other OS X menu bars. (#15182)

If an app has no menu bar (because `app.dock.hide()` has been called),
OS X will still render the menu bar of the previously-focused app.

This commit ensures simpleFullscreen windows will be drawn on top of
that menu bar by setting their level to NSPopUpMenuWindowLevel while
simpleFullscreen mode is active.

Ref: #11468
Kevin Lynagh 6 years ago
parent
commit
4279f2f3f8
2 changed files with 15 additions and 1 deletions
  1. 1 0
      atom/browser/native_window_mac.h
  2. 14 1
      atom/browser/native_window_mac.mm

+ 1 - 0
atom/browser/native_window_mac.h

@@ -213,6 +213,7 @@ class NativeWindowMac : public NativeWindow,
   bool was_maximizable_;
   bool was_movable_;
   NSRect original_frame_;
+  NSInteger original_level_;
   NSUInteger simple_fullscreen_mask_;
 
   base::scoped_nsobject<NSColor> background_color_before_vibrancy_;

+ 14 - 1
atom/browser/native_window_mac.mm

@@ -1057,6 +1057,10 @@ NativeWindowMac::NativeWindowMac(
 
   RegisterInputEventObserver(
       web_contents->GetWebContents()->GetRenderViewHost());
+
+  original_frame_ = [window_ frame];
+  original_level_ = [window_ level];
+
 }
 
 NativeWindowMac::~NativeWindowMac() {
@@ -1423,8 +1427,9 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
   if (simple_fullscreen && !is_simple_fullscreen_) {
     is_simple_fullscreen_ = true;
 
-    // Take note of the current window size
+    // Take note of the current window size and level
     original_frame_ = [window frame];
+    original_level_ = [window level];
 
     simple_fullscreen_options_ = [NSApp currentSystemPresentationOptions];
     simple_fullscreen_mask_ = [window styleMask];
@@ -1440,6 +1445,13 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
 
     NSRect fullscreenFrame = [window.screen frame];
 
+    // If our app has dock hidden, set the window level higher so another app's
+    // menu bar doesn't appear on top of our fullscreen app.
+    if ([[NSRunningApplication currentApplication] activationPolicy] !=
+        NSApplicationActivationPolicyRegular) {
+      window.level = NSPopUpMenuWindowLevel;
+    }
+
     if ( !fullscreen_window_title() ) {
       // Hide the titlebar
       SetStyleMask(false, NSTitledWindowMask);
@@ -1474,6 +1486,7 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
     }
 
     [window setFrame:original_frame_ display: YES animate: YES];
+    window.level = original_level_;
 
     [NSApp setPresentationOptions:simple_fullscreen_options_];