mirror of
https://codeberg.org/scip/swayipc.git
synced 2025-12-16 20:20:56 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9cd6e4a6b9 | |||
|
|
61ff94f09c | ||
| 47c55fae5c | |||
|
|
1cde07a07b | ||
| d64c1ddcc0 | |||
| e516aeab72 | |||
| 3102978317 | |||
| af9eaaf8ae | |||
| ce6d836234 | |||
| 9f08aefcff | |||
| ef2912d034 | |||
| 837443deb4 |
47
.github/workflows/ci.yaml
vendored
47
.github/workflows/ci.yaml
vendored
@@ -1,47 +0,0 @@
|
||||
name: build-and-test
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
version: ['1.22']
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
name: Build
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '${{ matrix.version }}'
|
||||
id: go
|
||||
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: build
|
||||
run: go build
|
||||
|
||||
# - name: test
|
||||
# run: make test
|
||||
|
||||
# - name: Update coverage report
|
||||
# uses: ncruces/go-coverage-report@main
|
||||
# with:
|
||||
# report: true
|
||||
# chart: true
|
||||
# amend: true
|
||||
# if: |
|
||||
# matrix.os == 'ubuntu-latest' &&
|
||||
# github.event_name == 'push'
|
||||
# continue-on-error: true
|
||||
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.22
|
||||
- uses: actions/checkout@v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
27
.woodpecker/build.yaml
Normal file
27
.woodpecker/build.yaml
Normal file
@@ -0,0 +1,27 @@
|
||||
matrix:
|
||||
platform:
|
||||
- linux/amd64
|
||||
goversion:
|
||||
- 1.24
|
||||
|
||||
labels:
|
||||
platform: ${platform}
|
||||
|
||||
steps:
|
||||
build:
|
||||
when:
|
||||
event: [push]
|
||||
image: golang:${goversion}
|
||||
commands:
|
||||
- go get
|
||||
- go build
|
||||
|
||||
linter:
|
||||
when:
|
||||
event: [push]
|
||||
image: golang:${goversion}
|
||||
commands:
|
||||
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
|
||||
- golangci-lint --version
|
||||
- golangci-lint run ./...
|
||||
depends_on: [build]
|
||||
28
README.md
28
README.md
@@ -1,9 +1,9 @@
|
||||
[](https://goreportcard.com/report/github.com/tlinden/swayipc)
|
||||
[](https://github.com/tlinden/swayipc/actions)
|
||||

|
||||
[](https://godoc.org/github.com/tlinden/swayipc)
|
||||
[](https://ci.codeberg.org/repos/15565)
|
||||
[](https://goreportcard.com/report/codeberg.org/scip/swayipc)
|
||||
[](https://codeberg.org/scip/swayipc/raw/branch/main/LICENSE)
|
||||
[](https://godoc.org/codeberg.org/scip/swayipc)
|
||||
|
||||
# swayipc - go bindings to control sway (and possibly i3)
|
||||
# swayipc - go bindings to control sway and swayfx
|
||||
|
||||
Package swayipc can be used to control [sway](https://swaywm.org/),
|
||||
[swayfx](https://github.com/WillPower3309/swayfx) and possibly
|
||||
@@ -26,7 +26,7 @@ haven't tested it on i3wm.
|
||||
The module uses the i3-IPC proctocol as outlined in sway-ipc(7).
|
||||
|
||||
For details on how to use the library, see the
|
||||
[reference documentation](https://godoc.org/github.com/tlinden/swayipc).
|
||||
[reference documentation](https://godoc.org/codeberg.org/scip/swayipc).
|
||||
|
||||
## Example usage
|
||||
|
||||
@@ -39,7 +39,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -66,16 +66,20 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
Also take a look into the **_examples** folder for more examples.
|
||||
Also take a look into the **_examples** folder for more examples.
|
||||
|
||||
You may take a look at the [tool swaycycle](https://github.com/tlinden/swaycycle)
|
||||
For a more comprehensive and practical example look at the
|
||||
[descratch](https://codeberg.org/scip/sway-descratch) program which
|
||||
you can use to selectively retrieve a window from the scratchpad.
|
||||
|
||||
You may also take a look at the [tool swaycycle](https://codeberg.org/scip/swaycycle)
|
||||
which is using this module.
|
||||
|
||||
## Installation
|
||||
|
||||
Execute this to add the module to your project:
|
||||
```sh
|
||||
go get github.com/tlinden/swayipc
|
||||
go get codeberg.org/scip/swayipc/v2
|
||||
```
|
||||
|
||||
## Acknowledgements
|
||||
@@ -91,7 +95,7 @@ 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:
|
||||
https://github.com/TLINDEN/swayipc/issues.
|
||||
https://codeberg.org/scip/swayipc/issues.
|
||||
|
||||
## Copyright and license
|
||||
|
||||
@@ -103,7 +107,7 @@ T.v.Dein <tom AT vondein DOT org>
|
||||
|
||||
## Project homepage
|
||||
|
||||
https://github.com/TLINDEN/swayipc
|
||||
https://codeberg.org/scip/swayipc
|
||||
|
||||
## Copyright and License
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
// Event callback function, needs to implement each subscribed events,
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -37,7 +37,7 @@ func main() {
|
||||
|
||||
// finally execute the given commands on it, you can use any run
|
||||
// command, see sway(5)
|
||||
responses, err := ipc.RunContainerCommand(focused.Id, "floating toggle, border toggle")
|
||||
responses, err := ipc.RunContainerCommand(focused.Id, "floating toggle", "border toggle")
|
||||
if err != nil {
|
||||
repr.Println(responses)
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/tlinden/swayipc"
|
||||
"codeberg.org/scip/swayipc/v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
16
bar.go
16
bar.go
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
17
command.go
17
command.go
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
38
doc.go
38
doc.go
@@ -15,43 +15,5 @@ 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).
|
||||
|
||||
Example usage:
|
||||
|
||||
In this example we retrieve the current focused window:
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tlinden/swayipc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ipc := swayipc.NewSwayIPC()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Also take a look into the **_examples** folder for more examples.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
17
event.go
17
event.go
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module github.com/tlinden/swayipc
|
||||
module codeberg.org/scip/swayipc/v2
|
||||
|
||||
go 1.23
|
||||
|
||||
|
||||
16
input.go
16
input.go
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
21
net.go
21
net.go
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
@@ -51,8 +34,8 @@ func (ipc *SwayIPC) Connect() error {
|
||||
}
|
||||
|
||||
// Close the socket.
|
||||
func (ipc *SwayIPC) Close() {
|
||||
ipc.socket.Close()
|
||||
func (ipc *SwayIPC) Close() error {
|
||||
return ipc.socket.Close()
|
||||
}
|
||||
|
||||
func (ipc *SwayIPC) sendHeader(messageType uint32, len uint32) error {
|
||||
|
||||
18
node.go
18
node.go
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
@@ -27,9 +11,11 @@ type Node struct {
|
||||
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"`
|
||||
Nodes []*Node `json:"nodes"`
|
||||
FloatingNodes []*Node `json:"floating_nodes"`
|
||||
Focused bool `json:"focused"`
|
||||
Visible bool `json:"visible"`
|
||||
Urgent bool `json:"urgent"`
|
||||
Sticky bool `json:"sticky"`
|
||||
Border string `json:"border"`
|
||||
|
||||
16
output.go
16
output.go
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
16
seat.go
16
seat.go
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
19
swayipc.go
19
swayipc.go
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
@@ -22,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "v0.2.0"
|
||||
VERSION = "v1.0.0"
|
||||
|
||||
IPC_HEADER_SIZE = 14
|
||||
IPC_MAGIC = "i3-ipc"
|
||||
|
||||
16
version.go
16
version.go
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
Copyright © 2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package swayipc
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user