-
Notifications
You must be signed in to change notification settings - Fork 22
/
xwayland.go
120 lines (101 loc) · 3.62 KB
/
xwayland.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
package wlroots
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
import "unsafe"
// #cgo pkg-config: wlroots wayland-server
// #cgo CFLAGS: -D_GNU_SOURCE -DWLR_USE_UNSTABLE
// #include <stdlib.h>
// #include <time.h>
// #include <wlr/types/wlr_xdg_shell.h>
// #include <wlr/xwayland.h>
import "C"
type XWayland struct {
p *C.struct_wlr_xwayland
}
/**
* An Xwayland user interface component. It has an absolute position in
* layout-local coordinates.
*
* The inner struct wlr_surface is valid once the associate event is emitted.
* Compositors can set up e.g. map and unmap listeners at this point. The
* struct wlr_surface becomes invalid when the dissociate event is emitted.
*/
type XWaylandSurface struct {
p *C.struct_wlr_xwayland_surface
}
func (x XWayland) Destroy() {
C.wlr_xwayland_destroy(x.p)
}
func (x XWayland) OnNewSurface(cb func(XWaylandSurface)) {
man.add(unsafe.Pointer(x.p), &x.p.events.new_surface, func(data unsafe.Pointer) {
surface := XWaylandSurface{p: (*C.struct_wlr_xwayland_surface)(data)}
man.track(unsafe.Pointer(surface.p), &surface.p.events.destroy)
man.add(unsafe.Pointer(surface.p.surface), &surface.p.surface.events.destroy, func(data unsafe.Pointer) {
man.delete(unsafe.Pointer(surface.p.surface))
})
cb(surface)
})
}
func (x XWayland) SetCursor(img XCursorImage) {
C.wlr_xwayland_set_cursor(x.p, img.p.buffer, img.p.width*4, img.p.width, img.p.height, C.int32_t(img.p.hotspot_x), C.int32_t(img.p.hotspot_y))
}
func (s XWaylandSurface) Activate(activated bool) {
C.wlr_xwayland_surface_activate(s.p, C.bool(activated))
}
func (s XWaylandSurface) Surface() Surface {
return Surface{p: s.p.surface}
}
func (s XWaylandSurface) Geometry() GeoBox {
return GeoBox{
X: int(s.p.x),
Y: int(s.p.y),
Width: int(s.p.width),
Height: int(s.p.height),
}
}
func (s XWaylandSurface) Configure(x int16, y int16, width uint16, height uint16) {
C.wlr_xwayland_surface_configure(s.p, C.int16_t(x), C.int16_t(y), C.uint16_t(width), C.uint16_t(height))
}
func (s XWaylandSurface) OnMap(cb func(XWaylandSurface)) {
man.add(unsafe.Pointer(s.p), &s.p.surface.events._map, func(data unsafe.Pointer) {
cb(s)
})
}
func (s XWaylandSurface) OnUnmap(cb func(XWaylandSurface)) {
man.add(unsafe.Pointer(s.p), &s.p.surface.events.unmap, func(data unsafe.Pointer) {
cb(s)
})
}
func (s XWaylandSurface) OnDestroy(cb func(XWaylandSurface)) {
man.add(unsafe.Pointer(s.p), &s.p.events.destroy, func(data unsafe.Pointer) {
cb(s)
})
}
func (s XWaylandSurface) OnRequestMove(cb func(surface XWaylandSurface)) {
man.add(unsafe.Pointer(s.p), &s.p.events.request_move, func(data unsafe.Pointer) {
cb(s)
})
}
func (s XWaylandSurface) OnRequestResize(cb func(surface XWaylandSurface, edges Edges)) {
man.add(unsafe.Pointer(s.p), &s.p.events.request_resize, func(data unsafe.Pointer) {
event := (*C.struct_wlr_xwayland_resize_event)(data)
cb(s, Edges(event.edges))
})
}
func (s XWaylandSurface) OnRequestConfigure(cb func(surface XWaylandSurface, x int16, y int16, width uint16, height uint16)) {
man.add(unsafe.Pointer(s.p), &s.p.events.request_configure, func(data unsafe.Pointer) {
event := (*C.struct_wlr_xwayland_surface_configure_event)(data)
cb(s, int16(event.x), int16(event.y), uint16(event.width), uint16(event.height))
})
}
/** Create an Xwayland server and XWM.
*
* The server supports a lazy mode in which Xwayland is only started when a
* client tries to connect.
*/
func (d Display) XWaylandCreate(compositor Compositor, lazy bool) XWayland {
p := C.wlr_xwayland_create(d.p, compositor.p, C.bool(lazy))
return XWayland{p: p}
}