mirror of
https://codeberg.org/scip/swaycycle.git
synced 2026-08-23 22:34:20 +02:00
upd to swayipc 2.1.1, use Node.Is* type predicates (#4)
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module swaycycle
|
||||
go 1.26
|
||||
|
||||
require (
|
||||
codeberg.org/scip/swayipc/v2 v2.1.0
|
||||
codeberg.org/scip/swayipc/v2 v2.1.1
|
||||
github.com/lmittmann/tint v1.1.3
|
||||
github.com/mattn/go-isatty v0.0.24
|
||||
github.com/spf13/pflag v1.0.10
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,5 +1,7 @@
|
||||
codeberg.org/scip/swayipc/v2 v2.1.0 h1:tBiOBOUFDOA38+acZwx4BO5Yo/VVwxbqkL+R2/zmW6c=
|
||||
codeberg.org/scip/swayipc/v2 v2.1.0/go.mod h1:cqicjgMgPS7tGTJgjqjSMvnLeMA+J3to/YnufcysCns=
|
||||
codeberg.org/scip/swayipc/v2 v2.1.1 h1:61MHQzzDAA4ynQ7GvaLoKSTllIvWc1Pv7+oEUAsWoVw=
|
||||
codeberg.org/scip/swayipc/v2 v2.1.1/go.mod h1:cqicjgMgPS7tGTJgjqjSMvnLeMA+J3to/YnufcysCns=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/lmittmann/tint v1.1.2 h1:2CQzrL6rslrsyjqLDwD11bZ5OpLBPU+g3G/r5LSfS8w=
|
||||
|
||||
32
main.go
32
main.go
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user