             selector: #selector(HeliumPanelController.willResignActive),
             name: NSNotification.Name.NSApplicationWillResignActive,
             object: nil)
-
-        // MARK: Load settings from panel.settings
-
-        NotificationCenter.default.addObserver(
-            self,
-            selector: #selector(HeliumPanelController.setFloatOverFullScreenApps),
-            name: NSNotification.Name(rawValue: settings.disabledFullScreenFloat.keyPath),
-            object:nil)
+    }
+
+    func documentViewDidLoad() {
+        // Moved later, called by view, when document is available
         setFloatOverFullScreenApps()
-
-        NotificationCenter.default.addObserver(
-            self,
-            selector: #selector(HeliumPanelController.willUpdateTitleBar),
-            name: NSNotification.Name(rawValue: settings.autoHideTitle.keyPath),
-            object:nil)
+        
         willUpdateTitleBar()
-
-        NotificationCenter.default.addObserver(
-            self,
-            selector: #selector(HeliumPanelController.didUpdateTitle(_:)),
-            name: NSNotification.Name(rawValue: settings.windowTitle.keyPath),
-            object: nil)
-        NotificationCenter.default.addObserver(
-            self,
-            selector: #selector(HeliumPanelController.willUpdateTranslucency),
-            name: NSNotification.Name(rawValue: settings.translucencyPreference.keyPath),
-            object:nil)
+        
         willUpdateTranslucency()
-
-        NotificationCenter.default.addObserver(
-            self,
-            selector: #selector(HeliumPanelController.willUpdateAlpha),
-            name: NSNotification.Name(rawValue: settings.opacityPercentage.keyPath),
-            object:nil)
-       willUpdateAlpha()
-
-    }
-
+        
+        willUpdateAlpha()
+    }
+    
     // MARK:- Mouse events
     override func mouseEntered(with theEvent: NSEvent) {
         if theEvent.modifierFlags.contains(.shift) {
             NSApp.activate(ignoringOtherApps: true)
-        }
+            Swift.print(String(format: "mouse up %@", (self.window?.title)!))
+        }
+        Swift.print(String(format: "mouse in %@", (self.window?.title)!))
         mouseOver = true
         updateTranslucency()
         willUpdateTitleBar()
     }
     
     override func mouseExited(with theEvent: NSEvent) {
+        Swift.print(String(format: "mouse ou %@", (self.window?.title)!))
         mouseOver = false
         updateTranslucency()
         willUpdateTitleBar()


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:- Actual functionality
    
    @objc func willUpdateTitleBar() {
        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
        } else {
            panel.titleVisibility = NSWindowTitleVisibility.visible;
            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()
        }
    }
    
