GetOutputs implemented
This commit is contained in:
parent
8bb43a4263
commit
f2690ddf0b
47
get_outputs.go
Normal file
47
get_outputs.go
Normal file
@ -0,0 +1,47 @@
|
||||
package sway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func (c *Client) GetOutputs(ctx context.Context) ([]Output, error) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if _, err := fmt.Fprint(c.conn, "i3-ipc"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := binary.Write(c.conn, binary.LittleEndian, uint32(0)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := binary.Write(c.conn, binary.LittleEndian, uint32(3)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := c.conn.Read(make([]byte, 6)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var length uint32
|
||||
if err := binary.Read(c.conn, binary.LittleEndian, &length); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var messageType uint32
|
||||
if err := binary.Read(c.conn, binary.LittleEndian, &messageType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results := []Output{}
|
||||
if err := json.NewDecoder(io.LimitReader(c.conn, int64(length))).Decode(&results); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
49
types.go
49
types.go
@ -34,6 +34,28 @@ func (w Workspace) String() string {
|
||||
return string(data)
|
||||
}
|
||||
|
||||
type Output struct {
|
||||
Name string `json:"name"`
|
||||
Make string `json:"make"`
|
||||
Model string `json:"model"`
|
||||
Serial string `json:"serial"`
|
||||
Active bool `json:"active"`
|
||||
DPMS bool `json:"dpms"`
|
||||
Power bool `json:"power"`
|
||||
Scale float64 `json:"scale"`
|
||||
SubPixelHinting SubPixelHinting `json:"subpixel_hinting"`
|
||||
Transform Transform `json:"transform"`
|
||||
CurrentWorkspace string `json:"current_workspace"`
|
||||
Modes []Mode `json:"modes"`
|
||||
CurrentMode Mode `json:"current_mode"`
|
||||
Rect Rectangle `json:"rect"`
|
||||
}
|
||||
|
||||
func (o Output) String() string {
|
||||
data, _ := json.MarshalIndent(o, "", "\t")
|
||||
return string(data)
|
||||
}
|
||||
|
||||
type WindowProperties struct {
|
||||
Title string `json:"title"`
|
||||
Instance string `json:"instance"`
|
||||
@ -175,6 +197,27 @@ const (
|
||||
InputTypeMouse InputType = "mouse"
|
||||
)
|
||||
|
||||
type SubPixelHinting = string
|
||||
|
||||
const (
|
||||
SubPixelHintingRGB SubPixelHinting = "rgb"
|
||||
SubPixelHintingBGR SubPixelHinting = "bgr"
|
||||
SubPixelHintingVRGB SubPixelHinting = "vrgb"
|
||||
SubPixelHintingVBGR SubPixelHinting = "vbgr"
|
||||
SubPixelHintingNone SubPixelHinting = "none"
|
||||
)
|
||||
|
||||
type Transform = string
|
||||
|
||||
const (
|
||||
Transform90 Transform = "90"
|
||||
Transform180 Transform = "180"
|
||||
Transform270 Transform = "270"
|
||||
TransformFlipped90 Transform = "flipped-90"
|
||||
TransformFlipped180 Transform = "flipped-180"
|
||||
TransformFlipped270 Transform = "flipped-270"
|
||||
)
|
||||
|
||||
type commandResult struct {
|
||||
Success bool `json:"success"`
|
||||
ParseError bool `json:"parse_error"`
|
||||
@ -193,3 +236,9 @@ func (r commandResult) GetError() error {
|
||||
func (r commandResult) HasError() bool {
|
||||
return !r.Success
|
||||
}
|
||||
|
||||
type Mode struct {
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Refresh int `json:"refresh"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user