2025-08-16 19:50:30 +02:00
|
|
|
[](https://goreportcard.com/report/github.com/tlinden/swayipc)
|
|
|
|
|
[](https://github.com/tlinden/swayipc/actions)
|
|
|
|
|

|
|
|
|
|
[](https://godoc.org/github.com/tlinden/swayipc)
|
2025-08-15 12:16:08 +02:00
|
|
|
|
2025-08-16 20:01:37 +02:00
|
|
|
# swayipc - go bindings to control sway and swayfx
|
2025-08-15 12:16:08 +02:00
|
|
|
|
2025-08-16 19:50:30 +02:00
|
|
|
Package swayipc can be used to control [sway](https://swaywm.org/),
|
|
|
|
|
[swayfx](https://github.com/WillPower3309/swayfx) and possibly
|
|
|
|
|
[i3wm](http://i3wm.org/) window managers via a unix domain socket.
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
## About
|
|
|
|
|
|
2025-08-16 19:50:30 +02:00
|
|
|
swaywm's interprocess communication (or ipc) is the interface sway,
|
|
|
|
|
swayfx and i3wm use to receive commands from client applications such
|
|
|
|
|
as sway-msg. It also features a publish/subscribe mechanism for
|
|
|
|
|
notifying interested parties of window manager events.
|
|
|
|
|
|
|
|
|
|
swayipc is a go module for controlling the window manager. This project
|
2025-08-15 12:16:08 +02:00
|
|
|
is intended to be useful for general scripting, and for applications
|
|
|
|
|
that interact with the window manager like status line generators,
|
2025-08-16 19:50:30 +02:00
|
|
|
notification daemons, and window pagers. It is primarily designed to
|
|
|
|
|
work with sway and swayfx, but may also work with i3wm, although I
|
|
|
|
|
haven't tested it on i3wm.
|
|
|
|
|
|
|
|
|
|
The module uses the i3-IPC proctocol as outlined in sway-ipc(7).
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
For details on how to use the library, see the
|
2025-08-16 19:50:30 +02:00
|
|
|
[reference documentation](https://godoc.org/github.com/tlinden/swayipc).
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
## Example usage
|
|
|
|
|
|
|
|
|
|
In this example we retrieve the current focused window:
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
|
2025-08-16 19:50:30 +02:00
|
|
|
"github.com/tlinden/swayipc"
|
2025-08-15 12:16:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-08-16 19:50:30 +02:00
|
|
|
ipc := swayipc.NewSwayIPC()
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
err := ipc.Connect()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer ipc.Close()
|
|
|
|
|
|
|
|
|
|
tree, err := ipc.GetTree()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
focused := tree.FindFocused()
|
|
|
|
|
|
|
|
|
|
if focused != nil {
|
|
|
|
|
fmt.Printf("focused node: %s\n id: %d\n Geometry: %dx%d\n",
|
|
|
|
|
focused.Name, focused.Id, focused.Geometry.Width,
|
|
|
|
|
focused.Geometry.Height)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2025-08-20 22:25:40 +02:00
|
|
|
Also take a look into the **_examples** folder for more examples. For
|
|
|
|
|
a more comprehensive and practical example look at the
|
|
|
|
|
`_examples/descratcher` program which you can use to selectively
|
|
|
|
|
retrieve a window from the scratchpad.
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
You may take a look at the [tool swaycycle](https://github.com/tlinden/swaycycle)
|
|
|
|
|
which is using this module.
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
Execute this to add the module to your project:
|
|
|
|
|
```sh
|
2025-08-16 19:50:30 +02:00
|
|
|
go get github.com/tlinden/swayipc
|
2025-08-15 12:16:08 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Acknowledgements
|
|
|
|
|
|
|
|
|
|
A couple of ideas have been taken from the [i3ipc python
|
|
|
|
|
module](https://github.com/altdesktop/i3ipc-python/), although this
|
|
|
|
|
one is not just a port of it and has been written from scratch.
|
|
|
|
|
|
|
|
|
|
## Getting help
|
|
|
|
|
|
2025-08-16 19:50:30 +02:00
|
|
|
Although I'm happy to hear from swayipc users in private email, that's the
|
2025-08-15 12:16:08 +02:00
|
|
|
best way for me to forget to do something.
|
|
|
|
|
|
|
|
|
|
In order to report a bug, unexpected behavior, feature requests or to
|
|
|
|
|
submit a patch, please open an issue on github:
|
2025-08-16 19:50:30 +02:00
|
|
|
https://github.com/TLINDEN/swayipc/issues.
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
## Copyright and license
|
|
|
|
|
|
|
|
|
|
This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3.
|
|
|
|
|
|
|
|
|
|
## Authors
|
|
|
|
|
|
|
|
|
|
T.v.Dein <tom AT vondein DOT org>
|
|
|
|
|
|
|
|
|
|
## Project homepage
|
|
|
|
|
|
2025-08-16 19:50:30 +02:00
|
|
|
https://github.com/TLINDEN/swayipc
|
2025-08-15 12:16:08 +02:00
|
|
|
|
|
|
|
|
## Copyright and License
|
|
|
|
|
|
|
|
|
|
Licensed under the GNU GENERAL PUBLIC LICENSE version 3.
|
|
|
|
|
|
|
|
|
|
## Author
|
|
|
|
|
|
|
|
|
|
T.v.Dein <tom AT vondein DOT org>
|
|
|
|
|
|