diff --git a/wayland_adapter/framework/core/wayland_pointer.cpp b/wayland_adapter/framework/core/wayland_pointer.cpp index dd7b79288b76b32e03ca2ff4e3b0be308710d81a..a8c3449624cbc283c30d2f81fb2bc4a412fba610 100644 --- a/wayland_adapter/framework/core/wayland_pointer.cpp +++ b/wayland_adapter/framework/core/wayland_pointer.cpp @@ -94,6 +94,7 @@ void WaylandPointer::OnPointerLeave(struct wl_resource *surface_resource) } wl_pointer_send_leave(pointer, serial, surface_resource); } + void WaylandPointer::OnPointerEnter(int32_t posX, int32_t posY, struct wl_resource *surface_resource) { wl_fixed_t posFixedX = wl_fixed_from_int(posX); @@ -110,6 +111,20 @@ void WaylandPointer::OnPointerEnter(int32_t posX, int32_t posY, struct wl_resour wl_pointer_send_enter(pointer, serial, surface_resource, posFixedX, posFixedY); } -void WaylandPointer::SetCursor(uint32_t serial, struct wl_resource *surface, int32_t hotsPotx, int32_t hotsPoty) {} +void WaylandPointer::SetCursor(uint32_t serial, struct wl_resource *surface, int32_t hotsPotx, int32_t hotsPoty) +{ + std::lock_guard lock(mutex_); + cursorSurface_ = surface; +} + +bool WaylandPointer::IsCursorSurface(struct wl_resource *surface) +{ + std::lock_guard lock(mutex_); + if (cursorSurface_ == nullptr || surface == nullptr) { + return false; + } + return cursorSurface_ == surface ? true : false; +} + } // namespace Wayland } // namespace FT \ No newline at end of file diff --git a/wayland_adapter/framework/core/wayland_pointer.h b/wayland_adapter/framework/core/wayland_pointer.h index 8e757168c18fe24e1bd8adc4a2f830d3356cb02a..901026f66193a5d3e7de81ab6bff9dcd79c6d78b 100644 --- a/wayland_adapter/framework/core/wayland_pointer.h +++ b/wayland_adapter/framework/core/wayland_pointer.h @@ -15,6 +15,7 @@ #pragma once +#include #include "wayland_resource_object.h" namespace FT { @@ -36,10 +37,13 @@ public: void OnPointerEnter(int32_t posX, int32_t posY, struct wl_resource *surface_resource); void OnPointerButton(uint32_t time, uint32_t button, bool isPressed); void OnPointerMotionAbsolute(uint32_t time, int32_t posX, int32_t posY); + bool IsCursorSurface(struct wl_resource *surface); private: WaylandPointer(struct wl_client *client, uint32_t version, uint32_t id); void SetCursor(uint32_t serial, struct wl_resource *surface, int32_t hotsPotx, int32_t hotsPoty); + struct wl_resource *cursorSurface_ = nullptr; + mutable std::mutex mutex_; }; } // namespace Wayland } // namespace FT \ No newline at end of file diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index f8b2ef4e920974f1ae2e670566610f492e165ad0..2c6b6870ca4f7526e1823b099ebc1c84ac2fdfcb 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -354,6 +354,10 @@ void WaylandSurface::SetWindowType(OHOS::Rosen::WindowType type) void WaylandSurface::Commit() { + if (isPointerSurface_) { + return; // it is pointer surface, we do not handle commit! + } + if (window_ == nullptr) { CreateWindow(); } else { @@ -416,8 +420,29 @@ void WaylandSurface::HandleCommit() { new_.Reset(); } +void WaylandSurface::CheckIsPointerSurface() +{ + OHOS::sptr wlSeat = WaylandSeat::GetWaylandSeatGlobal(); + if (wlSeat == nullptr) { + return; + } + + auto pointer = wlSeat->GetPointerResource(WlClient()); + if (pointer == nullptr) { + return; + } + + isPointerSurface_ = pointer->IsCursorSurface(WlResource()); + LOG_DEBUG("this surface Pointer Surface: %{public}d", isPointerSurface_); +} + void WaylandSurface::CreateWindow() { + CheckIsPointerSurface(); + if (isPointerSurface_) { + return; + } + OHOS::sptr option(new OHOS::Rosen::WindowOption()); option->SetWindowType(type_); option->SetWindowMode(mode_); diff --git a/wayland_adapter/framework/core/wayland_surface.h b/wayland_adapter/framework/core/wayland_surface.h index 41801218290cb7b1b09e142cb8cd4873f618bf9c..9788754e61fbf21201e480faaa345c2b36cf1313 100644 --- a/wayland_adapter/framework/core/wayland_surface.h +++ b/wayland_adapter/framework/core/wayland_surface.h @@ -77,6 +77,7 @@ private: void HandleCommit(); void CreateWindow(); void CopyBuffer(struct wl_shm_buffer *shm); + void CheckIsPointerSurface(); struct wl_resource *parent_ = nullptr; std::list commitCallbacks_; @@ -84,6 +85,7 @@ private: Rect rect_; SurfaceState old_; SurfaceState new_; + bool isPointerSurface_ = false; #ifdef ENABLE_GPU std::unique_ptr renderContext_;