upd to swayipc 2.1.1, use Node.Is* type predicates

This commit is contained in:
2026-08-23 22:30:48 +02:00
parent ed91eda7dc
commit b45cb9ee33
3 changed files with 7 additions and 29 deletions

32
main.go
View File

@@ -36,15 +36,9 @@ import (
)
const (
root = iota + 1
output
workspace
con
floating
LevelNotice = slog.Level(2)
VERSION = "v0.3.2"
VERSION = "v0.3.3"
)
var (
@@ -170,7 +164,7 @@ func cycle() error {
// get into the sway tree, determine current workspace and extract all
// its visible windows, store them in the global var Visibles
func processJSON(sway *swayipc.Node) error {
if !istype(sway, root) && len(sway.Nodes) == 0 {
if !sway.IsRoot() && len(sway.Nodes) == 0 {
return errors.New("invalid or empty JSON structure")
}
@@ -258,7 +252,7 @@ func switchFocus(id int, ipc *swayipc.SwayIPC) error {
// iterate recursively over given node list extracting visible windows
func recurseNodes(nodes []*swayipc.Node) {
for _, node := range nodes {
if istype(node, workspace) {
if node.IsWorkspace() {
if node.Name == CurrentWorkspace {
// floating_nodes need to be sorted because
// order changes each time they are focused.
@@ -279,7 +273,7 @@ func recurseNodes(nodes []*swayipc.Node) {
// the first nodes seen are workspaces, so if we see a con
// node, we are already inside the current workspace
if (istype(node, con) || istype(node, floating)) &&
if (node.IsContainer() || node.IsFloating()) &&
(node.Window > 0 || node.X11Window != "") {
Visibles = append(Visibles, node)
} else {
@@ -338,24 +332,6 @@ func setupLogging(output io.Writer) {
}
}
// istype is a little helper to distinguish sway tree node types
func istype(nd *swayipc.Node, which int) bool {
switch nd.Type {
case "root":
return which == swayipc.NodeTypeRoot
case "output":
return which == swayipc.NodeTypeOutput
case "workspace":
return which == swayipc.NodeTypeWorkspace
case "con":
return which == swayipc.NodeTypeCon
case "floating_con":
return which == swayipc.NodeTypeFloating
}
return false
}
// IsNoTty returns TRUE if stdout is NOT a tty or windows
func IsNoTty() bool {
if !isatty.IsTerminal(os.Stdout.Fd()) {