Skip to content

Commit d73e35a

Browse files
author
Ómar Högni Guðmarsson
authored
wayland: Fix pointer not being drawn on second VNC connect. (sony#418)
Use global_remove event to clean-up seat map. Signed-off-by: Ómar Högni Guðmarsson <[email protected]>
1 parent 434d509 commit d73e35a

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,31 +289,34 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = {
289289
ELINUX_LOG(TRACE) << "wl_seat_listener.capabilities";
290290

291291
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
292-
auto [iter_inputs, _] =
293-
self->seat_inputs_map_.emplace(seat, seat_inputs());
294-
auto& inputs = iter_inputs->second;
292+
auto seat_iter = self->seat_inputs_map_.find(seat);
293+
if (seat_iter == self->seat_inputs_map_.end()) {
294+
ELINUX_LOG(ERROR) << "Failed to find the seat";
295+
return;
296+
}
297+
auto& inputs = seat_iter->second;
295298

296299
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !inputs.pointer) {
297300
inputs.pointer = wl_seat_get_pointer(seat);
298301
wl_pointer_add_listener(inputs.pointer, &kWlPointerListener, self);
299302
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && inputs.pointer) {
300-
wl_pointer_destroy(inputs.pointer);
303+
wl_pointer_release(inputs.pointer);
301304
inputs.pointer = nullptr;
302305
}
303306

304307
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !inputs.touch) {
305308
inputs.touch = wl_seat_get_touch(seat);
306309
wl_touch_add_listener(inputs.touch, &kWlTouchListener, self);
307310
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && inputs.touch) {
308-
wl_touch_destroy(inputs.touch);
311+
wl_touch_release(inputs.touch);
309312
inputs.touch = nullptr;
310313
}
311314

312315
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !inputs.keyboard) {
313316
inputs.keyboard = wl_seat_get_keyboard(seat);
314317
wl_keyboard_add_listener(inputs.keyboard, &kWlKeyboardListener, self);
315318
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && inputs.keyboard) {
316-
wl_keyboard_destroy(inputs.keyboard);
319+
wl_keyboard_release(inputs.keyboard);
317320
inputs.keyboard = nullptr;
318321
}
319322
},
@@ -347,6 +350,11 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = {
347350
self->pointer_x_ = x_px;
348351
self->pointer_y_ = y_px;
349352
}
353+
354+
// Force redraw even though it is the same cursor name
355+
auto copy = self->cursor_info_.cursor_name;
356+
self->cursor_info_.cursor_name.clear();
357+
self->UpdateFlutterCursor(copy);
350358
},
351359
.leave = [](void* data,
352360
wl_pointer* pointer,
@@ -1513,16 +1521,6 @@ void ELinuxWindowWayland::UpdateVirtualKeyboardStatus(const bool show) {
15131521

15141522
void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) {
15151523
if (view_properties_.use_mouse_cursor) {
1516-
wl_pointer* pointer = nullptr;
1517-
for (auto& [_, inputs] : seat_inputs_map_) {
1518-
if (inputs.pointer != nullptr) {
1519-
pointer = inputs.pointer;
1520-
break;
1521-
}
1522-
}
1523-
if (!pointer) {
1524-
return;
1525-
}
15261524
if (cursor_name.compare(cursor_info_.cursor_name) == 0) {
15271525
return;
15281526
}
@@ -1644,6 +1642,7 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry,
16441642
wl_registry, name, &wl_seat_interface,
16451643
std::min(kMaxVersion, version))),
16461644
seat_inputs());
1645+
registry_names_to_seat_ptr_.emplace(name, inserted->first);
16471646
wl_seat_add_listener(inserted->first, &kWlSeatListener, this);
16481647
return;
16491648
}
@@ -1720,7 +1719,35 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry,
17201719
}
17211720

17221721
void ELinuxWindowWayland::WlUnRegistryHandler(wl_registry* wl_registry,
1723-
uint32_t name) {}
1722+
uint32_t name) {
1723+
// Just remove seats for now, as we don't need to do anything else.
1724+
// But there is also no interface name here.
1725+
auto seat_iter = registry_names_to_seat_ptr_.find(name);
1726+
if (seat_iter != registry_names_to_seat_ptr_.end()) {
1727+
auto seat = seat_iter->second;
1728+
auto seat_inputs_iter = seat_inputs_map_.find(seat);
1729+
if (seat_inputs_iter != seat_inputs_map_.end()) {
1730+
auto& inputs = seat_inputs_iter->second;
1731+
if (inputs.pointer) {
1732+
wl_pointer_release(inputs.pointer);
1733+
inputs.pointer = nullptr;
1734+
}
1735+
if (inputs.touch) {
1736+
wl_touch_release(inputs.touch);
1737+
inputs.touch = nullptr;
1738+
}
1739+
if (inputs.keyboard) {
1740+
wl_keyboard_release(inputs.keyboard);
1741+
inputs.keyboard = nullptr;
1742+
}
1743+
seat_inputs_map_.erase(seat_inputs_iter);
1744+
}
1745+
if (seat) {
1746+
wl_seat_destroy(seat);
1747+
}
1748+
registry_names_to_seat_ptr_.erase(name);
1749+
}
1750+
}
17241751

17251752
bool ELinuxWindowWayland::LoadCursorTheme(uint32_t size) {
17261753
if (!wl_shm_) {

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler {
171171
wl_output* wl_output_;
172172
wl_shm* wl_shm_;
173173
std::unordered_map<wl_seat*, seat_inputs> seat_inputs_map_;
174+
std::unordered_map<uint32_t, wl_seat*> registry_names_to_seat_ptr_;
174175
wl_surface* wl_cursor_surface_;
175176
xdg_wm_base* xdg_wm_base_;
176177
xdg_surface* xdg_surface_;

0 commit comments

Comments
 (0)