tray

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tray shows an icon in the system tray (macOS menu bar extras, Windows notification area, Linux AppIndicator / StatusNotifierItem).

t, err := tray.New(a, tray.Options{Icon: png, Template: true, Tooltip: "My App"})

The menu bar on macOS wants a monochrome template image while Windows and Linux show a coloured icon; give both and each platform picks its own:

tray.Options{Icon: colourPNG, MacIcon: templatePNG, Template: true}
m := menu.New()
m.Add("Open", show)
m.Separator()
m.Role(menu.Quit)
t.SetMenu(m)
t.OnClick(show)

With a menu set, by default a primary click opens it on macOS and Linux and a right click opens it on Windows; OnClick then fires only where the platform separates the two (Windows left click). Options.MenuOn changes that: MenuOnSecondary opens the menu on a right click and reports left clicks with OnClick (macOS, Windows); MenuOnPrimary opens it on a left click everywhere. Without a menu, every click reaches the handlers. On Linux the icon is a StatusNotifierItem (KDE, GNOME with the AppIndicator extension, most other panels): clicks and MenuOn work as above, and Bounds is the point of the last primary click (1x1). Where no StatusNotifierWatcher runs (or TANGO_LINUX_TRAY=appindicator) it falls back to libayatana-appindicator, which reports neither clicks nor bounds and opens the menu on any click; set a menu there.

All methods are safe from any goroutine; handlers run on the main thread. Changing the tray menu's items takes effect with Menu.Update.

Index

Constants

View Source
const (
	MenuOnDefault   = platform.TrayMenuDefault   // left click on macOS and Linux, right click on Windows
	MenuOnPrimary   = platform.TrayMenuPrimary   // left click; OnClick does not fire while a menu is set
	MenuOnSecondary = platform.TrayMenuSecondary // right click; left clicks reach OnClick
)

Variables

View Source
var ErrUnsupported = platform.ErrUnsupported

ErrUnsupported is platform.ErrUnsupported.

Functions

This section is empty.

Types

type MenuTrigger = platform.TrayMenuTrigger

MenuTrigger chooses which click opens the tray menu.

type Options

type Options struct {
	Icon []byte // PNG; 32x32 or 44x44 px (for 2x displays) works well
	// MacIcon, if set, is shown on macOS instead of Icon: typically a black
	// on transparent PNG (36x36 or 44x44 px) used with Template.
	MacIcon  []byte
	Template bool // macOS: the image is a monochrome template that follows the menu bar's appearance
	Tooltip  string
	Title    string      // macOS: text shown next to the icon
	MenuOn   MenuTrigger // which click opens the menu; see the package comment
}

Options configures a tray icon.

type Rect

type Rect = platform.Rect

Rect is a screen rectangle in logical px, origin top-left of the primary display.

type Tray

type Tray struct {
	// contains filtered or unexported fields
}

Tray is one tray icon. Create it with New.

func New

func New(a *tango.App, o Options) (*Tray, error)

New adds a tray icon. It returns ErrUnsupported where the platform has no tray (or, on Linux, neither a StatusNotifierWatcher nor an AppIndicator library is available).

func (*Tray) Bounds

func (t *Tray) Bounds() (Rect, bool)

Bounds returns the icon's rectangle on screen, if the platform knows it (useful to place a popover window under it; see sys/flyout). On Linux it is the 1x1 point of the last click on the icon.

func (*Tray) OnClick

func (t *Tray) OnClick(fn func())

OnClick adds fn for a primary click (see the package comment for when platforms report it).

func (*Tray) OnDoubleClick

func (t *Tray) OnDoubleClick(fn func())

OnDoubleClick adds fn for a double click (Windows; macOS reports it after the two single clicks).

func (*Tray) OnRightClick

func (t *Tray) OnRightClick(fn func())

OnRightClick adds fn for a secondary click.

func (*Tray) Remove

func (t *Tray) Remove()

Remove takes the icon away. The Tray is unusable afterwards.

func (*Tray) SetIcon

func (t *Tray) SetIcon(png []byte, template bool)

SetIcon replaces the icon (PNG); template as in Options.Template.

func (*Tray) SetMacIcon

func (t *Tray) SetMacIcon(png []byte)

SetMacIcon replaces the macOS image (Options.MacIcon); nil falls back to Icon.

func (*Tray) SetMenu

func (t *Tray) SetMenu(m *menu.Menu) error

SetMenu attaches m to the icon (nil removes the menu). Later changes to m are shown after m.Update().

func (*Tray) SetMenuOn

func (t *Tray) SetMenuOn(m MenuTrigger)

SetMenuOn chooses which click opens the menu (Options.MenuOn).

func (*Tray) SetTitle

func (t *Tray) SetTitle(text string)

SetTitle sets the text next to the icon (macOS).

func (*Tray) SetTooltip

func (t *Tray) SetTooltip(text string)

SetTooltip sets the hover text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL