linux

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 32 Imported by: 0 modules, 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 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 GPU renderer (render/vulkan) draws into dma-bufs (see DmabufSurface), or 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

View Source
const DefaultAction = defaultAction

DefaultAction is the action key that a click on a notification's body reports.

Variables

View Source
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

func CloseNotification(id uint32) error

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

func ReadSettings() platform.Settings

ReadSettings reads the desktop's settings from the settings portal: the dark style, high contrast, reduced motion, and on GNOME the text scale, caret blink and the title bar's buttons. What the portal does not report keeps its default. The caption buttons the app draws are GNOME's round ones.

func ReleaseSession added in v0.6.2

func ReleaseSession()

ReleaseSession closes the windows and lets go of the window session, so that another process takes it over with the windows where they were: KWin keeps a window's place in its session when the window's toplevel ends, and only while its entry in the session lives, so the windows go first, then their entries, then the session. The windows are gone from the screen at once; the process is about to be replaced. It runs on the UI thread, at once when called there, and waits until the compositor has handled it. Before the loop runs, or without one, as in tests, it does nothing.

func Run

func Run(start func() error) error

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

func SetNotificationHandlers(onAction func(id uint32, action string), onClosed func(id uint32))

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 struct {
	ID        uint32
	Label     string
	Disabled  bool
	Checked   bool
	Separator bool
	Submenu   []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) SetIcon

func (t *TrayIcon) SetIcon(img image.Image) error

SetIcon sets the image of the icon; nil is a generic program icon.

func (*TrayIcon) SetTooltip

func (t *TrayIcon) SetTooltip(s string)

SetTooltip sets the tooltip, which is also the item's title.

func (*TrayIcon) Show

func (t *TrayIcon) Show() error

Show adds the icon to the panel. It is an error when there is no session bus or no tray, and the icon is not shown then.

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.

Directories

Path Synopsis
Package wl is a small Wayland client: the wire protocol over the compositor's Unix socket, in pure Go, with no libwayland.
Package wl is a small Wayland client: the wire protocol over the compositor's Unix socket, in pure Go, with no libwayland.

Jump to

Keyboard shortcuts

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