|
| 1 | +From d2f5a74f9d9afc5bbbb550570b972fb5784e0b09 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Lachlan Frawley < [email protected]> |
| 3 | +Date: Thu, 22 Jun 2023 22:38:29 +0000 |
| 4 | +Subject: [PATCH] Track Wayland seats other than primary |
| 5 | + |
| 6 | +--- |
| 7 | + .../wayland/host/wayland_connection.cc | 7 ++++++ |
| 8 | + .../wayland/host/wayland_connection.h | 1 + |
| 9 | + .../platform/wayland/host/wayland_seat.cc | 24 ++++++++++++++----- |
| 10 | + 3 files changed, 26 insertions(+), 6 deletions(-) |
| 11 | + |
| 12 | +diff --git a/ui/ozone/platform/wayland/host/wayland_connection.cc b/ui/ozone/platform/wayland/host/wayland_connection.cc |
| 13 | +index f04dbf016..01005d419 100644 |
| 14 | +--- a/ui/ozone/platform/wayland/host/wayland_connection.cc |
| 15 | ++++ b/ui/ozone/platform/wayland/host/wayland_connection.cc |
| 16 | +@@ -609,6 +609,13 @@ void WaylandConnection::GlobalRemove(void* data, |
| 17 | + wl_registry* registry, |
| 18 | + uint32_t name) { |
| 19 | + auto* connection = static_cast<WaylandConnection*>(data); |
| 20 | ++ |
| 21 | ++ // We track the names of seats locally |
| 22 | ++ auto extra_seat_it = connection->extra_seats_.find(name); |
| 23 | ++ if(extra_seat_it != connection->extra_seats_.end()) { |
| 24 | ++ connection->extra_seats_.erase(extra_seat_it); |
| 25 | ++ } |
| 26 | ++ |
| 27 | + // The Wayland protocol distinguishes global objects by unique numeric names, |
| 28 | + // which the WaylandOutputManager uses as unique output ids. But, it is only |
| 29 | + // possible to figure out, what global object is going to be removed on the |
| 30 | +diff --git a/ui/ozone/platform/wayland/host/wayland_connection.h b/ui/ozone/platform/wayland/host/wayland_connection.h |
| 31 | +index c0197481b..e48f995ae 100644 |
| 32 | +--- a/ui/ozone/platform/wayland/host/wayland_connection.h |
| 33 | ++++ b/ui/ozone/platform/wayland/host/wayland_connection.h |
| 34 | +@@ -429,6 +429,7 @@ class WaylandConnection { |
| 35 | + zwp_relative_pointer_manager_; |
| 36 | + std::unique_ptr<WaylandZwpPointerGestures> zwp_pointer_gestures_; |
| 37 | + std::unique_ptr<WaylandSeat> seat_; |
| 38 | ++ base::flat_map<uint32_t, std::unique_ptr<WaylandSeat>> extra_seats_; |
| 39 | + std::unique_ptr<WaylandBufferManagerHost> buffer_manager_host_; |
| 40 | + std::unique_ptr<XdgActivation> xdg_activation_; |
| 41 | + std::unique_ptr<XdgForeignWrapper> xdg_foreign_; |
| 42 | +diff --git a/ui/ozone/platform/wayland/host/wayland_seat.cc b/ui/ozone/platform/wayland/host/wayland_seat.cc |
| 43 | +index 061e0560d..08b4b1380 100644 |
| 44 | +--- a/ui/ozone/platform/wayland/host/wayland_seat.cc |
| 45 | ++++ b/ui/ozone/platform/wayland/host/wayland_seat.cc |
| 46 | +@@ -33,8 +33,9 @@ void WaylandSeat::Instantiate(WaylandConnection* connection, |
| 47 | + CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName |
| 48 | + << "\" but got \"" << interface << "\""; |
| 49 | + |
| 50 | +- if (connection->seat_ || |
| 51 | +- !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) { |
| 52 | ++ // Only check if we can bind the interface |
| 53 | ++ if(!wl::CanBind(interface, version, kMinVersion, kMaxVersion)) { |
| 54 | ++ LOG(ERROR) << "Cannot bind wl_seat"; |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | +@@ -44,11 +45,22 @@ void WaylandSeat::Instantiate(WaylandConnection* connection, |
| 59 | + LOG(ERROR) << "Failed to bind to wl_seat global"; |
| 60 | + return; |
| 61 | + } |
| 62 | +- connection->seat_ = std::make_unique<WaylandSeat>(seat.release(), connection); |
| 63 | + |
| 64 | +- // The seat is one of objects needed for data exchange. Notify the connection |
| 65 | +- // so it might set up the rest if all other parts are in place. |
| 66 | +- connection->CreateDataObjectsIfReady(); |
| 67 | ++ // If we have no "primary" seat, then assume whatever seat we get first is |
| 68 | ++ // meant to be the primary seat |
| 69 | ++ if(!connection->seat_) { |
| 70 | ++ connection->seat_ = std::make_unique<WaylandSeat>(seat.release(), connection); |
| 71 | ++ |
| 72 | ++ // The seat is one of objects needed for data exchange. Notify the connection |
| 73 | ++ // so it might set up the rest if all other parts are in place. |
| 74 | ++ connection->CreateDataObjectsIfReady(); |
| 75 | ++ } else { |
| 76 | ++ if(connection->extra_seats_.find(name) != connection->extra_seats_.end()) { |
| 77 | ++ LOG(ERROR) << "Seat with name already exists"; |
| 78 | ++ return; |
| 79 | ++ } |
| 80 | ++ connection->extra_seats_.emplace(name, std::make_unique<WaylandSeat>(seat.release(), connection)); |
| 81 | ++ } |
| 82 | + } |
| 83 | + |
| 84 | + WaylandSeat::WaylandSeat(wl_seat* seat, WaylandConnection* connection) |
| 85 | +-- |
| 86 | +2.34.1 |
| 87 | + |
0 commit comments