Skip to content
Golang Sway IPC bindings and autotiling daemon
Go Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ipc
scripts
swaymgr
LICENSE
README.org

README.org

GoSway

Golang Sway IPC bindings and autotiling daemon.

Read a blog post(in Russian).

ipc

Install

go get github.com/Difrex/gosway/ipc

Usage

Initialize an new connection to the Sway socket

import (
	"github.com/Difrex/gosway/ipc"
)

sc, err := ipc.NewSwayConnection()
if err != nil {
    panic(err)
}

Workspaces

Workspaces list

ws, err := sc.GetWorkspaces()
if err != nil {
    panic(err)
}

for _, workspace := range ws {
    fmt.Println(workspace.Name)
}

Get focused workspace

ws, err := sc.GetFocusedWorkspace()
if err != nil {
    panic(err)
}

Get focused workspace windows

windows, err := sc.GetFocusedWorkspaceWindows()
if err != nil {
    panic(err)
}
for _, window := range windows {
    fmt.Println(window.Name)
}

Events subscribe

You needs a connection for sending command to the Sway and another one for events listener.

commandConn, err := ipc.NewSwayConnection()
if err != nil {
    panic(err)
}

listenerConn, err := ipc.NewSwayConnection()
if err != nil {
    panic(err)
}

// Run a listener
ch := make(chan *ipc.Event)
go subCon.SubscribeListener(ch)

for {
    event := <-ch
    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))
    }
}
You can’t perform that action at this time.