sway

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 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 sway is the sway/i3 IPC client: the i3 wire protocol over $SWAYSOCK, workspace snapshots, an event subscription, and layout commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FocusCommand

func FocusCommand(ws Workspace) string

FocusCommand is focus_command for a workspace the snapshot knows: by number when it has one, else by quoted name.

func IsRunning

func IsRunning() bool

IsRunning reports whether a sway socket is advertised.

func KeyboardLayout

func KeyboardLayout(inputs []Input) string

KeyboardLayout is refresh_keyboard_layout: the active layout of the first keyboard reporting one; "" when none does.

func Quote

func Quote(name string) string

Quote is service.rs's quote: a double-quoted workspace name with embedded backslashes and quotes escaped.

func SocketPath

func SocketPath() string

SocketPath reads $SWAYSOCK; empty when sway is not running.

func Subscribe

func Subscribe() (<-chan struct{}, func(), error)

Subscribe connects a second socket, subscribes to the workspace and window streams, and ticks per event; each tick is the cue to re-query. The channel closes when the stream ends; stop closes the socket.

func SubscribeTo

func SubscribeTo(events ...string) (<-chan struct{}, func(), error)

SubscribeTo is Subscribe over the named event streams.

func SubscribeWithoutTitles added in v0.3.3

func SubscribeWithoutTitles() (<-chan struct{}, func(), error)

SubscribeWithoutTitles is Subscribe but for a window's title changes.

Types

type Conn

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

Conn is one IPC connection. Requests serialize; events read on their own connection.

func Connect

func Connect() (*Conn, error)

Connect dials $SWAYSOCK.

func (*Conn) Close

func (c *Conn) Close() error

Close drops the connection.

func (*Conn) FocusBackAndForth

func (c *Conn) FocusBackAndForth(ctx context.Context) error

FocusBackAndForth is focus:last.

func (*Conn) FocusNextOnOutput

func (c *Conn) FocusNextOnOutput(ctx context.Context) error

FocusNextOnOutput is focus:next.

func (*Conn) FocusPrevOnOutput

func (c *Conn) FocusPrevOnOutput(ctx context.Context) error

FocusPrevOnOutput is focus:previous.

func (*Conn) FocusWorkspace

func (c *Conn) FocusWorkspace(ctx context.Context, ws Workspace) error

FocusWorkspace focuses one workspace (focus:this).

func (*Conn) Inputs

func (c *Conn) Inputs() ([]Input, error)

Inputs is GET_INPUTS.

func (*Conn) RunCommand

func (c *Conn) RunCommand(ctx context.Context, command string) error

RunCommand executes one sway command; the first error in the reply wins.

func (*Conn) Tree

func (c *Conn) Tree() ([]byte, error)

Tree returns the raw GET_TREE reply, for callers that walk fields Windows does not model (the launcher's window mode).

func (*Conn) Windows

func (c *Conn) Windows() ([]Window, error)

Windows walks GET_TREE into its leaf windows, tiling before floating per container, in tree order.

func (*Conn) Workspaces

func (c *Conn) Workspaces() ([]Workspace, error)

Workspaces lists the workspaces.

type Input

type Input struct {
	Type                string  `json:"type"`
	XkbActiveLayoutName *string `json:"xkb_active_layout_name"`
}

Input is one GET_INPUTS entry (types.rs's InputReply), the fields the keyboard layout reads.

type Window

type Window struct {
	ID          int64
	Title       string
	HasTitle    bool
	AppID       string
	HasAppID    bool
	WorkspaceID int64
	// HasWorkspace is false for windows outside any workspace (the
	// scratchpad's __i3 container still counts as a workspace node).
	HasWorkspace bool
	Focused      bool
	Floating     bool
	Urgent       bool
	// Visible says the window is on screen; Rect is its container's
	// global logical rectangle.
	Visible bool
	Rect    image.Rectangle
}

Window is one leaf window of the container tree (core/window.rs's snapshot), tagged with the enclosing workspace's id.

type Workspace

type Workspace struct {
	ID      int64  `json:"id"`
	Num     int    `json:"num"`
	Name    string `json:"name"`
	Visible bool   `json:"visible"`
	Focused bool   `json:"focused"`
	Urgent  bool   `json:"urgent"`
	Output  string `json:"output"`
}

Workspace is one workspace snapshot (types.rs's WorkspaceReply).

Jump to

Keyboard shortcuts

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