From ea4b48420feb9e3fce94d24b625f44b0f6b4d4b2 Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Mon, 18 Sep 2023 18:42:04 +0800 Subject: [PATCH] =?UTF-8?q?wayland=20server=E4=B8=8D=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=BC=A0=E6=A0=87surface=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/core/wayland_pointer.cpp | 17 ++++++++++++- .../framework/core/wayland_pointer.h | 4 +++ .../framework/core/wayland_surface.cpp | 25 +++++++++++++++++++ .../framework/core/wayland_surface.h | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/wayland_adapter/framework/core/wayland_pointer.cpp b/wayland_adapter/framework/core/wayland_pointer.cpp index dd7b792..a8c3449 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 8e75716..901026f 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 f8b2ef4..2c6b687 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 4180121..9788754 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_; -- Gitee