How to hihglight or focus the active application into MacOS using Swift

116 Views Asked by At

I'm looking something similar than HazeOver, Focus and other apps that helps to focus on the active application dimming or tinting with other color the not actives, but I'm trying to do it by my own using swift 5.7 on MacOS app but I do not find how to add a background color or tint color for the non active applications. Here you'll find a portion of my code:

    @objc func receiveFrontAppChangeNote(_ notification: Notification) {
        
        
        let application = NSWorkspace.shared.frontmostApplication!
        let currentApp = application.processIdentifier
              
        let options = CGWindowListOption(arrayLiteral: CGWindowListOption.excludeDesktopElements, CGWindowListOption.optionOnScreenOnly)
        let windowListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
        let windowInfoList = windowListInfo as NSArray? as? [[String: AnyObject]]
                               
        for info in windowInfoList! {
            let windowPID = info["kCGWindowOwnerPID"]   as! UInt32
            let windowNumber = info["kCGWindowNumber"]   as! UInt32
                            
            if  windowPID == currentApp {
                // This is the windowNumber of the Active Application
                print(windowNumber)
                
            }else{
                // This is a not active app
                let notActiveApp = NSRunningApplication(processIdentifier: pid_t(windowPID))
                
                // Add here how to tint or add background color to the notActiveApp 
                // ...                    
            }
            
        }
    }

Thanks to all!!

0

There are 0 best solutions below