 fileprivate let gap = CGFloat(4.0)
 
 class WindowController: NSWindowController, NSWindowDelegate {
+
+  func windowWillEnterFullScreen(_: Notification) {
+    self.unthemeTitlebar(dueFullScreen: true)
+  }
+
+  func windowDidExitFullScreen(_: Notification) {
+    if self.titlebarThemed {
+      self.themeTitlebar(nil)
+    }
+  }
 
   fileprivate var titlebarThemed = false
   fileprivate var repIcon: NSButton?

    self.titlebarThemed = true
  }

  fileprivate func unthemeTitlebar(dueFullScreen: Bool) {
    self.repIcon?.removeFromSuperview()
    self.titleView?.removeFromSuperview()

    self.repIcon = nil
    self.titleView = nil

    self.root.removeFromSuperview()


    }

    if window.styleMask.contains(.fullScreen) || themed == false {
      self.internalSetRepUrl(url)
      return
    }

    self.clearCustomTitle()

    window.titleVisibility = .visible
    self.internalSetRepUrl(url)

    guard let contentView = window.contentView else {
      return
    }

    window.titleVisibility = .hidden
    window.styleMask.insert(.fullSizeContentView)

    let title = NSTextField(labelWithString: window.title)
    title.configureForAutoLayout()
    contentView.addSubview(title)
    title.autoPinEdge(toSuperviewEdge: .top, withInset: 2)

    self.titleView = title

    if let button = window.standardWindowButton(.documentIconButton) {
      button.removeFromSuperview() // remove the rep icon from the original superview and add it to content view
      contentView.addSubview(button)
      button.autoSetDimension(.width, toSize: 16)
      button.autoSetDimension(.height, toSize: 16)
      button.autoPinEdge(toSuperviewEdge: .top, withInset: 3)

      // Center the rep icon and the title side by side in the content view:
      // rightView.left = leftView.right + gap
      // rightView.right = parentView.centerX + (leftView.width + gap + rightView.width) / 2
      contentView.addConstraint(NSLayoutConstraint(item: title, attribute: .left,
                                                   relatedBy: .equal,
                                                   toItem: button, attribute: .right,
                                                   multiplier: 1,
                                                   constant: gap))
      contentView.addConstraint(NSLayoutConstraint(item: title, attribute: .right,
                                                   relatedBy: .equal,
                                                   toItem: contentView, attribute: .centerX,
                                                   multiplier: 1,
                                                   constant: (button.frame.width + gap + title.frame.width) / 2))

      self.repIcon = button
    } else {
      title.autoAlignAxis(toSuperviewAxis: .vertical)
    }
  }

  // ====== >8 ======
