diff --git a/lcl/interfaces/cocoa/cocoaconfig.pas b/lcl/interfaces/cocoa/cocoaconfig.pas index 34ca3da5c9..dfbada06ea 100644 --- a/lcl/interfaces/cocoa/cocoaconfig.pas +++ b/lcl/interfaces/cocoa/cocoaconfig.pas @@ -86,6 +86,12 @@ var CocoaScrollerOverlayStyleKnobMinSize : Double = 25; + // by default on macOS, Notification is only Presented when the APP is + // in the background. + // when CocoaAlwaysPresentNotification is set to True, Notification is + // always Presented. + CocoaAlwaysPresentNotification : Boolean = True; + // for compatiblity with LCL 1.8 release. The macOS base is 72ppi CocoaBasePPI : Integer = 96; diff --git a/lcl/interfaces/cocoa/cocoatrayicon.inc b/lcl/interfaces/cocoa/cocoatrayicon.inc index 97967d2675..1af900bf7c 100644 --- a/lcl/interfaces/cocoa/cocoatrayicon.inc +++ b/lcl/interfaces/cocoa/cocoatrayicon.inc @@ -15,6 +15,12 @@ type procedure menuWillOpen(menu: NSMenu); message 'menuWillOpen:'; end; + { TCocoaUserNotificationCenterDelegate } + + TCocoaUserNotificationCenterDelegate = objcclass(NSObject, NSUserNotificationCenterDelegateProtocol) + function userNotificationCenter_shouldPresentNotification (center: NSUserNotificationCenter; notification: NSUserNotification): ObjCBOOL; message 'userNotificationCenter:shouldPresentNotification:'; + end; + { TCocoaStatusItemHandle } procedure TCocoaStatusItemHandle.lclAction(sender: id); @@ -34,7 +40,10 @@ begin if (ATrayIcon.icon <> nil) and (ATrayIcon.icon.Handle <> 0) then begin image := TCocoaBitmap(ATrayIcon.icon.Handle).image; - if image <> nil then statusitem.setImage(image); + if image <> nil then begin + statusItem.button.setImageScaling(NSImageScaleProportionallyUpOrDown); + statusItem.button.setImage(image); + end; end; // Show the menu @@ -61,6 +70,13 @@ begin menu.cancelTrackingWithoutAnimation; end; +function TCocoaUserNotificationCenterDelegate.userNotificationCenter_shouldPresentNotification + (center: NSUserNotificationCenter; notification: NSUserNotification + ): ObjCBOOL; +begin + Result:= True; +end; + { TCocoaWSCustomTrayIcon } class function TCocoaWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean; @@ -139,8 +155,23 @@ begin end; class function TCocoaWSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean; +var + nc: NSUserNotificationCenter; + message: NSUserNotification; begin - Result := False; + Result := True; + message:= NSUserNotification.alloc.init; + message.setTitle( StrToNSString(ATrayIcon.BalloonTitle) ); + message.setInformativeText( StrToNSString(ATrayIcon.BalloonHint) ); + + nc:= NSUserNotificationCenter.defaultUserNotificationCenter; + if CocoaConfig.CocoaAlwaysPresentNotification then begin + if NOT Assigned(nc.delegate) then + nc.setDelegate( TCocoaUserNotificationCenterDelegate.new ); + end; + nc.deliverNotification( message ); + + message.release; end; class function TCocoaWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint; diff --git a/lcl/interfaces/cocoa/cocoawsextctrls.pas b/lcl/interfaces/cocoa/cocoawsextctrls.pas index f99ef26df3..a6a3b085c0 100644 --- a/lcl/interfaces/cocoa/cocoawsextctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsextctrls.pas @@ -31,7 +31,7 @@ uses WSExtCtrls, WSLCLClasses, // LCL Cocoa CocoaPrivate, CocoaMenus, CocoaWSCommon, CocoaGDIObjects, CocoaScrollers, - Cocoa_Extra; + Cocoa_Extra, CocoaUtils, CocoaConfig; type