renovate the code, update to go 1.26 and satisfy linter (#3)

This commit is contained in:
T. von Dein
2026-08-22 17:59:59 +02:00
parent 9cd6e4a6b9
commit 6d9763a0a9
77 changed files with 681 additions and 227 deletions

94
node.go
View File

@@ -5,10 +5,18 @@ import (
"fmt"
)
// A node can be an output, a workspace, a container or a container
// containing a window.
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
)
// Node can be an output, a workspace, a container or a container
// containing other containers.
type Node struct {
Id int `json:"id"`
ID int `json:"id"`
Type string `json:"type"` // output, workspace or container
Name string `json:"name"` // workspace number or app name
Output string `json:"output"`
@@ -26,26 +34,24 @@ type Node struct {
Focus []int `json:"focus"`
Window int `json:"window"` // wayland native
X11Window string `json:"app_id"` // x11 compat
Current_workspace string `json:"current_workspace"`
CurrentWorkspace string `json:"current_workspace"`
Rect Rect `json:"rect"`
WindowRect Rect `json:"window_rect"`
DecoRect Rect `json:"deco_rect"`
Geometry Rect `json:"geometry"`
}
var __focused *Node
var __currentworkspace string
// Get the whole information tree, contains everything from output to
// containers as a tree of nodes. Each node has a field 'Nodes' which
// points to a list subnodes. Some nodes also have a field
// 'FloatingNodes' which points to a list of floating containers.
// GetTree returns the whole information tree, which contains
// everything from output to containers as a tree of nodes. Each node
// has a field 'Nodes' which points to a list subnodes. Some nodes
// also have a field 'FloatingNodes' which points to a list of
// floating containers.
//
// The top level node is the "root" node.
//
// Use the returned node oject to further investigate the wm setup.
func (ipc *SwayIPC) GetTree() (*Node, error) {
err := ipc.sendHeader(GET_TREE, 0)
err := ipc.sendHeader(MsgGettTree, 0)
if err != nil {
return nil, err
}
@@ -63,48 +69,48 @@ func (ipc *SwayIPC) GetTree() (*Node, error) {
return node, nil
}
// Usually called on the root node, returns the container which has
// currently the focus.
// FindFocused returns the container which has currently the
// focus. Usually called on the root node.
func (node *Node) FindFocused() *Node {
searchFocused(node.Nodes)
if __focused == nil {
searchFocused(node.FloatingNodes)
focused := searchFocused(node.Nodes)
if focused == nil {
return searchFocused(node.FloatingNodes)
}
return __focused
return nil
}
// internal recursive focus node searcher
func searchFocused(nodes []*Node) {
// FindCurrentWorkspace returns the current active
// workspace name. Usually called on the root node.
func (node *Node) FindCurrentWorkspace() string {
return searchCurrentWorkspace(node.Nodes)
}
// searchCurrentWorkspace search for current workspace
func searchCurrentWorkspace(nodes []*Node) string {
for _, node := range nodes {
if node.CurrentWorkspace != "" {
return node.CurrentWorkspace
} else {
return searchCurrentWorkspace(node.Nodes)
}
}
return ""
}
// searchFocused recursively search focused node
func searchFocused(nodes []*Node) *Node {
for _, node := range nodes {
if node.Focused {
__focused = node
return
return node
} else {
searchFocused(node.Nodes)
if __focused == nil {
searchFocused(node.FloatingNodes)
focused := searchFocused(node.Nodes)
if focused == nil {
return searchFocused(node.FloatingNodes)
}
}
}
}
// Usually called on the root node, returns the current active
// workspace name.
func (node *Node) FindCurrentWorkspace() string {
searchCurrentWorkspace(node.Nodes)
return __currentworkspace
}
// internal recursive workspace node searcher
func searchCurrentWorkspace(nodes []*Node) {
for _, node := range nodes {
if node.Current_workspace != "" {
__currentworkspace = node.Current_workspace
return
} else {
searchCurrentWorkspace(node.Nodes)
}
}
return nil
}