pastebin/scratchpad.go
Michael 4ea3244e48 scratchpad count for sway
Signed-off-by: Michael <michael.lindman@gmail.com>
2020-10-21 16:01:50 +01:00

45 lines
825 B
Go

package main
import (
"encoding/json"
"fmt"
"log"
"os/exec"
)
func main() {
var tree Tree
cmd, err := exec.Command("swaymsg", "-t", "get_tree").Output()
if err != nil {
log.Println(err)
}
if err := json.Unmarshal(cmd, &tree); err != nil {
log.Println(err)
}
for _, n := range tree.Nodes {
if n.Name == "__i3" {
for _, nodes := range n.Nodes {
if nodes.Name == "__i3_scratch" {
fmt.Println(len(nodes.FloatingNodes))
}
}
}
}
}
// Tree Sway tree
type Tree struct {
Nodes []struct {
ID int64 `json:"id"`
Name string `json:"name"`
Nodes []struct {
ID int `json:"id"`
Name string `json:"name"`
FloatingNodes []struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"floating_nodes"`
} `json:"nodes"`
} `json:"nodes"`
}