wire

package
v0.0.0-...-2f2df4f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 15 Imported by: 3

Documentation

Overview

Package wire defines types helpful for dealing with the Wayland wire protocol. It is primarly intended for usage by generated code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen() (*net.UnixListener, error)

Listen generates a new socket from the environment and listens on it.

func ListenPath

func ListenPath(path string) (*net.UnixListener, error)

ListenPath opens a socket at the given path.

func NewSocketPath

func NewSocketPath() (string, error)

NewSocketPath attempts to generate a valid path for opening a new socket to listen on.

func SocketPath

func SocketPath() string

SocketPath determines the path to the Wayland Unix domain socket based on the contents of the $WAYLAND_DISPLAY environment variable. It does not attempt to determine if the value corresponds to an actual socket.

Types

type Binder

type Binder interface {
	Bind(name uint32, obj NewID)
}

Binder is a type that can bind a name to an object. This is typically implemented by wl_registry, but it is provided as an interface here to allow generated code to use it.

type Conn

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

Conn represents a low-level Wayland connection. It is not generally used directly, instead being handled automatically by a State implementation.

func Dial

func Dial() (*Conn, error)

Dial opens a connection to the Wayland socket based on the current environment. It follows the procedure outlined at https://wayland-book.com/protocol-design/wire-protocol.html#transports

func NewConn

func NewConn(c *net.UnixConn) *Conn

NewConn creates a new Conn that wraps c. After this is called, use the provided Close method to close c instead of calling its own Close method.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying connection.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

type DebugObject

type DebugObject interface {
	// MethodName returns the string name of the specified local method.
	MethodName(opcode uint16) string
}

DebugObject is implemented by Objects that can provide debug information about themselves.

type Fixed

type Fixed int32

Fixed is a 24_8 fixed-point number. Wayland does not have support for floating point numbers in its core protocol and uses these instead.

func FixedFloat

func FixedFloat(v float64) Fixed

func FixedInt

func FixedInt(v int) Fixed

func (Fixed) Float

func (f Fixed) Float() float64

func (Fixed) Frac

func (f Fixed) Frac() int

func (Fixed) Int

func (f Fixed) Int() int

func (Fixed) String

func (f Fixed) String() string

type MessageBuffer

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

MessageBuffer holds message data that has been read from the socket but not yet decoded.

func ReadMessage

func ReadMessage(c *Conn) (*MessageBuffer, error)

ReadMessage reads message data from the socket into a buffer.

func (*MessageBuffer) Debug

func (r *MessageBuffer) Debug(sender Object) string

func (MessageBuffer) Err

func (r MessageBuffer) Err() error

func (MessageBuffer) Op

func (r MessageBuffer) Op() uint16

Op is the opcode of the message.

func (*MessageBuffer) ReadArray

func (r *MessageBuffer) ReadArray() []byte

func (*MessageBuffer) ReadFile

func (r *MessageBuffer) ReadFile() *os.File

func (*MessageBuffer) ReadFixed

func (r *MessageBuffer) ReadFixed() (v Fixed)

func (*MessageBuffer) ReadInt

func (r *MessageBuffer) ReadInt() (v int32)

func (*MessageBuffer) ReadNewID

func (r *MessageBuffer) ReadNewID() NewID

func (*MessageBuffer) ReadObject

func (r *MessageBuffer) ReadObject() uint32

func (*MessageBuffer) ReadString

func (r *MessageBuffer) ReadString() string

func (*MessageBuffer) ReadUint

func (r *MessageBuffer) ReadUint() (v uint32)

func (MessageBuffer) Sender

func (r MessageBuffer) Sender() uint32

Sender is the object ID of the sender of the message.

func (MessageBuffer) Size

func (r MessageBuffer) Size() uint16

Size is the total size of the message, including the 8 byte header.

type MessageBuilder

type MessageBuilder struct {
	// Method is the name of the method being called. It is included
	// purely for debugging purposes.
	Method string

	// Args is the original set of arguments passed to the function from
	// which this MessageBuilder was generated. It is included purely
	// for debugging purposes.
	Args []any
	// contains filtered or unexported fields
}

MessageBuilder is a message that is under construction.

func NewMessage

func NewMessage(sender Object, op uint16) *MessageBuilder

func (*MessageBuilder) Build

func (mb *MessageBuilder) Build(c *Conn) error

Build builds the message and sends it to c. The MessageBuilder should not be used again after this method is called.

func (*MessageBuilder) Op

func (mb *MessageBuilder) Op() uint16

func (*MessageBuilder) Sender

func (mb *MessageBuilder) Sender() Object

func (*MessageBuilder) String

func (mb *MessageBuilder) String() string

func (*MessageBuilder) WriteArray

func (mb *MessageBuilder) WriteArray(v []byte)

func (*MessageBuilder) WriteFile

func (mb *MessageBuilder) WriteFile(v *os.File)

func (*MessageBuilder) WriteFixed

func (mb *MessageBuilder) WriteFixed(v Fixed)

func (*MessageBuilder) WriteInt

func (mb *MessageBuilder) WriteInt(v int32)

func (*MessageBuilder) WriteNewID

func (mb *MessageBuilder) WriteNewID(v NewID)

func (*MessageBuilder) WriteObject

func (mb *MessageBuilder) WriteObject(v Object)

func (*MessageBuilder) WriteString

func (mb *MessageBuilder) WriteString(v string)

func (*MessageBuilder) WriteUint

func (mb *MessageBuilder) WriteUint(v uint32)

type NewID

type NewID struct {
	Interface string
	Version   uint32
	ID        uint32
}

NewID represents the Wayland new_id type when it doesn't have a pre-defined interface.

type Object

type Object interface {
	// ID returns the ID of the object. It returns 0 before the Object
	// is added to an object management system.
	ID() uint32

	// SetID is used by the object ID management system to tell the
	// object what its own ID should be. It should almost never be
	// called manually.
	SetID(id uint32)

	// Dispatch pertforms the operation requested by the message in the
	// buffer.
	Dispatch(msg *MessageBuffer) error

	// Delete is called by the object ID management system when an
	// object is deleted.
	Delete()
}

Object represents a Wayland protocol object.

type State

type State interface {
	// Add adds an object to the state. If the object has a non-zero ID,
	// that ID is used to track it. Otherwise, a new ID is generated and
	// assigned to the object.
	Add(Object)

	// Get returns the Object with the given ID. If no such object
	// exists, it returns nil.
	Get(uint32) Object

	// Enqueue adds an outgoing message to the state's queue. This
	// method is safe to call concurrently, but no such guarantees are
	// given about the rest of the State.
	Enqueue(*MessageBuilder)
}

State can track objects and send messages. There are individual implementations of this for the server and client, but an interface is provided here to allow them to be referenced and used by generated code.

type UnknownOpError

type UnknownOpError struct {
	Interface string
	Type      string
	Op        uint16
}

UnknownOpError is returned by Object.Dispatch if it is given a message with an invalid opcode.

func (UnknownOpError) Error

func (err UnknownOpError) Error() string

type UnknownSenderIDError

type UnknownSenderIDError struct {
	Msg *MessageBuffer
}

UnknownSenderIDError is returned by an attempt to dispatch an incoming message that indicates a method call on an object that the State doesn't know about.

func (UnknownSenderIDError) Error

func (err UnknownSenderIDError) Error() string

Jump to

Keyboard shortcuts

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