-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsync.go
More file actions
32 lines (27 loc) · 764 Bytes
/
sync.go
File metadata and controls
32 lines (27 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package i3
import "encoding/json"
// SyncRequest represents the payload of a Sync request.
type SyncRequest struct {
Window uint32 `json:"window"` // X11 window id
Rnd uint32 `json:"rnd"` // Random value for distinguishing requests
}
// SyncResult attests the sync command was successful.
type SyncResult struct {
Success bool `json:"success"`
}
// Sync sends a tick event with the provided payload.
//
// Sync is supported in i3 ≥ v4.16 (2018-11-04).
func Sync(req SyncRequest) (SyncResult, error) {
b, err := json.Marshal(req)
if err != nil {
return SyncResult{}, err
}
reply, err := roundTrip(messageTypeSync, b)
if err != nil {
return SyncResult{}, err
}
var tr SyncResult
err = json.Unmarshal(reply.Payload, &tr)
return tr, err
}