From 208374afa4ede558693a87aaf7032eb31d757768 Mon Sep 17 00:00:00 2001 From: mikeykhalil Date: Sat, 28 Apr 2018 20:07:32 -0700 Subject: [PATCH] clean up ignore double click event implementation --- atom/browser/api/atom_api_tray.cc | 2 ++ atom/browser/ui/tray_icon_cocoa.mm | 16 ++++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index 20ed32e35050..80a4d20c915c 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -177,7 +177,9 @@ void Tray::SetHighlightMode(TrayIcon::HighlightMode mode) { } void Tray::SetIgnoreDoubleClickEvents(bool ignore) { +#if defined(OS_MACOSX) tray_icon_->SetIgnoreDoubleClickEvents(ignore); +#endif } void Tray::DisplayBalloon(mate::Arguments* args, diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index c47121200f0e..166a6fe82ca9 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -287,24 +287,16 @@ const CGFloat kVerticalTitleMargin = 2; // If we are ignoring double click events, we should ignore the `clickCount` // value and immediately emit a click event. - if (ignoreDoubleClickEvents_ == YES) { - trayIcon_->NotifyClicked( - gfx::ScreenRectFromNSRect(event.window.frame), - gfx::ScreenPointFromNSPoint([event locationInWindow]), - ui::EventFlagsFromModifiers([event modifierFlags])); - [self setNeedsDisplay:YES]; - return; - } - - // Single click event. - if (event.clickCount == 1) + BOOL shouldBeHandledAsASingleClick = (event.clickCount == 1) || ignoreDoubleClickEvents_; + if (shouldBeHandledAsASingleClick) trayIcon_->NotifyClicked( gfx::ScreenRectFromNSRect(event.window.frame), gfx::ScreenPointFromNSPoint([event locationInWindow]), ui::EventFlagsFromModifiers([event modifierFlags])); // Double click event. - if (event.clickCount == 2) + BOOL shouldBeHandledAsADoubleClick = (event.clickCount == 2) && !ignoreDoubleClickEvents_; + if (shouldBeHandledAsADoubleClick) trayIcon_->NotifyDoubleClicked( gfx::ScreenRectFromNSRect(event.window.frame), ui::EventFlagsFromModifiers([event modifierFlags]));