Fix title of frameless window showing as empty under fullscreen
authorCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jun 2016 08:26:26 +0000 (17:26 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jun 2016 08:26:26 +0000 (17:26 +0900)
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm

index c1694c3..52ebcbc 100644 (file)
@@ -139,6 +139,9 @@ class NativeWindowMac : public NativeWindow {
   // The presentation options before entering kiosk mode.
   NSApplicationPresentationOptions kiosk_options_;
 
+  // The window title, for frameless windows we only set title when fullscreen.
+  std::string title_;
+
   // Force showing the buttons for frameless window.
   bool force_show_buttons_;
 
index 8bc4052..2b88b18 100644 (file)
@@ -193,10 +193,16 @@ bool ScopedDisableResize::disable_resize_ = false;
 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
   shell_->NotifyWindowEnterFullScreen();
 
+  // For frameless window we don't set title for normal mode since the title
+  // bar is expected to be empty, but after entering fullscreen mode we have
+  // to set one, because title bar is visible here.
+  NSWindow* window = shell_->GetNativeWindow();
+  if (shell_->transparent() || !shell_->has_frame())
+    [window setTitle:base::SysUTF8ToNSString(shell_->GetTitle())];
+
   // Restore the native toolbar immediately after entering fullscreen, if we do
   // this before leaving fullscreen, traffic light buttons will be jumping.
   if (shell_->should_hide_native_toolbar_in_fullscreen()) {
-    NSWindow* window = shell_->GetNativeWindow();
     base::scoped_nsobject<NSToolbar> toolbar(
         [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
     [toolbar setShowsBaselineSeparator:NO];
@@ -209,6 +215,11 @@ bool ScopedDisableResize::disable_resize_ = false;
 }
 
 - (void)windowWillExitFullScreen:(NSNotification*)notification {
+  // Restore the title bar to empty.
+  NSWindow* window = shell_->GetNativeWindow();
+  if (shell_->transparent() || !shell_->has_frame())
+    [window setTitle:@""];
+
   // Turn off the style for toolbar.
   if (shell_->should_hide_native_toolbar_in_fullscreen())
     shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask);
@@ -781,6 +792,8 @@ void NativeWindowMac::Center() {
 }
 
 void NativeWindowMac::SetTitle(const std::string& title) {
+  title_ = title;
+
   // We don't want the title to show in transparent or frameless window.
   if (transparent() || !has_frame())
     return;
@@ -789,7 +802,7 @@ void NativeWindowMac::SetTitle(const std::string& title) {
 }
 
 std::string NativeWindowMac::GetTitle() {
-  return base::SysNSStringToUTF8([window_ title]);
+  return title_;
 }
 
 void NativeWindowMac::FlashFrame(bool flash) {