77//
88
99#import " PTYNoteView.h"
10+ #import " NSAppearance+iTerm.h"
1011#import " SFSymbolEnum/SFSymbolEnum.h"
1112#import " iTermMouseCursor.h"
1213#import " NSImage+iTerm.h"
1314
1415static const CGFloat kMinWidth = 50 ;
15- static const CGFloat kMinHeight = 33 ;
16+ static const CGFloat kMinHeight = 39 ;
1617
17- static const CGFloat kLeftMargin = 5 ;
18- static const CGFloat kRightMargin = 14 ;
19- static const CGFloat kTopMargin = 4 ;
20- static const CGFloat kBottomMargin = 0 ;
21- static const CGFloat kKillButtonTopMargin = 2 ;
18+ static const CGFloat kLeftMargin = 8 ;
19+ static const CGFloat kRightMargin = 20 ;
20+ static const CGFloat kTopMargin = 6 ;
21+ static const CGFloat kBottomMargin = 2 ;
2222
2323static const CGFloat kInset = 5 ;
2424static const CGFloat kRadius = 5 ;
@@ -41,46 +41,63 @@ - (instancetype)initWithFrame:(NSRect)frame {
4141 self = [super initWithFrame: frame];
4242 if (self) {
4343 backgroundColor_ = [[self defaultBackgroundColor ] retain ];
44- NSImage *closeImage;
45- if (@available (macOS 11.0 , *)) {
46- closeImage = [NSImage imageWithSystemSymbolName: SFSymbolGetString (SFSymbolTrash)
47- accessibilityDescription: @" Delete annotation" ];
48- closeImage = [closeImage it_imageWithTintColor: [NSColor blackColor ]];
49- } else {
50- closeImage = [NSImage it_imageNamed: @" closebutton" forClass: self .class];
51- }
5244 killButton_ = [[NSButton alloc ] initWithFrame: NSMakeRect (0 , 0 , kButtonSize , kButtonSize )];
5345 [killButton_ setButtonType: NSButtonTypeMomentaryPushIn];
54- [killButton_ setImage: closeImage];
5546 [killButton_ setTarget: self ];
5647 [killButton_ setAction: @selector (kill: )];
5748 [killButton_ setBordered: NO ];
5849 [[killButton_ cell ] setHighlightsBy: NSContentsCellMask];
5950 [killButton_ setTitle: @" " ];
6051 [self addSubview: killButton_];
52+ [self updateKillButtonImage ];
6153 [killButton_ release ];
6254 }
6355 return self;
6456}
6557
58+ - (void )updateKillButtonImage {
59+ NSImage *closeImage;
60+ if (@available (macOS 11.0 , *)) {
61+ closeImage = [NSImage imageWithSystemSymbolName: SFSymbolGetString (SFSymbolTrash)
62+ accessibilityDescription: @" Delete annotation" ];
63+ NSColor *tintColor = self.effectiveAppearance .it_isDark ? [NSColor whiteColor ] : [NSColor blackColor ];
64+ closeImage = [closeImage it_imageWithTintColor: tintColor];
65+ } else {
66+ closeImage = [NSImage it_imageNamed: @" closebutton" forClass: self .class];
67+ }
68+ [killButton_ setImage: closeImage];
69+ }
70+
6671- (void )dealloc {
6772 [contentView_ release ];
6873 [backgroundColor_ release ];
6974 [super dealloc ];
7075}
7176
7277- (NSColor *)defaultBackgroundColor {
73- return [NSColor colorWithCalibratedRed: 252.0 /255.0
78+ if (self.effectiveAppearance .it_isDark ) {
79+ return [NSColor colorWithCalibratedRed: 50.0 /255.0
80+ green: 50.0 /255.0
81+ blue: 52.0 /255.0
82+ alpha: 1 ];
83+ }
84+ return [NSColor colorWithCalibratedRed: 250.0 /255.0
7485 green: 250.0 /255.0
75- blue: 198 .0 /255.0
86+ blue: 250 .0 /255.0
7687 alpha: 1 ];
7788}
7889
7990- (NSColor *)borderColor {
80- return [NSColor colorWithCalibratedRed: 255.0 /255.0
81- green: 229.0 /255.0
82- blue: 114.0 /255.0
83- alpha: 0.95 ];
91+ if (self.effectiveAppearance .it_isDark ) {
92+ return [NSColor colorWithCalibratedRed: 1
93+ green: 1
94+ blue: 1
95+ alpha: 0.4 ];
96+ }
97+ return [NSColor colorWithCalibratedRed: 0
98+ green: 0
99+ blue: 0
100+ alpha: 0.1 ];
84101}
85102
86103static NSPoint FlipPoint (NSPoint p, CGFloat height) {
@@ -312,11 +329,21 @@ - (NSBezierPath *)roundedRectangleWithPointerInRect:(NSRect)frame
312329- (void )viewDidMoveToSuperview {
313330 [super viewDidMoveToSuperview ];
314331
332+ [self updateKillButtonImage ];
333+
315334 NSClickGestureRecognizer *clickRecognizer = [[NSClickGestureRecognizer alloc ] initWithTarget: self action: @selector (handleClick: )];
316335 clickRecognizer.delegate = self;
317336 [self addGestureRecognizer: clickRecognizer];
318337}
319338
339+ - (void )viewDidChangeEffectiveAppearance {
340+ [super viewDidChangeEffectiveAppearance ];
341+ [backgroundColor_ release ];
342+ backgroundColor_ = [[self defaultBackgroundColor ] retain ];
343+ [self updateKillButtonImage ];
344+ [self setNeedsDisplay: YES ];
345+ }
346+
320347- (void )handleClick : (NSClickGestureRecognizer *)recognizer {
321348 if (recognizer.state == NSGestureRecognizerStateRecognized) {
322349 [self reorderAboveSiblings ];
@@ -487,28 +514,39 @@ - (void)layoutSubviews {
487514 bubbleFrame.size .width - kLeftMargin - kRightMargin ,
488515 bubbleFrame.size .height - kTopMargin - kBottomMargin ),
489516 self.frame .size .height );
517+ // Calculate what the centered position would be at minimum height to avoid jumps
518+ CGFloat minBubbleHeight = kMinHeight - kPointerLength - kInset ;
519+ CGFloat centeredMarginAtMinHeight = (minBubbleHeight - kButtonSize ) / 2.0 ;
520+ CGFloat killButtonY = NSMinY (bubbleFrame) + centeredMarginAtMinHeight;
490521 killButton_.frame = FlipRect (NSMakeRect (NSMaxX (bubbleFrame) - kButtonSize ,
491- NSMinY (bubbleFrame) + kKillButtonTopMargin ,
522+ killButtonY ,
492523 kButtonSize ,
493524 kButtonSize ),
494525 self.frame .size .height );
495526 [self .window invalidateCursorRectsForView: self ];
496527}
497528
498529- (NSSize )sizeThatFitsContentView {
530+ CGFloat width;
531+ CGFloat height;
499532 switch (tipEdge_) {
500533 case kPTYNoteViewTipEdgeBottom :
501534 case kPTYNoteViewTipEdgeTop :
502- return NSMakeSize (contentView_.frame .size .width + kLeftMargin + kRightMargin + kInset ,
503- contentView_.frame .size .height + kBottomMargin + kTopMargin + kPointerLength + kInset );
535+ width = contentView_.frame .size .width + kLeftMargin + kRightMargin + kInset ;
536+ height = contentView_.frame .size .height + kBottomMargin + kTopMargin + kPointerLength + kInset ;
537+ break ;
504538
505539 case kPTYNoteViewTipEdgeLeft :
506540 case kPTYNoteViewTipEdgeRight :
507- return NSMakeSize (contentView_.frame .size .width + kLeftMargin + kRightMargin + kPointerLength + kInset ,
508- contentView_.frame .size .height + kBottomMargin + kTopMargin + kInset );
541+ width = contentView_.frame .size .width + kLeftMargin + kRightMargin + kPointerLength + kInset ;
542+ height = contentView_.frame .size .height + kBottomMargin + kTopMargin + kInset ;
543+ break ;
544+
545+ default :
546+ assert (false );
547+ return NSMakeSize (0 , 0 );
509548 }
510- assert (false );
511- return NSMakeSize (0 , 0 );
549+ return NSMakeSize (MAX (width, kMinWidth ), MAX (height, kMinHeight ));
512550}
513551
514552- (void )kill : (id )sender {
0 commit comments