sni

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 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 sni is the StatusNotifierItem tray service: the watcher and host D-Bus roles, item discovery, and the snapshot store the bar module renders.

Index

Constants

View Source
const (
	DaemonName = "dev.stubbe.lys.SystemTray1"
	DaemonPath = dbus.ObjectPath("/dev/stubbe/lys/SystemTray")
)

lys-shell's own interface over the tray, which `lys-shell systray` drives (wayle-systray/src/dbus).

View Source
const (
	WatcherName  = "org.kde.StatusNotifierWatcher"
	WatcherPath  = "/StatusNotifierWatcher"
	WatcherIface = "org.kde.StatusNotifierWatcher"
	HostIface    = "org.kde.StatusNotifierHost"
	ItemIface    = "org.kde.StatusNotifierItem"
	PropsIface   = "org.freedesktop.DBus.Properties"
	// ProtocolVersion is the watcher's advertised protocol version.
	ProtocolVersion = int32(0)
)

D-Bus names for the SNI protocol.

View Source
const MenuIface = "com.canonical.dbusmenu"

MenuIface is the DBusMenu interface tray items publish their menus on.

Variables

This section is empty.

Functions

func ParseAddress

func ParseAddress(reg string) (bus, path string)

ParseAddress splits a watcher registration ("bus/path") into its bus name and object path. A missing path defaults to /StatusNotifierItem, as most items register bare.

func ServeDaemon

func ServeDaemon(conn *dbus.Conn, store *Store, activator Activator, isWatcher bool) (func(), error)

ServeDaemon exports the interface over the store; isWatcher is the host's watcher role.

Types

type Actions

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

Actions drives one item (the bar's click handlers).

func (*Actions) AboutToShow added in v0.2.0

func (a *Actions) AboutToShow(ctx context.Context, it Item, id int32) (needUpdate bool, err error)

AboutToShow tells the app the (sub)menu id is about to show, the spec's once per showing; needUpdate is the app asking for its layout to be read again before it shows.

func (*Actions) Activate

func (a *Actions) Activate(ctx context.Context, it Item, x, y int32) error

Activate sends the primary activation at the given coordinates.

func (*Actions) ContextMenu

func (a *Actions) ContextMenu(ctx context.Context, it Item, x, y int32) error

ContextMenu asks the item to show its own menu.

func (*Actions) MenuClicked

func (a *Actions) MenuClicked(ctx context.Context, it Item, id int32) error

MenuClicked sends the clicked event for a row (menu_event with MenuEvent::Clicked, data 0, the Unix time).

func (*Actions) MenuLayout added in v0.2.0

func (a *Actions) MenuLayout(ctx context.Context, it Item) (MenuItem, error)

MenuLayout reads the full layout (GetLayout) without AboutToShow: the re-read after a LayoutUpdated or ItemsPropertiesUpdated, which an app may itself send in answer to AboutToShow.

func (*Actions) OpenMenu added in v0.2.0

func (a *Actions) OpenMenu(ctx context.Context, it Item) (MenuItem, error)

OpenMenu is the menu about to be shown: AboutToShow on the root (a failure is fine - not every app implements it), then the full layout. The spec calls AboutToShow once per showing, so a menu already open re-reads with MenuLayout instead.

func (*Actions) Scroll

func (a *Actions) Scroll(ctx context.Context, it Item, delta int32, orientation string) error

Scroll sends a scroll delta ("horizontal"/"vertical").

func (*Actions) SecondaryActivate

func (a *Actions) SecondaryActivate(ctx context.Context, it Item, x, y int32) error

SecondaryActivate sends the middle-click activation.

type Activator

type Activator interface {
	Activate(ctx context.Context, it Item, x, y int32) error
}

Activator is the primary activation the daemon forwards to an item.

type Category

type Category string

Category describes the kind of application behind an item.

const (
	CategoryApplicationStatus Category = "ApplicationStatus"
	CategoryCommunications    Category = "Communications"
	CategorySystemServices    Category = "SystemServices"
	CategoryHardware          Category = "Hardware"
)

Categories.

func ParseCategory

func ParseCategory(s string) Category

ParseCategory defaults unknown strings, per the SNI spec.

type Daemon

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

Daemon is the dev.stubbe.lys.SystemTray1 object (SystemTrayDaemon).

func (*Daemon) Activate

func (d *Daemon) Activate(id string) *dbus.Error

Activate activates the first item whose SNI Id is id at (0, 0).

func (*Daemon) List

func (d *Daemon) List() ([]ListRow, *dbus.Error)

List snapshots the items.

type Host

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

Host plays the host role against a watcher (ours or an existing one), tracks items and their property changes, and hands out the item controls.

func NewHost

func NewHost(store *Store) (*Host, error)

NewHost connects to the session bus and claims the roles: when no watcher is running, this process becomes the watcher and hosts against itself.

func NewHostOn

func NewHostOn(conn *dbus.Conn, store *Store) (*Host, error)

NewHostOn runs the host on an existing connection (tests use a private bus).

func (*Host) Actions

func (h *Host) Actions() *Actions

Actions returns the item controls on the host's connection.

func (*Host) Close

func (h *Host) Close() error

Close releases the watcher name when we own it and stops the loop.

func (*Host) IsWatcher

func (h *Host) IsWatcher() bool

IsWatcher reports whether this process serves the watcher role (the Rust service in TrayMode::Auto having claimed it).

func (*Host) WantPixmapSize added in v0.2.0

func (h *Host) WantPixmapSize(px int) (release func())

WantPixmapSize asks the host to keep, of every pixmap property, the pixmap BestPixmap picks for px device pixels, until release. Items are read again whenever the set of wanted sizes changes, so a new size is served at once and a dropped one frees its pixmaps. It panics on a non-positive size, a programming error.

func (*Host) WatchMenu

func (h *Host) WatchMenu(key string) (<-chan struct{}, func())

WatchMenu returns a feed that ticks (debounced) whenever the item's menu layout or properties change, for as long as a menu is open; stop releases it and closes the feed, once however often it is called.

type Item

type Item struct {
	// Bus is the item's unique or well-known bus name; Path the
	// StatusNotifierItem object path.
	Bus  string
	Path string

	ID         string
	Title      string
	Category   Category
	Status     Status
	ItemIsMenu bool

	// IconPixmap, AttentionIconPixmap and OverlayIconPixmap hold only
	// the pixmaps BestPixmap picks for the sizes the host's consumers
	// want (Host.WantPixmapSize). AttentionMovieName is not read: the
	// tray draws the still attention icon instead.
	IconName            string
	IconPixmap          []Pixmap
	OverlayIconName     string
	OverlayIconPixmap   []Pixmap
	AttentionName       string
	AttentionIconPixmap []Pixmap
	IconThemePath       string
	Tooltip             Tooltip
	MenuPath            string
}

Item is one tray item's snapshot (the SNI properties the bar needs).

func (*Item) Key

func (it *Item) Key() string

Key is the store's identity for an item.

type ListRow

type ListRow struct {
	ID       string
	Title    string
	IconName string
	Status   string
}

ListRow is one List row: (id, title, icon name, status).

type MenuItem struct {
	ID          int32
	Label       string
	Enabled     bool
	Visible     bool
	Separator   bool
	Toggle      ToggleType
	ToggleState ToggleState
	IconName    string
	// IconData is PNG data (the icon-data property).
	IconData []byte
	// Shortcut is the spec's shortcut list: each entry is modifiers
	// then the key ("Control", "Shift", "q").
	Shortcut [][]string
	Children []MenuItem
}

MenuItem is one DBusMenu node with its children (types/menu.rs MenuItem). The root is the invisible container whose children are the menu's rows.

type Pixmap

type Pixmap struct {
	Width  int32
	Height int32
	Data   []byte
}

Pixmap is ARGB32 icon data in network byte order: Data holds at least Width x Height pixels.

func BestPixmap added in v0.2.0

func BestPixmap(pixmaps []Pixmap, target int) (Pixmap, bool)

BestPixmap is the pixmap drawn in a box of target device pixels: the one closest to target x target by summed width and height distance, the first on ties. It is the one rule both the host's retention and the tray's drawing follow.

type Status

type Status string

Status describes how prominent an item should be.

const (
	StatusPassive        Status = "Passive"
	StatusActive         Status = "Active"
	StatusNeedsAttention Status = "NeedsAttention"
)

Statuses.

func ParseStatus

func ParseStatus(s string) Status

ParseStatus defaults unknown strings, per the SNI spec.

type Store

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

Store is the item set with change feeds.

func NewStore

func NewStore() *Store

NewStore builds an empty store.

func (*Store) Get

func (s *Store) Get(key string) (Item, bool)

Get returns one item by key.

func (*Store) Items

func (s *Store) Items() []Item

Items snapshots the item list in registration order.

func (*Store) Put

func (s *Store) Put(it *Item)

Put inserts or replaces an item, preserving registration order.

func (*Store) Remove

func (s *Store) Remove(bus, path string) bool

Remove drops an item by its registration address.

func (*Store) Subscribe

func (s *Store) Subscribe() (<-chan struct{}, func())

Subscribe returns a feed that ticks whenever the item set or an item's snapshot changes. Every subscriber (one tray per output) sees every change; stop ends the feed.

type ToggleState

type ToggleState int8

ToggleState is a toggle row's state; ToggleUnknown is the spec's -1.

const (
	ToggleUnchecked ToggleState = 0
	ToggleChecked   ToggleState = 1
	ToggleUnknown   ToggleState = -1
)

Toggle states.

type ToggleType

type ToggleType uint8

ToggleType is a menu row's toggle kind (types/menu.rs ToggleType).

const (
	ToggleNone ToggleType = iota
	ToggleCheckmark
	ToggleRadio
)

Toggle types.

type Tooltip

type Tooltip struct {
	IconName    string
	Title       string
	Description string
}

Tooltip is the item's hover information. Its pixmaps are not read: nothing draws them.

Jump to

Keyboard shortcuts

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