Quartz Display Services provides a general notification mechanism for applications that need to know about display configuration changes. Any application can register a display reconfiguration callback function. At several points during reconfiguration, Quartz passes to your callback function the display ID, status flags, and optional private data. During a display mode change, for example, you could use a callback to print a log message that describes the new mode.
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 kCGDisplayBeginConfigurationFlag
flag is always set. After display reconfiguration, Quartz invokes your callback function once for each added, removed, and online display. At this time, all display state reported by Quartz Display Services, QuickDraw, and the Carbon Display Manager will be up to date. The flags indicate how the display configuration has changed.
Carbon and Cocoa already use this notification mechanism to respond to display reconfigurations. As a result, when a user or application changes a display mode, turns on mirroring, or disconnects a display, Carbon or Cocoa applications don't need to be concerned with repositioning or resizing their windows. The application frameworks handle this task automatically.
If you want to receive notifications of configuration changes, here is a brief description of the steps:
Register your notification callback function:
CGDisplayRegisterReconfigurationCallback (MyDisplayReconfigurationCallBack, &userInfo); |
When your function is called, check the parameters to see if action is required. For example:
void MyDisplayReconfigurationCallBack ( |
CGDirectDisplayID display, |
CGDisplayChangeSummaryFlags flags, |
void *userInfo) |
{ |
if (flags & kCGDisplaySetModeFlag) { |
/* handle mode change for this display */ |
} |
} |
When you no longer require notification, remove the callback registration:
CGDisplayRemoveReconfigurationCallback (MyDisplayReconfigurationCallBack, &userInfo); |
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-06-28)