Skip to content

Commit

Permalink
[V3-Linux] Systray OnClick on initial icon click (#3907)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
atterpac authored Nov 23, 2024
1 parent abcc37f commit d27e75c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions v3/examples/systray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Empty file modified v3/internal/dbus/generate.sh
100644 → 100755
Empty file.
20 changes: 12 additions & 8 deletions v3/pkg/application/systemtray_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d27e75c

Please sign in to comment.