From a25e81d3e0f6e0519f058741e36bbbd464d80faa Mon Sep 17 00:00:00 2001 From: "T. von Dein" Date: Sun, 23 Aug 2026 22:22:35 +0200 Subject: [PATCH] add Node.Is* predicates to comfortably check node type (#4) --- node.go | 30 +++++++++++++++++++++++++----- swayipc.go | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/node.go b/node.go index 7720bc1..0f9a6a5 100644 --- a/node.go +++ b/node.go @@ -6,11 +6,11 @@ import ( ) const ( - NodeTypeRoot = iota + 1 // A root node - NodeTypeOutput // An output node - NodeTypeWorkspace // A workspace - NodeTypeCon // A container node (containing more nodes) - NodeTypeFloating // A floating node + NodeTypeRoot = "root" + NodeTypeOutput = "output" + NodeTypeWorkspace = "workspace" + NodeTypeCon = "con" + NodeTypeFloating = "floating_con" ) // 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) } +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 func searchCurrentWorkspace(nodes []*Node) string { for _, node := range nodes { diff --git a/swayipc.go b/swayipc.go index fe00838..09b5ca0 100644 --- a/swayipc.go +++ b/swayipc.go @@ -8,7 +8,7 @@ import ( ) const ( - VERSION = "v2.1.0" + VERSION = "v2.1.1" IpcHeaderSize = 14 IpcMagix = "i3-ipc"