2 Commits

Author SHA1 Message Date
T. von Dein
7900f4f996 pkgdocfix (#5) 2026-09-02 20:07:48 +02:00
T. von Dein
a25e81d3e0 add Node.Is* predicates to comfortably check node type (#4) 2026-08-23 22:22:35 +02:00
4 changed files with 28 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
[![status-badge](https://ci.codeberg.org/api/badges/15565/status.svg)](https://ci.codeberg.org/repos/15565) [![status-badge](https://ci.codeberg.org/api/badges/15565/status.svg)](https://ci.codeberg.org/repos/15565)
[![Go Report Card](https://goreportcard.com/badge/codeberg.org/scip/swayipc)](https://goreportcard.com/report/codeberg.org/scip/swayipc) [![Go Report Card](https://goreportcard.com/badge/codeberg.org/scip/swayipc)](https://goreportcard.com/report/codeberg.org/scip/swayipc)
[![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://codeberg.org/scip/swayipc/raw/branch/main/LICENSE) [![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://codeberg.org/scip/swayipc/raw/branch/main/LICENSE)
[![GoDoc](https://godoc.org/codeberg.org/scip/swayipc?status.svg)](https://godoc.org/codeberg.org/scip/swayipc) [![GoDoc](https://godoc.org/codeberg.org/scip/swayipc?status.svg)](https://godoc.org/codeberg.org/scip/swayipc/v2)
# swayipc - go bindings to control sway and swayfx # swayipc - go bindings to control sway and swayfx
@@ -26,7 +26,7 @@ haven't tested it on i3wm.
The module uses the i3-IPC proctocol as outlined in sway-ipc(7). The module uses the i3-IPC proctocol as outlined in sway-ipc(7).
For details on how to use the library, see the For details on how to use the library, see the
[reference documentation](https://godoc.org/codeberg.org/scip/swayipc). [reference documentation](https://godoc.org/codeberg.org/scip/swayipc/v2).
## Example usage ## Example usage

2
go.mod
View File

@@ -1,5 +1,3 @@
module codeberg.org/scip/swayipc/v2 module codeberg.org/scip/swayipc/v2
go 1.26 go 1.26
require github.com/alecthomas/repr v0.5.1 // indirect

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.2"
IpcHeaderSize = 14 IpcHeaderSize = 14
IpcMagix = "i3-ipc" IpcMagix = "i3-ipc"