Files
niri/getters.go
2025-07-25 13:41:23 +02:00

104 lines
3.2 KiB
Go

package niri
import (
"fmt"
"image/color"
"git.tordarus.net/tordarus/slices"
)
func (c *Client) GetOutputs() ([]Output, error) {
resp := readSocket[map[string]map[string]Output](c.GetSocketPath(), asJsonReader("Outputs"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving outputs: %s", *resp.Err)
}
return slices.OfMap((*resp.OK)["Outputs"], slices.UnmapValue), nil
}
func (c *Client) GetWorkspaces() ([]Workspace, error) {
resp := readSocket[map[string][]Workspace](c.GetSocketPath(), asJsonReader("Workspaces"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving workspaces: %s", *resp.Err)
}
return (*resp.OK)["Workspaces"], nil
}
func (c *Client) GetWindows() ([]Window, error) {
resp := readSocket[map[string][]Window](c.GetSocketPath(), asJsonReader("Windows"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving windows: %s", *resp.Err)
}
return (*resp.OK)["Windows"], nil
}
func (c *Client) GetLayers() ([]LayerSurface, error) {
resp := readSocket[map[string][]LayerSurface](c.GetSocketPath(), asJsonReader("Layers"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving layers: %s", *resp.Err)
}
return (*resp.OK)["Layers"], nil
}
func (c *Client) GetKeyboardLayouts() (*KeyboardLayouts, error) {
resp := readSocket[map[string]KeyboardLayouts](c.GetSocketPath(), asJsonReader("KeyboardLayouts"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving layers: %s", *resp.Err)
}
value := (*resp.OK)["KeyboardLayouts"]
return &value, nil
}
func (c *Client) GetFocusedOutput() (*Output, error) {
resp := readSocket[map[string]Output](c.GetSocketPath(), asJsonReader("FocusedOutput"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving outputs: %s", *resp.Err)
}
value := (*resp.OK)["FocusedOutput"]
return &value, nil
}
func (c *Client) GetFocusedWindow() (*Window, error) {
resp := readSocket[map[string]Window](c.GetSocketPath(), asJsonReader("FocusedWindow"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving outputs: %s", *resp.Err)
}
value := (*resp.OK)["FocusedWindow"]
return &value, nil
}
func (c *Client) PickWindow() (*Window, error) {
resp := readSocket[map[string]Window](c.GetSocketPath(), asJsonReader("PickWindow"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving outputs: %s", *resp.Err)
}
value := (*resp.OK)["PickedWindow"]
return &value, nil
}
func (c *Client) PickColor() (color.Color, error) {
resp := readSocket[map[string]niriColor](c.GetSocketPath(), asJsonReader("PickColor"))
if resp.Err != nil {
return nil, fmt.Errorf("retrieving outputs: %s", *resp.Err)
}
value := (*resp.OK)["PickedColor"]
return value.AsColor(), nil
}
func (c *Client) GetVersion() (string, error) {
resp := readSocket[map[string]string](c.GetSocketPath(), asJsonReader("Version"))
if resp.Err != nil {
return "", fmt.Errorf("retrieving version: %s", *resp.Err)
}
value := (*resp.OK)["Version"]
return value, nil
}
func (c *Client) GetOverviewState() (bool, error) {
resp := readSocket[map[string]overviewState](c.GetSocketPath(), asJsonReader("OverviewState"))
if resp.Err != nil {
return false, fmt.Errorf("retrieving version: %s", *resp.Err)
}
value := (*resp.OK)["OverviewState"]
return value.IsOpen, nil
}