Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3-Linux] Systray OnClick on initial icon click #3907

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading