-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSurface.go
136 lines (108 loc) · 2.64 KB
/
Surface.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
package gowl
import (
"bytes"
)
var _ bytes.Buffer
type Surface struct {
id int32
enterListeners []chan SurfaceEnter
leaveListeners []chan SurfaceLeave
events []func(s *Surface, msg message) error
name string
}
func NewSurface() (s *Surface) {
s = new(Surface)
s.name = "Surface"
s.enterListeners = make([]chan SurfaceEnter, 0)
s.leaveListeners = make([]chan SurfaceLeave, 0)
s.events = append(s.events, surfaceEnter)
s.events = append(s.events, surfaceLeave)
return
}
func (s *Surface) HandleEvent(msg message) {
if s.events[msg.opcode] != nil {
s.events[msg.opcode](s, msg)
}
}
func (s *Surface) SetId(id int32) {
s.id = id
}
func (s *Surface) Id() int32 {
return s.id
}
func (s *Surface) Name() string {
return s.name
}
////
//// REQUESTS
////
func (s *Surface) Destroy() {
sendrequest(s, "wl_surface_destroy", )
}
func (s *Surface) Attach(buffer *Buffer, x int32, y int32) {
sendrequest(s, "wl_surface_attach", buffer, x, y)
}
func (s *Surface) Damage(x int32, y int32, width int32, height int32) {
sendrequest(s, "wl_surface_damage", x, y, width, height)
}
func (s *Surface) Frame(callback *Callback) {
sendrequest(s, "wl_surface_frame", callback)
}
func (s *Surface) SetOpaqueRegion(region *Region) {
sendrequest(s, "wl_surface_set_opaque_region", region)
}
func (s *Surface) SetInputRegion(region *Region) {
sendrequest(s, "wl_surface_set_input_region", region)
}
func (s *Surface) Commit() {
sendrequest(s, "wl_surface_commit", )
}
////
//// EVENTS
////
type SurfaceEnter struct {
Output *Output
}
func (s *Surface) AddEnterListener(channel chan SurfaceEnter) {
s.enterListeners = append(s.enterListeners, channel)
}
func surfaceEnter(s *Surface, msg message) (err error) {
var data SurfaceEnter
// Read output
output,err := readInt32(msg.buf)
if err != nil {
return
}
outputObj := getObject(output)
data.Output = outputObj.(*Output)
// Dispatch events
for _,channel := range s.enterListeners {
go func () {
channel <- data
} ()
}
return
}
type SurfaceLeave struct {
Output *Output
}
func (s *Surface) AddLeaveListener(channel chan SurfaceLeave) {
s.leaveListeners = append(s.leaveListeners, channel)
}
func surfaceLeave(s *Surface, msg message) (err error) {
var data SurfaceLeave
// Read output
output,err := readInt32(msg.buf)
if err != nil {
return
}
outputObj := getObject(output)
data.Output = outputObj.(*Output)
// Dispatch events
for _,channel := range s.leaveListeners {
go func () {
channel <- data
} ()
}
return
}