Skip to content

Commit 5e45a8e

Browse files
committed
Wire up the wl_shell interface connection.
1 parent c2f39a7 commit 5e45a8e

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

src/wayland_display.cc

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,41 @@
1515

1616
namespace flutter {
1717

18+
#define DISPLAY reinterpret_cast<WaylandDisplay*>(data)
19+
1820
const wl_registry_listener WaylandDisplay::kRegistryListener = {
1921
.global = [](void* data,
2022
struct wl_registry* wl_registry,
2123
uint32_t name,
2224
const char* interface,
2325
uint32_t version) -> void {
24-
reinterpret_cast<WaylandDisplay*>(data)->AnnounceRegistryInterface(
25-
wl_registry, name, interface, version);
26+
DISPLAY->AnnounceRegistryInterface(wl_registry, name, interface, version);
2627
},
28+
2729
.global_remove =
2830
[](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.
3153
},
3254
};
3355

@@ -64,6 +86,16 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height)
6486
}
6587

6688
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+
6799
if (egl_surface_) {
68100
eglDestroySurface(egl_display_, egl_surface_);
69101
egl_surface_ = nullptr;
@@ -112,6 +144,7 @@ bool WaylandDisplay::Run() {
112144
}
113145

114146
while (valid_) {
147+
FLWAY_LOG << "Dispatching." << std::endl;
115148
wl_display_dispatch(display_);
116149
}
117150

@@ -163,8 +196,8 @@ static void LogLastEGLError() {
163196
}
164197

165198
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."
168201
<< std::endl;
169202
return false;
170203
}
@@ -176,6 +209,19 @@ bool WaylandDisplay::SetupEGL() {
176209
return false;
177210
}
178211

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+
179225
window_ = wl_egl_window_create(surface_, screen_width_, screen_height_);
180226

181227
if (!window_) {
@@ -274,9 +320,14 @@ void WaylandDisplay::AnnounceRegistryInterface(struct wl_registry* wl_registry,
274320
const char* interface_name,
275321
uint32_t version) {
276322
if (strcmp(interface_name, "wl_compositor") == 0) {
277-
const struct wl_interface* interface = &wl_compositor_interface;
278323
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));
280331
return;
281332
}
282333

src/wayland_display.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ class WaylandDisplay : public FlutterApplication::RenderDelegate {
2828

2929
private:
3030
static const wl_registry_listener kRegistryListener;
31+
static const wl_shell_surface_listener kShellSurfaceListener;
3132
bool valid_ = false;
3233
const int screen_width_;
3334
const int screen_height_;
3435
wl_display* display_ = nullptr;
3536
wl_registry* registry_ = nullptr;
3637
wl_compositor* compositor_ = nullptr;
38+
wl_shell* shell_ = nullptr;
39+
wl_shell_surface* shell_surface_ = nullptr;
3740
wl_surface* surface_ = nullptr;
3841
wl_egl_window* window_ = nullptr;
3942
EGLDisplay egl_display_ = EGL_NO_DISPLAY;

0 commit comments

Comments
 (0)