             nf.minimumIntegerDigits = 3 // XXX
 
             for i in 0..<modes.count {
-                if let di = displayInfo(display:display, mode:modes[i]) {
-                    print("       \(di.width) * \(di.height) @ \(di.frequency)Hz")
-                }
+                let di = DisplayInfo.init(displayID:display, mode:modes[i])
+                print("       \(di.width) * \(di.height) @ \(di.frequency)Hz")
             }
         }
     }

                    if let modesArray = listModesByDisplayID(_displayID:onlineDisplayIDs[displayIndex]) {
                        var designatedWidthIndex:Int?
                        for i in 0..<modesArray.count {
                            if let di = displayInfo(display:onlineDisplayIDs[displayIndex], mode:modesArray[i]) {
                                if di.width == designatedWidth {
                                    designatedWidthIndex = i
                                    break
                                }
                            }
                        }
                        if designatedWidthIndex != nil {

// used by -l
func listDisplays(displayIDs:UnsafeMutablePointer<CGDirectDisplayID>, count:Int) -> Void {
    for i in 0..<count {
        let di = DisplayInfo.init(displayID:displayIDs[i])
        print("Display \(i):  \(di.width) * \(di.height) @ \(di.frequency)Hz")
    }
}

// return with, height and frequency info for corresponding displayID
struct DisplayInfo {
    var width, height:UInt
    var frequency:Int
    
    init(displayID:CGDirectDisplayID) {
        let mode = CGDisplayCopyDisplayMode(displayID)
        self.init(displayID:displayID, mode:mode)
    }
    
    init(displayID:CGDirectDisplayID, mode:CGDisplayMode?) {
        if let _mode = mode {
            width = UInt( _mode.width )
            height = UInt( _mode.height )
            
            var _frequency = Int( _mode.refreshRate )
            
            if _frequency == 0 {
                var link:CVDisplayLink?
                
                CVDisplayLinkCreateWithCGDisplay(displayID, &link)
                
                let time:CVTime = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link!)
                
                // timeValue is in fact already in Int64
                let timeValue = time.timeValue as Int64
                
                // a hack-y way to do ceil
                let timeScale = Int64(time.timeScale) + timeValue / 2
                
                _frequency = Int( timeScale / timeValue )
            }
            
            frequency = _frequency
        }
        else {
            width = 0
            height = 0
            frequency = 0
        }
    }
}


// run it
main()
