Documentation
¶
Overview ¶
Package tray is an implementation of StatusNotifierItem.
Package tray provides a pure Go implementation of the StatusNotifierItem D-Bus interface. This can be used to create system tray icons and menus in most Linux desktop environments.
Index ¶
- Variables
- type ARGB32
- type ActivateHandler
- type Category
- type Handler
- type Item
- func (item *Item) AttentionIconName() string
- func (item *Item) AttentionIconPixmap() []image.Image
- func (item *Item) AttentionMovieName() string
- func (item *Item) Category() Category
- func (item *Item) Close() error
- func (item *Item) Handler() Handler
- func (item *Item) ID() string
- func (item *Item) IconAccessibleDesc() string
- func (item *Item) IconName() string
- func (item *Item) IconPixmap() []image.Image
- func (item *Item) IsMenu() bool
- func (item *Item) Menu() *Menu
- func (item *Item) OverlayIconName() string
- func (item *Item) OverlayIconPixmap() []image.Image
- func (item *Item) SetProps(props ...ItemProp) error
- func (item *Item) Status() Status
- func (item *Item) Title() string
- func (item *Item) ToolTip() (iconName string, iconPixmap []image.Image, title, description string)
- func (item *Item) WindowID() uint32
- type ItemProp
- func ItemAttentionIconName(name string) ItemProp
- func ItemAttentionIconPixmap(images ...image.Image) ItemProp
- func ItemAttentionMovieName(name string) ItemProp
- func ItemCategory(category Category) ItemProp
- func ItemHandler(handler Handler) ItemProp
- func ItemID(id string) ItemProp
- func ItemIconAccessibleDesc(desc string) ItemProp
- func ItemIconName(name string) ItemProp
- func ItemIconPixmap(images ...image.Image) ItemProp
- func ItemIsMenu(itemIsMenu bool) ItemProp
- func ItemMenuHandler(handler MenuEventHandler) ItemProp
- func ItemMenuIconThemePath(path []string) ItemProp
- func ItemMenuStatus(status MenuStatus) ItemProp
- func ItemMenuTextDirection(direction TextDirection) ItemProp
- func ItemOverlayIconName(name string) ItemProp
- func ItemOverlayIconPixmap(images ...image.Image) ItemProp
- func ItemStatus(status Status) ItemProp
- func ItemTitle(title string) ItemProp
- func ItemToolTip(iconName string, iconPixmap []image.Image, title, description string) ItemProp
- func ItemWindowID(id uint32) ItemProp
- type Menu
- type MenuEventHandler
- type MenuEventID
- type MenuItem
- func (item *MenuItem) AddChild(props ...MenuItemProp) (*MenuItem, error)
- func (item *MenuItem) AppendChild(child *MenuItem) error
- func (item *MenuItem) Enabled() bool
- func (item *MenuItem) IconData() (image.Image, error)
- func (item *MenuItem) IconName() string
- func (item *MenuItem) Label() string
- func (item *MenuItem) MoveBefore(sibling *MenuItem) error
- func (item *MenuItem) Remove() error
- func (item *MenuItem) RequestActivation(timestamp uint32) error
- func (item *MenuItem) SetProps(props ...MenuItemProp) error
- func (item *MenuItem) Shortcut() [][]string
- func (item *MenuItem) ToggleState() MenuToggleState
- func (item *MenuItem) ToggleType() MenuToggleType
- func (item *MenuItem) Type() MenuType
- func (item *MenuItem) VendorProp(vendor, prop string) (any, bool)
- func (item *MenuItem) Visible() bool
- type MenuItemProp
- func MenuItemEnabled(enabled bool) MenuItemProp
- func MenuItemHandler(handler MenuEventHandler) MenuItemProp
- func MenuItemIconData(img image.Image) MenuItemProp
- func MenuItemIconName(name string) MenuItemProp
- func MenuItemLabel(label string) MenuItemProp
- func MenuItemShortcut(shortcut [][]string) MenuItemProp
- func MenuItemToggleState(state MenuToggleState) MenuItemProp
- func MenuItemToggleType(t MenuToggleType) MenuItemProp
- func MenuItemType(t MenuType) MenuItemProp
- func MenuItemVendorProp(vendor, prop string, value any) MenuItemProp
- func MenuItemVisible(visible bool) MenuItemProp
- type MenuStatus
- type MenuToggleState
- type MenuToggleType
- type MenuType
- type Orientation
- type Pixmap
- type Status
- type TextDirection
Constants ¶
This section is empty.
Variables ¶
var ARGB32Model color.Model = color.ModelFunc(argb32Model)
ARGB32Model is the color.Model implementation used by Pixmap.
Functions ¶
This section is empty.
Types ¶
type ARGB32 ¶ added in v0.1.7
type ARGB32 uint32
ARGB32 is the color.Color implementation used by Pixmap.
type ActivateHandler ¶
ActiveHandler is a convenience type for the common case of only needing to implement the Activate method of Handler. It calls itself when Activate is called and does nothing for all other methods.
func (ActivateHandler) Activate ¶
func (h ActivateHandler) Activate(x, y int) error
func (ActivateHandler) ContextMenu ¶
func (h ActivateHandler) ContextMenu(x, y int) error
func (ActivateHandler) Scroll ¶
func (h ActivateHandler) Scroll(delta int, orientation Orientation) error
func (ActivateHandler) SecondaryActivate ¶
func (h ActivateHandler) SecondaryActivate(x, y int) error
type Handler ¶
type Handler interface {
ContextMenu(x, y int) error
Activate(x, y int) error
SecondaryActivate(x, y int) error
Scroll(delta int, orientation Orientation) error
}
Handler specifies behavior for incoming events for a StatusNotifierItem. In most cases, Activate is the only method of interest, as that's the one that's called when an icon is clicked or double-clicked. For that common case, see ActivateHandler.
Errors returned by the methods of a Handler are sent over D-Bus as a response to the call that resulted in the Handler being invoked in the first place. In a lot of cases, this won't do much besides possibly showing up in a log somewhere, so it's probably best in those cases to handle it locally some other way, if appropriate, and then just return nil regardless.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item is a single StatusNotifierItem. Each item roughly corresponds to a single icon in the system tray.
func New ¶
New creates a new Item configured with the given props. It is recommended to at least set the ID and Icon properties, though these can be set later if preferred. The icon's behavior without them set will likely not be useful, however, if it isn't completely broken depending on the desktop environment.
func (*Item) AttentionIconName ¶
AttentionIconName returns the current value of the AttentionIconName property.
func (*Item) AttentionIconPixmap ¶
AttentionIconPixmap returns the current value of the AttentionIconPixmap property.
func (*Item) AttentionMovieName ¶
AttentionMovieName returns the current value of the AttentionMovieName property.
func (*Item) Close ¶
Close closes the underlying D-Bus connection, removing the item from the tray. The behavior of any calls to any methods either on this Item or on any associated Menu or MenuItem instances after calling this is undefined.
func (*Item) Handler ¶
Handler returns the Handler that is used to handle events triggered by the desktop environment.
func (*Item) IconAccessibleDesc ¶
IconAccessibleDesc returns the current value of the IconAccessibleDesc property.
func (*Item) IconPixmap ¶
IconPixmap returns the current value of the IconPixmap property.
func (*Item) OverlayIconName ¶
OverlayIconName returns the current value of the OverlayIconName property.
func (*Item) OverlayIconPixmap ¶
OverlayIconPixmap returns the current value of the OverlayIconPixmap property.
func (*Item) SetProps ¶
SetProps sets the given properties for the item, emits any necessary signals after setting all of them, and then returns any errors that happened. A non-nil error return does not necessarily indicate complete failure.
type ItemProp ¶
type ItemProp func(*itemProps)
ItemProp is a function that modifies the properties of an Item.
func ItemAttentionIconName ¶
ItemAttentionIconName sets the AttentionIconName property to the given value.
func ItemAttentionIconPixmap ¶
ItemAttentionIconPixmap sets the AttentionIconPixmap property to the given value.
func ItemAttentionMovieName ¶
ItemAttentionMovieName sets the AttentionMovieName property to the given value.
func ItemCategory ¶
ItemCategory sets the Category property to the given value.
func ItemIconAccessibleDesc ¶
ItemIconAccessibleDesc sets the IconAccessibleDesc property to the given value.
func ItemIconName ¶
ItemIconName sets the IconName property to the given value.
func ItemIconPixmap ¶
ItemIconPixmap sets the IconPixmap property to the given value.
func ItemIsMenu ¶
ItemIsMenu sets the ItemIsMenu property to the given value.
func ItemMenuHandler ¶
func ItemMenuHandler(handler MenuEventHandler) ItemProp
ItemMenuHandler sets the MenuEventHandler that is called when the menu receives incoming events. Generally speaking, clients will probably want to set handlers on MenuItem, not on the Menu itself.
func ItemMenuIconThemePath ¶
ItemMenuIconThemePath sets the item's associated menu's IconThemePath property.
func ItemMenuStatus ¶
func ItemMenuStatus(status MenuStatus) ItemProp
ItemMenuStatus sets the item's associated menu's Status property.
func ItemMenuTextDirection ¶
func ItemMenuTextDirection(direction TextDirection) ItemProp
ItemMenuTextDirection sets the item's associated menu's TextDirection property.
func ItemOverlayIconName ¶
ItemOverlayIconName sets the OverlayIconName property to the given value.
func ItemOverlayIconPixmap ¶
ItemOverlayIconPixmap sets the OverlayIconPixmap property to the given value.
func ItemStatus ¶
ItemStatus sets the Status property to the given value.
func ItemToolTip ¶
ItemToolTip sets the ToolTip property to the given values.
func ItemWindowID ¶
ItemWindowID sets the WindowId property to the given value.
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
Menu is the menu for a StatusNotifierItem as specififed by the dbusmenu interface. An instance of it is available via Item.Menu.
func (*Menu) AddChild ¶
func (menu *Menu) AddChild(props ...MenuItemProp) (*MenuItem, error)
AddChild creates a new MenuItem with the given properties and appends it as the last child of the root of the menu hierarchy.
func (*Menu) AppendChild ¶
AppendChild makes child the last child of the root of the menu hiearchy, moving it from wherever it currently is. The same rules about sub-menu conversion apply as they do in both [AddChild] and [Remove].
func (*Menu) IconThemePath ¶
IconThemePath returns the current value of the menu's IconThemePath property.
func (*Menu) Status ¶
func (menu *Menu) Status() MenuStatus
Status returns the current value of the menu's Status property.
func (*Menu) TextDirection ¶
func (menu *Menu) TextDirection() TextDirection
TextDirection returns the current value of the menu's TextDirection property.
type MenuEventHandler ¶
type MenuEventHandler func(eventID MenuEventID, data any, timestamp uint32) error
MenuEventHandler is a function that is called in response to events on both the Menu and on MenuItem. It is given a MenuEventID that identifies the type of event, such as Clicked, arbitrary data that is associated with the event, and a timestamp. The timestamp corresponds to an internal time value of the sender and is not a specific absolute point in time.
The error returned by the handler is sent as a response to the D-Bus call that triggered it, so in a lot of cases it is more useful to handle an error locally in some way and then return nil from the handler regardless.
For the simple common case of handling specifically Clicked events, see ClickedHandler.
func ClickedHandler ¶
func ClickedHandler(handler func(data any, timestamp uint32) error) MenuEventHandler
ClickedHandler is a convenience function that returns a MenuEventHandler that calls handler if and only if the event ID is Clicked.
type MenuEventID ¶
type MenuEventID string
MenuEventID is an identifier for the type of event that is being sent to a menu's event handler. The values defined in this package are not the only possible values. In particular, the spec defines a format for vendor-specific custom values. These can be parsed with the [ParseVendor] method.
const ( Clicked MenuEventID = "clicked" Hovered MenuEventID = "hovered" Opened MenuEventID = "opened" Closed MenuEventID = "closed" )
func (MenuEventID) ParseVendor ¶
func (id MenuEventID) ParseVendor() (vendor, event string, ok bool)
ParseVendor parses a vendor-specific custom event ID. If id contains such a value, it returns the vendor and event names as parsed from it. If it does not contain such a value, the returned bool will be false.
type MenuItem ¶
type MenuItem struct {
// contains filtered or unexported fields
}
MenuItem is a single item in the menu of the tray item. The item can be a regular single item or can be a sub-menu containing more items, recursively.
MenuItems are created by calling the AddChild method on either the Menu or on another MenuItem.
func (*MenuItem) AddChild ¶
func (item *MenuItem) AddChild(props ...MenuItemProp) (*MenuItem, error)
AddChild creates a new MenuItem with the given properties and append it as the last child of the MenuItem that it is called on. If the receiver MenuItem has no children before this, it will automatically be converted into a sub-menu MenuItem.
func (*MenuItem) AppendChild ¶
AppendChild makes child the last child of item, moving it from wherever it currently is. The same rules about sub-menu conversion apply as they do in both [AddChild] and [Remove].
func (*MenuItem) IconData ¶
IconData returns the current value of the item's "icon-data" property. This is one of two properties that determine what icon should be displayed in the menu by the environment, the other being "icon-name".
func (*MenuItem) IconName ¶
IconName returns the current value of the item's "icon-name" property. This is one of two properties that determine what icon should be displayed in the menu by the environment, the other being "icon-data".
func (*MenuItem) Label ¶
Label returns the current value of the item's "label" property. This is the text that should be displayed by the environment for the item in the menu.
func (*MenuItem) MoveBefore ¶
MoveBefore makes item the previous sibling of sibling. If necessary, this method will transfer item from its current parent to sibling's parent.
func (*MenuItem) Remove ¶
Remove removes item from the menu hierarchy completely. If its parent is another MenuItem and item is its only child, the parent is converted from a sub-menu item back into a regular one.
func (*MenuItem) RequestActivation ¶
RequestActivation sends a request to the environment that item be activated. What exactly this means is dependent on the environment and situation.
func (*MenuItem) SetProps ¶
func (item *MenuItem) SetProps(props ...MenuItemProp) error
SetProps sets all of the given properties on the item.
func (*MenuItem) Shortcut ¶
Shortcut returns the current value of the item's "shortcut" property. This is used by the environment to determine keyboard shortcuts and is of the form
[][]string{
[]string{"Control", "Alt", "e"},
}
func (*MenuItem) ToggleState ¶
func (item *MenuItem) ToggleState() MenuToggleState
ToggleState returns the current value of the item's "toggle-state" property.
func (*MenuItem) ToggleType ¶
func (item *MenuItem) ToggleType() MenuToggleType
ToggleType returns the current value of the item's "toggle-type" property.
func (*MenuItem) VendorProp ¶
VendorProp returns the current value of the vendor-specific custom property with the given vendor and property name. It returns false as its second return if no such property exists.
type MenuItemProp ¶
type MenuItemProp func(*menuItemProps)
func MenuItemEnabled ¶
func MenuItemEnabled(enabled bool) MenuItemProp
MenuItemEnabled sets a MenuItem's "enabled" property. See MenuItem.Enabled.
func MenuItemHandler ¶
func MenuItemHandler(handler MenuEventHandler) MenuItemProp
MenuItemHandler sets the event handler for a MenuItem.
func MenuItemIconData ¶
func MenuItemIconData(img image.Image) MenuItemProp
MenuItemIconData sets a MenuItem's "icon-data" property. See MenuItem.IconData.
func MenuItemIconName ¶
func MenuItemIconName(name string) MenuItemProp
MenuItemIconName sets a MenuItem's "icon-name" property. See MenuItem.IconName.
func MenuItemLabel ¶
func MenuItemLabel(label string) MenuItemProp
MenuItemLabel sets a MenuItem's "label" property. See MenuItem.Label.
func MenuItemShortcut ¶
func MenuItemShortcut(shortcut [][]string) MenuItemProp
MenuItemShortcut sets a MenuItem's "shortcut" property. See MenuItem.Shortcut.
func MenuItemToggleState ¶
func MenuItemToggleState(state MenuToggleState) MenuItemProp
MenuItemToggleState sets a MenuItem's "toggle-state" property. See MenuItem.ToggleState.
func MenuItemToggleType ¶
func MenuItemToggleType(t MenuToggleType) MenuItemProp
MenuItemToggleType sets a MenuItem's "toggle-type" property. See MenuItem.ToggleType.
func MenuItemType ¶
func MenuItemType(t MenuType) MenuItemProp
MenuItemType sets a MenuItem's "type" property. See MenuItem.Type.
func MenuItemVendorProp ¶
func MenuItemVendorProp(vendor, prop string, value any) MenuItemProp
MenuItemVendorProp sets a vendor-specific custom property with the given vendor and property name. See MenuItem.VendorProp.
func MenuItemVisible ¶
func MenuItemVisible(visible bool) MenuItemProp
MenuItemVisible sets a MenuItem's "visible" property. See MenuItem.Visible.
type MenuStatus ¶
type MenuStatus string
MenuStatus is the possible statuses of a menu.
const ( Normal MenuStatus = "normal" Notice MenuStatus = "notice" )
type MenuToggleState ¶
type MenuToggleState int
MenuToggleState is the two main states that a togglable menu item can be in. All values other than On and Off are considered to be indeterminate.
const ( Off MenuToggleState = 0 On MenuToggleState = 1 )
func (MenuToggleState) Indeterminate ¶
func (state MenuToggleState) Indeterminate() bool
Indeterminate returns true if state represents an indeterminate state other than On and Off.
type MenuToggleType ¶
type MenuToggleType string
MenuToggleType is the types of togglability that a menu item can have.
const ( NonToggleable MenuToggleType = "" Checkmark MenuToggleType = "checkmark" Radio MenuToggleType = "radio" )
type Orientation ¶
type Orientation string
Orientation is the possible directions of a scroll event.
const ( Horizontal Orientation = "horizontal" Vertical Orientation = "vertical" )
type Pixmap ¶ added in v0.1.7
Pixmap is the raw wire format of StatusNotifierItem icon data. The Data field is in a big endian ARGB32 format. For convenience, Pixmap implements draw.Image to simplify conversion to and from other formats.
func ToPixmap ¶ added in v0.1.7
ToPixmap converts an image.Image into a Pixmap. If an icon is being set to the same image more than once, it is more efficient to convert it to a Pixmap in advance using this function and then pass the result intead of the original image.Image.
func (Pixmap) ColorModel ¶ added in v0.1.7
type TextDirection ¶
type TextDirection string
TextDirection represents the possible configurations a menu's text direction.
const ( LeftToRight TextDirection = "ltr" RightToLeft TextDirection = "rtl" )