15
15
16
16
namespace flutter {
17
17
18
+ #define DISPLAY reinterpret_cast <WaylandDisplay*>(data)
19
+
18
20
const wl_registry_listener WaylandDisplay::kRegistryListener = {
19
21
.global = [](void * data,
20
22
struct wl_registry * wl_registry,
21
23
uint32_t name,
22
24
const char * interface,
23
25
uint32_t version) -> void {
24
- reinterpret_cast <WaylandDisplay*>(data)->AnnounceRegistryInterface (
25
- wl_registry, name, interface, version);
26
+ DISPLAY->AnnounceRegistryInterface (wl_registry, name, interface, version);
26
27
},
28
+
27
29
.global_remove =
28
30
[](void * data, struct wl_registry * wl_registry, uint32_t name) -> void {
29
- reinterpret_cast <WaylandDisplay*>(data)->UnannounceRegistryInterface (
30
- wl_registry, name);
31
+ DISPLAY->UnannounceRegistryInterface (wl_registry, name);
32
+ },
33
+ };
34
+
35
+ const wl_shell_surface_listener WaylandDisplay::kShellSurfaceListener = {
36
+ .ping = [](void * data,
37
+ struct wl_shell_surface * wl_shell_surface,
38
+ uint32_t serial) -> void {
39
+ wl_shell_surface_pong (DISPLAY->shell_surface_ , serial);
40
+ },
41
+
42
+ .configure = [](void * data,
43
+ struct wl_shell_surface * wl_shell_surface,
44
+ uint32_t edges,
45
+ int32_t width,
46
+ int32_t height) -> void {
47
+ FLWAY_ERROR << " Unhandled resize." << std::endl;
48
+ },
49
+
50
+ .popup_done = [](void * data,
51
+ struct wl_shell_surface * wl_shell_surface) -> void {
52
+ // Nothing to do.
31
53
},
32
54
};
33
55
@@ -64,6 +86,16 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height)
64
86
}
65
87
66
88
WaylandDisplay::~WaylandDisplay () {
89
+ if (shell_surface_) {
90
+ wl_shell_surface_destroy (shell_surface_);
91
+ shell_surface_ = nullptr ;
92
+ }
93
+
94
+ if (shell_) {
95
+ wl_shell_destroy (shell_);
96
+ shell_ = nullptr ;
97
+ }
98
+
67
99
if (egl_surface_) {
68
100
eglDestroySurface (egl_display_, egl_surface_);
69
101
egl_surface_ = nullptr ;
@@ -112,6 +144,7 @@ bool WaylandDisplay::Run() {
112
144
}
113
145
114
146
while (valid_) {
147
+ FLWAY_LOG << " Dispatching." << std::endl;
115
148
wl_display_dispatch (display_);
116
149
}
117
150
@@ -163,8 +196,8 @@ static void LogLastEGLError() {
163
196
}
164
197
165
198
bool WaylandDisplay::SetupEGL () {
166
- if (!compositor_) {
167
- FLWAY_ERROR << " EGL setup needs missing compositor connection."
199
+ if (!compositor_ || !shell_ ) {
200
+ FLWAY_ERROR << " EGL setup needs missing compositor and shell connection."
168
201
<< std::endl;
169
202
return false ;
170
203
}
@@ -176,6 +209,19 @@ bool WaylandDisplay::SetupEGL() {
176
209
return false ;
177
210
}
178
211
212
+ shell_surface_ = wl_shell_get_shell_surface (shell_, surface_);
213
+
214
+ if (!shell_surface_) {
215
+ FLWAY_ERROR << " Could not shell surface." << std::endl;
216
+ return false ;
217
+ }
218
+
219
+ wl_shell_surface_add_listener (shell_surface_, &kShellSurfaceListener , this );
220
+
221
+ wl_shell_surface_set_title (shell_surface_, " Flutter" );
222
+
223
+ wl_shell_surface_set_toplevel (shell_surface_);
224
+
179
225
window_ = wl_egl_window_create (surface_, screen_width_, screen_height_);
180
226
181
227
if (!window_) {
@@ -274,9 +320,14 @@ void WaylandDisplay::AnnounceRegistryInterface(struct wl_registry* wl_registry,
274
320
const char * interface_name,
275
321
uint32_t version) {
276
322
if (strcmp (interface_name, " wl_compositor" ) == 0 ) {
277
- const struct wl_interface * interface = &wl_compositor_interface;
278
323
compositor_ = static_cast <decltype (compositor_)>(
279
- wl_registry_bind (wl_registry, name, interface, version));
324
+ wl_registry_bind (wl_registry, name, &wl_compositor_interface, 1 ));
325
+ return ;
326
+ }
327
+
328
+ if (strcmp (interface_name, " wl_shell" ) == 0 ) {
329
+ shell_ = static_cast <decltype (shell_)>(
330
+ wl_registry_bind (wl_registry, name, &wl_shell_interface, 1 ));
280
331
return ;
281
332
}
282
333
0 commit comments