using common method for determining scale from displayID

This commit is contained in:
Stefan Csomor
2020-08-14 14:43:04 +02:00
committed by Vadim Zeitlin
parent 7dc67a1f9f
commit 99f7c8f3a4

View File

@@ -45,6 +45,14 @@ extern wxRect wxOSXGetDisplayClientArea(CGDirectDisplayID id);
namespace namespace
{ {
double wxGetScaleFactor( CGDirectDisplayID ID)
{
wxCFRef<CGDisplayModeRef> mode = CGDisplayCopyDisplayMode(ID);
size_t width = CGDisplayModeGetWidth(mode);
size_t pixelsw = CGDisplayModeGetPixelWidth(mode);
return (double)pixelsw/width;
}
wxRect wxGetDisplayGeometry(CGDirectDisplayID id) wxRect wxGetDisplayGeometry(CGDirectDisplayID id)
{ {
CGRect theRect = CGDisplayBounds(id); CGRect theRect = CGDisplayBounds(id);
@@ -257,10 +265,8 @@ int wxDisplayFactoryMacOSX::GetFromWindow(const wxWindow *window)
for ( int i = 0 ; i < theCount; ++i ) for ( int i = 0 ; i < theCount; ++i )
{ {
// find a screen intersecting having the same contentScale as the window itself // find a screen intersecting having the same contentScale as the window itself
wxCFRef<CGDisplayModeRef> mode = CGDisplayCopyDisplayMode(theIDs[i]); double scale = wxGetScaleFactor(theIDs[i]);
size_t width = CGDisplayModeGetWidth(mode); if ( fabs(scale - tlw->GetContentScaleFactor() ) < 0.01 )
size_t pixelsw = CGDisplayModeGetPixelWidth(mode);
if ( fabs( (double)pixelsw / width - tlw->GetContentScaleFactor() ) < 0.01 )
{ {
return wxOSXGetDisplayFromID(theIDs[i]); return wxOSXGetDisplayFromID(theIDs[i]);
} }
@@ -313,10 +319,7 @@ wxSize wxDisplayImplMacOSX::GetSizeMM() const
double wxDisplayImplMacOSX::GetScaleFactor() const double wxDisplayImplMacOSX::GetScaleFactor() const
{ {
wxCFRef<CGDisplayModeRef> mode = CGDisplayCopyDisplayMode(m_id); return wxGetScaleFactor(m_id);
size_t width = CGDisplayModeGetWidth(mode);
size_t pixelsw = CGDisplayModeGetPixelWidth(mode);
return (double)pixelsw / width;
} }
static int wxOSXCGDisplayModeGetBitsPerPixel( CGDisplayModeRef theValue ) static int wxOSXCGDisplayModeGetBitsPerPixel( CGDisplayModeRef theValue )