diff --git a/wayland_adapter/framework/core/wayland_data_device.cpp b/wayland_adapter/framework/core/wayland_data_device.cpp index d841ccb4710444fb18ae268b39106c175d82827b..d5ab3e9f83a9c428ee189a61439d01aa58218b57 100644 --- a/wayland_adapter/framework/core/wayland_data_device.cpp +++ b/wayland_adapter/framework/core/wayland_data_device.cpp @@ -123,8 +123,11 @@ int32_t WaylandDataDevice::PointerStartDrag( } auto seatResource = CastFromResource((seatResource_)); if (seatResource) { - auto keyboard = seatResource->GetChildKeyboard(); - wl_keyboard_send_leave(keyboard->WlResource(), serial, iconSurface->WlResource()); + std::list> KeyboardList; + seatResource->GetChildKeyboard(KeyboardList); + for (auto& keyboardResourceItem : KeyboardList) { + wl_keyboard_send_leave(keyboardResourceItem->WlResource(), serial, iconSurface->WlResource()); + } } return 0; diff --git a/wayland_adapter/framework/core/wayland_pointer.cpp b/wayland_adapter/framework/core/wayland_pointer.cpp index a8c3449624cbc283c30d2f81fb2bc4a412fba610..999b5cf8561992058075db7feeee662b68d42b2b 100644 --- a/wayland_adapter/framework/core/wayland_pointer.cpp +++ b/wayland_adapter/framework/core/wayland_pointer.cpp @@ -93,6 +93,7 @@ void WaylandPointer::OnPointerLeave(struct wl_resource *surface_resource) return; } wl_pointer_send_leave(pointer, serial, surface_resource); + wl_pointer_send_frame(pointer); } void WaylandPointer::OnPointerEnter(int32_t posX, int32_t posY, struct wl_resource *surface_resource) @@ -109,6 +110,7 @@ void WaylandPointer::OnPointerEnter(int32_t posX, int32_t posY, struct wl_resour } uint32_t serial = wl_display_next_serial(display); wl_pointer_send_enter(pointer, serial, surface_resource, posFixedX, posFixedY); + wl_pointer_send_frame(pointer); } void WaylandPointer::SetCursor(uint32_t serial, struct wl_resource *surface, int32_t hotsPotx, int32_t hotsPoty) diff --git a/wayland_adapter/framework/core/wayland_seat.cpp b/wayland_adapter/framework/core/wayland_seat.cpp index f0eea6f336c24fbc670c0f586e480b35d3c3be80..b9f2f207db7f927690d4a5eb0b41e94aaddbe0ed 100644 --- a/wayland_adapter/framework/core/wayland_seat.cpp +++ b/wayland_adapter/framework/core/wayland_seat.cpp @@ -98,7 +98,7 @@ void WaylandSeat::Bind(struct wl_client *client, uint32_t version, uint32_t id) return; } WaylandObjectsPool::GetInstance().AddObject(ObjectId(object->WlClient(), object->Id()), object); - seatResourcesMap_[client] = object; + seatResourcesMap_[client].emplace_back(object); if (thread_ != nullptr) { if (thread_->joinable()) { @@ -106,42 +106,56 @@ void WaylandSeat::Bind(struct wl_client *client, uint32_t version, uint32_t id) } thread_ = nullptr; } - thread_ = std::make_unique(&WaylandSeat::UpdateCapabilities, this); + thread_ = std::make_unique(&WaylandSeat::UpdateCapabilities, object->WlResource()); } -OHOS::sptr WaylandSeat::GetKeyboardResource(struct wl_client *client) +void WaylandSeat::GetKeyboardResource(struct wl_client *client, std::list>& list) { - if (seatResourcesMap_.count(client) == 0) { - return nullptr; + auto iter = seatResourcesMap_.find(client); + if (iter == seatResourcesMap_.end()) { + return; } - auto seatResource = seatResourcesMap_.at(client); - // Erase seat resource from map if it is destroyed. - if (seatResource == nullptr) { - seatResourcesMap_.erase(client); - return nullptr; + /* A wl_client object maybe has many seatResourceObjects, each seatResourceObject maybe has many keyboardResourceObjects + * so we need get all keyboardResourceObjects in this wl_client object. + */ + auto seatList = iter->second; + for (auto& seatResourceItem : seatList) { + std::list> KeyboardList; + seatResourceItem->GetChildKeyboard(KeyboardList); + if (KeyboardList.empty()) { + continue; + } + for (auto& keyboardResourceItem : KeyboardList) { + list.emplace_back(keyboardResourceItem); + } } - - return seatResource->GetChildKeyboard(); } -OHOS::sptr WaylandSeat::GetPointerResource(struct wl_client *client) +void WaylandSeat::GetPointerResource(struct wl_client *client, std::list>& list) { - if (seatResourcesMap_.count(client) == 0) { - return nullptr; + auto iter = seatResourcesMap_.find(client); + if (iter == seatResourcesMap_.end()) { + return; } - auto seatResource = seatResourcesMap_.at(client); - // Erase seat resource from map if it is destroyed. - if (seatResource == nullptr) { - seatResourcesMap_.erase(client); - return nullptr; + /* A wl_client object maybe has many seatResourceObjects, each seatResourceObject maybe has many pointerResourceObjects + * so we need get all pointerResourceObjects in this wl_client object. + */ + auto seatList = iter->second; + for (auto& seatResourceItem : seatList) { + std::list> pointerList; + seatResourceItem->GetChildPointer(pointerList); + if (pointerList.empty()) { + continue; + } + for (auto& pointerResourceItem : pointerList) { + list.emplace_back(pointerResourceItem); + } } - - return seatResource->GetChildPointer(); } -void WaylandSeat::UpdateCapabilities() +void WaylandSeat::UpdateCapabilities(struct wl_resource *resource) { LOG_INFO("UpdateCapabilities in"); uint32_t cap = 0; @@ -179,16 +193,7 @@ void WaylandSeat::UpdateCapabilities() usleep(3 * 1000); // wait for GetDeviceCb finish wait_count++; } - - for (auto iter = seatResourcesMap_.begin(); iter != seatResourcesMap_.end();) { - auto seatObj = iter->second; - if (seatObj == nullptr || seatObj->WlResource() == nullptr) { - iter = seatResourcesMap_.erase(iter); - } else { - wl_seat_send_capabilities(seatObj->WlResource(), cap); - ++iter; - } - } + wl_seat_send_capabilities(resource, cap); } WaylandSeatObject::WaylandSeatObject(struct wl_client *client, uint32_t version, uint32_t id) @@ -196,14 +201,23 @@ WaylandSeatObject::WaylandSeatObject(struct wl_client *client, uint32_t version, WaylandSeatObject::~WaylandSeatObject() noexcept {} -OHOS::sptr WaylandSeatObject::GetChildPointer() + +void WaylandSeatObject::GetChildPointer(std::list> &list) { - return pointer_; + auto iter = pointerResourcesMap_.find(WlClient()); + if (iter == pointerResourcesMap_.end()) { + return; + } + list = iter->second; } -OHOS::sptr WaylandSeatObject::GetChildKeyboard() +void WaylandSeatObject::GetChildKeyboard(std::list> &list) { - return keyboard_; + auto iter = keyboardResourcesMap_.find(WlClient()); + if (iter == keyboardResourcesMap_.end()) { + return; + } + list = iter->second; } void WaylandSeatObject::GetPointer(uint32_t id) @@ -213,7 +227,8 @@ void WaylandSeatObject::GetPointer(uint32_t id) LOG_ERROR("no memory"); return; } - pointer_ = pointer; + + pointerResourcesMap_[WlClient()].emplace_back(pointer); } void WaylandSeatObject::GetKeyboard(uint32_t id) @@ -223,8 +238,7 @@ void WaylandSeatObject::GetKeyboard(uint32_t id) LOG_ERROR("no memory"); return; } - - keyboard_ = keyboard; + keyboardResourcesMap_[WlClient()].emplace_back(keyboard); } void WaylandSeatObject::GetTouch(uint32_t id) diff --git a/wayland_adapter/framework/core/wayland_seat.h b/wayland_adapter/framework/core/wayland_seat.h index 2143e07741fef0a47b9a3644dcdf8b895903cada..90961eb3181b3216e3e17928e748fa26951182a5 100644 --- a/wayland_adapter/framework/core/wayland_seat.h +++ b/wayland_adapter/framework/core/wayland_seat.h @@ -16,6 +16,7 @@ #pragma once #include +#include #include "wayland_global.h" #include "wayland_pointer.h" #include "wayland_keyboard.h" @@ -38,15 +39,15 @@ class WaylandSeat final : public WaylandGlobal { public: static OHOS::sptr Create(struct wl_display *display); static OHOS::sptr GetWaylandSeatGlobal(); - OHOS::sptr GetPointerResource(struct wl_client *client); - OHOS::sptr GetKeyboardResource(struct wl_client *client); + void GetPointerResource(struct wl_client *client, std::list> &list); + void GetKeyboardResource(struct wl_client *client, std::list> &list); ~WaylandSeat() noexcept override; private: WaylandSeat(struct wl_display *display); void Bind(struct wl_client *client, uint32_t version, uint32_t id) override; - void UpdateCapabilities(); - std::unordered_map> seatResourcesMap_; + static void UpdateCapabilities(struct wl_resource *resource); + std::unordered_map>> seatResourcesMap_; std::unique_ptr thread_ = nullptr; }; @@ -56,16 +57,15 @@ class WaylandSeatObject final : public WaylandResourceObject { public: WaylandSeatObject(struct wl_client *client, uint32_t version, uint32_t id); ~WaylandSeatObject() noexcept; - OHOS::sptr GetChildPointer(); - OHOS::sptr GetChildKeyboard(); + void GetChildPointer(std::list> &list); + void GetChildKeyboard(std::list> &list); private: void GetPointer(uint32_t id); void GetKeyboard(uint32_t id); void GetTouch(uint32_t id); - - OHOS::sptr pointer_; - OHOS::sptr keyboard_; + std::unordered_map>> pointerResourcesMap_; + std::unordered_map>> keyboardResourcesMap_; }; } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index 56a374f6bc361e30e839cca11acae06b1d877f8f..a077929e85338960070571590abaa42e82121063 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -78,18 +78,17 @@ bool InputEventConsumer::OnInputEvent(const std::shared_ptr if (wlSeat == nullptr) { return false; } - auto keyboard = wlSeat->GetKeyboardResource(wlSurface_->WlClient()); - if (keyboard == nullptr) { - LOG_WARN("GetKeyboardResource fail"); - return false; - } + std::list> keyboardList; + wlSeat->GetKeyboardResource(wlSurface_->WlClient(), keyboardList); int32_t keyAction = MapKeyAction(keyEvent->GetKeyAction()); if (keyAction == INVALID_KEYACTION) { return false; } - keyboard->OnKeyboardKey(keyEvent->GetKeyCode(), keyAction, keyEvent->GetActionTime()); + for (auto &keyboard : keyboardList) { + keyboard->OnKeyboardKey(keyEvent->GetKeyCode(), keyAction, keyEvent->GetActionTime()); + } keyEvent->MarkProcessed(); return true; } @@ -107,17 +106,10 @@ bool InputEventConsumer::OnInputEvent(const std::shared_ptrMarkProcessed(); - auto pointer = wlSeat->GetPointerResource(wlSurface_->WlClient()); - if (pointer == nullptr) { - LOG_WARN("GetPointerResource fail"); - return false; - } - - auto keyboard = wlSeat->GetKeyboardResource(wlSurface_->WlClient()); - if (keyboard == nullptr) { - LOG_WARN("GetKeyboardResource fail"); - return false; - } + std::list> pointerList; + std::list> keyboardList; + wlSeat->GetPointerResource(wlSurface_->WlClient(), pointerList); + wlSeat->GetKeyboardResource(wlSurface_->WlClient(), keyboardList); OHOS::MMI::PointerEvent::PointerItem pointerItem; int32_t pointId = pointerEvent->GetPointerId(); @@ -127,20 +119,31 @@ bool InputEventConsumer::OnInputEvent(const std::shared_ptrGetPointerAction() == OHOS::MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW) { - pointer->OnPointerEnter(pointerItem.GetWindowX(), pointerItem.GetWindowY(), wlSurface_->WlResource()); - keyboard->OnKeyboardEnter(wlSurface_->WlResource()); + for (auto &pointer : pointerList) { + pointer->OnPointerEnter(pointerItem.GetWindowX(), pointerItem.GetWindowY(), wlSurface_->WlResource()); + } + for (auto &keyboard : keyboardList) { + keyboard->OnKeyboardEnter(wlSurface_->WlResource()); + } } else if (pointerEvent->GetPointerAction() == OHOS::MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW) { - pointer->OnPointerLeave(wlSurface_->WlResource()); - keyboard->OnKeyboardLeave(wlSurface_->WlResource()); + for (auto &pointer : pointerList) { + pointer->OnPointerLeave(wlSurface_->WlResource()); + } + for (auto &keyboard : keyboardList) { + keyboard->OnKeyboardLeave(wlSurface_->WlResource()); + } } else if (pointerEvent->GetPointerAction() == OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN || pointerEvent->GetPointerAction() == OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_UP) { int32_t buttonId = MapPointerActionButton(pointerEvent->GetButtonId()); if (buttonId != OHOS::MMI::PointerEvent::BUTTON_NONE) { - pointer->OnPointerButton(pointerEvent->GetActionTime(), buttonId, pointerItem.IsPressed()); + for (auto &pointer : pointerList) { + pointer->OnPointerButton(pointerEvent->GetActionTime(), buttonId, pointerItem.IsPressed()); + } } } else if (pointerEvent->GetPointerAction() == OHOS::MMI::PointerEvent::POINTER_ACTION_MOVE) { - pointer->OnPointerMotionAbsolute( - pointerEvent->GetActionTime(), pointerItem.GetWindowX(), pointerItem.GetWindowY()); + for (auto &pointer : pointerList) { + pointer->OnPointerMotionAbsolute(pointerEvent->GetActionTime(), pointerItem.GetWindowX(), pointerItem.GetWindowY()); + } } return true; } @@ -427,12 +430,15 @@ void WaylandSurface::CheckIsPointerSurface() return; } - auto pointer = wlSeat->GetPointerResource(WlClient()); - if (pointer == nullptr) { - return; + std::list> pointerList; + wlSeat->GetPointerResource(WlClient(), pointerList); + for (auto &pointer : pointerList) { + isPointerSurface_ = pointer->IsCursorSurface(WlResource()); + if (isPointerSurface_) { + break; + } } - isPointerSurface_ = pointer->IsCursorSurface(WlResource()); LOG_DEBUG("this surface Pointer Surface: %{public}d", isPointerSurface_); }