CGDisplayReconfigurationCallBack
A client-supplied callback function that’s invoked whenever the configuration of a local display is changed.
Declaration
typealias CGDisplayReconfigurationCallBack = (CGDirectDisplayID, CGDisplayChangeSummaryFlags, UnsafeMutableRawPointer?) -> VoidParameters
- display:
The display being reconfigured.
- flags:
Flags that indicate which display configuration parameters are changing.
- userInfo:
The
userInfoargument passed to the function Cgdisplayregisterreconfigurationcallback(_:_:) when the callback function is registered.
Discussion
If you named your function MyDisplayReconfigurationCallBack, you would declare it like this:
Discussion
To register a display reconfiguration callback function, you call the function CGDisplayRegisterReconfigurationCallback(_:_:). Quartz invokes your callback function when:
Your application calls a function to reconfigure a local display.
Your application is listening for events in the event-processing thread, and another application calls a function to reconfigure a local display.
The user changes the display hardware configuration—for example, by disconnecting a display or changing a system preferences setting.
Before display reconfiguration, Quartz invokes your callback function once for each online display to indicate a pending configuration change. The flags argument is always set to kCGDisplayBeginConfigurationFlag. The only display-specific information contained by this callback is the display ID number.The reason is that details of how a reconfiguration affects a particular device rely on device-specific behaviors which may not be available to a device driver.
After display reconfiguration, Quartz invokes your callback function once for each added, removed, and online display. At this time, all display state reported by Core Graphics and QuickDraw will be up to date. The flags argument indicates how the display configuration has changed. Note that in the case of removed displays, calls into Quartz with the removed display ID will fail.
The following code example illustrates how to test for specific conditions:
void MyDisplayReconfigurationCallBack (
CGDirectDisplayID display,
CGDisplayChangeSummaryFlags flags,
void *userInfo)
{
if (flags & kCGDisplayAddFlag) {
// display has been added
}
else if (flags & kCGDisplayRemoveFlag) {
// display has been removed
}
}Your callback function should avoid attempting to change display configurations and should not raise exceptions or perform a nonlocal return such as calling longjmp. When you are finished using a callback registration, you should call the function CGDisplayRemoveReconfigurationCallback(_:_:) to remove it.