/
output.go
233 lines (185 loc) · 5.27 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package wlr
/*
#include <wlr/backend/wayland.h>
#include <wlr/backend/x11.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
*/
import "C"
import (
"errors"
"image"
"unsafe"
)
type Output struct {
p *C.struct_wlr_output
}
func (o Output) OnDestroy(cb func(Output)) Listener {
return newListener(&o.p.events.destroy, func(lis Listener, data unsafe.Pointer) {
cb(o)
})
}
func (o Output) Name() string {
return C.GoString(o.p.name)
}
func (o Output) Scale() float32 {
return float32(o.p.scale)
}
func (o Output) SetScale(scale float32) {
C.wlr_output_set_scale(o.p, C.float(scale))
}
func (o Output) Transform() OutputTransform {
return OutputTransform(o.p.transform)
}
func (o Output) SetTransform(transform OutputTransform) {
C.wlr_output_set_transform(o.p, C.enum_wl_output_transform(transform))
}
func (o Output) TransformMatrix() *Matrix {
return matrixFromC(&o.p.transform_matrix)
}
func (o Output) OnFrame(cb func(Output)) Listener {
return newListener(&o.p.events.frame, func(lis Listener, data unsafe.Pointer) {
cb(o)
})
}
func (o Output) RenderSoftwareCursors(damage image.Rectangle) {
var cd *C.pixman_region32_t
if damage != image.ZR {
t := rectToC(damage)
cd = &t
}
C.wlr_output_render_software_cursors(o.p, cd)
}
func (o Output) TransformedResolution() (int, int) {
var width, height C.int
C.wlr_output_transformed_resolution(o.p, &width, &height)
return int(width), int(height)
}
func (o Output) EffectiveResolution() (int, int) {
var width, height C.int
C.wlr_output_effective_resolution(o.p, &width, &height)
return int(width), int(height)
}
func (o Output) InitRender(a Allocator, r Renderer) {
C.wlr_output_init_render(o.p, a.p, r.p)
}
func (o Output) AttachRender() (int, error) {
var bufferAge C.int
if !C.wlr_output_attach_render(o.p, &bufferAge) {
return 0, errors.New("can't make output context current")
}
return int(bufferAge), nil
}
func (o Output) Rollback() {
C.wlr_output_rollback(o.p)
}
func (o Output) CreateGlobal() {
C.wlr_output_create_global(o.p)
}
func (o Output) DestroyGlobal() {
C.wlr_output_destroy_global(o.p)
}
func (o Output) Commit() {
C.wlr_output_commit(o.p)
}
func (o Output) Modes() (modes []OutputMode) {
offset := int(unsafe.Offsetof(C.struct_wlr_output_mode{}.link))
listForEach(&o.p.modes, offset, func(mode *C.struct_wlr_output_mode) bool {
modes = append(modes, OutputMode{p: mode})
return true
})
return modes
}
func (o Output) SetMode(mode OutputMode) {
C.wlr_output_set_mode(o.p, mode.p)
}
func (o Output) Enable(enable bool) {
C.wlr_output_enable(o.p, C.bool(enable))
}
func (o Output) SetTitle(title string) error {
if C.wlr_output_is_wl(o.p) {
C.wlr_wl_output_set_title(o.p, C.CString(title))
} else if C.wlr_output_is_x11(o.p) {
C.wlr_x11_output_set_title(o.p, C.CString(title))
} else {
return errors.New("this output type cannot have a title")
}
return nil
}
func (o Output) PreferredMode() OutputMode {
p := C.wlr_output_preferred_mode(o.p)
return OutputMode{p: p}
}
func (o Output) Width() int {
return int(o.p.width)
}
func (o Output) Height() int {
return int(o.p.height)
}
type OutputLayout struct {
p *C.struct_wlr_output_layout
}
func CreateOutputLayout() OutputLayout {
p := C.wlr_output_layout_create()
return OutputLayout{p: p}
}
func (l OutputLayout) Destroy() {
C.wlr_output_layout_destroy(l.p)
}
func (l OutputLayout) AddAuto(output Output) {
C.wlr_output_layout_add_auto(l.p, output.p)
}
func (l OutputLayout) Add(output Output, lx, ly int) {
C.wlr_output_layout_add(l.p, output.p, C.int(lx), C.int(ly))
}
func (l OutputLayout) OutputCoords(output Output) (x float64, y float64) {
var ox, oy C.double
C.wlr_output_layout_output_coords(l.p, output.p, &ox, &oy)
return float64(ox), float64(oy)
}
func (l OutputLayout) OutputAt(x, y float64) Output {
p := C.wlr_output_layout_output_at(l.p, C.double(x), C.double(y))
return Output{p: p}
}
func (l OutputLayout) Get(output Output) OutputLayoutOutput {
p := C.wlr_output_layout_get(l.p, output.p)
return OutputLayoutOutput{p: p}
}
type OutputLayoutOutput struct {
p *C.struct_wlr_output_layout_output
}
func (o OutputLayoutOutput) X() int {
return int(o.p.x)
}
func (o OutputLayoutOutput) Y() int {
return int(o.p.y)
}
type OutputMode struct {
p *C.struct_wlr_output_mode
}
func (m OutputMode) Width() int32 {
return int32(m.p.width)
}
func (m OutputMode) Height() int32 {
return int32(m.p.height)
}
func (m OutputMode) RefreshRate() int32 {
return int32(m.p.refresh)
}
func (m OutputMode) Valid() bool {
return m.p != nil
}
type OutputTransform int
const (
OutputTransformNormal OutputTransform = C.WL_OUTPUT_TRANSFORM_NORMAL
OutputTransform90 OutputTransform = C.WL_OUTPUT_TRANSFORM_90
OutputTransform180 OutputTransform = C.WL_OUTPUT_TRANSFORM_180
OutputTransform270 OutputTransform = C.WL_OUTPUT_TRANSFORM_270
OutputTransformFlipped OutputTransform = C.WL_OUTPUT_TRANSFORM_FLIPPED
OutputTransformFlipped90 OutputTransform = C.WL_OUTPUT_TRANSFORM_FLIPPED_90
OutputTransformFlipped180 OutputTransform = C.WL_OUTPUT_TRANSFORM_FLIPPED_180
OutputTransformFlipped270 OutputTransform = C.WL_OUTPUT_TRANSFORM_FLIPPED_270
)
func (transform OutputTransform) Invert() OutputTransform {
return OutputTransform(C.wlr_output_transform_invert(C.enum_wl_output_transform(transform)))
}