X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/96dabe431382e288fc1ccc561f62c400895ac0fa..525454303e200c514b6c1078284b86fb73572852:/src/osx/core/display.cpp diff --git a/src/osx/core/display.cpp b/src/osx/core/display.cpp index 45dcdd802f..998eff23f7 100644 --- a/src/osx/core/display.cpp +++ b/src/osx/core/display.cpp @@ -60,10 +60,12 @@ public: virtual wxVideoMode GetCurrentMode() const; virtual bool ChangeMode(const wxVideoMode& mode); + virtual bool IsPrimary() const; + private: CGDirectDisplayID m_id; - DECLARE_NO_COPY_CLASS(wxDisplayImplMacOSX) + wxDECLARE_NO_COPY_CLASS(wxDisplayImplMacOSX); }; class wxDisplayFactoryMacOSX : public wxDisplayFactory @@ -76,22 +78,62 @@ public: virtual int GetFromPoint(const wxPoint& pt); protected: - DECLARE_NO_COPY_CLASS(wxDisplayFactoryMacOSX) + wxDECLARE_NO_COPY_CLASS(wxDisplayFactoryMacOSX); }; // ============================================================================ // wxDisplayFactoryMacOSX implementation // ============================================================================ +// gets all displays that are not mirror displays + +static CGDisplayErr wxOSXGetDisplayList(CGDisplayCount maxDisplays, + CGDirectDisplayID *displays, + CGDisplayCount *displayCount) +{ + CGDisplayErr error = kCGErrorSuccess; + CGDisplayCount onlineCount; + + error = CGGetOnlineDisplayList(0,NULL,&onlineCount); + if ( error == kCGErrorSuccess ) + { + *displayCount = 0; + if ( onlineCount > 0 ) + { + CGDirectDisplayID *onlineDisplays = new CGDirectDisplayID[onlineCount]; + error = CGGetOnlineDisplayList(onlineCount,onlineDisplays,&onlineCount); + if ( error == kCGErrorSuccess ) + { + for ( CGDisplayCount i = 0; i < onlineCount; ++i ) + { + if ( CGDisplayMirrorsDisplay(onlineDisplays[i]) != kCGNullDirectDisplay ) + continue; + + if ( displays == NULL ) + *displayCount += 1; + else + { + if ( *displayCount < maxDisplays ) + { + displays[*displayCount] = onlineDisplays[i]; + *displayCount += 1; + } + } + } + } + delete[] onlineDisplays; + } + + } + return error; +} + unsigned wxDisplayFactoryMacOSX::GetCount() { CGDisplayCount count; -#ifdef __WXDEBUG__ - CGDisplayErr err = -#endif - CGGetActiveDisplayList(0, NULL, &count); + CGDisplayErr err = wxOSXGetDisplayList(0, NULL, &count); - wxASSERT(err == CGDisplayNoErr); + wxCHECK_MSG( err == CGDisplayNoErr, 0, "wxOSXGetDisplayList() failed" ); return count; } @@ -110,7 +152,7 @@ int wxDisplayFactoryMacOSX::GetFromPoint(const wxPoint& p) { theCount = GetCount(); CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount]; - err = CGGetActiveDisplayList(theCount, theIDs, &theCount); + err = wxOSXGetDisplayList(theCount, theIDs, &theCount); wxASSERT(err == CGDisplayNoErr); for (nWhich = 0; nWhich < (int) theCount; ++nWhich) @@ -136,12 +178,9 @@ wxDisplayImpl *wxDisplayFactoryMacOSX::CreateDisplay(unsigned n) CGDisplayCount theCount = GetCount(); CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount]; -#ifdef __WXDEBUG__ - CGDisplayErr err = -#endif - CGGetActiveDisplayList(theCount, theIDs, &theCount); + CGDisplayErr err = wxOSXGetDisplayList(theCount, theIDs, &theCount); + wxCHECK_MSG( err == CGDisplayNoErr, NULL, "wxOSXGetDisplayList() failed" ); - wxASSERT( err == CGDisplayNoErr ); wxASSERT( n < theCount ); wxDisplayImplMacOSX *display = new wxDisplayImplMacOSX(n, theIDs[n]); @@ -155,6 +194,11 @@ wxDisplayImpl *wxDisplayFactoryMacOSX::CreateDisplay(unsigned n) // wxDisplayImplMacOSX implementation // ============================================================================ +bool wxDisplayImplMacOSX::IsPrimary() const +{ + return CGDisplayIsMain(m_id); +} + wxRect wxDisplayImplMacOSX::GetGeometry() const { CGRect theRect = CGDisplayBounds(m_id); @@ -223,10 +267,14 @@ wxVideoMode wxDisplayImplMacOSX::GetCurrentMode() const bool wxDisplayImplMacOSX::ChangeMode( const wxVideoMode& mode ) { - // Changing to default mode (wxDefaultVideoMode) doesn't - // work because we don't have access to the system's 'scrn' - // resource which holds the user's mode which the system - // will return to after this app is done +#ifndef __WXOSX_IPHONE__ + if (mode == wxDefaultVideoMode) + { + CGRestorePermanentDisplayConfiguration(); + return true; + } +#endif + boolean_t bExactMatch; CFDictionaryRef theCGMode = CGDisplayBestModeForParametersAndRefreshRate( m_id,