From 6b5d0f9a448482f7c35c1d31825cb5b1875de7b6 Mon Sep 17 00:00:00 2001 From: atterpac Date: Sat, 23 Nov 2024 12:23:31 -0700 Subject: [PATCH] Support linux systrays first click to open - Convert event handling to switch statement for better readability - Fix menu event handlers to properly trigger open/close callbacks - Update click behavior to use doubleClickHandler for Activate CHANGELOG.md --- mkdocs-website/docs/en/changelog.md | 1 + v3/examples/systray/main.go | 11 +++++++++++ v3/internal/dbus/generate.sh | 0 v3/pkg/application/systemtray_linux.go | 20 ++++++++++++-------- 4 files changed, 24 insertions(+), 8 deletions(-) mode change 100644 => 100755 v3/internal/dbus/generate.sh diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 996ece43689..14ac2445009 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 in [#3888](https://github.com/wailsapp/wails/pull/3888) ### Changed +- Refactored systray click messaging to better align with user interactions by @atterpac in [#3907](https://github.com/wailsapp/wails/pull/3907) - Asset embed to include `all:frontend/dist` to support frameworks that generate subfolders by @atterpac in [#3887](https://github.com/wailsapp/wails/pull/3887) - Taskfile refactor by [leaanthony](https://github.com/leaanthony) in [#3748](https://github.com/wailsapp/wails/pull/3748) - Upgrade to `go-webview2` v1.0.16 by [leaanthony](https://github.com/leaanthony) diff --git a/v3/examples/systray/main.go b/v3/examples/systray/main.go index 94cf3de341b..d2b1165292a 100644 --- a/v3/examples/systray/main.go +++ b/v3/examples/systray/main.go @@ -92,6 +92,17 @@ func main() { }) systemTray.SetMenu(myMenu) + systemTray.OnClick(func() { + println("System tray clicked!") + }) + + systemTray.OnDoubleClick(func() { + println("System tray double clicked!") + }) + + systemTray.OnRightClick(func() { + println("System tray right clicked!") + }) //systemTray.AttachWindow(window).WindowOffset(5) diff --git a/v3/internal/dbus/generate.sh b/v3/internal/dbus/generate.sh old mode 100644 new mode 100755 diff --git a/v3/pkg/application/systemtray_linux.go b/v3/pkg/application/systemtray_linux.go index 57eb49f8ff0..ad6fa358d8c 100644 --- a/v3/pkg/application/systemtray_linux.go +++ b/v3/pkg/application/systemtray_linux.go @@ -421,7 +421,7 @@ func newSystemTrayImpl(s *SystemTray) systemTrayImpl { } func (s *linuxSystemTray) openMenu() { - // FIXME: Use DBUS to open? + // FIXME: Emit com.canonical to open? globalApplication.info("systray error: openMenu not implemented on Linux") } @@ -622,17 +622,19 @@ func (s *linuxSystemTray) GetProperty(id int32, name string) (value dbus.Variant // Event is com.canonical.dbusmenu.Event method. func (s *linuxSystemTray) Event(id int32, eventID string, data dbus.Variant, timestamp uint32) (err *dbus.Error) { - if eventID == "clicked" { + switch eventID { + case "clicked": if item, ok := s.itemMap[id]; ok { InvokeAsync(item.menuItem.handleClick) } - } - if eventID == "opened" { + case "opened": + if s.parent.clickHandler != nil { + s.parent.clickHandler() + } if s.parent.onMenuOpen != nil { s.parent.onMenuOpen() } - } - if eventID == "closed" { + case "closed": if s.parent.onMenuClose != nil { s.parent.onMenuClose() } @@ -698,14 +700,16 @@ func (s *linuxSystemTray) GetLayout(parentID int32, recursionDepth int32, proper // Activate implements org.kde.StatusNotifierItem.Activate method. func (s *linuxSystemTray) Activate(x int32, y int32) (err *dbus.Error) { - s.parent.clickHandler() + if s.parent.doubleClickHandler != nil { + s.parent.doubleClickHandler() + } return } // ContextMenu is org.kde.StatusNotifierItem.ContextMenu method func (s *linuxSystemTray) ContextMenu(x int32, y int32) (err *dbus.Error) { fmt.Println("ContextMenu", x, y) - return + return nil } func (s *linuxSystemTray) Scroll(delta int32, orientation string) (err *dbus.Error) {