mirror of
https://codeberg.org/scip/swaycycle.git
synced 2026-08-24 06:44:18 +02:00
Compare commits
2 Commits
release-64
...
update-swa
| Author | SHA1 | Date | |
|---|---|---|---|
| b45cb9ee33 | |||
|
|
ed91eda7dc |
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module swaycycle
|
|||||||
go 1.26
|
go 1.26
|
||||||
|
|
||||||
require (
|
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/lmittmann/tint v1.1.3
|
||||||
github.com/mattn/go-isatty v0.0.24
|
github.com/mattn/go-isatty v0.0.24
|
||||||
github.com/spf13/pflag v1.0.10
|
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 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.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 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||||
github.com/lmittmann/tint v1.1.2 h1:2CQzrL6rslrsyjqLDwD11bZ5OpLBPU+g3G/r5LSfS8w=
|
github.com/lmittmann/tint v1.1.2 h1:2CQzrL6rslrsyjqLDwD11bZ5OpLBPU+g3G/r5LSfS8w=
|
||||||
|
|||||||
32
main.go
32
main.go
@@ -36,15 +36,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
root = iota + 1
|
|
||||||
output
|
|
||||||
workspace
|
|
||||||
con
|
|
||||||
floating
|
|
||||||
|
|
||||||
LevelNotice = slog.Level(2)
|
LevelNotice = slog.Level(2)
|
||||||
|
|
||||||
VERSION = "v0.3.2"
|
VERSION = "v0.3.3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -170,7 +164,7 @@ func cycle() error {
|
|||||||
// get into the sway tree, determine current workspace and extract all
|
// get into the sway tree, determine current workspace and extract all
|
||||||
// its visible windows, store them in the global var Visibles
|
// its visible windows, store them in the global var Visibles
|
||||||
func processJSON(sway *swayipc.Node) error {
|
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")
|
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
|
// iterate recursively over given node list extracting visible windows
|
||||||
func recurseNodes(nodes []*swayipc.Node) {
|
func recurseNodes(nodes []*swayipc.Node) {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if istype(node, workspace) {
|
if node.IsWorkspace() {
|
||||||
if node.Name == CurrentWorkspace {
|
if node.Name == CurrentWorkspace {
|
||||||
// floating_nodes need to be sorted because
|
// floating_nodes need to be sorted because
|
||||||
// order changes each time they are focused.
|
// 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
|
// the first nodes seen are workspaces, so if we see a con
|
||||||
// node, we are already inside the current workspace
|
// 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 != "") {
|
(node.Window > 0 || node.X11Window != "") {
|
||||||
Visibles = append(Visibles, node)
|
Visibles = append(Visibles, node)
|
||||||
} else {
|
} 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
|
// IsNoTty returns TRUE if stdout is NOT a tty or windows
|
||||||
func IsNoTty() bool {
|
func IsNoTty() bool {
|
||||||
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user