-
Notifications
You must be signed in to change notification settings - Fork 8
/
ShellSurface.go
186 lines (147 loc) · 4.17 KB
/
ShellSurface.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 ShellSurface struct {
id int32
pingListeners []chan ShellSurfacePing
configureListeners []chan ShellSurfaceConfigure
popupDoneListeners []chan ShellSurfacePopupDone
events []func(s *ShellSurface, msg message) error
name string
}
func NewShellSurface() (s *ShellSurface) {
s = new(ShellSurface)
s.name = "ShellSurface"
s.pingListeners = make([]chan ShellSurfacePing, 0)
s.configureListeners = make([]chan ShellSurfaceConfigure, 0)
s.popupDoneListeners = make([]chan ShellSurfacePopupDone, 0)
s.events = append(s.events, shellSurfacePing)
s.events = append(s.events, shellSurfaceConfigure)
s.events = append(s.events, shellSurfacePopupDone)
return
}
func (s *ShellSurface) HandleEvent(msg message) {
if s.events[msg.opcode] != nil {
s.events[msg.opcode](s, msg)
}
}
func (s *ShellSurface) SetId(id int32) {
s.id = id
}
func (s *ShellSurface) Id() int32 {
return s.id
}
func (s *ShellSurface) Name() string {
return s.name
}
////
//// REQUESTS
////
func (s *ShellSurface) Pong(serial uint32) {
sendrequest(s, "wl_shell_surface_pong", serial)
}
func (s *ShellSurface) Move(seat *Seat, serial uint32) {
sendrequest(s, "wl_shell_surface_move", seat, serial)
}
func (s *ShellSurface) Resize(seat *Seat, serial uint32, edges uint32) {
sendrequest(s, "wl_shell_surface_resize", seat, serial, edges)
}
func (s *ShellSurface) SetToplevel() {
sendrequest(s, "wl_shell_surface_set_toplevel", )
}
func (s *ShellSurface) SetTransient(parent *Surface, x int32, y int32, flags uint32) {
sendrequest(s, "wl_shell_surface_set_transient", parent, x, y, flags)
}
func (s *ShellSurface) SetFullscreen(method uint32, framerate uint32, output *Output) {
sendrequest(s, "wl_shell_surface_set_fullscreen", method, framerate, output)
}
func (s *ShellSurface) SetPopup(seat *Seat, serial uint32, parent *Surface, x int32, y int32, flags uint32) {
sendrequest(s, "wl_shell_surface_set_popup", seat, serial, parent, x, y, flags)
}
func (s *ShellSurface) SetMaximized(output *Output) {
sendrequest(s, "wl_shell_surface_set_maximized", output)
}
func (s *ShellSurface) SetTitle(title string) {
sendrequest(s, "wl_shell_surface_set_title", title)
}
func (s *ShellSurface) SetClass(class_ string) {
sendrequest(s, "wl_shell_surface_set_class", class_)
}
////
//// EVENTS
////
type ShellSurfacePing struct {
Serial uint32
}
func (s *ShellSurface) AddPingListener(channel chan ShellSurfacePing) {
s.pingListeners = append(s.pingListeners, channel)
}
func shellSurfacePing(s *ShellSurface, msg message) (err error) {
var data ShellSurfacePing
// Read serial
serial,err := readUint32(msg.buf)
if err != nil {
return
}
data.Serial = serial
// Dispatch events
for _,channel := range s.pingListeners {
go func () {
channel <- data
} ()
}
return
}
type ShellSurfaceConfigure struct {
Edges uint32
Width int32
Height int32
}
func (s *ShellSurface) AddConfigureListener(channel chan ShellSurfaceConfigure) {
s.configureListeners = append(s.configureListeners, channel)
}
func shellSurfaceConfigure(s *ShellSurface, msg message) (err error) {
var data ShellSurfaceConfigure
// Read edges
edges,err := readUint32(msg.buf)
if err != nil {
return
}
data.Edges = edges
// 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
// Dispatch events
for _,channel := range s.configureListeners {
go func () {
channel <- data
} ()
}
return
}
type ShellSurfacePopupDone struct {
}
func (s *ShellSurface) AddPopupDoneListener(channel chan ShellSurfacePopupDone) {
s.popupDoneListeners = append(s.popupDoneListeners, channel)
}
func shellSurfacePopupDone(s *ShellSurface, msg message) (err error) {
var data ShellSurfacePopupDone
// Dispatch events
for _,channel := range s.popupDoneListeners {
go func () {
channel <- data
} ()
}
return
}