-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp_cursor_shape_manager.go
137 lines (117 loc) · 3.33 KB
/
wp_cursor_shape_manager.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
package main
import (
"errors"
"fmt"
)
type WpCursorShapeDevice struct {
Object *WaylandObject
Pointer *WlPointer
serial *uint32
shape *uint32 // wp_cursor_shape_device_v1.shape
}
func (w *WpCursorShapeDevice) Destroy() error {
return nil
}
func (*WpCursorShapeDevice) DashboardShouldDisplay() bool {
return true
}
func (*WpCursorShapeDevice) DashboardCategory() string {
return "Cursor shape"
}
var shapeName = [...]string{"default", "context_menu", "help", "pointer", "progress", "wait", "cell",
"crosshair", "text", "vertical_text", "alias", "copy", "move", "no_drop", "not_allowed",
"grab", "grabbing", "e_resize", "n_resize", "ne_resize", "nw_resize", "s_resize", "se_resize",
"sw_resize", "w_resize", "ew_resize", "ns_resize", "nesw_resize", "nwse_resize", "col_resize",
"row_resize", "all_scroll", "zoom_in", "zoom_out" }
func (w *WpCursorShapeDevice) DashboardPrint(printer func(string, ...interface{})) error {
if w.shape == nil {
printer("%s - %s, shape: not set", Indent(0), w.Object)
} else if int(*w.shape) > len(shapeName) {
printer("%s - %s, shape(unknown id): %d", Indent(0), *w.shape)
} else {
printer("%s - %s, shape: %s", Indent(0), w.Object, shapeName[*w.shape-1])
}
return nil
}
type WpCursorShapeDeviceImpl struct {
client *Client
}
func RegisterCursorShapeDevice(client *Client) {
r := &WpCursorShapeDeviceImpl{
client: client,
}
client.Impls["wp_cursor_shape_device_v1"] = r
}
func (w *WpCursorShapeDeviceImpl) Request(packet *WaylandPacket) error {
object := w.client.ObjectMap[packet.ObjectId]
shapeDevice, ok := object.Data.(*WpCursorShapeDevice)
if !ok {
return errors.New("object is not wp_cursor_shape_device_v1")
}
switch packet.Opcode {
case 0: // destroy
case 1: // set_shape
serial, err := packet.ReadUint32()
if err != nil {
return err
}
shape, err := packet.ReadUint32()
if err != nil {
return err
}
shapeDevice.serial = &serial
shapeDevice.shape = &shape
}
return nil
}
func (w *WpCursorShapeDeviceImpl) Event(packet *WaylandPacket) error {
return errors.New("wp_cursor_shape_device_v1 has no events")
}
type WpCursorShapeManager struct {
Object *WaylandObject
}
func (w *WpCursorShapeManager) Destroy() error {
return nil
}
type WpCursorShapeManagerImpl struct {
client *Client
}
func RegisterCursorShapeManager(client *Client) {
r := &WpCursorShapeManagerImpl{
client: client,
}
client.Impls["wp_cursor_shape_manager_v1"] = r
}
func (w *WpCursorShapeManagerImpl) Request(packet *WaylandPacket) error {
switch packet.Opcode {
case 0: // destroy
case 1: // get_pointer
oid, err := packet.ReadUint32() // new_id<wp_cursor_shape_device_v1>
if err != nil {
return err
}
pid, err := packet.ReadUint32() // object<wl_pointer>
if err != nil {
return err
}
pobj, ok := w.client.ObjectMap[pid]
if !ok {
return fmt.Errorf("no such pointer object: %d", pid)
}
pointer, ok := pobj.Data.(*WlPointer)
if !ok {
return fmt.Errorf("object is not wl_pointer: %d", pid)
}
obj := w.client.NewObject(oid, "wp_cursor_shape_device_v1")
obj.Data = &WpCursorShapeDevice {
Object: obj,
Pointer: pointer,
}
case 2: // get_tablet_tool_v2
// Not implemented
}
return nil
}
func (w *WpCursorShapeManagerImpl) Event(packet *WaylandPacket) error {
return errors.New("wp_cursor_shape_manager_v1 has no events")
}