modes

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 31 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 modes holds the launch modes (crates/wayle-launcher/src/ modes): drun, run, window, ssh, the file browsers, script and dmenu, combi, and the lys-shell-only calc, emoji, clipboard, and keys modes.

Index

Constants

This section is empty.

Variables

AllDrunFields is -drun-match-fields all.

Functions

func Eval

func Eval(input string) (float64, bool)

Eval evaluates an expression, false when it is not one. Incomplete input is not an error worth reporting: half of what is typed here is a half-finished expression, so a failure shows no row. Infinite and NaN results are not answers either.

func FormatResult

func FormatResult(v float64) string

FormatResult writes a result the way a person would: no trailing zeros, no ".0" on a whole number.

func GlyphFromCodes

func GlyphFromCodes(codes []uint32) string

GlyphFromCodes assembles the glyph. A 0 is GTK's placeholder for a variation selector or skin tone; with none chosen GTK substitutes U+FE0F, which makes the emoji render as emoji rather than monochrome text, so this does the same. Values that are not characters (a surrogate, past U+10FFFF) are dropped.

func IsIgnored

func IsIgnored(entry string, prefixes []string) bool

IsIgnored reports whether an entry is one the user keeps out of history (rofi -ignored-prefixes). It matches the command - the executable for run, the desktop id for drun - because that is what history stores; an empty prefix matches nothing.

func ParseIcon

func ParseIcon(value string) launcher.Icon

ParseIcon reads one icon value: a thumbnail:// request, an absolute path, or a theme name.

func ParseRanges

func ParseRanges(raw string) []uint32

ParseRanges reads a dmenu-style index list, "1,3-5,8"; parts that do not parse are skipped.

Types

type Calc

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

Calc is the calculator mode (calc.rs): the query is an expression and the first row is its result. rofi needs rofi-calc, a plugin, and qalc for this; here it is a mode like any other. Enter copies the result, Shift+Enter puts it back in the input so the next expression builds on it. The evaluator is deliberately small - arithmetic, parentheses, a handful of functions and constants - and does no units; qalc through a script mode is still the answer for those.

func NewCalc

func NewCalc() *Calc

NewCalc builds the mode.

func (*Calc) Activate

Activate copies the result; the alternate accept continues with it.

func (*Calc) AllowsCustom

func (*Calc) AllowsCustom() bool

AllowsCustom is false: typed text is never itself the answer.

func (*Calc) Load

Load shows the current result, if any.

func (*Calc) Name

func (*Calc) Name() string

Name is "calc".

func (*Calc) Query

func (c *Calc) Query(query string) (launcher.ModeState, bool)

Query evaluates the query; the list changes only when the answer does, so an equivalent spelling does not fight the selection.

type Clipboard

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

Clipboard lists the session's clipboard history (clipboard.rs): the cliphist | rofi -dmenu | wl-copy pipeline without a second daemon. Accepting a row puts it back under the mime it arrived with, so a copied file goes back as a file and an image as an image.

func NewClipboard

func NewClipboard(history ClipboardHistory) *Clipboard

NewClipboard builds the mode; a nil history is a compositor without data-control, which the mode says rather than looking empty.

func (*Clipboard) Activate

Activate restores the entry; kb-custom-1/2 forget one or all.

func (*Clipboard) AllowsCustom

func (*Clipboard) AllowsCustom() bool

AllowsCustom is false.

func (*Clipboard) Load

Load lists the history, most recent first.

func (*Clipboard) Name

func (*Clipboard) Name() string

Name is "clipboard".

type ClipboardHistory

type ClipboardHistory interface {
	Entries() *clipboard.Snapshot
	Forget(id uint64) bool
	Clear()
	Copy(id uint64) bool
}

ClipboardHistory is what the clipboard mode needs from the session's clipboard service; *clipboard.Clipboard implements it.

type Combi

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

Combi merges several modes into one list, !bang filterable (combi.rs).

func NewCombi

func NewCombi(children []launcher.Mode, displayFormat string) *Combi

NewCombi builds over child modes (rofi -combi-modes) with a row template over {mode} and {text}.

func (*Combi) Activate

func (c *Combi) Activate(ctx context.Context, target launcher.Target, kind launcher.ActivateKind, input string) launcher.Action

Activate routes a row to its owner; custom input goes to the first child that accepts it.

func (*Combi) Delete

func (c *Combi) Delete(ctx context.Context, index uint32) launcher.Action

Delete routes shift-delete to the row's owner.

func (*Combi) Load

func (c *Combi) Load(ctx context.Context) launcher.ModeState

Load loads and merges every child.

func (*Combi) Name

func (*Combi) Name() string

Name is "combi".

func (*Combi) Subset

func (c *Combi) Subset(bang string) ([]bool, bool)

Subset masks the rows of children whose name starts with the bang.

type Dmenu

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

Dmenu is dmenu mode: rows arrive from the CLI over a channel, and an accept exits the session with the selection (dmenu.rs).

func NewDmenu

func NewDmenu(cfg DmenuConfig, rows <-chan []string) *Dmenu

NewDmenu builds the mode over the CLI's row stream; the channel closes when the rows are done.

func (*Dmenu) Activate

func (d *Dmenu) Activate(_ context.Context, target launcher.Target, kind launcher.ActivateKind, input string) launcher.Action

Activate exits with the row (or the typed text, index -1) and rofi's code: 0, or 9+N for kb-custom-N.

func (*Dmenu) ActivateMany

func (d *Dmenu) ActivateMany(_ context.Context, indices []uint32, _ string) launcher.Action

ActivateMany exits with every picked row, in the given order.

func (*Dmenu) Load

func (d *Dmenu) Load(ctx context.Context) launcher.ModeState

Load drains the whole row stream, then builds the list.

func (*Dmenu) Name

func (*Dmenu) Name() string

Name is "dmenu".

type DmenuConfig

type DmenuConfig struct {
	// Prompt is -p; nil for the mode's default.
	Prompt *string
	// Message is -mesg.
	Message     *string
	MarkupRows  bool
	MultiSelect bool
	// NoCustom is -no-custom or -only-match.
	NoCustom bool
	// Urgent and Active are the -u and -a indices, ranges expanded.
	Urgent []uint32
	Active []uint32
}

DmenuConfig is the part of the CLI's dmenu flags the engine needs.

type Drun

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

Drun launches applications from desktop entries (drun.rs).

func NewDrun

func NewDrun(cfg DrunConfig, history *launcher.History) *Drun

NewDrun builds the mode; a nil history disables frecency and recording.

func (*Drun) Activate

func (d *Drun) Activate(_ context.Context, target launcher.Target, kind launcher.ActivateKind, _ string) launcher.Action

Activate launches the row (recording it); custom input runs as a command, as rofi's drun does.

func (*Drun) Delete

func (d *Drun) Delete(ctx context.Context, index uint32) launcher.Action

Delete forgets the row's history entry and reloads.

func (*Drun) Load

Load lists the apps (and links), frecency first, then by name.

func (*Drun) Name

func (*Drun) Name() string

Name is "drun".

type DrunConfig

type DrunConfig struct {
	// Categories shows only apps in these categories (empty = all).
	Categories []string
	// ExcludeCategories hides apps in these.
	ExcludeCategories []string
	MatchFields       []DrunField
	// DisplayFormat is the row template over {name} {generic} {exec}
	// {categories} {comment}, [..] optional.
	DisplayFormat string
	// ShowActions adds desktop actions as rows.
	ShowActions bool
	// URLLauncher opens Type=Link entries.
	URLLauncher string
	// Terminal runs Terminal=true apps; empty autodetects.
	Terminal   string
	MaxHistory uint32
	// FallbackIcon is the icon for entries naming none
	// (-application-fallback-icon); empty is no icon.
	FallbackIcon    string
	IgnoredPrefixes []string
}

DrunConfig is drun's knobs (rofi's -drun-* family).

func DefaultDrunConfig

func DefaultDrunConfig() DrunConfig

DefaultDrunConfig is DrunConfig::default.

type DrunField

type DrunField uint8

DrunField is a desktop-entry field fed to the matcher (-drun-match-fields).

const (
	DrunFieldName DrunField = iota
	DrunFieldGeneric
	DrunFieldExec
	DrunFieldCategories
	DrunFieldComment
	DrunFieldKeywords
)

drun match fields.

type Emoji

type Emoji struct {
	// Glyph is the emoji itself.
	Glyph string
	// Name is what to call it, localized where there is a translation.
	Name string
	// Keywords are everything the matcher sees beyond the name.
	Keywords []string
}

Emoji is one emoji as the mode needs it.

func AvailableEmoji

func AvailableEmoji() []Emoji

AvailableEmoji reads the table for the current locale, widening to English. It is parsed once per process.

type EmojiMode

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

EmojiMode picks an emoji by name; accept copies it (emoji.rs).

func NewEmoji

func NewEmoji() *EmojiMode

NewEmoji reads the table (once per process).

func (*EmojiMode) Activate

Activate copies the glyph.

func (*EmojiMode) AllowsCustom

func (*EmojiMode) AllowsCustom() bool

AllowsCustom is false: typed text matching no emoji is not an emoji.

func (*EmojiMode) Load

Load lists every emoji.

func (*EmojiMode) Name

func (*EmojiMode) Name() string

Name is "emoji".

type FileBrowser

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

FileBrowser is filebrowser and recursivebrowser (filebrowser.rs).

func NewFileBrowser

func NewFileBrowser(cfg FileBrowserConfig) *FileBrowser

NewFileBrowser roots the browser at the configured directory.

func (*FileBrowser) Activate

Activate enters a directory, opens a file, or follows a typed path.

func (*FileBrowser) Load

Load lists the current directory.

func (*FileBrowser) Name

func (f *FileBrowser) Name() string

Name is filebrowser or recursivebrowser.

type FileBrowserConfig

type FileBrowserConfig struct {
	// Directory is the start directory; empty is $HOME.
	Directory        string
	Sorting          FileSort
	DirectoriesFirst bool
	ShowHidden       bool
	// Command opens a picked file; empty is xdg-open.
	Command string
	// Recursive lists every file below (recursivebrowser).
	Recursive bool
}

FileBrowserConfig is the file browser's knobs.

func DefaultFileBrowserConfig

func DefaultFileBrowserConfig() FileBrowserConfig

DefaultFileBrowserConfig is FileBrowserConfig::default.

type FileSort

type FileSort uint8

FileSort is the file browser's ordering.

const (
	FileSortName FileSort = iota
	FileSortMtime
	FileSortAtime
	FileSortCtime
)

File orderings; the time orders are newest first.

type Keys

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

Keys lists the launcher's own keybindings (keys.rs). Read-only: the rows are informational.

func NewKeys

func NewKeys(bindings []launcher.Binding) *Keys

NewKeys lists the session's effective bindings.

func (*Keys) Activate

Activate does nothing.

func (*Keys) AllowsCustom

func (*Keys) AllowsCustom() bool

AllowsCustom is false: typed text is not a binding.

func (*Keys) Load

Load lists "kb-<action>: <keys>" rows, none selectable.

func (*Keys) Name

func (*Keys) Name() string

Name is "keys".

type Run

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

Run executes commands found on $PATH (run.rs).

func NewRun

func NewRun(cfg RunConfig, history *launcher.History) *Run

NewRun builds the mode; a nil history disables recency and recording.

func (*Run) Activate

func (r *Run) Activate(_ context.Context, target launcher.Target, kind launcher.ActivateKind, _ string) launcher.Action

Activate runs the row's command or the typed one; Alt runs it in a terminal.

func (*Run) Delete

func (r *Run) Delete(ctx context.Context, index uint32) launcher.Action

Delete forgets the row's history entry and reloads.

func (*Run) Load

func (r *Run) Load(ctx context.Context) launcher.ModeState

Load lists the $PATH executables (plus the list command's lines), recently used first, then alphabetically.

func (*Run) Name

func (*Run) Name() string

Name is "run".

type RunConfig

type RunConfig struct {
	// RunCommand is the plain accept template ({cmd}).
	RunCommand string
	// ShellCommand is the alt accept template ({terminal}, {cmd}).
	ShellCommand string
	// ListCommand adds its stdout lines as entries.
	ListCommand string
	// Terminal is the terminal emulator; empty autodetects.
	Terminal string
	// MaxHistory caps the recorded history.
	MaxHistory uint32
	// IgnoredPrefixes keeps matching commands out of history.
	IgnoredPrefixes []string
}

RunConfig is the run mode's knobs (rofi's -run-* family).

func DefaultRunConfig

func DefaultRunConfig() RunConfig

DefaultRunConfig is RunConfig::default.

type SSH

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

SSH connects to known hosts in a terminal (ssh.rs).

func NewSSH

func NewSSH(cfg SSHConfig, history *launcher.History) *SSH

NewSSH builds the mode.

func (*SSH) Activate

func (s *SSH) Activate(_ context.Context, target launcher.Target, kind launcher.ActivateKind, _ string) launcher.Action

Activate connects to the row's host or the typed one.

func (*SSH) Delete

func (s *SSH) Delete(ctx context.Context, index uint32) launcher.Action

Delete forgets the host's history entry and reloads.

func (*SSH) Load

Load lists ~/.ssh/config hosts (plus known_hosts and /etc/hosts when enabled), recently used first, then alphabetically.

func (*SSH) Name

func (*SSH) Name() string

Name is "ssh".

type SSHConfig

type SSHConfig struct {
	// Client is the ssh binary.
	Client string
	// Command is the connect template ({terminal}, {ssh-client},
	// {host}).
	Command string
	// ParseHosts adds /etc/hosts names.
	ParseHosts bool
	// ParseKnownHosts adds ~/.ssh/known_hosts names.
	ParseKnownHosts bool
	// Terminal is the terminal emulator; empty autodetects.
	Terminal   string
	MaxHistory uint32
}

SSHConfig is the ssh mode's knobs (rofi's -ssh-* family).

func DefaultSSHConfig

func DefaultSSHConfig() SSHConfig

DefaultSSHConfig is SshConfig::default.

type Script

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

Script is a custom script mode speaking the rofi-script(5) protocol (script.rs): the script runs with no argument to produce the list, and again with the selected entry as argv[1] on every interaction. ROFI_RETV says why (0 init, 1 select, 2 custom, 3 delete, 10..28 kb-custom-N); ROFI_INFO, ROFI_DATA, and ROFI_INPUT carry the row's info, script-owned state, and the query. Header lines (\0key\x1fvalue) set mode options; row suffixes (text\0icon\x1fname\x1f...) set row metadata.

func NewScript

func NewScript(name, script string) *Script

NewScript is a script mode named name running script.

func (*Script) Activate

func (s *Script) Activate(ctx context.Context, target launcher.Target, kind launcher.ActivateKind, input string) launcher.Action

Activate re-runs the script with the accepted entry.

func (*Script) Delete

func (s *Script) Delete(ctx context.Context, index uint32) launcher.Action

Delete re-runs the script with ROFI_RETV=3 for the row.

func (*Script) Load

func (s *Script) Load(ctx context.Context) launcher.ModeState

Load runs the script for its initial list. An initially empty script is an empty list; closing only applies after a selection.

func (*Script) Name

func (s *Script) Name() string

Name is the configured mode name.

type Window

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

Window switches between open windows (window.rs).

func NewWindow

func NewWindow(cfg WindowConfig) *Window

NewWindow builds the mode; the compositor is detected from the environment.

func (*Window) Activate

func (w *Window) Activate(ctx context.Context, target launcher.Target, kind launcher.ActivateKind, _ string) launcher.Action

Activate focuses the window, or runs -window-command on Alt.

func (*Window) AllowsCustom

func (*Window) AllowsCustom() bool

AllowsCustom is false.

func (*Window) Delete

func (w *Window) Delete(ctx context.Context, index uint32) launcher.Action

Delete closes the window (when close-on-delete) and reloads.

func (*Window) Load

func (w *Window) Load(ctx context.Context) launcher.ModeState

Load lists the windows, most recently focused first; the focused one sorts last so plain Enter switches to the previous window, as rofi.

func (*Window) Name

func (w *Window) Name() string

Name is window or windowcd.

type WindowConfig

type WindowConfig struct {
	// Format is the row template: {w} workspace, {c} class, {t} title,
	// {n} name, {r} role.
	Format      string
	MatchFields []WindowField
	// HideActive leaves the focused window out.
	HideActive bool
	// CloseOnDelete makes shift-delete close the window.
	CloseOnDelete bool
	// WindowCommand is the alt accept command, {window} substituted.
	WindowCommand string
	// CurrentDesktopOnly restricts the list to the current workspace
	// (windowcd).
	CurrentDesktopOnly bool
}

WindowConfig is the window mode's knobs (rofi's -window-* family).

func DefaultWindowConfig

func DefaultWindowConfig() WindowConfig

DefaultWindowConfig is WindowConfig::default.

type WindowField

type WindowField uint8

WindowField is a window field fed to the matcher (-window-match-fields).

const (
	WindowFieldTitle WindowField = iota
	WindowFieldClass
	WindowFieldName
	WindowFieldRole
	WindowFieldDesktop
)

Window match fields.

Jump to

Keyboard shortcuts

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