Generate wxEVT_DPI_CHANGED event under Mac

This commit is contained in:
Stefan Csomor
2020-07-18 18:24:28 +02:00
committed by Vadim Zeitlin
parent 1ebf8daa2a
commit fa58dc2c45

View File

@@ -321,6 +321,7 @@ static void *EffectiveAppearanceContext = &EffectiveAppearanceContext;
- (BOOL)windowShouldClose:(id)window; - (BOOL)windowShouldClose:(id)window;
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
- (void)windowWillEnterFullScreen:(NSNotification *)notification; - (void)windowWillEnterFullScreen:(NSNotification *)notification;
- (void)windowDidChangeBackingProperties:(NSNotification *)notification;
@end @end
@@ -612,7 +613,43 @@ extern int wxOSXGetIdFromSelector(SEL action );
[view setFrameSize: expectedframerect.size]; [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 - (void)addObservers:(NSWindow*)win
{ {
[win addObserver:self forKeyPath:@"effectiveAppearance" [win addObserver:self forKeyPath:@"effectiveAppearance"