Skip to content

Instantly share code, notes, and snippets.

@Dameck
Created April 6, 2019 20:00
Show Gist options
  • Save Dameck/d61602bae2bb7c715be19504613d9596 to your computer and use it in GitHub Desktop.
Save Dameck/d61602bae2bb7c715be19504613d9596 to your computer and use it in GitHub Desktop.
func flashScreen() {
let inDuration : CGDisplayFadeInterval = 0.5
let outDuration : CGDisplayFadeInterval = 0.5
let redColor = NSColor.red
var token : CGDisplayFadeReservationToken = UInt32(kCGDisplayFadeReservationInvalidToken)
let color = redColor.usingColorSpace(NSColorSpace.sRGB)!
if CGAcquireDisplayFadeReservation(inDuration + outDuration, &token) == CGError.success {
CGDisplayFade(token,
inDuration,
0.0 as CGDisplayBlendFraction,
0.2 as CGDisplayBlendFraction,
Float(color.redComponent),
Float(color.greenComponent),
Float(color.blueComponent),
boolean_t(1))
CGDisplayFade(token,
inDuration,
0.2 as CGDisplayBlendFraction,
0.0 as CGDisplayBlendFraction,
Float(color.redComponent),
Float(color.greenComponent),
Float(color.blueComponent),
boolean_t(1))
CGReleaseDisplayFadeReservation(token)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment