-
Notifications
You must be signed in to change notification settings - Fork 8
/
Seat.go
88 lines (69 loc) · 1.52 KB
/
Seat.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
package gowl
import (
"bytes"
)
var _ bytes.Buffer
type Seat struct {
id int32
capabilitiesListeners []chan SeatCapabilities
events []func(s *Seat, msg message) error
name string
}
func NewSeat() (s *Seat) {
s = new(Seat)
s.name = "Seat"
s.capabilitiesListeners = make([]chan SeatCapabilities, 0)
s.events = append(s.events, seatCapabilities)
return
}
func (s *Seat) HandleEvent(msg message) {
if s.events[msg.opcode] != nil {
s.events[msg.opcode](s, msg)
}
}
func (s *Seat) SetId(id int32) {
s.id = id
}
func (s *Seat) Id() int32 {
return s.id
}
func (s *Seat) Name() string {
return s.name
}
////
//// REQUESTS
////
func (s *Seat) GetPointer(id *Pointer) {
sendrequest(s, "wl_seat_get_pointer", id)
}
func (s *Seat) GetKeyboard(id *Keyboard) {
sendrequest(s, "wl_seat_get_keyboard", id)
}
func (s *Seat) GetTouch(id *Touch) {
sendrequest(s, "wl_seat_get_touch", id)
}
////
//// EVENTS
////
type SeatCapabilities struct {
Capabilities uint32
}
func (s *Seat) AddCapabilitiesListener(channel chan SeatCapabilities) {
s.capabilitiesListeners = append(s.capabilitiesListeners, channel)
}
func seatCapabilities(s *Seat, msg message) (err error) {
var data SeatCapabilities
// Read capabilities
capabilities,err := readUint32(msg.buf)
if err != nil {
return
}
data.Capabilities = capabilities
// Dispatch events
for _,channel := range s.capabilitiesListeners {
go func () {
channel <- data
} ()
}
return
}