From 74a4ccbb396c831e0fdecc7325136336e75fb1c9 Mon Sep 17 00:00:00 2001 From: Joshua Searles Date: Sun, 16 Sep 2018 18:57:58 -0400 Subject: [PATCH] Add support for click event in Windows --- systray.go | 10 ++++++++++ systray_nonwindows.go | 3 +++ systray_windows.go | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/systray.go b/systray.go index d4331732..41f3076f 100644 --- a/systray.go +++ b/systray.go @@ -16,6 +16,8 @@ import ( ) var ( + // ClickedCh is the channel which will be notified when the systray icon is clicked + ClickedCh = make(chan struct{}) hasStarted = int64(0) hasQuit = int64(0) ) @@ -179,3 +181,11 @@ func systrayMenuItemSelected(id int32) { default: } } + +func systrayClicked() { + select { + case ClickedCh <- struct{}{}: + default: + showMenu() + } +} diff --git a/systray_nonwindows.go b/systray_nonwindows.go index 0ed03b47..e629e690 100644 --- a/systray_nonwindows.go +++ b/systray_nonwindows.go @@ -19,6 +19,9 @@ func nativeLoop() { C.nativeLoop() } +func showMenu() { +} + func quit() { C.quit() } diff --git a/systray_windows.go b/systray_windows.go index 68e20cf6..d25e9246 100644 --- a/systray_windows.go +++ b/systray_windows.go @@ -254,8 +254,10 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui systrayExit() case t.wmSystrayMessage: switch lParam { - case WM_RBUTTONUP, WM_LBUTTONUP: + case WM_RBUTTONUP: t.showMenu() + case WM_LBUTTONUP: + systrayClicked() } case t.wmTaskbarCreated: // on explorer.exe restarts t.nid.add() @@ -610,6 +612,10 @@ func nativeLoop() { } } +func showMenu() { + wt.showMenu() +} + func quit() { const WM_CLOSE = 0x0010