Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/difrex/gosway
Golang Sway IPC bindings
https://github.com/difrex/gosway
golang ipc sway tiling
Last synced: 1 day ago
JSON representation
Golang Sway IPC bindings
- Host: GitHub
- URL: https://github.com/difrex/gosway
- Owner: Difrex
- License: apache-2.0
- Created: 2019-04-07T13:51:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-12T14:38:59.000Z (8 months ago)
- Last Synced: 2024-09-26T10:08:35.812Z (about 2 months ago)
- Topics: golang, ipc, sway, tiling
- Language: Go
- Homepage:
- Size: 60.5 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
* GoSway
Golang [[https://github.com/swaywm/sway][Sway]] IPC bindings.
* Install
#+begin_src
go get github.com/Difrex/gosway/ipc
#+end_src* Usage
Initialize an new connection to the Sway socket
#+begin_src go
import (
"github.com/Difrex/gosway/ipc"
)sc, err := ipc.NewSwayConnection()
if err != nil {
panic(err)
}
#+end_src*** Workspaces
Workspaces list
#+begin_src go
ws, err := sc.GetWorkspaces()
if err != nil {
panic(err)
}for _, workspace := range ws {
fmt.Println(workspace.Name)
}
#+end_srcGet focused workspace
#+begin_src go
ws, err := sc.GetFocusedWorkspace()
if err != nil {
panic(err)
}
#+end_srcGet focused workspace windows
#+begin_src go
windows, err := sc.GetFocusedWorkspaceWindows()
if err != nil {
panic(err)
}
for _, window := range windows {
fmt.Println(window.Name)
}
#+end_src* Events subscribe
You needs a connection for sending command to the Sway and another one for events listener.
#+begin_src go
commandConn, err := ipc.NewSwayConnection()
if err != nil {
panic(err)
}subCon, err := ipc.NewSwayConnection()
if err != nil {
panic(err)
}// Subscribe only to the window related events
_, err = subCon.SendCommand(ipc.IPC_SUBSCRIBE, `["window"]`)
if err != nil {
panic(err)
}// Listen for the events
s := subCon.Subscribe()
defer s.Close()for {
select {
case event := <-s.Events:
if event.Change == "new" {
commandConn.RunSwayCommand(fmt.Sprintf("[con_id=%d] split h", event.Container.ID))
commandConn.RunSwayCommand(fmt.Sprintf("[con_id=%d] move down", event.Container.ID))
}
case err := <-s.Errors:
fmt.Println("Error:", err)
break
}
}
#+end_src