//-------------------------------------------------------------- // // Implementation of sample code // //-------------------------------------------------------------- OSErr RVSetVideoRequest (VideoRequestRecPtr requestRecPtr) { GDHandle aMonitor; Boolean displayMgrPresent; unsigned long displayMgrVersion; OSErr err; Boolean isColor; long value = 0; Gestalt(gestaltDisplayMgrVers, (long*)&displayMgrVersion); Gestalt(gestaltDisplayMgrAttr,&value); displayMgrPresent=value&(1<<gestaltDisplayMgrPresent); if (displayMgrPresent) { if (requestRecPtr->displayMode && requestRecPtr->depthMode) { if (requestRecPtr->availBitDepth == 1) // Based on avail bit depth, isColor = KMonoDev; // set the device to a mono device, or else isColor = kColorDev; // set the device to a color device SetDeviceAttribute(requestRecPtr->screenDevice,gdDevType,isColor); // see how many monitors we have, aMonitor will be nil if we have only one. aMonitor = DMGetFirstScreenDevice (dmOnlyActiveDisplays); // get the first guy aMonitor = DMGetNextScreenDevice ( aMonitor, dmOnlyActiveDisplays ); // get the next guy if (nil == aMonitor || displayMgrVersion >= 0x00020000) { // only call DMSetDisplayMode if we have one monitor or DM2.0 is installed // since DM1.0 does not automatically gravitate monitors and our gravitate code // is not implemented. err = DMSetDisplayMode( requestRecPtr->screenDevice, // GDevice requestRecPtr->displayMode, // DM1.0 uses this &requestRecPtr->depthMode, // DM1.0 uses this (unsigned long) &(requestRecPtr->switchInfo), // DM2.0 uses this rather than displayMode/depthMode combo nil); if (noErr == err) { // Do the monitor gravitate here if we are using a version less than DM2.0 if (displayMgrVersion < 0x00020000) GravitateMonitors (); } else if (kDMDriverNotDisplayMgrAwareErr == err) { // DM not supported by driver, so all we can do is set the bit depth err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor); } } else { // we have more than one monitor and DM1.0 is installed, so all we can do is set the bit depth err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor); } return (err); // we did try to set the request } } return (-1); // return a generic error }
bool wxDisplay::ChangeMode(const wxVideoMode& mode) { unsigned long dwDMVer; Gestalt(gestaltDisplayMgrVers, (long*)&dwDMVer); if (GetCount() == 1 || dwDMVer >= 0x020000) { if (mode == wxDefaultVideoMode) { //#ifndef __DARWIN__ // Handle hDisplayState; // if (DMBeginConfigureDisplays(&hDisplayState) != noErr) // { // wxLogSysError(wxT("Could not lock display for display mode changing!")); // return false; // } // wxASSERT( DMUseScreenPrefs(true, hDisplayState) == noErr); // DMEndConfigureDisplays(hDisplayState); // return true; //#else //hmmmmm.... return true; //#endif } //0 & NULL for params 2 & 3 of DMSetVideoMode signal it to use defaults (current mode) //DM 2.0+ doesn't use params 2 & 3 of DMSetDisplayMode //so we have to use this icky structure VDSwitchInfoRec sMode; memset(&sMode, 0, sizeof(VDSwitchInfoRec) ); DMListIndexType nNumModes; DMListType pModes; DMDisplayModeListIteratorUPP uppMLI; DisplayIDType nDisplayID; wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr); //Create a new list... wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr, wxT("Could not create a new display mode list") ); uppMLI = NewDMDisplayModeListIteratorUPP(DMModeInfoProc); wxASSERT(uppMLI); DMModeInfoRec sModeInfo; sModeInfo.bMatched = false; sModeInfo.pMode = &mode; unsigned int i; for(i = 0; i < nNumModes; ++i) { wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL, uppMLI, &sModeInfo) == noErr); if (sModeInfo.bMatched == true) { sMode = sModeInfo.sMode; break; } } if(i == nNumModes) return false; DisposeDMDisplayModeListIteratorUPP(uppMLI); wxASSERT(DMDisposeList(pModes) == noErr); // For the really paranoid - // unsigned long flags; // Boolean bok; // wxASSERT(noErr == DMCheckDisplayMode(m_priv->m_hndl, sMode.csData, // sMode.csMode, &flags, NULL, &bok)); // wxASSERT(bok); Handle hDisplayState; if (DMBeginConfigureDisplays(&hDisplayState) != noErr) { wxLogSysError(wxT("Could not lock display for display mode changing!")); return false; } unsigned long dwBPP = (unsigned long) mode.bpp; if (DMSetDisplayMode(m_priv->m_hndl, sMode.csData, (unsigned long*) &(dwBPP), NULL //(unsigned long) &sMode , hDisplayState ) != noErr) { DMEndConfigureDisplays(hDisplayState); wxMessageBox(wxString::Format(wxT("Could not set the display mode"))); return false; } DMEndConfigureDisplays(hDisplayState); } else //DM 1.0, 1.2, 1.x { wxLogSysError(wxString::Format(wxT("Monitor gravitation not supported yet. dwDMVer:%u"), (unsigned int) dwDMVer)); return false; } return true; }