From ce8aa073eedc61b14bc10222ba3942f505379c61 Mon Sep 17 00:00:00 2001 From: Seppe Stas Date: Tue, 2 Jun 2015 21:43:37 +0200 Subject: [PATCH 1/5] Added `bounds` payload to tray `clicked` event Used [Shell_NotifyIconGetRect function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378426) to get the bounds of the application's tray icon. Note: only works with Windows 7 and later. Related to #1159, #1500. --- atom/browser/ui/win/notify_icon.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 99b7153631af..bce258901861 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -49,7 +49,18 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos, bool left_mouse_click) { // Pass to the observer if appropriate. if (left_mouse_click) { - NotifyClicked(); + NOTIFYICONIDENTIFIER icon_id; + memset(&icon_id, 0, sizeof(NOTIFYICONIDENTIFIER)); + icon_id.uID = icon_id_; + icon_id.hWnd = window_; + icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER); + + RECT rect; + Shell_NotifyIconGetRect(&icon_id, &rect); + + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; + NotifyClicked(gfx::Rect(rect.left, rect.top, width, height)); return; } From e920ce3e243790c0548f0602098872734e17ae66 Mon Sep 17 00:00:00 2001 From: Seppe Stas Date: Tue, 2 Jun 2015 23:19:49 +0200 Subject: [PATCH 2/5] Updated tray api docs to reflect changes in ce8aa07 --- docs/api/tray.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/tray.md b/docs/api/tray.md index ae2a471856e9..d85ac1a1dac8 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -55,7 +55,7 @@ Creates a new tray icon associated with the `image`. Emitted when the tray icon is clicked. -__Note:__ The `bounds` payload is only implemented on OS X. +__Note:__ The `bounds` payload is only implemented on OS X and Windows 7 or newer. ### Event: 'double-clicked' From e5c4e34ac4c6527c5f3a85283d564837dc4542f5 Mon Sep 17 00:00:00 2001 From: Seppe Stas Date: Wed, 3 Jun 2015 07:54:38 +0200 Subject: [PATCH 3/5] Ow :poop:, where did that extra space come from? --- atom/browser/ui/win/notify_icon.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index bce258901861..d319539823cc 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -59,7 +59,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos, Shell_NotifyIconGetRect(&icon_id, &rect); int width = rect.right - rect.left; - int height = rect.bottom - rect.top; + int height = rect.bottom - rect.top; NotifyClicked(gfx::Rect(rect.left, rect.top, width, height)); return; } From 16c08e7e374718be487f566d557c2bdb1ba356ea Mon Sep 17 00:00:00 2001 From: Seppe Stas Date: Mon, 8 Jun 2015 19:04:56 +0200 Subject: [PATCH 4/5] Switched to `gfx::Rect` constructor that takes a RECT As per @zcbenz's suggestion the rect passed to the click event handler now passes a rect constructed using `gfx::Rect(const RECT& r)`. --- atom/browser/ui/win/notify_icon.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index d319539823cc..473a2bcac8d4 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -58,9 +58,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos, RECT rect; Shell_NotifyIconGetRect(&icon_id, &rect); - int width = rect.right - rect.left; - int height = rect.bottom - rect.top; - NotifyClicked(gfx::Rect(rect.left, rect.top, width, height)); + NotifyClicked(gfx::Rect(rect)); return; } From cac97cca0da04513edd33614af910b803b1a39cb Mon Sep 17 00:00:00 2001 From: Seppe Stas Date: Mon, 8 Jun 2015 19:07:46 +0200 Subject: [PATCH 5/5] Initialized rect with zeros As per @zcbenz 's remark: The rect should be initialized with zeros to prevent random values being passed to the click event handler when `Shell_NotifyIconGetRect` fails. --- atom/browser/ui/win/notify_icon.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 473a2bcac8d4..955a047fe1f5 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -55,7 +55,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos, icon_id.hWnd = window_; icon_id.cbSize = sizeof(NOTIFYICONIDENTIFIER); - RECT rect; + RECT rect = { 0 }; Shell_NotifyIconGetRect(&icon_id, &rect); NotifyClicked(gfx::Rect(rect));