From 05fbfdaf6273962966105524c0b7c5ce97fa89d6 Mon Sep 17 00:00:00 2001 From: Adrian Campos Date: Wed, 24 Jun 2020 15:50:55 -0700 Subject: [PATCH] Add support for popup menu open/close event in Windows --- systray.go | 6 ++++++ systray_windows.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/systray.go b/systray.go index 729b521a..d6a1cea1 100644 --- a/systray.go +++ b/systray.go @@ -15,6 +15,12 @@ import ( var ( log = golog.LoggerFor("systray") + // MenuOpenedCh is the channel which will be notified when the popup menu is shown + MenuOpenedCh = make(chan struct{}) + + // MenuClosedCh is the channel which will be notified when the popup menu is closed + MenuClosedCh = make(chan struct{}) + systrayReady func() systrayExit func() menuItems = make(map[int32]*MenuItem) diff --git a/systray_windows.go b/systray_windows.go index 02b5e6d9..faf0e188 100644 --- a/systray_windows.go +++ b/systray_windows.go @@ -599,6 +599,11 @@ func (t *winTray) hideMenuItem(menuItemId, parentId uint32) error { } func (t *winTray) showMenu() error { + select { + case MenuOpenedCh <- struct{}{}: + default: + } + const ( TPM_BOTTOMALIGN = 0x0020 TPM_LEFTALIGN = 0x0000 @@ -623,6 +628,11 @@ func (t *winTray) showMenu() error { return err } + select { + case MenuClosedCh <- struct{}{}: + default: + } + return nil }