add Node.Is* predicates to comfortably check node type (#4)

This commit is contained in:
T. von Dein
2026-08-23 22:22:35 +02:00
parent 6d9763a0a9
commit a25e81d3e0
2 changed files with 26 additions and 6 deletions

30
node.go
View File

@@ -6,11 +6,11 @@ import (
) )
const ( const (
NodeTypeRoot = iota + 1 // A root node NodeTypeRoot = "root"
NodeTypeOutput // An output node NodeTypeOutput = "output"
NodeTypeWorkspace // A workspace NodeTypeWorkspace = "workspace"
NodeTypeCon // A container node (containing more nodes) NodeTypeCon = "con"
NodeTypeFloating // A floating node NodeTypeFloating = "floating_con"
) )
// Node can be an output, a workspace, a container or a container // Node can be an output, a workspace, a container or a container
@@ -86,6 +86,26 @@ func (node *Node) FindCurrentWorkspace() string {
return searchCurrentWorkspace(node.Nodes) return searchCurrentWorkspace(node.Nodes)
} }
func (node *Node) IsRoot() bool {
return node.Type == NodeTypeRoot
}
func (node *Node) IsOutput() bool {
return node.Type == NodeTypeOutput
}
func (node *Node) IsWorkspace() bool {
return node.Type == NodeTypeWorkspace
}
func (node *Node) IsContainer() bool {
return node.Type == NodeTypeCon
}
func (node *Node) IsFloating() bool {
return node.Type == NodeTypeFloating
}
// searchCurrentWorkspace search for current workspace // searchCurrentWorkspace search for current workspace
func searchCurrentWorkspace(nodes []*Node) string { func searchCurrentWorkspace(nodes []*Node) string {
for _, node := range nodes { for _, node := range nodes {

View File

@@ -8,7 +8,7 @@ import (
) )
const ( const (
VERSION = "v2.1.0" VERSION = "v2.1.1"
IpcHeaderSize = 14 IpcHeaderSize = 14
IpcMagix = "i3-ipc" IpcMagix = "i3-ipc"