-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
68 lines (63 loc) · 1.22 KB
/
event.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"errors"
)
type eventType uint32
// Event types; cf <https://i3wm.org/docs/ipc.html#_events>
const (
eventWorkspace eventType = 0
eventOutput = 1
eventMode = 2
eventWindow = 3
eventBarconfigUpdate = 4
eventBinding = 5
eventShutdown = 6
eventTick = 7
)
const eventN = 8
func (t eventType) String() string {
switch t {
case eventWorkspace:
return "workspace"
case eventOutput:
return "output"
case eventMode:
return "mode"
case eventWindow:
return "window"
case eventBarconfigUpdate:
return "barconfig_update"
case eventBinding:
return "binding"
case eventShutdown:
return "shutdown"
case eventTick:
return "tick"
default:
panic("invalid eventType")
}
}
func eventFromString(t string) (eventType, error) {
switch t {
case "workspace":
return eventWorkspace, nil
case "output":
return eventOutput, nil
case "mode":
return eventMode, nil
case "window":
return eventWindow, nil
case "barconfig_update":
return eventBarconfigUpdate, nil
case "binding":
return eventBinding, nil
case "shutdown":
return eventShutdown, nil
case "tick":
return eventTick, nil
default:
msg := fmt.Sprintf("unknown event string %v", t)
return eventWorkspace, errors.New(msg)
}
}