wayland

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package wayland implements a pure Go Wayland client.

This package provides a Wayland client implementation that communicates directly with the Wayland compositor over Unix sockets, without using libwayland-client.so. This enables zero-CGO builds on Linux.

Wire Protocol

Wayland uses a binary wire protocol over Unix domain sockets. Messages consist of a header (object ID + size/opcode) followed by arguments. All values are encoded as 32-bit little-endian words.

The wire format is:

+--------+--------+--------+--------+
| Object ID (4 bytes)               |
+--------+--------+--------+--------+
| Size (16 bits) | Opcode (16 bits) |
+--------+--------+--------+--------+
| Arguments...                      |
+--------+--------+--------+--------+

Argument Types

The protocol supports several argument types:

  • int: Signed 32-bit integer
  • uint: Unsigned 32-bit integer
  • fixed: Signed 24.8 fixed-point number
  • string: Length-prefixed UTF-8 string (padded to 4 bytes)
  • object: Object ID (uint32)
  • new_id: New object ID (uint32), sometimes with interface+version
  • array: Length-prefixed byte array (padded to 4 bytes)
  • fd: File descriptor (passed via SCM_RIGHTS)

Core Interfaces

This package implements the core Wayland interfaces:

  • wl_display: The connection to the compositor (object ID 1)
  • wl_registry: Global registry for binding to interfaces

Additional interfaces (wl_compositor, wl_surface, xdg_wm_base, etc.) are implemented in separate files.

Usage

Connect to the compositor and bind to required interfaces:

display, err := wayland.Connect()
if err != nil {
    return err
}
defer display.Close()

registry, err := display.GetRegistry()
if err != nil {
    return err
}

// Wait for globals to be advertised
display.Roundtrip()

File Descriptors

Wayland uses SCM_RIGHTS to pass file descriptors for shared memory buffers and DMA-BUF handles. This requires special socket handling via the golang.org/x/sys/unix package.

Thread Safety

The Display type is safe for concurrent use from multiple goroutines. Individual objects should be accessed from a single goroutine or protected by external synchronization.

Index

Constants

View Source
const (
	DecorationModeClientSide uint32 = 1 // Client draws decorations
	DecorationModeServerSide uint32 = 2 // Server draws decorations
)

Decoration mode constants for zxdg_toplevel_decoration_v1.

View Source
const (
	SeatCapabilityPointer  uint32 = 1 // The seat has pointer (mouse) devices.
	SeatCapabilityKeyboard uint32 = 2 // The seat has keyboard devices.
	SeatCapabilityTouch    uint32 = 4 // The seat has touch devices.
)

wl_seat capability bitmask.

View Source
const (
	ButtonLeft   uint32 = 0x110 // Left mouse button (BTN_LEFT).
	ButtonRight  uint32 = 0x111 // Right mouse button (BTN_RIGHT).
	ButtonMiddle uint32 = 0x112 // Middle mouse button (BTN_MIDDLE).
	ButtonSide   uint32 = 0x113 // Side mouse button (BTN_SIDE).
	ButtonExtra  uint32 = 0x114 // Extra mouse button (BTN_EXTRA).
)

Linux input event button codes (from linux/input-event-codes.h).

View Source
const (
	PointerButtonStateReleased uint32 = 0 // Button is not pressed.
	PointerButtonStatePressed  uint32 = 1 // Button is pressed.
)

Pointer button state values.

View Source
const (
	PointerAxisVerticalScroll   uint32 = 0 // Vertical scroll axis.
	PointerAxisHorizontalScroll uint32 = 1 // Horizontal scroll axis.
)

Pointer axis values.

View Source
const (
	PointerAxisSourceWheel      uint32 = 0 // Scroll wheel.
	PointerAxisSourceFinger     uint32 = 1 // Finger on touchpad.
	PointerAxisSourceContinuous uint32 = 2 // Continuous coordinate space.
	PointerAxisSourceWheelTilt  uint32 = 3 // Wheel tilt.
)

Pointer axis source values (v5+).

View Source
const (
	KeyboardKeymapFormatNoKeymap uint32 = 0 // No keymap; client must interpret raw keycodes.
	KeyboardKeymapFormatXKBV1    uint32 = 1 // XKB keymap format.
)

Keyboard keymap format values.

View Source
const (
	KeyStateReleased uint32 = 0 // Key is released.
	KeyStatePressed  uint32 = 1 // Key is pressed.
)

Keyboard key state values.

View Source
const (
	InterfaceWlCompositor            = "wl_compositor"
	InterfaceWlShm                   = "wl_shm"
	InterfaceWlSeat                  = "wl_seat"
	InterfaceWlOutput                = "wl_output"
	InterfaceXdgWmBase               = "xdg_wm_base"
	InterfaceWlSubcompositor         = "wl_subcompositor"
	InterfaceWlDataDeviceManager     = "wl_data_device_manager"
	InterfaceZwpLinuxDmabuf          = "zwp_linux_dmabuf_v1"
	InterfaceZxdgDecorationManagerV1 = "zxdg_decoration_manager_v1"
)

Well-known Wayland interface names.

View Source
const (
	XdgToplevelStateMaximized   uint32 = 1 // Window is maximized
	XdgToplevelStateFullscreen  uint32 = 2 // Window is fullscreen
	XdgToplevelStateResizing    uint32 = 3 // Window is being resized
	XdgToplevelStateActivated   uint32 = 4 // Window is focused/activated
	XdgToplevelStateTiledLeft   uint32 = 5 // Window is tiled on left edge
	XdgToplevelStateTiledRight  uint32 = 6 // Window is tiled on right edge
	XdgToplevelStateTiledTop    uint32 = 7 // Window is tiled on top edge
	XdgToplevelStateTiledBottom uint32 = 8 // Window is tiled on bottom edge
)

XdgToplevel state values. These are passed in the states array of the configure event.

View Source
const (
	XdgToplevelWmCapabilityWindowMenu uint32 = 1 // show_window_menu is available
	XdgToplevelWmCapabilityMaximize   uint32 = 2 // set_maximized / unset_maximized are available
	XdgToplevelWmCapabilityFullscreen uint32 = 3 // set_fullscreen / unset_fullscreen are available
	XdgToplevelWmCapabilityMinimize   uint32 = 4 // set_minimized is available
)

XdgToplevelWmCapability values (v5+). Advertised by the compositor via wm_capabilities event to indicate which window management features are supported.

View Source
const (
	XdgToplevelResizeEdgeNone        uint32 = 0
	XdgToplevelResizeEdgeTop         uint32 = 1
	XdgToplevelResizeEdgeBottom      uint32 = 2
	XdgToplevelResizeEdgeLeft        uint32 = 4
	XdgToplevelResizeEdgeTopLeft     uint32 = 5
	XdgToplevelResizeEdgeBottomLeft  uint32 = 6
	XdgToplevelResizeEdgeRight       uint32 = 8
	XdgToplevelResizeEdgeTopRight    uint32 = 9
	XdgToplevelResizeEdgeBottomRight uint32 = 10
)

ResizeEdge values for interactive resize operations.

View Source
const (
	XdgPositionerAnchorNone        uint32 = 0
	XdgPositionerAnchorTop         uint32 = 1
	XdgPositionerAnchorBottom      uint32 = 2
	XdgPositionerAnchorLeft        uint32 = 3
	XdgPositionerAnchorRight       uint32 = 4
	XdgPositionerAnchorTopLeft     uint32 = 5
	XdgPositionerAnchorBottomLeft  uint32 = 6
	XdgPositionerAnchorTopRight    uint32 = 7
	XdgPositionerAnchorBottomRight uint32 = 8
)

XdgPositionerAnchor values for anchor position.

View Source
const (
	XdgPositionerGravityNone        uint32 = 0
	XdgPositionerGravityTop         uint32 = 1
	XdgPositionerGravityBottom      uint32 = 2
	XdgPositionerGravityLeft        uint32 = 3
	XdgPositionerGravityRight       uint32 = 4
	XdgPositionerGravityTopLeft     uint32 = 5
	XdgPositionerGravityBottomLeft  uint32 = 6
	XdgPositionerGravityTopRight    uint32 = 7
	XdgPositionerGravityBottomRight uint32 = 8
)

XdgPositionerGravity values for gravity direction.

View Source
const (
	XdgPositionerConstraintAdjustmentNone    uint32 = 0
	XdgPositionerConstraintAdjustmentSlideX  uint32 = 1
	XdgPositionerConstraintAdjustmentSlideY  uint32 = 2
	XdgPositionerConstraintAdjustmentFlipX   uint32 = 4
	XdgPositionerConstraintAdjustmentFlipY   uint32 = 8
	XdgPositionerConstraintAdjustmentResizeX uint32 = 16
	XdgPositionerConstraintAdjustmentResizeY uint32 = 32
)

XdgPositionerConstraintAdjustment flags for constraint adjustment.

Variables

View Source
var (
	ErrDisplayNotConnected = errors.New("wayland: display not connected")
	ErrNoWaylandSocket     = errors.New("wayland: no wayland socket found")
	ErrProtocolError       = errors.New("wayland: protocol error from compositor")
	ErrConnectionClosed    = errors.New("wayland: connection closed")
	ErrNoMessage           = errors.New("wayland: no message available")
)

Errors returned by Display operations.

View Source
var (
	ErrMessageTooLarge     = errors.New("wayland: message exceeds maximum size")
	ErrMessageTooSmall     = errors.New("wayland: message smaller than header")
	ErrBufferTooSmall      = errors.New("wayland: buffer too small for message")
	ErrInvalidStringLen    = errors.New("wayland: invalid string length")
	ErrInvalidArrayLen     = errors.New("wayland: invalid array length")
	ErrUnexpectedEOF       = errors.New("wayland: unexpected end of message")
	ErrStringNotTerminated = errors.New("wayland: string not null-terminated")
)

Errors returned by the wire protocol.

Functions

func EncodeMessage

func EncodeMessage(msg *Message) ([]byte, error)

EncodeMessage encodes a Message to wire format. Returns the encoded bytes (FDs must be passed separately via SCM_RIGHTS).

func FixedToFloat

func FixedToFloat(f Fixed) float64

FixedToFloat is a helper that safely converts Fixed to float without overflow.

func RequiredGlobals

func RequiredGlobals() []string

RequiredGlobals returns a list of interface names required for a typical application.

Types

type CSDButtonState added in v0.26.0

type CSDButtonState struct {
	Hovered bool
	Pressed bool
}

CSDButtonState tracks interaction state for a control button.

type CSDEdge added in v0.26.0

type CSDEdge int

CSD edge identifiers.

const (
	CSDEdgeTop CSDEdge = iota
	CSDEdgeLeft
	CSDEdgeRight
	CSDEdgeBottom
)

type CSDHitResult added in v0.26.0

type CSDHitResult int

CSDHitResult identifies what region of a decoration a point falls in.

const (
	CSDHitNone     CSDHitResult = iota
	CSDHitCaption               // empty title bar area — drag to move
	CSDHitClose                 // close button
	CSDHitMaximize              // maximize/restore button
	CSDHitMinimize              // minimize button
	CSDHitResizeN               // top edge resize
	CSDHitResizeS               // bottom edge resize
	CSDHitResizeW               // left edge resize
	CSDHitResizeE               // right edge resize
	CSDHitResizeNW              // top-left corner resize
	CSDHitResizeNE              // top-right corner resize
	CSDHitResizeSW              // bottom-left corner resize
	CSDHitResizeSE              // bottom-right corner resize
)

type CSDManager added in v0.26.0

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

CSDManager manages client-side decorations using 4 wl_subsurfaces. It creates and maintains title bar (top) and border (left/right/bottom) subsurfaces around the main content surface.

func NewCSDManager added in v0.26.0

func NewCSDManager(
	display *Display,
	compositor *WlCompositor,
	subcompositor *WlSubcompositor,
	shm *WlShm,
	parent *WlSurface,
	painter CSDPainter,
) *CSDManager

NewCSDManager creates a CSD manager for the given parent surface.

func (*CSDManager) BorderWidth added in v0.26.0

func (m *CSDManager) BorderWidth() int

BorderWidth returns the side/bottom border width in pixels.

func (*CSDManager) BottomSurface added in v0.26.0

func (m *CSDManager) BottomSurface() *WlSurface

BottomSurface returns the bottom border wl_surface.

func (*CSDManager) Create added in v0.26.0

func (m *CSDManager) Create(contentWidth, contentHeight int, title string) error

Create creates all 4 decoration subsurfaces and their initial buffers.

func (*CSDManager) Destroy added in v0.26.0

func (m *CSDManager) Destroy()

Destroy destroys all decoration subsurfaces and frees resources.

func (*CSDManager) HitTestBorder added in v0.26.0

func (m *CSDManager) HitTestBorder(edge CSDEdge, x, y, width, height int) CSDHitResult

HitTestBorder performs hit-testing on a border subsurface.

func (*CSDManager) HitTestTop added in v0.26.0

func (m *CSDManager) HitTestTop(x, y int) CSDHitResult

HitTestTop performs hit-testing on the title bar subsurface.

func (*CSDManager) LeftSurface added in v0.26.0

func (m *CSDManager) LeftSurface() *WlSurface

LeftSurface returns the left border wl_surface.

func (*CSDManager) RepaintTitleBar added in v0.26.0

func (m *CSDManager) RepaintTitleBar()

RepaintTitleBar repaints only the title bar (for hover/press state changes).

func (*CSDManager) RightSurface added in v0.26.0

func (m *CSDManager) RightSurface() *WlSurface

RightSurface returns the right border wl_surface.

func (*CSDManager) SetFocused added in v0.26.0

func (m *CSDManager) SetFocused(focused bool)

SetFocused updates the focused state.

func (*CSDManager) SetState added in v0.26.0

func (m *CSDManager) SetState(state CSDState)

SetState updates the decoration state and repaints the title bar.

func (*CSDManager) State added in v0.26.0

func (m *CSDManager) State() *CSDState

State returns the current CSD state.

func (*CSDManager) TitleBarHeight added in v0.26.0

func (m *CSDManager) TitleBarHeight() int

TitleBarHeight returns the title bar height in pixels.

func (*CSDManager) TopSurface added in v0.26.0

func (m *CSDManager) TopSurface() *WlSurface

TopSurface returns the title bar wl_surface (for pointer event routing).

type CSDPainter added in v0.26.0

type CSDPainter interface {
	// TitleBarHeight returns the title bar height in pixels.
	TitleBarHeight() int

	// BorderWidth returns the side/bottom border width in pixels.
	BorderWidth() int

	// PaintTitleBar renders the title bar into an ARGB8888 buffer.
	// buf must be width*height*4 bytes. Stride = width*4.
	PaintTitleBar(buf []byte, width, height int, state CSDState)

	// PaintBorder renders a side/bottom border into an ARGB8888 buffer.
	PaintBorder(buf []byte, width, height int, edge CSDEdge)

	// HitTestTitleBar determines what the pointer is over in the title bar.
	HitTestTitleBar(x, y, width, height int) CSDHitResult
}

CSDPainter renders CSD decoration pixels into ARGB8888 buffers.

type CSDState added in v0.26.0

type CSDState struct {
	Title     string
	Focused   bool
	Maximized bool
	Close     CSDButtonState
	Maximize  CSDButtonState
	Minimize  CSDButtonState
}

CSDState holds the current decoration state for painting.

type Decoder

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

Decoder decodes Wayland messages from wire format.

func NewDecoder

func NewDecoder(buf []byte) *Decoder

NewDecoder creates a new Decoder with the given buffer.

func (*Decoder) Array

func (d *Decoder) Array() ([]byte, error)

Array reads a length-prefixed byte array.

func (*Decoder) DecodeHeader

func (d *Decoder) DecodeHeader() (ObjectID, Opcode, int, error)

DecodeHeader decodes a message header from the buffer. Returns the object ID, opcode, total message size, and any error.

func (*Decoder) DecodeMessage

func (d *Decoder) DecodeMessage() (*Message, error)

DecodeMessage decodes a complete message from the buffer. The decoder must be positioned at the start of a message.

func (*Decoder) FD

func (d *Decoder) FD() (int, error)

FD reads a file descriptor from the ancillary data.

func (*Decoder) Fixed

func (d *Decoder) Fixed() (Fixed, error)

Fixed reads a fixed-point number.

func (*Decoder) HasMore

func (d *Decoder) HasMore() bool

HasMore returns true if there are more bytes to read.

func (*Decoder) Int32

func (d *Decoder) Int32() (int32, error)

Int32 reads a signed 32-bit integer.

func (*Decoder) NewID

func (d *Decoder) NewID() (ObjectID, error)

NewID reads a new_id (just the object ID).

func (*Decoder) Object

func (d *Decoder) Object() (ObjectID, error)

Object reads an object ID.

func (*Decoder) Remaining

func (d *Decoder) Remaining() int

Remaining returns the number of unread bytes.

func (*Decoder) Reset

func (d *Decoder) Reset(buf []byte, fds []int)

Reset resets the decoder with a new buffer and file descriptors.

func (*Decoder) Skip

func (d *Decoder) Skip(n int) error

Skip advances the offset by n bytes.

func (*Decoder) String

func (d *Decoder) String() (string, error)

String reads a length-prefixed, null-terminated string.

func (*Decoder) Uint32

func (d *Decoder) Uint32() (uint32, error)

Uint32 reads an unsigned 32-bit integer.

type DefaultCSDPainter added in v0.26.0

type DefaultCSDPainter struct{}

DefaultCSDPainter provides a dark-themed title bar matching ui/core/titlebar/DefaultPainter.

func (DefaultCSDPainter) BorderWidth added in v0.26.0

func (DefaultCSDPainter) BorderWidth() int

func (DefaultCSDPainter) HitTestTitleBar added in v0.26.0

func (DefaultCSDPainter) HitTestTitleBar(x, y, width, height int) CSDHitResult

func (DefaultCSDPainter) PaintBorder added in v0.26.0

func (DefaultCSDPainter) PaintBorder(buf []byte, width, height int, _ CSDEdge)

func (DefaultCSDPainter) PaintTitleBar added in v0.26.0

func (DefaultCSDPainter) PaintTitleBar(buf []byte, width, height int, state CSDState)

func (DefaultCSDPainter) TitleBarHeight added in v0.26.0

func (DefaultCSDPainter) TitleBarHeight() int

type Display

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

Display represents a connection to the Wayland compositor. It is always object ID 1 in the Wayland protocol.

func Connect

func Connect() (*Display, error)

Connect establishes a connection to the Wayland compositor. It looks for the socket at $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY. If WAYLAND_DISPLAY is not set, it defaults to "wayland-0".

func ConnectTo

func ConnectTo(socketPath string) (*Display, error)

ConnectTo establishes a connection to the Wayland compositor at the given socket path.

func (*Display) AllocID

func (d *Display) AllocID() ObjectID

AllocID allocates a new object ID.

func (*Display) Close

func (d *Display) Close() error

Close closes the connection to the compositor.

func (*Display) Dispatch

func (d *Display) Dispatch() error

Dispatch reads and dispatches all pending events from the compositor.

func (*Display) DispatchOne

func (d *Display) DispatchOne() error

DispatchOne reads and dispatches a single event from the compositor.

func (*Display) DisplayID

func (d *Display) DisplayID() ObjectID

DisplayID returns the object ID of the display (always 1).

func (*Display) Fd

func (d *Display) Fd() int

Fd returns the file descriptor of the socket connection. This can be used with poll/epoll for event loop integration.

func (*Display) Flush

func (d *Display) Flush() error

Flush sends any buffered data to the compositor. This is typically not needed as messages are sent immediately.

func (*Display) GetProtocolError

func (d *Display) GetProtocolError() error

GetProtocolError returns any protocol error received from the compositor. Returns nil if no error has occurred.

func (*Display) GetRegistry

func (d *Display) GetRegistry() (*Registry, error)

GetRegistry requests the global registry from the compositor. The Registry is used to bind to global interfaces like wl_compositor.

func (*Display) Ptr

func (d *Display) Ptr() uintptr

Ptr returns the file descriptor as a uintptr for use with Vulkan surface creation. This is used with VK_KHR_wayland_surface extension. Note: In Wayland, we pass the fd as the "display pointer" since the Display struct wraps a Unix socket connection, not a C pointer.

func (*Display) RecvMessage

func (d *Display) RecvMessage() (*Message, error)

RecvMessage receives a message from the compositor. It may block if no message is available.

Wayland uses SOCK_STREAM sockets which do not preserve message boundaries. A single recvmsg() call may return multiple messages. We decode all messages from the buffer and queue extras for subsequent calls, preventing message loss that caused missing globals like xdg_wm_base (gogpu#74).

func (*Display) RegisterObject added in v0.21.0

func (d *Display) RegisterObject(id ObjectID, handler ObjectHandler)

RegisterObject registers an object handler for event dispatch. Events sent to the given object ID will be routed to the handler.

func (*Display) Roundtrip

func (d *Display) Roundtrip() error

Roundtrip performs a synchronous roundtrip to the compositor. It sends a sync request and waits for the callback, ensuring all previous requests have been processed.

func (*Display) SendMessage

func (d *Display) SendMessage(msg *Message) error

SendMessage sends a message to the compositor.

func (*Display) SetErrorHandler

func (d *Display) SetErrorHandler(handler func(objectID ObjectID, code uint32, message string))

SetErrorHandler sets a callback for protocol errors. The handler receives the object ID, error code, and error message.

func (*Display) Sync

func (d *Display) Sync() (<-chan uint32, error)

Sync sends a sync request and returns a channel that receives the callback data. This is used for roundtrip synchronization with the compositor.

func (*Display) UnregisterObject added in v0.21.0

func (d *Display) UnregisterObject(id ObjectID)

UnregisterObject removes an object handler from event dispatch.

type Encoder

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

Encoder encodes Wayland messages to the wire format.

func NewEncoder

func NewEncoder(capacity int) *Encoder

NewEncoder creates a new Encoder with the given initial buffer capacity.

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the encoded message bytes.

func (*Encoder) EncodeMessage

func (e *Encoder) EncodeMessage(objectID ObjectID, opcode Opcode, args []byte) ([]byte, error)

EncodeMessage encodes a complete message with header. The FDs field is not encoded here; FDs are passed via SCM_RIGHTS.

func (*Encoder) PutArray

func (e *Encoder) PutArray(data []byte)

PutArray appends a length-prefixed byte array. The array is padded to a 4-byte boundary.

func (*Encoder) PutFixed

func (e *Encoder) PutFixed(v Fixed)

PutFixed appends a fixed-point number.

func (*Encoder) PutInt32

func (e *Encoder) PutInt32(v int32)

PutInt32 appends a signed 32-bit integer.

func (*Encoder) PutNewID

func (e *Encoder) PutNewID(id ObjectID)

PutNewID appends a new_id argument (just the object ID, no interface/version).

func (*Encoder) PutNewIDFull

func (e *Encoder) PutNewIDFull(iface string, version uint32, id ObjectID)

PutNewIDFull appends a new_id argument with interface name and version. This is used for wl_registry.bind and similar dynamic binding.

func (*Encoder) PutObject

func (e *Encoder) PutObject(id ObjectID)

PutObject appends an object ID.

func (*Encoder) PutString

func (e *Encoder) PutString(s string)

PutString appends a length-prefixed, null-terminated string. The string is padded to a 4-byte boundary.

func (*Encoder) PutUint32

func (e *Encoder) PutUint32(v uint32)

PutUint32 appends an unsigned 32-bit integer.

func (*Encoder) Reset

func (e *Encoder) Reset()

Reset clears the encoder's buffer for reuse.

type Fixed

type Fixed int32

Fixed represents a Wayland fixed-point number (24.8 format). The upper 24 bits are the integer part, lower 8 bits are the fractional part.

func FixedFromFloat

func FixedFromFloat(f float64) Fixed

FixedFromFloat converts a float64 to Fixed (24.8 format).

func FixedFromInt

func FixedFromInt(i int32) Fixed

FixedFromInt converts an integer to Fixed.

func FloatToFixed

func FloatToFixed(f float64) Fixed

FloatToFixed converts a float64 to Fixed with clamping to valid range.

func (Fixed) Float

func (f Fixed) Float() float64

Float returns the Fixed value as a float64.

func (Fixed) Int

func (f Fixed) Int() int32

Int returns the integer part of the Fixed value.

type Global

type Global struct {
	// Name is the unique identifier for this global (used for binding).
	Name uint32

	// Interface is the interface name (e.g., "wl_compositor").
	Interface string

	// Version is the interface version supported by the compositor.
	Version uint32
}

Global represents a Wayland global interface advertised by the compositor.

type InputCallbacks added in v0.26.0

type InputCallbacks struct {
	// Pointer events on main surface
	OnPointerEnter  func(serial uint32, x, y float64)
	OnPointerLeave  func(serial uint32)
	OnPointerMotion func(timeMs uint32, x, y float64)
	OnPointerButton func(serial, timeMs, button, state uint32)
	OnPointerAxis   func(timeMs, axis uint32, value float64)

	// Keyboard events
	OnKeyboardKeymap    func(format uint32, fd int, size uint32)
	OnKeyboardEnter     func(serial uint32, keys []uint32)
	OnKeyboardLeave     func(serial uint32)
	OnKeyboardKey       func(serial, timeMs, key, state uint32)
	OnKeyboardModifiers func(serial, modsDepressed, modsLatched, modsLocked, group uint32)
	OnKeyboardRepeat    func(rate, delay int32)

	// Touch events
	OnTouchDown   func(serial, timeMs uint32, id int32, x, y float64)
	OnTouchUp     func(serial, timeMs uint32, id int32)
	OnTouchMotion func(timeMs uint32, id int32, x, y float64)
	OnTouchCancel func()

	// Close event from xdg_toplevel
	OnClose func()

	// Configure event from xdg_toplevel (width, height, states)
	OnConfigure func(width, height int32)
}

InputCallbacks holds Go-side callbacks for input events. Set by the platform layer (platform_linux.go) after LibwaylandHandle is created.

type KeyboardEnterEvent

type KeyboardEnterEvent struct {
	Serial  uint32   // Serial number.
	Surface ObjectID // The surface that gained keyboard focus.
	Keys    []uint32 // Array of currently pressed keys.
}

KeyboardEnterEvent contains data for the keyboard enter event.

type KeyboardKeyEvent

type KeyboardKeyEvent struct {
	Serial uint32 // Serial number.
	Time   uint32 // Timestamp in milliseconds.
	Key    uint32 // Key code (Linux evdev key code).
	State  uint32 // Key state (pressed/released).
}

KeyboardKeyEvent contains data for the key event.

type KeyboardKeymapEvent

type KeyboardKeymapEvent struct {
	Format uint32 // Keymap format (XKB or none).
	FD     int    // File descriptor containing the keymap.
	Size   uint32 // Size of the keymap data.
}

KeyboardKeymapEvent contains data for the keymap event.

type KeyboardLeaveEvent

type KeyboardLeaveEvent struct {
	Serial  uint32   // Serial number.
	Surface ObjectID // The surface that lost keyboard focus.
}

KeyboardLeaveEvent contains data for the keyboard leave event.

type KeyboardModifiersEvent

type KeyboardModifiersEvent struct {
	Serial        uint32 // Serial number.
	ModsDepressed uint32 // Currently pressed modifiers.
	ModsLatched   uint32 // Latched modifiers (e.g., Caps Lock toggled once).
	ModsLocked    uint32 // Locked modifiers (e.g., Caps Lock on).
	Group         uint32 // Keyboard layout group.
}

KeyboardModifiersEvent contains data for the modifiers event.

type KeyboardRepeatInfo

type KeyboardRepeatInfo struct {
	Rate  int32 // Key repeat rate in characters per second.
	Delay int32 // Delay before key repeat starts in milliseconds.
}

KeyboardRepeatInfo contains data for the repeat_info event.

type LibwaylandHandle added in v0.21.0

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

LibwaylandHandle holds C pointers from libwayland-client.so.0 for Vulkan surface creation. Vulkan's VK_KHR_wayland_surface requires real wl_display* and wl_surface* from the C library. Our pure Go Wayland speaks wire protocol directly and doesn't have C structs.

This follows the same pattern as x11/platform.go's xlibHandle: load the shared library via goffi, call minimal functions to get C pointers, use them for Vulkan only.

Unlike X11 (where Window IDs are server-side and shared across connections), Wayland surfaces are client-side proxies, so we must create the surface on the C connection too.

Key design: Global names from the pure Go Wayland registry are used to bind compositor and xdg_wm_base on the C connection. The xdg-shell role (xdg_surface + xdg_toplevel) is set up with goffi callbacks for configure/ping events. Callbacks are safe here because wl_display_roundtrip is called from Go — the callback fires on the same Go-managed thread (G is already loaded).

func OpenLibwayland added in v0.21.0

func OpenLibwayland(compositorName, compositorVersion, xdgWmBaseName, xdgWmBaseVersion, decorName, decorVersion uint32) (*LibwaylandHandle, error)

OpenLibwayland loads libwayland-client.so.0 and creates Vulkan-ready C pointers. compositorName/Version and xdgWmBaseName/Version come from the pure Go Wayland registry — global names are server-assigned and identical across all client connections. The xdg-shell role is required for Vulkan presentation (without it, the compositor won't composite the surface and vkQueuePresentKHR blocks forever).

func (*LibwaylandHandle) CSDActive added in v0.26.0

func (h *LibwaylandHandle) CSDActive() bool

CSDActive returns true if client-side decorations are active.

func (*LibwaylandHandle) CSDBorders added in v0.26.0

func (h *LibwaylandHandle) CSDBorders() (titleBarH, borderW int)

CSDBorders returns the CSD border dimensions: titleBarHeight, borderWidth. Used to subtract CSD borders from configure dimensions (GLFW pattern).

func (*LibwaylandHandle) Close added in v0.21.0

func (h *LibwaylandHandle) Close()

Close disconnects from the Wayland display and frees C resources. Destroys objects in reverse creation order.

func (*LibwaylandHandle) DispatchCSDEvents added in v0.26.0

func (h *LibwaylandHandle) DispatchCSDEvents() error

DispatchCSDEvents processes pending events on the C display (non-blocking). Flushes outgoing requests and dispatches any already-queued events. Must be called from the event loop (PollEvents). Returns error if the Wayland connection is broken.

func (*LibwaylandHandle) DispatchDefaultQueue added in v0.26.0

func (h *LibwaylandHandle) DispatchDefaultQueue() error

DispatchDefaultQueue dispatches pending events on the default queue (non-blocking). This handles xdg events, pointer, keyboard, touch — everything on the main display.

func (*LibwaylandHandle) Display added in v0.21.0

func (h *LibwaylandHandle) Display() uintptr

Display returns the wl_display* C pointer for Vulkan surface creation.

func (*LibwaylandHandle) Flush added in v0.26.0

func (h *LibwaylandHandle) Flush() error

Flush sends all buffered requests to the compositor.

func (*LibwaylandHandle) GetDisplayFD added in v0.26.0

func (h *LibwaylandHandle) GetDisplayFD() int

GetDisplayFD returns the Wayland display file descriptor for polling.

func (*LibwaylandHandle) InputSeat added in v0.26.0

func (h *LibwaylandHandle) InputSeat() uintptr

InputSeat returns the main input seat proxy pointer. Used by platform for serial-based operations.

func (*LibwaylandHandle) IsMaximized added in v0.26.0

func (h *LibwaylandHandle) IsMaximized() bool

IsMaximized returns true if the window is currently maximized.

func (*LibwaylandHandle) MarshalVoidOnToplevel added in v0.26.0

func (h *LibwaylandHandle) MarshalVoidOnToplevel(opcode uint32, args ...uintptr)

MarshalVoidOnToplevel sends a void request to the xdg_toplevel. Used for minimize, maximize, unset_maximized, fullscreen, etc.

func (*LibwaylandHandle) ResizeCSD added in v0.26.0

func (h *LibwaylandHandle) ResizeCSD(contentW, contentH int)

ResizeCSD updates all 4 CSD subsurface buffers and positions when the content area dimensions change (maximize, restore, interactive resize).

GLFW pattern: surfaces and subsurfaces are NEVER destroyed (only on window close). This preserves pointer state and avoids stale coordinates after maximize→restore transitions. All 4 decorations remain visible at all times, including when maximized (title bar + borders at screen edges).

Called from xdgSurfaceConfigureCb after ack_configure and before the parent surface commit. Subsurfaces in sync mode cache their commits until parent commit.

func (*LibwaylandHandle) Roundtrip added in v0.26.0

func (h *LibwaylandHandle) Roundtrip() error

Roundtrip performs a blocking roundtrip to the compositor.

func (*LibwaylandHandle) SetAppID added in v0.21.0

func (h *LibwaylandHandle) SetAppID(appID string)

SetAppID sets the application ID on the C xdg_toplevel. Uses xdg_toplevel.set_app_id (opcode 3, signature "s").

func (*LibwaylandHandle) SetAsInputHandler added in v0.26.0

func (h *LibwaylandHandle) SetAsInputHandler()

SetAsInputHandler sets this handle as the active input callback target.

func (*LibwaylandHandle) SetFullscreen added in v0.26.0

func (h *LibwaylandHandle) SetFullscreen()

SetFullscreen requests fullscreen mode on the C xdg_toplevel. Uses xdg_toplevel.set_fullscreen (opcode 11, signature "?o").

func (*LibwaylandHandle) SetInputCallbacks added in v0.26.0

func (h *LibwaylandHandle) SetInputCallbacks(cb *InputCallbacks)

SetInputCallbacks sets the input event callbacks. Must be called before SetupInput.

func (*LibwaylandHandle) SetMaxSize added in v0.26.0

func (h *LibwaylandHandle) SetMaxSize(width, height int32)

SetMaxSize sets the maximum window size on the C xdg_toplevel. Uses xdg_toplevel.set_max_size (opcode 7, signature "ii").

func (*LibwaylandHandle) SetMinSize added in v0.26.0

func (h *LibwaylandHandle) SetMinSize(width, height int32)

SetMinSize sets the minimum window size on the C xdg_toplevel. Uses xdg_toplevel.set_min_size (opcode 8, signature "ii").

func (*LibwaylandHandle) SetPendingCSDResize added in v0.26.1

func (h *LibwaylandHandle) SetPendingCSDResize(contentW, contentH int)

SetPendingCSDResize sets CSD content dimensions for deferred resize. Called by the platform layer when it determines CSD needs to resize (e.g., restore from maximize with saved dimensions). The actual resize happens in xdgSurfaceConfigureCb after ack_configure.

func (*LibwaylandHandle) SetTitle added in v0.21.0

func (h *LibwaylandHandle) SetTitle(title string)

SetTitle sets the window title on the C xdg_toplevel. Uses xdg_toplevel.set_title (opcode 2, signature "s").

func (*LibwaylandHandle) SetupCSD added in v0.26.0

func (h *LibwaylandHandle) SetupCSD(subcompName, subcompVersion, shmName, shmVersion, seatName, seatVersion uint32, contentW, contentH int, title string, painter CSDPainter, onClose func()) error

SetupCSD creates client-side decoration subsurfaces on the C display. This must be called after the main surface and xdg_toplevel are set up. subcompName/Version and shmName/Version come from the Pure Go registry.

func (*LibwaylandHandle) SetupInput added in v0.26.0

func (h *LibwaylandHandle) SetupInput(seatName, seatVersion uint32) error

SetupInput binds wl_seat on the C display and sets up pointer, keyboard, and touch listeners. Also registers xdg_toplevel listeners for configure/close. seatName/seatVersion come from the registry (discovered by registry listener).

func (*LibwaylandHandle) SetupToplevelListeners added in v0.26.0

func (h *LibwaylandHandle) SetupToplevelListeners() error

SetupToplevelListeners adds configure and close listeners on the xdg_toplevel. Must be called after setupXdgRole.

func (*LibwaylandHandle) Surface added in v0.21.0

func (h *LibwaylandHandle) Surface() uintptr

Surface returns the wl_surface* C pointer for Vulkan surface creation.

func (*LibwaylandHandle) Toplevel added in v0.26.0

func (h *LibwaylandHandle) Toplevel() uintptr

Toplevel returns the xdg_toplevel proxy pointer. Used by CSD for move/resize operations.

type Message

type Message struct {
	// ObjectID is the target object for requests or source object for events.
	ObjectID ObjectID

	// Opcode identifies the specific request or event.
	Opcode Opcode

	// Args contains the message arguments as raw bytes.
	// Use Decoder to extract typed values.
	Args []byte

	// FDs contains file descriptors passed with this message (SCM_RIGHTS).
	FDs []int
}

Message represents a Wayland wire protocol message. It can be either a request (client to server) or event (server to client).

func (*Message) Size

func (m *Message) Size() int

Size returns the total wire size of this message in bytes.

type MessageBuilder

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

MessageBuilder helps construct message arguments.

func NewMessageBuilder

func NewMessageBuilder() *MessageBuilder

NewMessageBuilder creates a new MessageBuilder.

func (*MessageBuilder) Build

func (b *MessageBuilder) Build() ([]byte, []int)

Build returns the encoded arguments and file descriptors.

func (*MessageBuilder) BuildMessage

func (b *MessageBuilder) BuildMessage(objectID ObjectID, opcode Opcode) *Message

BuildMessage returns a complete Message with the given header and built arguments.

func (*MessageBuilder) PutArray

func (b *MessageBuilder) PutArray(data []byte) *MessageBuilder

PutArray appends a byte array.

func (*MessageBuilder) PutFD

func (b *MessageBuilder) PutFD(fd int) *MessageBuilder

PutFD queues a file descriptor to be passed with the message.

func (*MessageBuilder) PutFixed

func (b *MessageBuilder) PutFixed(v Fixed) *MessageBuilder

PutFixed appends a fixed-point number.

func (*MessageBuilder) PutInt32

func (b *MessageBuilder) PutInt32(v int32) *MessageBuilder

PutInt32 appends a signed 32-bit integer.

func (*MessageBuilder) PutNewID

func (b *MessageBuilder) PutNewID(id ObjectID) *MessageBuilder

PutNewID appends a new_id argument.

func (*MessageBuilder) PutNewIDFull

func (b *MessageBuilder) PutNewIDFull(iface string, version uint32, id ObjectID) *MessageBuilder

PutNewIDFull appends a new_id with interface name and version.

func (*MessageBuilder) PutObject

func (b *MessageBuilder) PutObject(id ObjectID) *MessageBuilder

PutObject appends an object ID.

func (*MessageBuilder) PutString

func (b *MessageBuilder) PutString(s string) *MessageBuilder

PutString appends a string.

func (*MessageBuilder) PutUint32

func (b *MessageBuilder) PutUint32(v uint32) *MessageBuilder

PutUint32 appends an unsigned 32-bit integer.

func (*MessageBuilder) Reset

func (b *MessageBuilder) Reset()

Reset clears the builder for reuse.

type ObjectHandler added in v0.21.0

type ObjectHandler interface {
	// contains filtered or unexported methods
}

ObjectHandler is implemented by Wayland objects that receive events. Objects register themselves with Display to receive event dispatch.

type ObjectID

type ObjectID uint32

ObjectID represents a Wayland object identifier. Object ID 0 is null/invalid. Object ID 1 is always wl_display.

type Opcode

type Opcode uint16

Opcode represents a Wayland request or event opcode.

const (
	DisplayErrorInvalidObject  Opcode = 0 // server couldn't find object
	DisplayErrorInvalidMethod  Opcode = 1 // method doesn't exist on the specified interface
	DisplayErrorNoMemory       Opcode = 2 // server is out of memory
	DisplayErrorImplementation Opcode = 3 // implementation error in compositor
)

Display error codes (from wayland.xml).

type PointerAxisEvent

type PointerAxisEvent struct {
	Time  uint32  // Timestamp in milliseconds.
	Axis  uint32  // Axis type (vertical/horizontal).
	Value float64 // Scroll amount (positive = down/right).
}

PointerAxisEvent contains data for the pointer axis (scroll) event.

type PointerButtonEvent

type PointerButtonEvent struct {
	Serial uint32 // Serial number for grabs.
	Time   uint32 // Timestamp in milliseconds.
	Button uint32 // Button code (BTN_LEFT, BTN_RIGHT, etc.).
	State  uint32 // Button state (pressed/released).
}

PointerButtonEvent contains data for the pointer button event.

type PointerEnterEvent

type PointerEnterEvent struct {
	Serial   uint32   // Serial number for cursor changes.
	Surface  ObjectID // The surface the pointer entered.
	SurfaceX float64  // X position in surface-local coordinates.
	SurfaceY float64  // Y position in surface-local coordinates.
}

PointerEnterEvent contains data for the pointer enter event.

type PointerLeaveEvent

type PointerLeaveEvent struct {
	Serial  uint32   // Serial number.
	Surface ObjectID // The surface the pointer left.
}

PointerLeaveEvent contains data for the pointer leave event.

type PointerMotionEvent

type PointerMotionEvent struct {
	Time     uint32  // Timestamp in milliseconds.
	SurfaceX float64 // X position in surface-local coordinates.
	SurfaceY float64 // Y position in surface-local coordinates.
}

PointerMotionEvent contains data for the pointer motion event.

type Registry

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

Registry represents the wl_registry interface. It receives advertisements of global interfaces from the compositor and allows clients to bind to them.

func (*Registry) Bind

func (r *Registry) Bind(name uint32, iface string, version uint32) (ObjectID, error)

Bind binds to a global interface, creating a new object. Returns the object ID of the newly created object.

Parameters:

  • name: The name of the global (from the global event)
  • iface: The interface name (must match the global's interface)
  • version: The version to bind (must be <= global's version)

func (*Registry) BindCompositor

func (r *Registry) BindCompositor(version uint32) (ObjectID, error)

BindCompositor binds to the wl_compositor global.

func (*Registry) BindOutput added in v0.26.0

func (r *Registry) BindOutput(name uint32, version uint32) (ObjectID, error)

BindOutput binds to a wl_output global by its name.

func (*Registry) BindSeat

func (r *Registry) BindSeat(version uint32) (ObjectID, error)

BindSeat binds to the wl_seat global.

func (*Registry) BindShm

func (r *Registry) BindShm(version uint32) (ObjectID, error)

BindShm binds to the wl_shm global.

func (*Registry) BindSubcompositor added in v0.26.0

func (r *Registry) BindSubcompositor(version uint32) (ObjectID, error)

BindSubcompositor binds to the wl_subcompositor global.

func (*Registry) BindXdgWmBase

func (r *Registry) BindXdgWmBase(version uint32) (ObjectID, error)

BindXdgWmBase binds to the xdg_wm_base global.

func (*Registry) BindZxdgDecorationManager added in v0.21.0

func (r *Registry) BindZxdgDecorationManager(version uint32) (ObjectID, error)

BindZxdgDecorationManager binds to the zxdg_decoration_manager_v1 global.

func (*Registry) CheckRequiredGlobals

func (r *Registry) CheckRequiredGlobals() []string

CheckRequiredGlobals checks if all required globals are available. Returns a list of missing interface names, or nil if all are present.

func (*Registry) FindAllGlobals added in v0.26.0

func (r *Registry) FindAllGlobals(iface string) []uint32

FindAllGlobals finds all globals with the given interface name. Returns their names (for use with Bind).

func (*Registry) FindGlobal

func (r *Registry) FindGlobal(iface string) (uint32, error)

FindGlobal finds a global by interface name and returns its name. Returns an error if the global is not found.

func (*Registry) GetGlobal

func (r *Registry) GetGlobal(name uint32) *Global

GetGlobal returns a global by name. Returns nil if the global is not found.

func (*Registry) GetGlobalByInterface

func (r *Registry) GetGlobalByInterface(iface string) *Global

GetGlobalByInterface returns a global by interface name. Returns nil if the global is not found.

func (*Registry) GlobalVersion

func (r *Registry) GlobalVersion(iface string) uint32

GlobalVersion returns the version of a global interface. Returns 0 if the global is not found.

func (*Registry) HasGlobal

func (r *Registry) HasGlobal(iface string) bool

HasGlobal returns true if a global with the given interface exists.

func (*Registry) ID

func (r *Registry) ID() ObjectID

ID returns the object ID of the registry.

func (*Registry) ListGlobals

func (r *Registry) ListGlobals() []*Global

ListGlobals returns a copy of all known globals.

func (*Registry) SetGlobalHandler

func (r *Registry) SetGlobalHandler(handler func(global *Global))

SetGlobalHandler sets a callback for the global event. The handler is called when the compositor advertises a new global.

func (*Registry) SetGlobalRemoveHandler

func (r *Registry) SetGlobalRemoveHandler(handler func(name uint32))

SetGlobalRemoveHandler sets a callback for the global_remove event. The handler is called when a global is no longer available.

func (*Registry) WaitForGlobals

func (r *Registry) WaitForGlobals(required []string, maxAttempts int) error

WaitForGlobals waits for all required globals to be advertised. It performs roundtrips until all required globals are available or the maximum number of attempts is reached.

type ShmFormat

type ShmFormat uint32

ShmFormat represents a pixel format supported by wl_shm. These match the wl_shm_format enum from wayland.xml.

const (
	// ShmFormatARGB8888 is 32-bit ARGB (8-8-8-8), little-endian.
	ShmFormatARGB8888 ShmFormat = 0

	// ShmFormatXRGB8888 is 32-bit RGB (8-8-8-8), little-endian, no alpha.
	ShmFormatXRGB8888 ShmFormat = 1

	// ShmFormatC8 is 8-bit color index.
	ShmFormatC8 ShmFormat = 0x20203843

	// ShmFormatRGB332 is 8-bit RGB (3-3-2).
	ShmFormatRGB332 ShmFormat = 0x38424752

	// ShmFormatBGR233 is 8-bit BGR (2-3-3).
	ShmFormatBGR233 ShmFormat = 0x38524742

	// ShmFormatXRGB4444 is 16-bit xRGB (4-4-4-4).
	ShmFormatXRGB4444 ShmFormat = 0x32315258

	// ShmFormatXBGR4444 is 16-bit xBGR (4-4-4-4).
	ShmFormatXBGR4444 ShmFormat = 0x32314258

	// ShmFormatRGBX4444 is 16-bit RGBx (4-4-4-4).
	ShmFormatRGBX4444 ShmFormat = 0x32315852

	// ShmFormatBGRX4444 is 16-bit BGRx (4-4-4-4).
	ShmFormatBGRX4444 ShmFormat = 0x32315842

	// ShmFormatARGB4444 is 16-bit ARGB (4-4-4-4).
	ShmFormatARGB4444 ShmFormat = 0x32315241

	// ShmFormatABGR4444 is 16-bit ABGR (4-4-4-4).
	ShmFormatABGR4444 ShmFormat = 0x32314241

	// ShmFormatRGBA4444 is 16-bit RGBA (4-4-4-4).
	ShmFormatRGBA4444 ShmFormat = 0x32314152

	// ShmFormatBGRA4444 is 16-bit BGRA (4-4-4-4).
	ShmFormatBGRA4444 ShmFormat = 0x32314142

	// ShmFormatXRGB1555 is 16-bit xRGB (1-5-5-5).
	ShmFormatXRGB1555 ShmFormat = 0x35315258

	// ShmFormatXBGR1555 is 16-bit xBGR (1-5-5-5).
	ShmFormatXBGR1555 ShmFormat = 0x35314258

	// ShmFormatRGBX5551 is 16-bit RGBx (5-5-5-1).
	ShmFormatRGBX5551 ShmFormat = 0x35315852

	// ShmFormatBGRX5551 is 16-bit BGRx (5-5-5-1).
	ShmFormatBGRX5551 ShmFormat = 0x35315842

	// ShmFormatARGB1555 is 16-bit ARGB (1-5-5-5).
	ShmFormatARGB1555 ShmFormat = 0x35315241

	// ShmFormatABGR1555 is 16-bit ABGR (1-5-5-5).
	ShmFormatABGR1555 ShmFormat = 0x35314241

	// ShmFormatRGBA5551 is 16-bit RGBA (5-5-5-1).
	ShmFormatRGBA5551 ShmFormat = 0x35314152

	// ShmFormatBGRA5551 is 16-bit BGRA (5-5-5-1).
	ShmFormatBGRA5551 ShmFormat = 0x35314142

	// ShmFormatRGB565 is 16-bit RGB (5-6-5).
	ShmFormatRGB565 ShmFormat = 0x36314752

	// ShmFormatBGR565 is 16-bit BGR (5-6-5).
	ShmFormatBGR565 ShmFormat = 0x36314742

	// ShmFormatRGB888 is 24-bit RGB (8-8-8).
	ShmFormatRGB888 ShmFormat = 0x34324752

	// ShmFormatBGR888 is 24-bit BGR (8-8-8).
	ShmFormatBGR888 ShmFormat = 0x34324742

	// ShmFormatXBGR8888 is 32-bit xBGR (8-8-8-8).
	ShmFormatXBGR8888 ShmFormat = 0x34324258

	// ShmFormatRGBX8888 is 32-bit RGBx (8-8-8-8).
	ShmFormatRGBX8888 ShmFormat = 0x34325852

	// ShmFormatBGRX8888 is 32-bit BGRx (8-8-8-8).
	ShmFormatBGRX8888 ShmFormat = 0x34325842

	// ShmFormatABGR8888 is 32-bit ABGR (8-8-8-8).
	ShmFormatABGR8888 ShmFormat = 0x34324241

	// ShmFormatRGBA8888 is 32-bit RGBA (8-8-8-8).
	ShmFormatRGBA8888 ShmFormat = 0x34324152

	// ShmFormatBGRA8888 is 32-bit BGRA (8-8-8-8).
	ShmFormatBGRA8888 ShmFormat = 0x34324142
)

Common wl_shm_format values (subset).

func (ShmFormat) String

func (f ShmFormat) String() string

String returns a human-readable name for common formats.

type TouchDownEvent added in v0.20.1

type TouchDownEvent struct {
	Serial  uint32   // Serial number.
	Time    uint32   // Timestamp in milliseconds.
	Surface ObjectID // The surface that was touched.
	ID      int32    // Touch point ID.
	X       float64  // Surface-local X coordinate.
	Y       float64  // Surface-local Y coordinate.
}

TouchDownEvent contains data for the touch down event.

type TouchMotionEvent added in v0.20.1

type TouchMotionEvent struct {
	Time uint32  // Timestamp in milliseconds.
	ID   int32   // Touch point ID.
	X    float64 // Surface-local X coordinate.
	Y    float64 // Surface-local Y coordinate.
}

TouchMotionEvent contains data for the touch motion event.

type TouchUpEvent added in v0.20.1

type TouchUpEvent struct {
	Serial uint32 // Serial number.
	Time   uint32 // Timestamp in milliseconds.
	ID     int32  // Touch point ID.
}

TouchUpEvent contains data for the touch up event.

type WlBuffer

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

WlBuffer represents the wl_buffer interface. A buffer contains pixel data that can be attached to a surface.

func NewWlBuffer

func NewWlBuffer(display *Display, objectID ObjectID) *WlBuffer

NewWlBuffer creates a WlBuffer from an object ID. It auto-registers with Display for event dispatch (release events).

func (*WlBuffer) Destroy

func (b *WlBuffer) Destroy() error

Destroy destroys the buffer.

func (*WlBuffer) ID

func (b *WlBuffer) ID() ObjectID

ID returns the object ID of the buffer.

func (*WlBuffer) SetReleaseHandler

func (b *WlBuffer) SetReleaseHandler(handler func())

SetReleaseHandler sets a callback for the release event. The release event is sent when the compositor is done using the buffer. After receiving this event, the client can safely modify or reuse the buffer.

type WlCallback

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

WlCallback represents the wl_callback interface. Callbacks are used for one-shot notifications, typically for frame synchronization.

func NewWlCallback

func NewWlCallback(display *Display, objectID ObjectID) *WlCallback

NewWlCallback creates a WlCallback from an object ID.

func (*WlCallback) Done

func (c *WlCallback) Done() <-chan uint32

Done returns a channel that receives the callback data when the callback fires. The channel is closed after the callback fires.

func (*WlCallback) ID

func (c *WlCallback) ID() ObjectID

ID returns the object ID of the callback.

type WlCompositor

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

WlCompositor represents the wl_compositor interface. It is responsible for creating surfaces and regions.

func NewWlCompositor

func NewWlCompositor(display *Display, objectID ObjectID) *WlCompositor

NewWlCompositor creates a WlCompositor from a bound object ID. The objectID should be obtained from Registry.BindCompositor().

func (*WlCompositor) CreateSurface

func (c *WlCompositor) CreateSurface() (*WlSurface, error)

CreateSurface creates a new surface. The returned surface is used for creating a window via xdg_shell or for Vulkan/EGL surface creation.

func (*WlCompositor) ID

func (c *WlCompositor) ID() ObjectID

ID returns the object ID of the compositor.

type WlKeyboard

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

WlKeyboard represents the wl_keyboard interface. This interface provides access to keyboard input events.

func NewWlKeyboard

func NewWlKeyboard(display *Display, objectID ObjectID) *WlKeyboard

NewWlKeyboard creates a WlKeyboard from an object ID. It auto-registers with Display for event dispatch (keymap, key, modifiers events).

func (*WlKeyboard) FocusedSurface

func (k *WlKeyboard) FocusedSurface() ObjectID

FocusedSurface returns the surface that currently has keyboard focus. Returns 0 if no surface has focus.

func (*WlKeyboard) ID

func (k *WlKeyboard) ID() ObjectID

ID returns the object ID of the keyboard.

func (*WlKeyboard) KeymapFD

func (k *WlKeyboard) KeymapFD() int

KeymapFD returns the file descriptor for the keymap. Returns -1 if no keymap has been received. The caller is responsible for closing this FD when done.

func (*WlKeyboard) KeymapSize

func (k *WlKeyboard) KeymapSize() uint32

KeymapSize returns the size of the keymap data.

func (*WlKeyboard) LastSerial

func (k *WlKeyboard) LastSerial() uint32

LastSerial returns the last event serial.

func (*WlKeyboard) Release

func (k *WlKeyboard) Release() error

Release destroys the keyboard object (v3+).

func (*WlKeyboard) RepeatInfo

func (k *WlKeyboard) RepeatInfo() (rate, delay int32)

RepeatInfo returns the key repeat rate and delay.

func (*WlKeyboard) SetEnterHandler

func (k *WlKeyboard) SetEnterHandler(handler func(event *KeyboardEnterEvent))

SetEnterHandler sets a callback for the enter event.

func (*WlKeyboard) SetKeyHandler

func (k *WlKeyboard) SetKeyHandler(handler func(event *KeyboardKeyEvent))

SetKeyHandler sets a callback for the key event.

func (*WlKeyboard) SetKeymapHandler

func (k *WlKeyboard) SetKeymapHandler(handler func(event *KeyboardKeymapEvent))

SetKeymapHandler sets a callback for the keymap event. The handler receives the keymap format, file descriptor, and size. Note: The FD must be closed by the application when no longer needed.

func (*WlKeyboard) SetLeaveHandler

func (k *WlKeyboard) SetLeaveHandler(handler func(event *KeyboardLeaveEvent))

SetLeaveHandler sets a callback for the leave event.

func (*WlKeyboard) SetModifiersHandler

func (k *WlKeyboard) SetModifiersHandler(handler func(event *KeyboardModifiersEvent))

SetModifiersHandler sets a callback for the modifiers event.

func (*WlKeyboard) SetRepeatInfoHandler

func (k *WlKeyboard) SetRepeatInfoHandler(handler func(info *KeyboardRepeatInfo))

SetRepeatInfoHandler sets a callback for the repeat_info event (v4+).

type WlOutput added in v0.26.0

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

WlOutput represents the wl_output interface. It provides information about an output (monitor), including its scale factor.

func NewWlOutput added in v0.26.0

func NewWlOutput(display *Display, objectID ObjectID) *WlOutput

NewWlOutput creates a WlOutput from a bound object ID. It auto-registers with Display for event dispatch.

func (*WlOutput) ID added in v0.26.0

func (o *WlOutput) ID() ObjectID

ID returns the object ID of the output.

func (*WlOutput) Scale added in v0.26.0

func (o *WlOutput) Scale() int32

Scale returns the current scale factor for this output. Returns 1 if no scale event has been received yet.

func (*WlOutput) SetScaleHandler added in v0.26.0

func (o *WlOutput) SetScaleHandler(handler func(scale int32))

SetScaleHandler sets a callback for the scale event. The handler is called when the compositor sends a new scale factor.

type WlPointer

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

WlPointer represents the wl_pointer interface. This interface provides access to pointer (mouse) input events.

func NewWlPointer

func NewWlPointer(display *Display, objectID ObjectID) *WlPointer

NewWlPointer creates a WlPointer from an object ID. It auto-registers with Display for event dispatch (motion, button, axis events).

func (*WlPointer) EnteredSurface

func (p *WlPointer) EnteredSurface() ObjectID

EnteredSurface returns the surface the pointer is currently over. Returns 0 if the pointer is not over any surface.

func (*WlPointer) ID

func (p *WlPointer) ID() ObjectID

ID returns the object ID of the pointer.

func (*WlPointer) LastSerial

func (p *WlPointer) LastSerial() uint32

LastSerial returns the last event serial (useful for cursor changes).

func (*WlPointer) Position

func (p *WlPointer) Position() (x, y float64)

Position returns the current pointer position in surface-local coordinates.

func (*WlPointer) Release

func (p *WlPointer) Release() error

Release destroys the pointer object (v3+).

func (*WlPointer) SetAxisDiscreteHandler

func (p *WlPointer) SetAxisDiscreteHandler(handler func(axis uint32, discrete int32))

SetAxisDiscreteHandler sets a callback for the axis_discrete event (v5+).

func (*WlPointer) SetAxisHandler

func (p *WlPointer) SetAxisHandler(handler func(event *PointerAxisEvent))

SetAxisHandler sets a callback for the axis (scroll) event.

func (*WlPointer) SetAxisSourceHandler

func (p *WlPointer) SetAxisSourceHandler(handler func(source uint32))

SetAxisSourceHandler sets a callback for the axis_source event (v5+).

func (*WlPointer) SetAxisStopHandler

func (p *WlPointer) SetAxisStopHandler(handler func(time uint32, axis uint32))

SetAxisStopHandler sets a callback for the axis_stop event (v5+).

func (*WlPointer) SetButtonHandler

func (p *WlPointer) SetButtonHandler(handler func(event *PointerButtonEvent))

SetButtonHandler sets a callback for the button event.

func (*WlPointer) SetCursor

func (p *WlPointer) SetCursor(serial uint32, surface *WlSurface, hotspotX, hotspotY int32) error

SetCursor sets the pointer cursor image. The serial should be from a recent pointer event (enter/button/motion). Pass surface=0 to hide the cursor. hotspotX/hotspotY specify the cursor hotspot offset within the surface.

func (*WlPointer) SetEnterHandler

func (p *WlPointer) SetEnterHandler(handler func(event *PointerEnterEvent))

SetEnterHandler sets a callback for the enter event.

func (*WlPointer) SetFrameHandler

func (p *WlPointer) SetFrameHandler(handler func())

SetFrameHandler sets a callback for the frame event (v5+). The frame event marks the end of a group of related events.

func (*WlPointer) SetLeaveHandler

func (p *WlPointer) SetLeaveHandler(handler func(event *PointerLeaveEvent))

SetLeaveHandler sets a callback for the leave event.

func (*WlPointer) SetMotionHandler

func (p *WlPointer) SetMotionHandler(handler func(event *PointerMotionEvent))

SetMotionHandler sets a callback for the motion event.

type WlSeat

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

WlSeat represents the wl_seat interface. A seat is a group of input devices (keyboard, pointer, touch) that belong together (e.g., a laptop's built-in keyboard and touchpad).

func NewWlSeat

func NewWlSeat(display *Display, objectID ObjectID, version uint32) *WlSeat

NewWlSeat creates a WlSeat from a bound object ID. The objectID should be obtained from Registry.BindSeat(). It auto-registers with Display for event dispatch (capabilities, name events).

func (*WlSeat) Capabilities

func (s *WlSeat) Capabilities() uint32

Capabilities returns the current capability bitmask.

func (*WlSeat) GetKeyboard

func (s *WlSeat) GetKeyboard() (*WlKeyboard, error)

GetKeyboard creates a wl_keyboard object for this seat. Returns an error if the seat does not have keyboard capability.

func (*WlSeat) GetPointer

func (s *WlSeat) GetPointer() (*WlPointer, error)

GetPointer creates a wl_pointer object for this seat. Returns an error if the seat does not have pointer capability.

func (*WlSeat) GetTouch added in v0.20.1

func (s *WlSeat) GetTouch() (*WlTouch, error)

GetTouch creates a wl_touch object for this seat. Returns an error if the seat does not have touch capability.

func (*WlSeat) HasKeyboard

func (s *WlSeat) HasKeyboard() bool

HasKeyboard returns true if the seat has a keyboard device.

func (*WlSeat) HasPointer

func (s *WlSeat) HasPointer() bool

HasPointer returns true if the seat has a pointer device.

func (*WlSeat) HasTouch

func (s *WlSeat) HasTouch() bool

HasTouch returns true if the seat has a touch device.

func (*WlSeat) ID

func (s *WlSeat) ID() ObjectID

ID returns the object ID of the seat.

func (*WlSeat) Name

func (s *WlSeat) Name() string

Name returns the seat name (empty if not yet received or version < 2).

func (*WlSeat) Release

func (s *WlSeat) Release() error

Release destroys the seat object (v5+). This releases any resources held by the server for this seat binding.

func (*WlSeat) SetCapabilitiesHandler

func (s *WlSeat) SetCapabilitiesHandler(handler func(capabilities uint32))

SetCapabilitiesHandler sets a callback for the capabilities event. The handler is called when the seat's capabilities change.

func (*WlSeat) SetNameHandler

func (s *WlSeat) SetNameHandler(handler func(name string))

SetNameHandler sets a callback for the name event (v2+). The handler is called when the seat name is received.

func (*WlSeat) Version

func (s *WlSeat) Version() uint32

Version returns the interface version.

type WlShm

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

WlShm represents the wl_shm interface. It provides shared memory support for creating buffers.

func NewWlShm

func NewWlShm(display *Display, objectID ObjectID) *WlShm

NewWlShm creates a WlShm from a bound object ID. The objectID should be obtained from Registry.BindShm(). It auto-registers with Display for event dispatch (format events).

func (*WlShm) CreatePool

func (s *WlShm) CreatePool(fd int, size int32) (*WlShmPool, error)

CreatePool creates a new shared memory pool from a file descriptor. The fd should be a file descriptor to a shared memory object (e.g., from shm_open or memfd_create). The size is the size of the pool in bytes. The file descriptor is consumed by this call and should not be used afterward.

func (*WlShm) Formats

func (s *WlShm) Formats() []ShmFormat

Formats returns a copy of the supported pixel formats. This list is populated by format events from the compositor. Call Display.Roundtrip() after binding to ensure formats are received.

func (*WlShm) HasFormat

func (s *WlShm) HasFormat(format ShmFormat) bool

HasFormat returns true if the given format is supported.

func (*WlShm) ID

func (s *WlShm) ID() ObjectID

ID returns the object ID of the shm.

func (*WlShm) SetFormatHandler

func (s *WlShm) SetFormatHandler(handler func(format ShmFormat))

SetFormatHandler sets a callback for the format event. The handler is called when the compositor advertises a supported format.

type WlShmPool

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

WlShmPool represents the wl_shm_pool interface. A pool is a chunk of shared memory from which buffers can be created.

func NewWlShmPool

func NewWlShmPool(display *Display, objectID ObjectID, size int32) *WlShmPool

NewWlShmPool creates a WlShmPool from an object ID.

func (*WlShmPool) CreateBuffer

func (p *WlShmPool) CreateBuffer(offset, width, height, stride int32, format ShmFormat) (*WlBuffer, error)

CreateBuffer creates a buffer from this pool. Parameters:

  • offset: byte offset within the pool
  • width: width of the buffer in pixels
  • height: height of the buffer in pixels
  • stride: number of bytes per row
  • format: pixel format

func (*WlShmPool) Destroy

func (p *WlShmPool) Destroy() error

Destroy destroys the pool. Buffers created from this pool remain valid after the pool is destroyed.

func (*WlShmPool) ID

func (p *WlShmPool) ID() ObjectID

ID returns the object ID of the pool.

func (*WlShmPool) Resize

func (p *WlShmPool) Resize(size int32) error

Resize resizes the pool. This can only make the pool larger. The size parameter is the new size in bytes.

func (*WlShmPool) Size

func (p *WlShmPool) Size() int32

Size returns the size of the pool in bytes.

type WlSubcompositor added in v0.26.0

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

WlSubcompositor represents the wl_subcompositor interface. It creates subsurfaces that are composited relative to a parent surface.

func NewWlSubcompositor added in v0.26.0

func NewWlSubcompositor(display *Display, objectID ObjectID) *WlSubcompositor

NewWlSubcompositor creates a WlSubcompositor from a bound object ID.

func (*WlSubcompositor) Destroy added in v0.26.0

func (sc *WlSubcompositor) Destroy() error

Destroy destroys the subcompositor.

func (*WlSubcompositor) GetSubsurface added in v0.26.0

func (sc *WlSubcompositor) GetSubsurface(surface, parent *WlSurface) (*WlSubsurface, error)

GetSubsurface creates a subsurface for the given surface, attached to parent. The surface must not already be a subsurface or have a role. The subsurface is initially in sync mode and positioned at (0, 0).

func (*WlSubcompositor) ID added in v0.26.0

func (sc *WlSubcompositor) ID() ObjectID

ID returns the object ID.

type WlSubsurface added in v0.26.0

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

WlSubsurface represents the wl_subsurface interface. A subsurface is composited relative to its parent surface. It has its own wl_surface for content (buffers, damage, commit).

func (*WlSubsurface) Destroy added in v0.26.0

func (ss *WlSubsurface) Destroy() error

Destroy destroys the subsurface. The wl_surface is not destroyed.

func (*WlSubsurface) ID added in v0.26.0

func (ss *WlSubsurface) ID() ObjectID

ID returns the object ID.

func (*WlSubsurface) Parent added in v0.26.0

func (ss *WlSubsurface) Parent() *WlSurface

Parent returns the parent wl_surface.

func (*WlSubsurface) PlaceAbove added in v0.26.0

func (ss *WlSubsurface) PlaceAbove(sibling *WlSurface) error

PlaceAbove places this subsurface above the given sibling surface. The sibling must be a sibling subsurface or the parent surface.

func (*WlSubsurface) PlaceBelow added in v0.26.0

func (ss *WlSubsurface) PlaceBelow(sibling *WlSurface) error

PlaceBelow places this subsurface below the given sibling surface.

func (*WlSubsurface) SetDesync added in v0.26.0

func (ss *WlSubsurface) SetDesync() error

SetDesync sets the subsurface to desynchronized mode. In desync mode, the subsurface's commits take effect immediately.

func (*WlSubsurface) SetPosition added in v0.26.0

func (ss *WlSubsurface) SetPosition(x, y int32) error

SetPosition sets the position of the subsurface relative to its parent. The position is applied on the next parent surface commit (double-buffered).

func (*WlSubsurface) SetSync added in v0.26.0

func (ss *WlSubsurface) SetSync() error

SetSync sets the subsurface to synchronized mode. In sync mode, the subsurface's state (position, buffer) is committed atomically with the parent surface's state. This is the default mode.

func (*WlSubsurface) Surface added in v0.26.0

func (ss *WlSubsurface) Surface() *WlSurface

Surface returns the child wl_surface associated with this subsurface.

type WlSurface

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

WlSurface represents the wl_surface interface. A surface is a rectangular area used to display content. Surfaces are used as the basis for windows, popups, and subsurfaces.

func NewWlSurface

func NewWlSurface(display *Display, objectID ObjectID) *WlSurface

NewWlSurface creates a WlSurface from an object ID. It auto-registers with Display for event dispatch (enter, leave events).

func (*WlSurface) Attach

func (s *WlSurface) Attach(buffer ObjectID, x, y int32) error

Attach attaches a buffer to the surface. The x and y arguments specify the offset from the new buffer's position to the current surface position. If buffer is 0, the surface is unmapped.

func (*WlSurface) Commit

func (s *WlSurface) Commit() error

Commit commits the pending surface state. This atomically applies all pending changes (buffer, damage, etc.) and submits them to the compositor.

func (*WlSurface) Damage

func (s *WlSurface) Damage(x, y, width, height int32) error

Damage marks a region of the surface as damaged. This tells the compositor which parts of the surface have changed. The compositor uses this to optimize repainting.

func (*WlSurface) DamageBuffer

func (s *WlSurface) DamageBuffer(x, y, width, height int32) error

DamageBuffer marks a region of the buffer as damaged (version 4+). This is similar to Damage but uses buffer coordinates instead of surface coordinates.

func (*WlSurface) Destroy

func (s *WlSurface) Destroy() error

Destroy destroys the surface. All resources associated with this surface are released.

func (*WlSurface) Frame

func (s *WlSurface) Frame() (*WlCallback, error)

Frame requests a frame callback for animation synchronization. The returned callback will be triggered when it's time to draw the next frame.

func (*WlSurface) ID

func (s *WlSurface) ID() ObjectID

ID returns the object ID of the surface.

func (*WlSurface) Ptr

func (s *WlSurface) Ptr() uintptr

Ptr returns the object ID as a uintptr for use with Vulkan surface creation. This is used with VK_KHR_wayland_surface extension. Note: In pure Go Wayland implementation, we return the object ID since we don't have a C wl_surface pointer. The GPU backend will need to handle this appropriately.

func (*WlSurface) SetBufferScale

func (s *WlSurface) SetBufferScale(scale int32) error

SetBufferScale sets the buffer scale factor (version 3+). This is used for HiDPI displays. A scale of 2 means each buffer pixel covers 2x2 surface pixels.

func (*WlSurface) SetBufferTransform

func (s *WlSurface) SetBufferTransform(transform int32) error

SetBufferTransform sets the buffer transformation (version 2+). The transform specifies how to rotate/flip the buffer contents.

func (*WlSurface) SetEnterHandler

func (s *WlSurface) SetEnterHandler(handler func(outputID ObjectID))

SetEnterHandler sets a callback for the enter event. The handler is called when the surface enters an output (monitor).

func (*WlSurface) SetInputRegion

func (s *WlSurface) SetInputRegion(region ObjectID) error

SetInputRegion sets the input region of the surface. Only input events within this region will be delivered to the client. Pass 0 to accept input on the entire surface.

func (*WlSurface) SetLeaveHandler

func (s *WlSurface) SetLeaveHandler(handler func(outputID ObjectID))

SetLeaveHandler sets a callback for the leave event. The handler is called when the surface leaves an output (monitor).

func (*WlSurface) SetOpaqueRegion

func (s *WlSurface) SetOpaqueRegion(region ObjectID) error

SetOpaqueRegion sets the opaque region of the surface. The compositor may optimize painting by not drawing content behind opaque regions. Pass 0 to unset the opaque region.

type WlTouch added in v0.20.1

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

WlTouch represents the wl_touch interface. This interface provides access to touch input events.

func NewWlTouch added in v0.20.1

func NewWlTouch(display *Display, objectID ObjectID) *WlTouch

NewWlTouch creates a WlTouch from an object ID. It auto-registers with Display for event dispatch (down, up, motion events).

func (*WlTouch) ID added in v0.20.1

func (t *WlTouch) ID() ObjectID

ID returns the object ID of the touch.

func (*WlTouch) LastSerial added in v0.20.1

func (t *WlTouch) LastSerial() uint32

LastSerial returns the last event serial.

func (*WlTouch) Release added in v0.20.1

func (t *WlTouch) Release() error

Release destroys the touch object (v3+).

func (*WlTouch) SetCancelHandler added in v0.20.1

func (t *WlTouch) SetCancelHandler(handler func())

SetCancelHandler sets a callback for the touch cancel event. Cancel indicates that the compositor has taken over touch processing.

func (*WlTouch) SetDownHandler added in v0.20.1

func (t *WlTouch) SetDownHandler(handler func(event *TouchDownEvent))

SetDownHandler sets a callback for the touch down event.

func (*WlTouch) SetFrameHandler added in v0.20.1

func (t *WlTouch) SetFrameHandler(handler func())

SetFrameHandler sets a callback for the touch frame event. The frame event marks the end of a group of related touch events.

func (*WlTouch) SetMotionHandler added in v0.20.1

func (t *WlTouch) SetMotionHandler(handler func(event *TouchMotionEvent))

SetMotionHandler sets a callback for the touch motion event.

func (*WlTouch) SetUpHandler added in v0.20.1

func (t *WlTouch) SetUpHandler(handler func(event *TouchUpEvent))

SetUpHandler sets a callback for the touch up event.

type XdgPopup

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

XdgPopup represents the xdg_popup interface. This is the interface for popup windows (menus, tooltips, etc.).

func NewXdgPopup

func NewXdgPopup(display *Display, objectID ObjectID, xdgSurface *XdgSurface) *XdgPopup

NewXdgPopup creates an XdgPopup from an object ID. It auto-registers with Display for event dispatch (configure, popup_done, repositioned events).

func (*XdgPopup) Destroy

func (p *XdgPopup) Destroy() error

Destroy destroys the xdg_popup.

func (*XdgPopup) Grab

func (p *XdgPopup) Grab(seat ObjectID, serial uint32) error

Grab grabs keyboard focus for this popup. This makes the popup receive keyboard input until it's dismissed. The seat and serial identify the input event that triggered this.

func (*XdgPopup) ID

func (p *XdgPopup) ID() ObjectID

ID returns the object ID of the xdg_popup.

func (*XdgPopup) Reposition

func (p *XdgPopup) Reposition(positioner *XdgPositioner, token uint32) error

Reposition repositions the popup using a new positioner (v3+).

func (*XdgPopup) SetConfigureHandler

func (p *XdgPopup) SetConfigureHandler(handler func(x, y, width, height int32))

SetConfigureHandler sets a callback for the configure event.

func (*XdgPopup) SetPopupDoneHandler

func (p *XdgPopup) SetPopupDoneHandler(handler func())

SetPopupDoneHandler sets a callback for the popup_done event. This is called when the popup should be dismissed.

func (*XdgPopup) SetRepositionedHandler

func (p *XdgPopup) SetRepositionedHandler(handler func(token uint32))

SetRepositionedHandler sets a callback for the repositioned event (v3+).

func (*XdgPopup) Surface

func (p *XdgPopup) Surface() *WlSurface

Surface returns the underlying wl_surface.

func (*XdgPopup) XdgSurface

func (p *XdgPopup) XdgSurface() *XdgSurface

XdgSurface returns the parent xdg_surface.

type XdgPositioner

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

XdgPositioner represents the xdg_positioner interface. Positioners are used to position popup surfaces relative to their parent.

func NewXdgPositioner

func NewXdgPositioner(display *Display, objectID ObjectID) *XdgPositioner

NewXdgPositioner creates an XdgPositioner from an object ID.

func (*XdgPositioner) Destroy

func (p *XdgPositioner) Destroy() error

Destroy destroys the xdg_positioner.

func (*XdgPositioner) ID

func (p *XdgPositioner) ID() ObjectID

ID returns the object ID of the xdg_positioner.

func (*XdgPositioner) SetAnchor

func (p *XdgPositioner) SetAnchor(anchor uint32) error

SetAnchor sets the anchor point on the anchor rectangle.

func (*XdgPositioner) SetAnchorRect

func (p *XdgPositioner) SetAnchorRect(x, y, width, height int32) error

SetAnchorRect sets the anchor rectangle in the parent surface coordinates. The popup is positioned relative to this rectangle.

func (*XdgPositioner) SetConstraintAdjustment

func (p *XdgPositioner) SetConstraintAdjustment(adjustment uint32) error

SetConstraintAdjustment sets how the popup position should be adjusted if it would be constrained by the compositor (e.g., off-screen).

func (*XdgPositioner) SetGravity

func (p *XdgPositioner) SetGravity(gravity uint32) error

SetGravity sets the direction the popup should grow from the anchor.

func (*XdgPositioner) SetOffset

func (p *XdgPositioner) SetOffset(x, y int32) error

SetOffset sets an offset from the calculated position.

func (*XdgPositioner) SetParentConfigure

func (p *XdgPositioner) SetParentConfigure(serial uint32) error

SetParentConfigure sets the parent configure serial (v3+).

func (*XdgPositioner) SetParentSize

func (p *XdgPositioner) SetParentSize(width, height int32) error

SetParentSize sets the parent surface size for positioning (v3+).

func (*XdgPositioner) SetReactive

func (p *XdgPositioner) SetReactive() error

SetReactive marks the popup as reactive (v3+). Reactive popups can be repositioned when the parent moves.

func (*XdgPositioner) SetSize

func (p *XdgPositioner) SetSize(width, height int32) error

SetSize sets the size of the popup to be positioned.

type XdgSurface

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

XdgSurface represents the xdg_surface interface. An xdg_surface wraps a wl_surface and provides the foundation for toplevel windows and popup windows.

func NewXdgSurface

func NewXdgSurface(display *Display, objectID ObjectID, surface *WlSurface) *XdgSurface

NewXdgSurface creates an XdgSurface from an object ID. It auto-registers with Display for event dispatch (configure events).

func (*XdgSurface) AckConfigure

func (s *XdgSurface) AckConfigure(serial uint32) error

AckConfigure acknowledges a configure event. This must be called after receiving a configure event and applying the new state. The surface cannot be committed until this is done.

func (*XdgSurface) Destroy

func (s *XdgSurface) Destroy() error

Destroy destroys the xdg_surface. The underlying wl_surface is not destroyed.

func (*XdgSurface) GetPopup

func (s *XdgSurface) GetPopup(parent *XdgSurface, positioner *XdgPositioner) (*XdgPopup, error)

GetPopup creates an xdg_popup role for this surface. The parent parameter is the xdg_surface that this popup is relative to. The positioner determines where the popup appears.

func (*XdgSurface) GetToplevel

func (s *XdgSurface) GetToplevel() (*XdgToplevel, error)

GetToplevel creates an xdg_toplevel role for this surface. The surface becomes a toplevel window (not a popup).

func (*XdgSurface) ID

func (s *XdgSurface) ID() ObjectID

ID returns the object ID of the xdg_surface.

func (*XdgSurface) IsConfigured

func (s *XdgSurface) IsConfigured() bool

IsConfigured returns true if the surface has received at least one configure event.

func (*XdgSurface) SetConfigureHandler

func (s *XdgSurface) SetConfigureHandler(handler func(serial uint32))

SetConfigureHandler sets a callback for the configure event. The handler receives the serial number that must be acknowledged.

func (*XdgSurface) SetWindowGeometry

func (s *XdgSurface) SetWindowGeometry(x, y, width, height int32) error

SetWindowGeometry sets the window geometry. The geometry defines the visible bounds of the window, excluding decorations and shadows. This is important for proper sizing.

func (*XdgSurface) Surface

func (s *XdgSurface) Surface() *WlSurface

Surface returns the underlying wl_surface.

type XdgToplevel

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

XdgToplevel represents the xdg_toplevel interface. This is the interface for top-level application windows.

func NewXdgToplevel

func NewXdgToplevel(display *Display, objectID ObjectID, xdgSurface *XdgSurface) *XdgToplevel

NewXdgToplevel creates an XdgToplevel from an object ID. It auto-registers with Display for event dispatch (configure, close events).

func (*XdgToplevel) AppID

func (t *XdgToplevel) AppID() string

AppID returns the current application ID.

func (*XdgToplevel) Bounds added in v0.23.3

func (t *XdgToplevel) Bounds() XdgToplevelBounds

Bounds returns the last configure_bounds values (v4+). Returns zero values if no configure_bounds event has been received.

func (*XdgToplevel) Close

func (t *XdgToplevel) Close() error

Close sends a close request to the application. This is a hint that the user wants to close the window. The application should handle this by cleaning up and destroying the surface.

func (*XdgToplevel) Destroy

func (t *XdgToplevel) Destroy() error

Destroy destroys the xdg_toplevel. This removes the toplevel role from the xdg_surface.

func (*XdgToplevel) HasWmCapability added in v0.23.3

func (t *XdgToplevel) HasWmCapability(capability uint32) bool

HasWmCapability returns true if the compositor supports the given capability (v5+).

func (*XdgToplevel) ID

func (t *XdgToplevel) ID() ObjectID

ID returns the object ID of the xdg_toplevel.

func (*XdgToplevel) Move

func (t *XdgToplevel) Move(seat ObjectID, serial uint32) error

Move starts an interactive move operation. The seat and serial identify the input event that triggered this.

func (*XdgToplevel) Resize

func (t *XdgToplevel) Resize(seat ObjectID, serial uint32, edges uint32) error

Resize starts an interactive resize operation. The seat and serial identify the input event that triggered this. The edges parameter indicates which edge(s) are being resized.

func (*XdgToplevel) SetAppID

func (t *XdgToplevel) SetAppID(appID string) error

SetAppID sets the application ID. This identifies the application for desktop integration (icons, etc.). It should match the .desktop file name.

func (*XdgToplevel) SetCloseHandler

func (t *XdgToplevel) SetCloseHandler(handler func())

SetCloseHandler sets a callback for the close event. The handler is called when the compositor requests the window close.

func (*XdgToplevel) SetConfigureBoundsHandler added in v0.23.3

func (t *XdgToplevel) SetConfigureBoundsHandler(handler func(bounds *XdgToplevelBounds))

SetConfigureBoundsHandler sets a callback for the configure_bounds event (v4+). The handler receives the recommended maximum window bounds from the compositor.

func (*XdgToplevel) SetConfigureHandler

func (t *XdgToplevel) SetConfigureHandler(handler func(config *XdgToplevelConfig))

SetConfigureHandler sets a callback for the configure event. The handler receives the suggested dimensions and window states.

func (*XdgToplevel) SetFullscreen

func (t *XdgToplevel) SetFullscreen(output ObjectID) error

SetFullscreen requests that the window go fullscreen. The output parameter specifies which output to use (nil for default).

func (*XdgToplevel) SetMaxSize

func (t *XdgToplevel) SetMaxSize(width, height int32) error

SetMaxSize sets the maximum window size. A size of 0 means no limit for that dimension.

func (*XdgToplevel) SetMaximized

func (t *XdgToplevel) SetMaximized() error

SetMaximized requests that the window be maximized. The compositor may or may not honor this request.

func (*XdgToplevel) SetMinSize

func (t *XdgToplevel) SetMinSize(width, height int32) error

SetMinSize sets the minimum window size. A size of 0 means no minimum for that dimension.

func (*XdgToplevel) SetMinimized

func (t *XdgToplevel) SetMinimized() error

SetMinimized requests that the window be minimized.

func (*XdgToplevel) SetParent

func (t *XdgToplevel) SetParent(parent *XdgToplevel) error

SetParent sets the parent toplevel for this window. This creates a child/parent relationship (e.g., for dialogs). Pass nil to remove the parent.

func (*XdgToplevel) SetTitle

func (t *XdgToplevel) SetTitle(title string) error

SetTitle sets the window title. This is shown in the title bar and task switchers.

func (*XdgToplevel) SetWmCapabilitiesHandler added in v0.23.3

func (t *XdgToplevel) SetWmCapabilitiesHandler(handler func(capabilities []uint32))

SetWmCapabilitiesHandler sets a callback for the wm_capabilities event (v5+). The handler receives the list of supported window management capabilities.

func (*XdgToplevel) ShowWindowMenu

func (t *XdgToplevel) ShowWindowMenu(seat ObjectID, serial uint32, x, y int32) error

ShowWindowMenu shows the window menu (right-click menu on title bar). The seat and serial identify the input event that triggered this.

func (*XdgToplevel) Surface

func (t *XdgToplevel) Surface() *WlSurface

Surface returns the underlying wl_surface.

func (*XdgToplevel) Title

func (t *XdgToplevel) Title() string

Title returns the current window title.

func (*XdgToplevel) UnsetFullscreen

func (t *XdgToplevel) UnsetFullscreen() error

UnsetFullscreen requests that the window exit fullscreen mode.

func (*XdgToplevel) UnsetMaximized

func (t *XdgToplevel) UnsetMaximized() error

UnsetMaximized requests that the window exit maximized state.

func (*XdgToplevel) WmCapabilities added in v0.23.3

func (t *XdgToplevel) WmCapabilities() []uint32

WmCapabilities returns the last wm_capabilities values (v5+). Returns nil if no wm_capabilities event has been received.

func (*XdgToplevel) XdgSurface

func (t *XdgToplevel) XdgSurface() *XdgSurface

XdgSurface returns the parent xdg_surface.

type XdgToplevelBounds added in v0.23.3

type XdgToplevelBounds struct {
	// Width is the recommended maximum width (0 means unknown).
	Width int32
	// Height is the recommended maximum height (0 means unknown).
	Height int32
}

XdgToplevelBounds holds the recommended window geometry bounds from a configure_bounds event (v4+).

type XdgToplevelConfig

type XdgToplevelConfig struct {
	// Width is the suggested width (0 means client chooses).
	Width int32

	// Height is the suggested height (0 means client chooses).
	Height int32

	// States contains the current window states.
	States []uint32

	// Helper booleans derived from States
	Maximized   bool
	Fullscreen  bool
	Resizing    bool
	Activated   bool
	TiledLeft   bool
	TiledRight  bool
	TiledTop    bool
	TiledBottom bool
}

XdgToplevelConfig holds the configuration from a toplevel configure event.

type XdgWmBase

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

XdgWmBase represents the xdg_wm_base interface. This is the main interface for creating XDG shell surfaces (windows). It must respond to ping events to prove the client is responsive.

func NewXdgWmBase

func NewXdgWmBase(display *Display, objectID ObjectID) *XdgWmBase

NewXdgWmBase creates an XdgWmBase from a bound object ID. The objectID should be obtained from Registry.BindXdgWmBase(). It auto-registers with Display for event dispatch (ping events).

func (*XdgWmBase) CreatePositioner

func (x *XdgWmBase) CreatePositioner() (*XdgPositioner, error)

CreatePositioner creates a new xdg_positioner. Positioners are used to position popups relative to their parent surface.

func (*XdgWmBase) Destroy

func (x *XdgWmBase) Destroy() error

Destroy destroys the xdg_wm_base object. All xdg_surface objects created through this interface must be destroyed first.

func (*XdgWmBase) GetXdgSurface

func (x *XdgWmBase) GetXdgSurface(surface *WlSurface) (*XdgSurface, error)

GetXdgSurface creates an XdgSurface for the given wl_surface. The xdg_surface interface is the basis for toplevel windows and popups.

func (*XdgWmBase) ID

func (x *XdgWmBase) ID() ObjectID

ID returns the object ID of the xdg_wm_base.

func (*XdgWmBase) Pong

func (x *XdgWmBase) Pong(serial uint32) error

Pong responds to a ping request from the compositor. A client must respond to pings to prove it is not hung. This is typically called automatically by the event dispatcher.

func (*XdgWmBase) SetPingHandler

func (x *XdgWmBase) SetPingHandler(handler func(serial uint32))

SetPingHandler sets a callback for the ping event. By default, XdgWmBase auto-responds to pings. This handler is called after the auto-response if set.

type ZxdgDecorationManager added in v0.21.0

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

ZxdgDecorationManager represents the zxdg_decoration_manager_v1 interface. It allows clients to request server-side or client-side window decorations.

func NewZxdgDecorationManager added in v0.21.0

func NewZxdgDecorationManager(display *Display, objectID ObjectID) *ZxdgDecorationManager

NewZxdgDecorationManager creates a ZxdgDecorationManager from a bound object ID.

func (*ZxdgDecorationManager) Destroy added in v0.21.0

func (m *ZxdgDecorationManager) Destroy() error

Destroy destroys the decoration manager.

func (*ZxdgDecorationManager) GetToplevelDecoration added in v0.21.0

func (m *ZxdgDecorationManager) GetToplevelDecoration(toplevel *XdgToplevel) (*ZxdgToplevelDecoration, error)

GetToplevelDecoration creates a decoration object for the given xdg_toplevel.

func (*ZxdgDecorationManager) ID added in v0.21.0

ID returns the object ID.

type ZxdgToplevelDecoration added in v0.21.0

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

ZxdgToplevelDecoration represents the zxdg_toplevel_decoration_v1 interface. It allows requesting a specific decoration mode for a toplevel window.

func NewZxdgToplevelDecoration added in v0.21.0

func NewZxdgToplevelDecoration(display *Display, objectID ObjectID) *ZxdgToplevelDecoration

NewZxdgToplevelDecoration creates a ZxdgToplevelDecoration from an object ID. It auto-registers with Display for event dispatch (configure events).

func (*ZxdgToplevelDecoration) Destroy added in v0.21.0

func (d *ZxdgToplevelDecoration) Destroy() error

Destroy destroys the toplevel decoration object.

func (*ZxdgToplevelDecoration) ID added in v0.21.0

ID returns the object ID.

func (*ZxdgToplevelDecoration) Mode added in v0.21.0

func (d *ZxdgToplevelDecoration) Mode() uint32

Mode returns the current decoration mode set by the compositor.

func (*ZxdgToplevelDecoration) SetConfigureHandler added in v0.21.0

func (d *ZxdgToplevelDecoration) SetConfigureHandler(handler func(mode uint32))

SetConfigureHandler sets a callback for the configure event. The handler receives the decoration mode chosen by the compositor.

func (*ZxdgToplevelDecoration) SetMode added in v0.21.0

func (d *ZxdgToplevelDecoration) SetMode(mode uint32) error

SetMode requests a specific decoration mode. Use DecorationModeClientSide or DecorationModeServerSide.

func (*ZxdgToplevelDecoration) UnsetMode added in v0.21.0

func (d *ZxdgToplevelDecoration) UnsetMode() error

UnsetMode removes any previously set decoration mode preference. The compositor will choose the mode.

Jump to

Keyboard shortcuts

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