From e7e5597c9514fcf0c1a9b3e6f6fe0b5dd86d9056 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 10 Jul 2023 20:44:30 +1000 Subject: [PATCH] [v3 mac] Fix right click. Slight refactor. --- v3/examples/systray/main.go | 2 -- v3/pkg/application/systemtray_darwin.go | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/v3/examples/systray/main.go b/v3/examples/systray/main.go index b35a0b6c..2bc02217 100644 --- a/v3/examples/systray/main.go +++ b/v3/examples/systray/main.go @@ -68,11 +68,9 @@ func main() { }) systemTray.SetMenu(myMenu) - systemTray.AttachWindow(window).WindowOffset(5) err := app.Run() - if err != nil { log.Fatal(err) } diff --git a/v3/pkg/application/systemtray_darwin.go b/v3/pkg/application/systemtray_darwin.go index 2d3efecb..67df1fe7 100644 --- a/v3/pkg/application/systemtray_darwin.go +++ b/v3/pkg/application/systemtray_darwin.go @@ -33,7 +33,7 @@ type button int const ( leftButtonDown button = 1 - rightButtonDown button = 2 + rightButtonDown button = 3 ) // system tray map @@ -197,19 +197,28 @@ func (s *macosSystemTray) processClick(b button) { s.parent.clickHandler() return } + if s.parent.attachedWindow.Window != nil { + s.parent.defaultClickHandler() + return + } + if s.menu != nil { + C.showMenu(s.nsStatusItem, s.nsMenu) + } case rightButtonDown: // Check if we have a callback if s.parent.rightClickHandler != nil { s.parent.rightClickHandler() return } - } - // Open the default menu if we have one - if s.menu != nil { + if s.menu != nil { + if s.parent.attachedWindow.Window != nil { + s.parent.attachedWindow.Window.Hide() + } + C.showMenu(s.nsStatusItem, s.nsMenu) + return + } if s.parent.attachedWindow.Window != nil { - // If we have an attached window, then we need to hide it - s.parent.attachedWindow.Window.Hide() + s.parent.defaultClickHandler() } - C.showMenu(s.nsStatusItem, s.nsMenu) } }