From 2da5e78d753ac3661fd6ca30e2fa555d6ab10aaa Mon Sep 17 00:00:00 2001 From: Emanuel Stadler Date: Tue, 4 Aug 2026 16:21:50 +0200 Subject: [PATCH 1/2] Cache bezel background rendering --- UI/BezelWindow.h | 4 ++++ UI/BezelWindow.m | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/UI/BezelWindow.h b/UI/BezelWindow.h index 0a6f9a6..4ead5da 100755 --- a/UI/BezelWindow.h +++ b/UI/BezelWindow.h @@ -42,6 +42,10 @@ NSImageView *iconView; id delegate; Boolean color; + NSColor *backgroundColorCache; + NSSize backgroundColorCacheSize; + float backgroundColorCacheAlpha; + Boolean backgroundColorCacheColor; } - (id)initWithContentRect:(NSRect)contentRect diff --git a/UI/BezelWindow.m b/UI/BezelWindow.m index cf607f2..83a2fc0 100755 --- a/UI/BezelWindow.m +++ b/UI/BezelWindow.m @@ -190,7 +190,25 @@ -(NSRect) charFrame -(NSColor*) backgroundColor { - return [self sizedBezelBackgroundWithRadius:25.0 withAlpha:[[NSUserDefaults standardUserDefaults] floatForKey:@"bezelAlpha"]]; + NSSize backgroundSize = [self frame].size; + float backgroundAlpha = [[NSUserDefaults standardUserDefaults] floatForKey:@"bezelAlpha"]; + + // AppKit may call -update frequently on modern macOS. Rebuilding the + // bitmap pattern on every update is unnecessarily expensive and can keep + // the main thread busy while the bezel is idle. Rebuild only when one of + // the inputs that affects the background has changed. + if (backgroundColorCache != nil + && NSEqualSizes(backgroundColorCacheSize, backgroundSize) + && backgroundColorCacheAlpha == backgroundAlpha + && backgroundColorCacheColor == color) + return backgroundColorCache; + + [backgroundColorCache release]; + backgroundColorCache = [[self sizedBezelBackgroundWithRadius:25.0 withAlpha:backgroundAlpha] retain]; + backgroundColorCacheSize = backgroundSize; + backgroundColorCacheAlpha = backgroundAlpha; + backgroundColorCacheColor = color; + return backgroundColorCache; } - (void) setAlpha:(float)newValue @@ -314,6 +332,7 @@ -(BOOL)canBecomeKeyWindow - (void)dealloc { + [backgroundColorCache release]; [textField release]; [charField release]; [iconView release]; From 1c0fcb92069d04bbeb989a27cee7d66e90aabde4 Mon Sep 17 00:00:00 2001 From: Emanuel Stadler Date: Sun, 9 Aug 2026 20:34:24 +0200 Subject: [PATCH 2/2] Release CGColor objects after layer assignment --- UI/BezelWindow.m | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/UI/BezelWindow.m b/UI/BezelWindow.m index 83a2fc0..26ecff9 100755 --- a/UI/BezelWindow.m +++ b/UI/BezelWindow.m @@ -50,14 +50,18 @@ - (id)initWithContentRect:(NSRect)contentRect [[self contentView] addSubview:sourceFieldBackground]; [sourceFieldBackground.textField setEditable:NO]; [sourceFieldBackground.textField setTextColor:[NSColor whiteColor]]; - [sourceFieldBackground.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45)]; + CGColorRef sourceBackgroundColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45); + [sourceFieldBackground.background.layer setBackgroundColor:sourceBackgroundColor]; + CGColorRelease(sourceBackgroundColor); [sourceFieldBackground.textField setBordered:NO]; sourceFieldApp = [[RoundRecTextField alloc] initWithFrame:[self sourceFrameLeft]]; [[self contentView] addSubview:sourceFieldApp]; [sourceFieldApp.textField setEditable:NO]; [sourceFieldApp.textField setTextColor:[NSColor whiteColor]]; - [sourceFieldApp.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.0)]; + CGColorRef sourceAppColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.0); + [sourceFieldApp.background.layer setBackgroundColor:sourceAppColor]; + CGColorRelease(sourceAppColor); [sourceFieldApp.textField setBordered:NO]; [sourceFieldApp.textField setAlignment:NSLeftTextAlignment]; @@ -77,7 +81,9 @@ - (id)initWithContentRect:(NSRect)contentRect [[self contentView] addSubview:sourceFieldDate]; [sourceFieldDate.textField setEditable:NO]; [sourceFieldDate.textField setTextColor:[NSColor whiteColor]]; - [sourceFieldDate.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.0)]; + CGColorRef sourceDateColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.0); + [sourceFieldDate.background.layer setBackgroundColor:sourceDateColor]; + CGColorRelease(sourceDateColor); [sourceFieldDate.textField setBordered:NO]; [sourceFieldDate.textField setAlignment:NSRightTextAlignment]; font = [sourceFieldDate.textField font]; @@ -92,7 +98,9 @@ - (id)initWithContentRect:(NSRect)contentRect //[[textField cell] setScrollable:YES]; //[[textField cell] setWraps:NO]; [textField.textField setTextColor:[NSColor whiteColor]]; - [textField.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45)]; + CGColorRef textFieldColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45); + [textField.background.layer setBackgroundColor:textFieldColor]; + CGColorRelease(textFieldColor); [textField.textField setBordered:NO]; [textField.textField setAlignment:NSLeftTextAlignment]; @@ -101,7 +109,9 @@ - (id)initWithContentRect:(NSRect)contentRect [[self contentView] addSubview:charField]; [charField.textField setEditable:NO]; [charField.textField setTextColor:[NSColor whiteColor]]; - [charField.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45)]; + CGColorRef charFieldColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45); + [charField.background.layer setBackgroundColor:charFieldColor]; + CGColorRelease(charFieldColor); [charField.textField setBordered:NO]; [charField.textField setAlignment:NSCenterTextAlignment]; [charField.textField setStringValue:@"Empty"]; @@ -132,10 +142,16 @@ - (void) update { [textField setFrame:textFrame]; NSRect charFrame = [self charFrame]; [charField setFrame:charFrame]; - if (showSourceField) - [sourceFieldBackground.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45)]; - else if ( nil != sourceFieldApp ) - [sourceFieldBackground.background.layer setBackgroundColor:CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.0)]; + if (showSourceField) { + CGColorRef sourceBackgroundColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.45); + [sourceFieldBackground.background.layer setBackgroundColor:sourceBackgroundColor]; + CGColorRelease(sourceBackgroundColor); + } + else if ( nil != sourceFieldApp ) { + CGColorRef sourceBackgroundColor = CGColorCreateGenericRGB(0.1, 0.1, 0.1, 0.0); + [sourceFieldBackground.background.layer setBackgroundColor:sourceBackgroundColor]; + CGColorRelease(sourceBackgroundColor); + } showSourceField = savedShowSourceField;