use renamed ipc module

This commit is contained in:
2025-08-16 19:59:32 +02:00
parent 14cc48feb4
commit ab8b3a7816
3 changed files with 19 additions and 26 deletions

14
go.mod
View File

@@ -3,14 +3,16 @@ module swaycycle
go 1.23
require (
github.com/alecthomas/repr v0.5.1 // indirect
github.com/lmittmann/tint v1.1.2
github.com/mattn/go-isatty v0.0.20
github.com/spf13/pflag v1.0.7
github.com/tlinden/swayipc v0.0.0-20250816175030-177eecd4757f
github.com/tlinden/yadu v0.1.3
)
require (
github.com/fatih/color v1.16.0 // indirect
github.com/lmittmann/tint v1.1.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/pflag v1.0.7 // indirect
github.com/tlinden/i3ipc v0.0.0-20250815101608-4f7e27528be3 // indirect
github.com/tlinden/yadu v0.1.3 // indirect
golang.org/x/sys v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

8
go.sum
View File

@@ -1,5 +1,3 @@
github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg=
github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
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=
@@ -11,15 +9,15 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/tlinden/i3ipc v0.0.0-20250815101608-4f7e27528be3 h1:/kIZO4852sAVemXtqnsBid0r4Q1h87jDwHa8f7v1h5I=
github.com/tlinden/i3ipc v0.0.0-20250815101608-4f7e27528be3/go.mod h1:mc0toDHmgqgX6FpE69U5yMPnHuLTdekHRslSLDp8xSE=
github.com/tlinden/swayipc v0.0.0-20250816175030-177eecd4757f h1:SP/fEurr6crxQI+j85L61rMppsHmOlJwxVzXnCvYJ40=
github.com/tlinden/swayipc v0.0.0-20250816175030-177eecd4757f/go.mod h1:JwlMIC7eBwV8soCt2UDqlAyBudobLo07ZvepIA0irY8=
github.com/tlinden/yadu v0.1.3 h1:5cRCUmj+l5yvlM2irtpFBIJwVV2DPEgYSaWvF19FtcY=
github.com/tlinden/yadu v0.1.3/go.mod h1:l3bRmHKL9zGAR6pnBHY2HRPxBecf7L74BoBgOOpTcUA=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

23
main.go
View File

@@ -27,7 +27,7 @@ import (
"github.com/lmittmann/tint"
"github.com/mattn/go-isatty"
"github.com/tlinden/i3ipc"
"github.com/tlinden/swayipc"
"github.com/tlinden/yadu"
flag "github.com/spf13/pflag"
@@ -42,18 +42,11 @@ const (
LevelNotice = slog.Level(2)
VERSION = "v0.3.0"
IPC_HEADER_SIZE = 14
IPC_MAGIC = "i3-ipc"
// message types
IPC_GET_TREE = 4
IPC_RUN_COMMAND = 0
VERSION = "v0.4.0"
)
var (
Visibles = []*i3ipc.Node{}
Visibles = []*swayipc.Node{}
CurrentWorkspace = ""
Debug = false
Dumptree = false
@@ -112,7 +105,7 @@ func main() {
}
// connect to sway unix socket
ipc := i3ipc.NewI3ipc()
ipc := swayipc.NewSwayIPC()
err := ipc.Connect()
if err != nil {
@@ -144,7 +137,7 @@ func main() {
// get into the sway tree, determine current workspace and extract all
// its visible windows, store them in the global var Visibles
func processJSON(sway *i3ipc.Node) error {
func processJSON(sway *swayipc.Node) error {
if !istype(sway, root) && len(sway.Nodes) == 0 {
return fmt.Errorf("Invalid or empty JSON structure")
}
@@ -195,7 +188,7 @@ func findNextWindow() int {
}
// actually switch focus using a swaymsg command
func switchFocus(id int, ipc *i3ipc.I3ipc) error {
func switchFocus(id int, ipc *swayipc.SwayIPC) error {
responses, err := ipc.RunContainerCommand(id, "focus")
if err != nil {
log.Fatalf("failed to send focus command to container %d: %w (%s)",
@@ -208,7 +201,7 @@ func switchFocus(id int, ipc *i3ipc.I3ipc) error {
}
// iterate recursively over given node list extracting visible windows
func recurseNodes(nodes []*i3ipc.Node) {
func recurseNodes(nodes []*swayipc.Node) {
for _, node := range nodes {
// we handle nodes and floating_nodes identical
node.Nodes = append(node.Nodes, node.FloatingNodes...)
@@ -275,7 +268,7 @@ func setupLogging(output io.Writer) {
}
// little helper to distinguish sway tree node types
func istype(nd *i3ipc.Node, which int) bool {
func istype(nd *swayipc.Node, which int) bool {
switch nd.Type {
case "root":
return which == root