From fa58dc2c4540a17c6459bad58c5795d5bedad09a Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 18 Jul 2020 18:24:28 +0200 Subject: [PATCH] Generate wxEVT_DPI_CHANGED event under Mac --- src/osx/cocoa/nonownedwnd.mm | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index f38eeddde4..a0ad84b8d4 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -321,6 +321,7 @@ static void *EffectiveAppearanceContext = &EffectiveAppearanceContext; - (BOOL)windowShouldClose:(id)window; - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; - (void)windowWillEnterFullScreen:(NSNotification *)notification; +- (void)windowDidChangeBackingProperties:(NSNotification *)notification; @end @@ -612,7 +613,43 @@ extern int wxOSXGetIdFromSelector(SEL action ); [view setFrameSize: expectedframerect.size]; } } - + +// from https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html + +- (void)windowDidChangeBackingProperties:(NSNotification *)notification +{ + NSWindow* theWindow = (NSWindow*)[notification object]; + wxNonOwnedWindowCocoaImpl* windowimpl = [theWindow WX_implementation]; + wxNonOwnedWindow* wxpeer = windowimpl ? windowimpl->GetWXPeer() : NULL; + if (wxpeer) + { + CGFloat newBackingScaleFactor = [theWindow backingScaleFactor]; + CGFloat oldBackingScaleFactor = [[[notification userInfo] + objectForKey:@"NSBackingPropertyOldScaleFactorKey"] + doubleValue]; + if (newBackingScaleFactor != oldBackingScaleFactor) + { + wxSize oldDPI((int)(oldBackingScaleFactor*72.0),(int)(oldBackingScaleFactor*72.0)); + wxSize newDPI((int)(newBackingScaleFactor*72.0),(int)(newBackingScaleFactor*72.0)); + + wxDPIChangedEvent event(oldDPI, newDPI); + event.SetEventObject(wxpeer); + wxpeer->HandleWindowEvent(event); + + } + + NSColorSpace *newColorSpace = [theWindow colorSpace]; + NSColorSpace *oldColorSpace = [[notification userInfo] + objectForKey:@"NSBackingPropertyOldColorSpaceKey"]; + if (![newColorSpace isEqual:oldColorSpace]) + { + wxSysColourChangedEvent event; + event.SetEventObject(wxpeer); + wxpeer->HandleWindowEvent(event); + } + } +} + - (void)addObservers:(NSWindow*)win { [win addObserver:self forKeyPath:@"effectiveAppearance"