     //MARK:- Actual functionality
     
     @objc func willUpdateTitleBar() {
-        if settings.autoHideTitle.value == true {
+        if settings.autoHideTitle.value == true && !mouseOver {
             panel.titleVisibility = NSWindowTitleVisibility.hidden;
+            panel.titlebarAppearsTransparent = true
+//            panel.styleMask = NSWindowStyleMask(rawValue: NSWindowStyleMask.fullSizeContentView.rawValue + panel.styleMask.rawValue)
             panel.styleMask = NSWindowStyleMask.borderless
-            panel.title = settings.windowTitle.value
         } else {
             panel.titleVisibility = NSWindowTitleVisibility.visible;
-            panel.styleMask = NSWindowStyleMask(rawValue: UInt(settings.windowStyle.value))
-            panel.title = settings.windowTitle.value
+            panel.styleMask = panel.lastStyleMask
+            
+            let docIconButton = panel.standardWindowButton(.documentIconButton)
+            if let doc = self.document {
+                docIconButton?.image = (doc as! Document).displayImage
+                panel.title = doc.displayName
+            }
+            else
+            {
+                docIconButton?.image = NSApp.applicationIconImage
+            }
+            panel.styleMask = panel.lastStyleMask
+            panel.title = (document?.displayName)!
+            
+            self.synchronizeWindowTitleWithDocumentName()
         }
     }
     


import AppKit

internal struct Settings {
    internal class Setup<T> {
        private let key: String
        private var setting: T
        
        init(_ userDefaultsKey: String, value: T) {
            self.key = userDefaultsKey
            self.setting = value
        }
        
        var keyPath: String {
            get {
                return self.key
            }
        }
        var `default`: T {
            get {
                if let value = UserDefaults.standard.object(forKey: self.key) as? T {
                    return value
                } else {
                    // Sets existing setting if failed
                    return self.setting
                }
            }
        }
        var value: T {
            get {
                return self.setting
            }
            set (value) {
                self.setting = value
                //  Inform all interested parties for this panel's controller only only
                NotificationCenter.default.post(name: Notification.Name(rawValue: self.keyPath), object: nil)
            }
        }
    }
    
    let autoHideTitle = Setup<Bool>("autoHideTitle", value: false)
    let disabledFullScreenFloat = Setup<Bool>("disabledFullScreenFloat", value: false)
    let windowTitle = Setup<String>("windowTitle", value: "Helium")
    let windowStyle = Setup<Int>("windowStyle", value: 0)
    let opacityPercentage = Setup<Int>("opacityPercentage", value: 60)
    
    // See values in HeliumPanelController.TranslucencyPreference
    let translucencyPreference = Setup<HeliumPanelController.TranslucencyPreference>("rawTranslucencyPreference", value: .never)
}

class HeliumPanelController : NSWindowController,NSWindowDelegate {

    var settings:Settings = Settings()
    
    var webViewController: WebViewController {
        get {
            return self.window?.contentViewController as! WebViewController


    // MARK: Window lifecycle
    override func windowDidLoad() {
        panel.standardWindowButton(.closeButton)?.image = NSApp.applicationIconImage
        panel.isFloatingPanel = true
        
        NotificationCenter.default.addObserver(
            self,
