implemented more stuff along with samples

This commit is contained in:
2025-08-14 22:59:38 +02:00
parent a09b04ab7a
commit f5b0ee026f
26 changed files with 2768 additions and 12 deletions

24
node.go
View File

@@ -1,5 +1,10 @@
package i3ipc
import (
"encoding/json"
"fmt"
)
type Node struct {
Id int `json:"id"`
Type string `json:"type"` // output, workspace or container
@@ -27,6 +32,25 @@ type Node struct {
var __focused *Node
var __currentworkspace string
func (ipc *I3ipc) GetTree() (*Node, error) {
err := ipc.sendHeader(GET_TREE, 0)
if err != nil {
return nil, err
}
payload, err := ipc.readResponse()
if err != nil {
return nil, err
}
node := &Node{}
if err := json.Unmarshal(payload, &node); err != nil {
return nil, fmt.Errorf("failed to unmarshal json: %w", err)
}
return node, nil
}
func (node *Node) FindFocused() *Node {
searchFocused(node.Nodes)
if __focused == nil {