Documentation
¶
Overview ¶
Package linux is the Linux platform adapter, for Wayland compositors. It is pure Go: it speaks the Wayland protocol itself (see package wl), loads libxkbcommon at run time for keyboard layouts, and presents frames that the CPU renderer (render/soft) draws into shared memory.
One goroutine, locked to its thread, runs the event loop for every window of the process, as on Windows.
Index ¶
- Constants
- Variables
- func Clock() int64
- func CloseNotification(id uint32) error
- func OnUIThread() bool
- func Open(opts platform.WindowOptions, h platform.Handler) (platform.Window, error)
- func Post(fn func())
- func Quit()
- func ReadSettings() platform.Settings
- func Run(start func() error) error
- func SetAppID(id string)
- func SetNotificationHandlers(onAction func(id uint32, action string), onClosed func(id uint32))
- func ShowNotification(n Notification) (uint32, error)
- type MenuItem
- type Notification
- type TrayIcon
- type TrayOptions
Constants ¶
const DefaultAction = defaultAction
DefaultAction is the action key that a click on a notification's body reports.
Variables ¶
var ErrNoTrayHost = errors.New("the desktop shows no tray icons (no StatusNotifierWatcher on the session bus; GNOME needs the AppIndicator extension)")
ErrNoTrayHost is returned by Show when the desktop shows no tray icons: no StatusNotifierWatcher runs on the session bus. GNOME has one only with the AppIndicator extension.
Functions ¶
func Clock ¶
func Clock() int64
Clock returns the monotonic clock in nanoseconds, the clock of Event.Arrived and of frame statistics.
func CloseNotification ¶
CloseNotification removes a notification from the screen and the history.
func OnUIThread ¶
func OnUIThread() bool
OnUIThread reports whether the caller runs on the UI thread. The loop's goroutine is locked to its thread, so no other goroutine runs there.
func Open ¶
Open creates a window. It must be called on the UI thread. The handler's OnCreate runs before the window appears, and its first frame is drawn before that too.
func Post ¶
func Post(fn func())
Post runs fn on the UI thread, in order with the other posted functions. It is safe from any goroutine and wakes the loop if it is idle.
func Quit ¶
func Quit()
Quit ends the loop when it next runs. It is safe from any goroutine; the windows must already be closed (or their OnDestroy has run).
func ReadSettings ¶
ReadSettings reads the desktop's settings from the settings portal: the dark style, high contrast, reduced motion, and on GNOME the text scale and caret blink. What the portal does not report keeps its default.
func Run ¶
Run connects to the compositor and runs the event loop on the calling goroutine, which becomes the UI thread, until Quit is called. It calls start on the UI thread before the loop runs; start typically opens the first window. An error from start is returned without running the loop.
func SetAppID ¶
func SetAppID(id string)
SetAppID names the app for the compositor, in place of the executable's name. It applies to the windows opened after it, so call it before the first. The desktop matches it to the .desktop file of the same name, which gives the app's icon and name in the task manager.
func SetNotificationHandlers ¶
SetNotificationHandlers sets the functions called, on the UI thread, when the user clicks a notification (its body or a button) and when a notification closes.
func ShowNotification ¶
func ShowNotification(n Notification) (uint32, error)
ShowNotification shows n and returns its id. It is safe from any goroutine.
Types ¶
type MenuItem ¶
MenuItem is an item of a tray menu. ID is the command that Chosen receives. A separator, and an item with a Submenu, is never chosen.
type Notification ¶
type Notification struct {
AppName string // the app's name, which the server shows and groups by
Title string
Body string
Image image.Image // shown beside the text; may be nil
// Actions are (key, label) pairs of the buttons. A click on the body
// reports DefaultAction.
Actions [][2]string
Silent bool
// Replaces is the id of a notification this one replaces, or 0.
Replaces uint32
}
Notification is a desktop notification.
type TrayIcon ¶
type TrayIcon struct {
// contains filtered or unexported fields
}
TrayIcon is a tray icon. Its methods run on the UI thread; the bus calls the objects it exports from other goroutines, which read the state under mu.
func NewTrayIcon ¶
func NewTrayIcon(o TrayOptions) *TrayIcon
NewTrayIcon returns an icon that is not shown yet; see Show.
func (*TrayIcon) Remove ¶
func (t *TrayIcon) Remove()
Remove takes the icon out of the panel. Show adds it again.
func (*TrayIcon) SetTooltip ¶
SetTooltip sets the tooltip, which is also the item's title.
type TrayOptions ¶
type TrayOptions struct {
// ID is unique in the process; it names the icon on the bus.
ID uint32
// AppName is the app's name, which panels show in their settings and use
// to remember the user's choice to show or hide the icon.
AppName string
Tooltip string
// Icon is the image of the icon; nil is a generic program icon.
Icon image.Image
// Click runs for a click (Activate).
Click func()
// DoubleClick runs for a second click soon after the first.
DoubleClick func()
// Menu returns the menu; nil means the icon has none.
Menu func() []MenuItem
// Chosen runs with the ID of the menu item the user chose.
Chosen func(id uint32)
}
TrayOptions describes a tray icon.