     //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()
         }
     }
     

        }
    }
   
    @objc fileprivate func didUpdateTitle(_ notification: Notification) {
        panel.title = settings.windowTitle.value
    }
    
    fileprivate func didRequestFile() {
        
        let open = NSOpenPanel()

    
    @IBAction func percentagePress(_ sender: NSMenuItem) {
        settings.opacityPercentage.value = sender.tag
        willUpdateAlpha()
    }

    @IBAction func translucencyPress(_ sender: NSMenuItem) {
        settings.translucencyPreference.value = HeliumPanelController.TranslucencyPreference(rawValue: sender.tag)!
        translucencyPreference = settings.translucencyPreference.value
        willUpdateTranslucency()
    }

    override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
        switch menuItem.title {
        case "Preferences":
            break
        case "Auto-hide Title Bar":
            menuItem.state = settings.autoHideTitle.value ? NSOnState : NSOffState
            break
        //Transluceny Menu
        case "Never":
            menuItem.state = settings.translucencyPreference.value == .never ? NSOnState : NSOffState
            break
        case "Always":
            menuItem.state = settings.translucencyPreference.value == .always ? NSOnState : NSOffState
            break
        case "Mouse Over":
            menuItem.state = settings.translucencyPreference.value == .mouseOver ? NSOnState : NSOffState
            break
        case "Mouse Outside":
            menuItem.state = settings.translucencyPreference.value == .mouseOutside ? NSOnState : NSOffState
            break
        case "Float Above All Spaces":
            menuItem.state = settings.disabledFullScreenFloat.value ? NSOffState : NSOnState
            break;
        case "Hide Helium in menu bar":
            menuItem.state = UserSettings.HideAppMenu.value ? NSOnState : NSOffState
            break
        case "Home Page":
            break
        case "Magic URL Redirects":
            menuItem.state = UserSettings.disabledMagicURLs.value ? NSOffState : NSOnState
            break
            
        default:
            // Opacity menu item have opacity as tag value
            if menuItem.tag >= 10 {
                if let hwc = NSApp.keyWindow?.windowController {
                    menuItem.state = (menuItem.tag == (hwc as! HeliumPanelController).settings.opacityPercentage.value ? NSOnState : NSOffState)
                    menuItem.target = hwc
                }
                else
                {
                    menuItem.state = (menuItem.tag == settings.opacityPercentage.value ? NSOnState : NSOffState)
                    menuItem.target = self
                }
            }
            break
        }
        Swift.print(String(format: "hwc %@ %@", menuItem.title, menuItem.state == NSOnState ? "on" : "off"))
        return true;
    }

    //MARK:- Notifications
