client

package module
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 12 Imported by: 0

README

hypland ipc client

This is a client for the Hypland IPC server. It is used to communicate with the Hypland server.

Installation
go get -u github.com/labi-le/hyprland-ipc-client

Example

package main

import (
	"fmt"
	"os"
	"github.com/labi-le/hyprland-ipc-client"
)

type ed struct {
	client.DummyEvHandler
}

func main() {
	c := client.MustClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"))
	e := &ed{}
	client.Subscribe(c, e, client.EventActiveLayout)
}

func (e *ed) ActiveLayout(layout client.ActiveLayout) {
	fmt.Println("ActiveLayout", layout.Type, layout.Name)
}

Documentation

Index

Constants

View Source
const (
	BufSize   = 8192
	Separator = ">>"
	Success   = "ok"
)

Variables

This section is empty.

Functions

func Get

func Get(size int) []byte

Get returns a byte slice with given length from the built-in pool.

func Put

func Put(buf []byte)

Put returns the byte slice to the built-in pool.

func Subscribe

func Subscribe(c IPC, ev EventHandler, events ...EventType) error

func UnsafeBytes

func UnsafeBytes(s string) []byte

UnsafeBytes returns a byte pointer without allocation.

Types

type ActiveLayout

type ActiveLayout struct {
	Type, Name string
}

type ActiveWindow

type ActiveWindow struct {
	Name, Title string
}

type ActiveWorkspace

type ActiveWorkspace WorkspaceName

type Bind

type Bind struct {
	Locked      bool   `json:"locked"`
	Mouse       bool   `json:"mouse"`
	Release     bool   `json:"release"`
	Repeat      bool   `json:"repeat"`
	NoConsuming bool   `json:"non_consuming"`
	ModMask     int    `json:"modmask"`
	SubMap      string `json:"submap"`
	Key         string `json:"key"`
	KeyCode     int    `json:"keycode"`
	Dispatcher  string `json:"dispatcher"`
	Arg         string `json:"arg"`
}

type ByteQueue

type ByteQueue struct {
	*PriorityQueue[[]byte]
}

func NewByteQueue

func NewByteQueue() *ByteQueue

func (*ByteQueue) Glue

func (q *ByteQueue) Glue() []byte

type Client

type Client struct {
	Address        string    `json:"address"`
	At             []int     `json:"at"`
	Size           []int     `json:"size"`
	Workspace      Workspace `json:"workspace"`
	Floating       bool      `json:"floating"`
	Monitor        int       `json:"monitor"`
	Class          string    `json:"class"`
	Title          string    `json:"title"`
	Pid            int       `json:"pid"`
	Xwayland       bool      `json:"xwayland"`
	Pinned         bool      `json:"pinned"`
	Fullscreen     bool      `json:"fullscreen"`
	FullscreenMode int       `json:"fullscreenMode"`
}

type CloseLayer

type CloseLayer string

type CloseWindow

type CloseWindow struct {
	Address string
}

type CursorPos

type CursorPos struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type Devices

type Devices struct {
	Mice []struct {
		Address      string  `json:"address"`
		Name         string  `json:"name"`
		DefaultSpeed float64 `json:"defaultSpeed"`
	} `json:"mice"`
	Keyboards []struct {
		Address      string `json:"address"`
		Name         string `json:"name"`
		Rules        string `json:"rules"`
		Model        string `json:"model"`
		Layout       string `json:"layout"`
		Variant      string `json:"variant"`
		Options      string `json:"options"`
		ActiveKeymap string `json:"active_keymap"`
		Main         bool   `json:"main"`
	} `json:"keyboards"`
	Tablets  []interface{} `json:"tablets"`
	Touch    []interface{} `json:"touch"`
	Switches []struct {
		Address string `json:"address"`
		Name    string `json:"name"`
	} `json:"switches"`
}

type DummyEvHandler

type DummyEvHandler struct{}

func (*DummyEvHandler) ActiveLayout

func (e *DummyEvHandler) ActiveLayout(ActiveLayout)

func (*DummyEvHandler) ActiveWindow

func (e *DummyEvHandler) ActiveWindow(ActiveWindow)

func (*DummyEvHandler) CloseLayer

func (e *DummyEvHandler) CloseLayer(CloseLayer)

func (*DummyEvHandler) CloseWindow

func (e *DummyEvHandler) CloseWindow(CloseWindow)

func (*DummyEvHandler) CreateWorkspace

func (e *DummyEvHandler) CreateWorkspace(WorkspaceName)

func (*DummyEvHandler) DestroyWorkspace

func (e *DummyEvHandler) DestroyWorkspace(WorkspaceName)

func (*DummyEvHandler) FocusedMonitor

func (e *DummyEvHandler) FocusedMonitor(FocusedMonitor)

func (*DummyEvHandler) Fullscreen

func (e *DummyEvHandler) Fullscreen(bool)

func (*DummyEvHandler) MonitorAdded

func (e *DummyEvHandler) MonitorAdded(MonitorName)

func (*DummyEvHandler) MonitorRemoved

func (e *DummyEvHandler) MonitorRemoved(MonitorName)

func (*DummyEvHandler) MoveWindow

func (e *DummyEvHandler) MoveWindow(MoveWindow)

func (*DummyEvHandler) MoveWorkspace

func (e *DummyEvHandler) MoveWorkspace(MoveWorkspace)

func (*DummyEvHandler) OpenLayer

func (e *DummyEvHandler) OpenLayer(OpenLayer)

func (*DummyEvHandler) OpenWindow

func (e *DummyEvHandler) OpenWindow(OpenWindow)

func (*DummyEvHandler) SubMap

func (e *DummyEvHandler) SubMap(SubMap)

func (*DummyEvHandler) Workspace

func (e *DummyEvHandler) Workspace(WorkspaceName)

type DummyIPC

type DummyIPC struct{}

func (DummyIPC) ActiveWindow

func (d DummyIPC) ActiveWindow() (Window, error)

func (DummyIPC) ActiveWorkspace

func (d DummyIPC) ActiveWorkspace() (Workspace, error)

func (DummyIPC) Binds

func (d DummyIPC) Binds() ([]Bind, error)

func (DummyIPC) Clients

func (d DummyIPC) Clients() ([]Client, error)

func (DummyIPC) CursorPos

func (d DummyIPC) CursorPos() (CursorPos, error)

func (DummyIPC) Devices

func (d DummyIPC) Devices() (Devices, error)

func (DummyIPC) Dispatch

func (d DummyIPC) Dispatch(*ByteQueue) ([]byte, error)

func (DummyIPC) GetOption

func (d DummyIPC) GetOption(string) (string, error)

func (DummyIPC) Keyword

func (d DummyIPC) Keyword(*ByteQueue) error

func (DummyIPC) Kill

func (d DummyIPC) Kill() error

func (DummyIPC) Layers

func (d DummyIPC) Layers() (Layers, error)

func (DummyIPC) Monitors

func (d DummyIPC) Monitors() ([]Monitor, error)

func (DummyIPC) Receive

func (d DummyIPC) Receive() ([]ReceivedData, error)

func (DummyIPC) Reload

func (d DummyIPC) Reload() error

func (DummyIPC) SetCursor

func (d DummyIPC) SetCursor(string, string) error

func (DummyIPC) Splash

func (d DummyIPC) Splash() (string, error)

func (DummyIPC) Version

func (d DummyIPC) Version() (Version, error)

func (DummyIPC) Workspaces

func (d DummyIPC) Workspaces() ([]Workspace, error)

type EventHandler

type EventHandler interface {
	// Workspace emitted on workspace change. Is emitted ONLY when a user requests a workspace change, and is not emitted on mouse movements (see activemon)
	Workspace(w WorkspaceName)
	// FocusedMonitor emitted on the active monitor being changed.
	FocusedMonitor(m FocusedMonitor)
	// ActiveWindow emitted on the active window being changed.
	ActiveWindow(w ActiveWindow)
	// Fullscreen emitted when a fullscreen status of a window changes.
	Fullscreen(f bool)
	// MonitorRemoved emitted when a monitor is removed (disconnected)
	MonitorRemoved(m MonitorName)
	// MonitorAdded emitted when a monitor is added (connected)
	MonitorAdded(m MonitorName)
	// CreateWorkspace emitted when a workspace is created
	CreateWorkspace(w WorkspaceName)
	// DestroyWorkspace emitted when a workspace is destroyed
	DestroyWorkspace(w WorkspaceName)
	// MoveWorkspace emitted when a workspace is moved to a different monitor
	MoveWorkspace(w MoveWorkspace)
	// ActiveLayout emitted on a layout change of the active keyboard
	ActiveLayout(l ActiveLayout)
	// OpenWindow emitted when a window is opened
	OpenWindow(o OpenWindow)
	// CloseWindow emitted when a window is closed
	CloseWindow(c CloseWindow)
	// MoveWindow emitted when a window is moved to a workspace
	MoveWindow(m MoveWindow)
	// OpenLayer emitted when a layerSurface is mapped
	OpenLayer(l OpenLayer)
	// CloseLayer emitted when a layerSurface is unmapped
	CloseLayer(c CloseLayer)
	// SubMap emitted when a keybind submap changes. Empty means default.
	SubMap(s SubMap)
}

EventHandler Hyprland will write to each connected ipc live events like this:

type EventType

type EventType string
const (
	EventWorkspace        EventType = "workspace"
	EventFocusedMonitor   EventType = "focusedmon"
	EventActiveWindow     EventType = "activewindow"
	EventFullscreen       EventType = "fullscreen"
	EventMonitorRemoved   EventType = "monitorremoved"
	EventMonitorAdded     EventType = "monitoradded"
	EventCreateWorkspace  EventType = "createworkspace"
	EventDestroyWorkspace EventType = "destroyworkspace"
	EventMoveWorkspace    EventType = "moveworkspace"
	EventActiveLayout     EventType = "activelayout"
	EventOpenWindow       EventType = "openwindow"
	EventCloseWindow      EventType = "closewindow"
	EventMoveWindow       EventType = "movewindow"
	EventOpenLayer        EventType = "openlayer"
	EventCloseLayer       EventType = "closelayer"
	EventSubMap           EventType = "submap"
)

func GetAllEvents

func GetAllEvents() []EventType

type FocusedMonitor

type FocusedMonitor struct {
	MonitorName
	WorkspaceName
}

type IPC

type IPC interface {
	Receive() ([]ReceivedData, error)
	Dispatch(args *ByteQueue) ([]byte, error)
	Workspaces() ([]Workspace, error)
	ActiveWorkspace() (Workspace, error)
	Monitors() ([]Monitor, error)
	Clients() ([]Client, error)
	ActiveWindow() (Window, error)
	Layers() (Layers, error)
	Devices() (Devices, error)
	Keyword(args *ByteQueue) error
	Version() (Version, error)
	Kill() error
	Splash() (string, error)
	Reload() error
	SetCursor(theme, size string) error
	GetOption(name string) (string, error)
	CursorPos() (CursorPos, error)
	Binds() ([]Bind, error)
}

type IPCClient

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

func MustClient

func MustClient(sign string) *IPCClient

func NewClient

func NewClient(readSock, writeSock string) *IPCClient

func (*IPCClient) ActiveWindow

func (c *IPCClient) ActiveWindow() (Window, error)

func (*IPCClient) ActiveWorkspace

func (c *IPCClient) ActiveWorkspace() (Workspace, error)

func (*IPCClient) Binds

func (c *IPCClient) Binds() ([]Bind, error)

func (*IPCClient) Clients

func (c *IPCClient) Clients() ([]Client, error)

func (*IPCClient) CursorPos

func (c *IPCClient) CursorPos() (CursorPos, error)

func (*IPCClient) Devices

func (c *IPCClient) Devices() (Devices, error)

func (*IPCClient) Dispatch

func (c *IPCClient) Dispatch(a *ByteQueue) ([]byte, error)

func (*IPCClient) GetOption

func (c *IPCClient) GetOption(name string) (string, error)

func (*IPCClient) Keyword

func (c *IPCClient) Keyword(args *ByteQueue) error

func (*IPCClient) Kill

func (c *IPCClient) Kill() error

func (*IPCClient) Layers

func (c *IPCClient) Layers() (Layers, error)

func (*IPCClient) Monitors

func (c *IPCClient) Monitors() ([]Monitor, error)

func (*IPCClient) Receive

func (c *IPCClient) Receive() ([]ReceivedData, error)

func (*IPCClient) Reload

func (c *IPCClient) Reload() error

func (*IPCClient) SetCursor

func (c *IPCClient) SetCursor(theme, size string) error

func (*IPCClient) Splash

func (c *IPCClient) Splash() (string, error)

func (*IPCClient) Version

func (c *IPCClient) Version() (Version, error)

func (*IPCClient) Workspaces

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

type Layer

type Layer struct {
	Levels map[int][]LayerField `json:"levels"`
}

type LayerField

type LayerField struct {
	Address   string `json:"address"`
	X         int    `json:"x"`
	Y         int    `json:"y"`
	W         int    `json:"w"`
	H         int    `json:"h"`
	Namespace string `json:"namespace"`
}

type Layers

type Layers map[string]Layer

type Monitor

type Monitor struct {
	Id              int           `json:"id"`
	Name            string        `json:"name"`
	Description     string        `json:"description"`
	Width           int           `json:"width"`
	Height          int           `json:"height"`
	RefreshRate     float64       `json:"refreshRate"`
	X               int           `json:"x"`
	Y               int           `json:"y"`
	ActiveWorkspace WorkspaceType `json:"activeWorkspace"`
	Reserved        []int         `json:"reserved"`
	Scale           float64       `json:"scale"`
	Transform       int           `json:"transform"`
	Focused         bool          `json:"focused"`
	DpmsStatus      bool          `json:"dpmsStatus"`
}

type MonitorName

type MonitorName string

type MoveWindow

type MoveWindow struct {
	Address string
	WorkspaceName
}

type MoveWorkspace

type MoveWorkspace struct {
	WorkspaceName
	MonitorName
}

type OpenLayer

type OpenLayer string

type OpenWindow

type OpenWindow struct {
	Address, Class, Title string
	WorkspaceName
}

type Pool

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

Pool consists of 32 sync.Pool, representing byte slices of length from 0 to 32 in powers of 2.

func (*Pool) Get

func (p *Pool) Get(size int) (buf []byte)

Get retrieves a byte slice of the length requested by the caller from pool or allocates a new one.

func (*Pool) Put

func (p *Pool) Put(buf []byte)

Put returns the byte slice to the pool.

type PriorityQueue

type PriorityQueue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any]() *PriorityQueue[T]

func (*PriorityQueue[T]) Add

func (q *PriorityQueue[T]) Add(value T)

func (*PriorityQueue[T]) Back

func (q *PriorityQueue[T]) Back(value T)

func (*PriorityQueue[T]) IsEmpty

func (q *PriorityQueue[T]) IsEmpty() bool

func (*PriorityQueue[T]) Len

func (q *PriorityQueue[T]) Len() int

func (*PriorityQueue[T]) Peek

func (q *PriorityQueue[T]) Peek() T

func (*PriorityQueue[T]) Pop

func (q *PriorityQueue[T]) Pop() T

func (*PriorityQueue[T]) Push

func (q *PriorityQueue[T]) Push(priority int, value T)

func (*PriorityQueue[T]) Reset

func (q *PriorityQueue[T]) Reset()

type ReceivedData

type ReceivedData struct {
	Type EventType
	Data string
}

type SubMap

type SubMap string

type Version

type Version struct {
	Branch        string   `json:"branch"`
	Commit        string   `json:"commit"`
	Dirty         bool     `json:"dirty"`
	CommitMessage string   `json:"commit_message"`
	CommitDate    string   `json:"commit_date"`
	Tag           string   `json:"tag"`
	Commits       string   `json:"commits"`
	Flags         []string `json:"flags"`
}

type Window

type Window struct {
	Address   string        `json:"address"`
	At        []int         `json:"at"`
	Size      []int         `json:"size"`
	Workspace WorkspaceType `json:"workspace"`
	Floating  bool          `json:"floating"`
	Monitor   int           `json:"monitor"`
	Class     string        `json:"class"`
	Title     string        `json:"title"`
	Pid       int           `json:"pid"`
	Xwayland  bool          `json:"xwayland"`
}

type Workspace

type Workspace struct {
	WorkspaceType
	Monitor         string `json:"monitor"`
	Windows         int    `json:"windows"`
	HasFullScreen   bool   `json:"hasfullscreen"`
	LastWindow      string `json:"lastwindow"`
	LastWindowTitle string `json:"lastwindowtitle"`
}

type WorkspaceName

type WorkspaceName string

type WorkspaceType

type WorkspaceType struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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