launcheripc

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 18 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 launcheripc is the launcher socket (wayle-ipc launcher_socket.rs): the protocol between `lys-shell launcher` (the rofi shim) and the launcher surface in the shell, with both halves - the CLI's client and the shell's server.

One persistent connection per session carries newline-delimited JSON frames, and the connection doubles as the session's lifetime: when the CLI dies the server sees EOF and closes the surface; when the server replies with a terminal frame, the CLI prints it and exits with rofi's code. The wire is the Rust shell's byte for byte, so either CLI talks to either shell.

Index

Constants

View Source
const (
	FrameOpen      = "open"
	FrameRows      = "rows"
	FrameRowsDone  = "rows-done"
	FrameOpened    = "opened"
	FrameBusy      = "busy"
	FrameResult    = "result"
	FrameCancelled = "cancelled"
	FrameDump      = "dump"
)

Frame type tags.

View Source
const RowChunk = 2000

RowChunk is the number of rows per rows frame when streaming stdin.

Variables

View Source
var ErrDisconnected = errors.New("launcher session ended unexpectedly")

ErrDisconnected is the shell closing the connection without a terminal frame.

Functions

func SocketPath

func SocketPath() (string, error)

SocketPath is $XDG_RUNTIME_DIR/lys-shell/launcher.sock; an error naming XDG_RUNTIME_DIR when the process has no absolute one.

Types

type Client

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

Client is the CLI's connection to the launcher surface. The write half must stay open for the whole session: closing it half-closes the socket, and the shell reads that EOF as the client dying and tears the surface down.

func Open

func Open(options SessionOptions, replace bool) (*Client, error)

Open connects the launcher socket and sends the open frame.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection: the one EOF the shell should see.

func (*Client) FinishRows

func (c *Client) FinishRows() error

FinishRows signals stdin EOF. It does not close the write half.

func (*Client) NextFrame

func (c *Client) NextFrame() (ServerFrame, error)

NextFrame reads the next shell frame; EOF is ErrDisconnected. The shell owes its first frame at once, and the rest whenever the person acts.

func (*Client) SendRows

func (c *Client) SendRows(items []string) error

SendRows sends one chunk of dmenu rows.

type ClientFrame

type ClientFrame struct {
	Type string `json:"type"`
	// Options and Replace are the open frame's.
	Options *SessionOptions `json:"options,omitempty"`
	Replace bool            `json:"replace,omitempty"`
	// Items is the rows frame's chunk.
	Items []string `json:"items,omitempty"`
}

ClientFrame is a CLI -> shell frame: open (Options, Replace), rows (Items), or rows-done.

func (ClientFrame) MarshalJSON

func (f ClientFrame) MarshalJSON() ([]byte, error)

MarshalJSON writes the variant's fields, all of them: serde requires an open frame's replace and a rows frame's items.

type Handler

type Handler interface {
	// Open starts a session. It is called on the connection's
	// goroutine and must not block; the surface eventually Replies.
	Open(s *Session)
	// ClientGone reports a CLI whose socket died (ctrl-C): close the
	// session if it is still the live one, and Reply to release the
	// connection.
	ClientGone(id uint64)
}

Handler is the surface side of the socket.

type Selected

type Selected struct {
	// Index is the row's input index; -1 for accepted custom input.
	Index int64  `json:"index"`
	Text  string `json:"text"`
}

Selected is one accepted row.

type Server

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

Server accepts launcher sessions.

func NewServer

func NewServer(handler Handler) *Server

NewServer serves sessions to handler.

func (*Server) Listen

func (s *Server) Listen() (stop func(), err error)

Listen binds the socket (removing a stale one, restricting it to the user) and accepts in the background. stop closes the listener and removes the socket file.

type ServerFrame

type ServerFrame struct {
	Type string `json:"type"`
	// Code is the rofi exit code: 0 accept, 1 cancel, 10..28
	// kb-custom-N.
	Code     int        `json:"code"`
	Selected []Selected `json:"selected,omitempty"`
	// Filter is the query at accept time (rofi -format f/F).
	Filter string   `json:"filter"`
	Items  []string `json:"items,omitempty"`
}

ServerFrame is a shell -> CLI frame: opened, busy, result (Code, Selected, Filter), cancelled (Code), or dump (Items).

func Busy

func Busy() ServerFrame

Busy is the reply when another session is live and replace was not asked for.

func Cancelled

func Cancelled() ServerFrame

Cancelled is a cancelled frame with rofi's code 1.

func Dump

func Dump(items []string) ServerFrame

Dump is the -dump reply: the filtered rows in display order.

func Result

func Result(code int, selected []Selected, filter string) ServerFrame

Result is a result frame.

func (ServerFrame) MarshalJSON

func (f ServerFrame) MarshalJSON() ([]byte, error)

MarshalJSON writes only the fields the frame's variant carries, as serde's tagged enum does.

type Session

type Session struct {
	// ID is the connection's identity; ClientGone names it.
	ID      uint64
	Options SessionOptions
	// Replace is rofi -replace: displace a live session instead of
	// answering busy.
	Replace bool
	// Rows streams the dmenu rows; it closes on rows-done or when the
	// client goes away.
	Rows <-chan []string
	// contains filtered or unexported fields
}

Session is one CLI session handed to the surface.

func NewSession

func NewSession(id uint64, options SessionOptions, replace bool, rows <-chan []string) (*Session, <-chan ServerFrame)

NewSession builds a session and the channel its terminal frame comes out of (one frame; a Release sends the zero frame). The server opens every session through it; a surface under test opens them directly.

func (*Session) Release

func (s *Session) Release()

Release ends the session without a frame: the client is gone, so there is nobody to answer.

func (*Session) Reply

func (s *Session) Reply(f ServerFrame)

Reply sends the session's terminal frame (result, cancelled, busy, or dump); the server writes it and closes the connection. Only the first call counts.

type SessionOptions

type SessionOptions struct {
	Mode         *string  `json:"mode,omitempty"`
	Modes        []string `json:"modes,omitempty"`
	Dmenu        bool     `json:"dmenu,omitempty"`
	ErrorMessage *string  `json:"error-message,omitempty"`

	Prompt      *string `json:"prompt,omitempty"`
	Lines       *uint32 `json:"lines,omitempty"`
	Mesg        *string `json:"mesg,omitempty"`
	Filter      *string `json:"filter,omitempty"`
	Select      *string `json:"select,omitempty"`
	SelectedRow *uint32 `json:"selected-row,omitempty"`
	WindowTitle *string `json:"window-title,omitempty"`

	MultiSelect            bool     `json:"multi-select,omitempty"`
	OnlyMatch              bool     `json:"only-match,omitempty"`
	NoCustom               bool     `json:"no-custom,omitempty"`
	Password               bool     `json:"password,omitempty"`
	MarkupRows             bool     `json:"markup-rows,omitempty"`
	Sync                   bool     `json:"sync,omitempty"`
	Dump                   bool     `json:"dump,omitempty"`
	Urgent                 []uint32 `json:"urgent,omitempty"`
	Active                 []uint32 `json:"active,omitempty"`
	BallotSelected         *string  `json:"ballot-selected,omitempty"`
	BallotUnselected       *string  `json:"ballot-unselected,omitempty"`
	DisplayColumns         []uint32 `json:"display-columns,omitempty"`
	DisplayColumnSeparator *string  `json:"display-column-separator,omitempty"`
	EllipsizeMode          *string  `json:"ellipsize-mode,omitempty"`
	KeepRight              bool     `json:"keep-right,omitempty"`

	Matching        *string `json:"matching,omitempty"`
	Tokenize        *bool   `json:"tokenize,omitempty"`
	NegateChar      *string `json:"negate-char,omitempty"`
	NormalizeMatch  *bool   `json:"normalize-match,omitempty"`
	Sort            *bool   `json:"sort,omitempty"`
	SortingMethod   *string `json:"sorting-method,omitempty"`
	CaseSensitive   *bool   `json:"case-sensitive,omitempty"`
	CaseSmart       *bool   `json:"case-smart,omitempty"`
	CaseInsensitive *bool   `json:"case-insensitive,omitempty"`

	Location        *uint8  `json:"location,omitempty"`
	Width           *Width  `json:"width,omitempty"`
	XOffset         *int32  `json:"xoffset,omitempty"`
	YOffset         *int32  `json:"yoffset,omitempty"`
	Monitor         *string `json:"monitor,omitempty"`
	NoFixedNumLines bool    `json:"no-fixed-num-lines,omitempty"`
	SidebarMode     *bool   `json:"sidebar-mode,omitempty"`
	Cycle           *bool   `json:"cycle,omitempty"`
	AutoSelect      *bool   `json:"auto-select,omitempty"`
	HoverSelect     *bool   `json:"hover-select,omitempty"`
	ShowIcons       *bool   `json:"show-icons,omitempty"`
	IconTheme       *string `json:"icon-theme,omitempty"`

	Terminal                *string  `json:"terminal,omitempty"`
	RunCommand              *string  `json:"run-command,omitempty"`
	RunShellCommand         *string  `json:"run-shell-command,omitempty"`
	RunListCommand          *string  `json:"run-list-command,omitempty"`
	SSHClient               *string  `json:"ssh-client,omitempty"`
	SSHCommand              *string  `json:"ssh-command,omitempty"`
	ParseHosts              *bool    `json:"parse-hosts,omitempty"`
	ParseKnownHosts         *bool    `json:"parse-known-hosts,omitempty"`
	WindowFormat            *string  `json:"window-format,omitempty"`
	WindowCommand           *string  `json:"window-command,omitempty"`
	WindowMatchFields       []string `json:"window-match-fields,omitempty"`
	HideActiveWindow        *bool    `json:"hide-active-window,omitempty"`
	DrunCategories          []string `json:"drun-categories,omitempty"`
	DrunExcludeCategories   []string `json:"drun-exclude-categories,omitempty"`
	DrunMatchFields         []string `json:"drun-match-fields,omitempty"`
	DrunDisplayFormat       *string  `json:"drun-display-format,omitempty"`
	DrunShowActions         *bool    `json:"drun-show-actions,omitempty"`
	DrunURLLauncher         *string  `json:"drun-url-launcher,omitempty"`
	ApplicationFallbackIcon *string  `json:"application-fallback-icon,omitempty"`
	IgnoredPrefixes         []string `json:"ignored-prefixes,omitempty"`
	CombiModes              []string `json:"combi-modes,omitempty"`
	CombiDisplayFormat      *string  `json:"combi-display-format,omitempty"`

	// KbOverrides maps an action (no kb- prefix) to its key list.
	KbOverrides map[string]string `json:"kb-overrides,omitempty"`
	// MouseOverrides maps an action (me-/ml- prefix kept, the two
	// namespaces have their own names) to its binding list.
	MouseOverrides map[string]string `json:"mouse-overrides,omitempty"`
	// DisplayNames maps a mode to its display name (-display-<mode>).
	DisplayNames map[string]string `json:"display-names,omitempty"`

	OnSelectionChanged *string `json:"on-selection-changed,omitempty"`
	OnEntryAccepted    *string `json:"on-entry-accepted,omitempty"`
	OnModeChanged      *string `json:"on-mode-changed,omitempty"`
	OnMenuCanceled     *string `json:"on-menu-canceled,omitempty"`
	OnMenuError        *string `json:"on-menu-error,omitempty"`

	Font          *string `json:"font,omitempty"`
	Style         *string `json:"style,omitempty"`
	PreviewCmd    *string `json:"preview-cmd,omitempty"`
	CompleterMode *string `json:"completer-mode,omitempty"`
}

SessionOptions is the open frame's per-invocation options: rofi's flag surface. Every field is optional; the shell merges the set ones over [launcher] (launcher_socket.rs SessionOptions, kebab-case).

type Width

type Width struct {
	Unit WidthUnit
	// Value is the percent, the char count, or the pixels.
	Value float64
}

Width is a parsed -width. The zero Width is no width.

func ParseWidth

func ParseWidth(raw string) (Width, error)

ParseWidth reads a rofi -width: NNpx is pixels, a negative number a character count, anything else a percentage. Not a number is an error naming the value.

func (Width) MarshalJSON

func (w Width) MarshalJSON() ([]byte, error)

MarshalJSON writes serde's externally tagged form: {"percent":60.0}, {"chars":30}, {"pixels":600}.

func (*Width) UnmarshalJSON

func (w *Width) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the tagged form; an unknown tag is an error.

type WidthUnit

type WidthUnit uint8

WidthUnit is the unit of a rofi -width value.

const (
	// WidthPercent is `-width 60`: percent of the monitor's width.
	WidthPercent WidthUnit = iota + 1
	// WidthChars is `-width -30`: a character count, measured against
	// the font's advance.
	WidthChars
	// WidthPixels is `-width 600px`.
	WidthPixels
)

Width units, distinguished by syntax in rofi rather than a suffix.

Jump to

Keyboard shortcuts

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