-
Notifications
You must be signed in to change notification settings - Fork 8
/
Output.go
186 lines (155 loc) · 3.21 KB
/
Output.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package gowl
import (
"bytes"
)
var _ bytes.Buffer
type Output struct {
id int32
geometryListeners []chan OutputGeometry
modeListeners []chan OutputMode
events []func(o *Output, msg message) error
name string
}
func NewOutput() (o *Output) {
o = new(Output)
o.name = "Output"
o.geometryListeners = make([]chan OutputGeometry, 0)
o.modeListeners = make([]chan OutputMode, 0)
o.events = append(o.events, outputGeometry)
o.events = append(o.events, outputMode)
return
}
func (o *Output) HandleEvent(msg message) {
if o.events[msg.opcode] != nil {
o.events[msg.opcode](o, msg)
}
}
func (o *Output) SetId(id int32) {
o.id = id
}
func (o *Output) Id() int32 {
return o.id
}
func (o *Output) Name() string {
return o.name
}
////
//// REQUESTS
////
////
//// EVENTS
////
type OutputGeometry struct {
X int32
Y int32
PhysicalWidth int32
PhysicalHeight int32
Subpixel int32
Make string
Model string
Transform int32
}
func (o *Output) AddGeometryListener(channel chan OutputGeometry) {
o.geometryListeners = append(o.geometryListeners, channel)
}
func outputGeometry(o *Output, msg message) (err error) {
var data OutputGeometry
// Read x
x,err := readInt32(msg.buf)
if err != nil {
return
}
data.X = x
// Read y
y,err := readInt32(msg.buf)
if err != nil {
return
}
data.Y = y
// Read physical_width
physical_width,err := readInt32(msg.buf)
if err != nil {
return
}
data.PhysicalWidth = physical_width
// Read physical_height
physical_height,err := readInt32(msg.buf)
if err != nil {
return
}
data.PhysicalHeight = physical_height
// Read subpixel
subpixel,err := readInt32(msg.buf)
if err != nil {
return
}
data.Subpixel = subpixel
// Read make
make,err := readString(msg.buf)
if err != nil {
return
}
data.Make = make
// Read model
model,err := readString(msg.buf)
if err != nil {
return
}
data.Model = model
// Read transform
transform,err := readInt32(msg.buf)
if err != nil {
return
}
data.Transform = transform
// Dispatch events
for _,channel := range o.geometryListeners {
go func () {
channel <- data
} ()
}
return
}
type OutputMode struct {
Flags uint32
Width int32
Height int32
Refresh int32
}
func (o *Output) AddModeListener(channel chan OutputMode) {
o.modeListeners = append(o.modeListeners, channel)
}
func outputMode(o *Output, msg message) (err error) {
var data OutputMode
// Read flags
flags,err := readUint32(msg.buf)
if err != nil {
return
}
data.Flags = flags
// Read width
width,err := readInt32(msg.buf)
if err != nil {
return
}
data.Width = width
// Read height
height,err := readInt32(msg.buf)
if err != nil {
return
}
data.Height = height
// Read refresh
refresh,err := readInt32(msg.buf)
if err != nil {
return
}
data.Refresh = refresh
// Dispatch events
for _,channel := range o.modeListeners {
go func () {
channel <- data
} ()
}
return
}