From 5bcd2b0dfbf29aa0fb7bf82dc58f7865858aa3a0 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 16 Mar 2021 13:24:19 +0000 Subject: [PATCH] NSViewComponentPeer: Force repaint when window becomes key This resolves an issue on macOS Catalina when using JUCE_COREGRAPHICS_DRAW_ASYNC where windows would sometimes fail to completely repaint when they were unminimized. --- .../native/juce_mac_NSViewComponentPeer.mm | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 26ca406308..2c0dcf5462 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -726,6 +726,12 @@ public: [notificationCenter removeObserver: view name: NSWindowWillMiniaturizeNotification object: currentWindow]; + + #if JUCE_COREGRAPHICS_DRAW_ASYNC + [notificationCenter removeObserver: view + name: NSWindowDidBecomeKeyNotification + object: currentWindow]; + #endif } if (isSharedWindow && [view window] == window && newWindow == nullptr) @@ -1112,6 +1118,13 @@ public: selector: dismissModalsSelector name: NSWindowWillMiniaturizeNotification object: currentWindow]; + + #if JUCE_COREGRAPHICS_DRAW_ASYNC + [notificationCenter addObserver: view + selector: becomeKeySelector + name: NSWindowDidBecomeKeyNotification + object: currentWindow]; + #endif } } @@ -1121,6 +1134,11 @@ public: sendModalInputAttemptIfBlocked(); } + void becomeKey() + { + component.repaint(); + } + void liveResizingStart() { if (constrainer == nullptr) @@ -1488,6 +1506,7 @@ public: static const SEL frameChangedSelector; static const SEL asyncMouseDownSelector; static const SEL asyncMouseUpSelector; + static const SEL becomeKeySelector; private: static NSView* createViewInstance(); @@ -1657,6 +1676,7 @@ const SEL NSViewComponentPeer::dismissModalsSelector = @selector (dismissModals const SEL NSViewComponentPeer::frameChangedSelector = @selector (frameChanged:); const SEL NSViewComponentPeer::asyncMouseDownSelector = @selector (asyncMouseDown:); const SEL NSViewComponentPeer::asyncMouseUpSelector = @selector (asyncMouseUp:); +const SEL NSViewComponentPeer::becomeKeySelector = @selector (becomeKey:); JUCE_END_IGNORE_WARNINGS_GCC_LIKE //============================================================================== @@ -1727,6 +1747,7 @@ struct JuceNSViewClass : public ObjCClass addMethod (NSViewComponentPeer::asyncMouseDownSelector, asyncMouseDown, "v@:@"); addMethod (NSViewComponentPeer::asyncMouseUpSelector, asyncMouseUp, "v@:@"); addMethod (NSViewComponentPeer::frameChangedSelector, frameChanged, "v@:@"); + addMethod (NSViewComponentPeer::becomeKeySelector, becomeKey, "v@:@"); addProtocol (@protocol (NSTextInput)); @@ -1795,6 +1816,7 @@ private: static void frameChanged (id self, SEL, NSNotification*) { if (auto* p = getOwner (self)) p->redirectMovedOrResized(); } static void viewDidMoveToWindow (id self, SEL) { if (auto* p = getOwner (self)) p->viewMovedToWindow(); } static void dismissModals (id self, SEL) { if (auto* p = getOwner (self)) p->dismissModals(); } + static void becomeKey (id self, SEL) { if (auto* p = getOwner (self)) p->becomeKey(); } static void viewWillDraw (id self, SEL) {