renovate the code, update to go 1.26 and satisfy linter (#3)

This commit is contained in:
T. von Dein
2026-08-22 17:59:59 +02:00
parent 9cd6e4a6b9
commit 6d9763a0a9
77 changed files with 681 additions and 227 deletions

View File

@@ -1,3 +1,6 @@
// Package swayipc can be used to control the sway and swayfx window
// managers ()and possibly i3wm)via a unix domain socket.
package swayipc
import (
@@ -5,41 +8,43 @@ import (
)
const (
VERSION = "v1.0.0"
VERSION = "v2.1.0"
IPC_HEADER_SIZE = 14
IPC_MAGIC = "i3-ipc"
IPC_MAGIC_LEN = 6
IpcHeaderSize = 14
IpcMagix = "i3-ipc"
IpcMagicLen = 6
)
// message types
const (
MsgRunCommand = iota
MsgGetWorkspaces
MsgSubscribe
MsgGetOutputs
MsgGettTree
MsgGetMarks
MsgGetBarConfig
MsgGetVersion
MsgGetBindingModes
MsgGetConfig
MsgSendTick
MsgSync
MsgGetBindingState
)
const (
// message types
RUN_COMMAND = iota
GET_WORKSPACES
SUBSCRIBE
GET_OUTPUTS
GET_TREE
GET_MARKS
GET_BAR_CONFIG
GET_VERSION
GET_BINDING_MODES
GET_CONFIG
SEND_TICK
SYNC
GET_BINDING_STATE
GET_INPUTS = 100
GET_SEATS = 101
MsgGetInputs = 100
MsgGetSeats = 101
)
// This is the primary struct to work with the swayipc module.
// SwayIPC is the primary struct to work with the swayipc module.
type SwayIPC struct {
socket net.Conn
SocketFile string // filename of the i3 IPC socket
Events *Event // store subscribed events, see swayipc.Subscribe()
}
// A rectangle struct, used at various places for geometry etc.
// Rect stores geometrical information, used at various places for geometry etc.
type Rect struct {
X int `json:"x"` // X coordinate
Y int `json:"y"` // Y coordinate
@@ -47,25 +52,26 @@ type Rect struct {
Height int `json:"height"`
}
// Stores responses retrieved via ipc
// Response stores meta data retrieved via ipc
type Response struct {
Success bool `json:"success"`
ParseError bool `json:"parse_error"`
Error string `json:"error"`
}
// Stores the user config for the WM
// Config stores the user config for the WM
type Config struct {
Config string `json:"config"`
}
// Stores the binding state
// State stores the binding state
type State struct {
Name string `json:"name"`
}
// Create a new swayipc.SwayIPC object. Filename argument is optional and
// may denote a filename or the name of an environment variable.
// NewSwayIPC returns a new swayipc.SwayIPC object. Filename argument
// is optional and may denote a filename or the name of an environment
// variable.
//
// By default and if nothing is specified we look for the environment
// variable SWAYSOCK and use the file it points to as unix domain
@@ -82,7 +88,7 @@ func NewSwayIPC(file ...string) *SwayIPC {
return ipc
}
// internal convenience wrapper
// get is a wrapper around sendHeader+readResponse
func (ipc *SwayIPC) get(command uint32) (*RawResponse, error) {
err := ipc.sendHeader(command, 0)
if err != nil {