Implement 'right-clicked' tray event on OS X.
This commit is contained in:
parent
e54fda6b34
commit
cca4f4abd5
6 changed files with 24 additions and 6 deletions
|
@ -60,6 +60,10 @@ void Tray::OnBalloonClosed() {
|
||||||
Emit("balloon-closed");
|
Emit("balloon-closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tray::OnRightClicked(const gfx::Rect& bounds) {
|
||||||
|
Emit("right-clicked", bounds);
|
||||||
|
}
|
||||||
|
|
||||||
bool Tray::IsDestroyed() const {
|
bool Tray::IsDestroyed() const {
|
||||||
return !tray_icon_;
|
return !tray_icon_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ class Tray : public mate::EventEmitter,
|
||||||
void OnBalloonShow() override;
|
void OnBalloonShow() override;
|
||||||
void OnBalloonClicked() override;
|
void OnBalloonClicked() override;
|
||||||
void OnBalloonClosed() override;
|
void OnBalloonClosed() override;
|
||||||
|
void OnRightClicked(const gfx::Rect&) override;
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
bool IsDestroyed() const override;
|
bool IsDestroyed() const override;
|
||||||
|
|
|
@ -46,4 +46,8 @@ void TrayIcon::NotifyBalloonClosed() {
|
||||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonClosed());
|
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds) {
|
||||||
|
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnRightClicked(bounds));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -56,6 +56,7 @@ class TrayIcon {
|
||||||
void NotifyBalloonShow();
|
void NotifyBalloonShow();
|
||||||
void NotifyBalloonClicked();
|
void NotifyBalloonClicked();
|
||||||
void NotifyBalloonClosed();
|
void NotifyBalloonClosed();
|
||||||
|
void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TrayIcon();
|
TrayIcon();
|
||||||
|
|
|
@ -75,7 +75,7 @@ const CGFloat kMargin = 3;
|
||||||
title_width + kStatusItemLength,
|
title_width + kStatusItemLength,
|
||||||
[[statusItem_ statusBar] thickness]);
|
[[statusItem_ statusBar] thickness]);
|
||||||
[title_ drawInRect:title_rect
|
[title_ drawInRect:title_rect
|
||||||
withAttributes:[self titleAttributes]];
|
withAttributes:[self titleAttributes]];
|
||||||
[statusItem_ setLength:title_width + kStatusItemLength];
|
[statusItem_ setLength:title_width + kStatusItemLength];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,11 +129,7 @@ const CGFloat kMargin = 3;
|
||||||
[statusItem_ popUpStatusItemMenu:[menu_controller_ menu]];
|
[statusItem_ popUpStatusItemMenu:[menu_controller_ menu]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSRect frame = event.window.frame;
|
trayIcon_->NotifyClicked([self getBoundsFromEvent:event]);
|
||||||
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
|
||||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
|
||||||
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
|
||||||
trayIcon_->NotifyClicked(bounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.clickCount == 2 && !menu_controller_) {
|
if (event.clickCount == 2 && !menu_controller_) {
|
||||||
|
@ -142,11 +138,22 @@ const CGFloat kMargin = 3;
|
||||||
[self setNeedsDisplay:YES];
|
[self setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)rightMouseUp:(NSEvent*)event {
|
||||||
|
trayIcon_->NotifyRightClicked([self getBoundsFromEvent:event]);
|
||||||
|
}
|
||||||
|
|
||||||
-(BOOL) shouldHighlight {
|
-(BOOL) shouldHighlight {
|
||||||
BOOL is_menu_open = [menu_controller_ isMenuOpen];
|
BOOL is_menu_open = [menu_controller_ isMenuOpen];
|
||||||
return isHighlightEnable_ && (inMouseEventSequence_ || is_menu_open);
|
return isHighlightEnable_ && (inMouseEventSequence_ || is_menu_open);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(gfx::Rect) getBoundsFromEvent:(NSEvent*)event {
|
||||||
|
NSRect frame = event.window.frame;
|
||||||
|
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
||||||
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||||
|
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
|
@ -18,6 +18,7 @@ class TrayIconObserver {
|
||||||
virtual void OnBalloonShow() {}
|
virtual void OnBalloonShow() {}
|
||||||
virtual void OnBalloonClicked() {}
|
virtual void OnBalloonClicked() {}
|
||||||
virtual void OnBalloonClosed() {}
|
virtual void OnBalloonClosed() {}
|
||||||
|
virtual void OnRightClicked(const gfx::Rect&) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~TrayIconObserver() {}
|
virtual ~TrayIconObserver() {}
|
||||||
|
|
Loading…
Reference in a new issue