From eea2fd2f3f9a9fe47d8672adc18905f9d017ca65 Mon Sep 17 00:00:00 2001 From: gxalpha Date: Tue, 1 Mar 2022 13:43:29 +0100 Subject: [PATCH] UI: Add status overlay for macOS dock icon Adds an implementation for the dock icon status overlay on macOS (which doesn't rely on QtMacExtras, which means it also works on Qt6). --- UI/platform-osx.mm | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index af66ab723..1a5ab3f13 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -202,9 +202,57 @@ void EnableOSXDockIcon(bool enable) NSApplicationActivationPolicyProhibited]; } -// Not implemented yet +@interface DockView : NSView { +@private + QIcon icon; +} +@end + +@implementation DockView +- (id)initWithIcon:(QIcon)icon +{ + self = [super init]; + self->icon = icon; + return self; +} +- (void)drawRect:(NSRect)dirtyRect +{ + CGSize size = dirtyRect.size; + + /* Draw regular app icon */ + NSImage *appIcon = [[NSWorkspace sharedWorkspace] + iconForFile:[[NSBundle mainBundle] bundlePath]]; + [appIcon drawInRect:CGRectMake(0, 0, size.width, size.height)]; + + /* Draw small icon on top */ + float iconSize = 0.45; + CGImageRef image = + icon.pixmap(size.width, size.height).toImage().toCGImage(); + CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; + CGContextDrawImage(context, + CGRectMake(size.width * (1 - iconSize), 0, + size.width * iconSize, + size.height * iconSize), + image); + CGImageRelease(image); +} +@end + void TaskbarOverlayInit() {} -void TaskbarOverlaySetStatus(TaskbarOverlayStatus) {} +void TaskbarOverlaySetStatus(TaskbarOverlayStatus status) +{ + QIcon icon; + if (status == TaskbarOverlayStatusActive) + icon = QIcon::fromTheme("obs-active", + QIcon(":/res/images/active_mac.png")); + else if (status == TaskbarOverlayStatusPaused) + icon = QIcon::fromTheme("obs-paused", + QIcon(":/res/images/paused_mac.png")); + + NSDockTile *tile = [NSApp dockTile]; + [tile setContentView:[[DockView alloc] initWithIcon:icon]]; + [tile display]; +} /* * This custom NSApplication subclass makes the app compatible with CEF. Qt