forked from proxypoke/i3ipc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputs.go
46 lines (41 loc) · 1.36 KB
/
outputs.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Author: slowpoke <mail plus git at slowpoke dot io>
// Repository: https://github.com/proxypoke/i3ipc
//
// This program is free software under the terms of the
// Do What The Fuck You Want To Public License.
// It comes without any warranty, to the extent permitted by
// applicable law. For a copy of the license, see COPYING or
// head to http://sam.zoy.org/wtfpl/COPYING.
package i3ipc
import (
"encoding/json"
)
// Struct representing an output. For documentation of the fields,
// refer to http://i3wm.org/docs/ipc.html#_outputs_reply.
type Output struct {
Name string
Active bool
Rect Rect
Current_Workspace string
//Primary bool
}
// GetOutputs fetches the list of current outputs.
func (self *IPCSocket) GetOutputs() (outputs []Output, err error) {
json_reply, err := self.Raw(I3GetOutputs, "")
if err != nil {
return
}
err = json.Unmarshal(json_reply, &outputs)
if err == nil {
return
}
// Outputs which aren't displaying any workspace will have JSON-null set as
// their value for current_workspace. Since Go's equivalent, nil, can't be
// assigned to strings, it will cause Unmarshall to return with an
// UnmarshalTypeError, but otherwise correctly unmarshal the JSON input. We
// simply ignore this error due to this reason.
if _, ok := err.(*json.UnmarshalTypeError); ok {
err = nil
}
return
}