From cb3b3805949e7dc0a1b6a57349e3b32bae0088b2 Mon Sep 17 00:00:00 2001 From: jiangwenyu1 Date: Thu, 7 Sep 2023 20:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81wl=5Fseat=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wayland_adapter/framework/BUILD.gn | 1 + .../framework/core/wayland_seat.cpp | 44 +++++++++++++++++++ wayland_adapter/framework/core/wayland_seat.h | 1 + wayland_adapter/test/wayland_demo.cpp | 29 +++++++++++- wayland_adapter/utils/src/wayland_global.cpp | 1 + wayland_adapter/wayland_server.cpp | 2 + wayland_adapter/wayland_server.h | 2 + 7 files changed, 79 insertions(+), 1 deletion(-) diff --git a/wayland_adapter/framework/BUILD.gn b/wayland_adapter/framework/BUILD.gn index b8feb35..27d151a 100644 --- a/wayland_adapter/framework/BUILD.gn +++ b/wayland_adapter/framework/BUILD.gn @@ -49,6 +49,7 @@ ft_source_set("wayland_framewok_sources") { "$display_server_root/rosen/modules/render_service_client/ft_build:librender_service_client", "//build/gn/configs/system_libs:hilog", "//build/gn/configs/system_libs:image", + "//build/gn/configs/system_libs:mmi", "//display_server/drivers/hal/base:ft_event_loop", "//wayland_adapter/utils:wayland_adapter_utils_sources", "//wayland_adapter/wayland_protocols:wayland_protocols_sources", diff --git a/wayland_adapter/framework/core/wayland_seat.cpp b/wayland_adapter/framework/core/wayland_seat.cpp index 01909f2..397c16e 100644 --- a/wayland_adapter/framework/core/wayland_seat.cpp +++ b/wayland_adapter/framework/core/wayland_seat.cpp @@ -17,7 +17,10 @@ #include "wayland_objects_pool.h" #include "version.h" +#include "input_manager.h" +#include +using namespace OHOS::MMI; namespace FT { namespace Wayland { namespace { @@ -71,6 +74,47 @@ void WaylandSeat::Bind(struct wl_client *client, uint32_t version, uint32_t id) return; } WaylandObjectsPool::GetInstance().AddObject(ObjectId(object->WlClient(), object->Id()), object); + UpdateCapabilities(object); +} + +void WaylandSeat::UpdateCapabilities(OHOS::sptr object) +{ + uint32_t cap = 0; + int32_t DevNums = 0; + int32_t hasGetDevNums = 0; + bool isGetIds = false; + int wait_count = 0; + + auto GetDeviceCb = [&hasGetDevNums, &cap](std::shared_ptr inputDevice) { + LOG_INFO("Get device success, id=%{public}d, name=%{public}s, type=%{public}d", + inputDevice->GetId(), inputDevice->GetName().c_str(), inputDevice->GetType()); + if (inputDevice->GetType() == (int32_t)DEVICE_TYPE_MOUSE) { + cap |= WL_SEAT_CAPABILITY_POINTER; + } else if (inputDevice->GetType() == (int32_t)DEVICE_TYPE_KEYBOARD) { + cap |= WL_SEAT_CAPABILITY_KEYBOARD; + } + hasGetDevNums++; + }; + auto GetDeviceIdsCb = [&DevNums, &isGetIds](std::vector ids) { + DevNums = ids.size(); + isGetIds = true; + }; + (void)InputManager::GetInstance()->GetDeviceIds(GetDeviceIdsCb); + while (!isGetIds && wait_count < 100) { + usleep(3 * 1000); // wait for GetDeviceIdsCb finish + wait_count++; + } + + for (int32_t i = 0; i < DevNums; i++) { + InputManager::GetInstance()->GetDevice(i, GetDeviceCb); + } + + wait_count = 0; + while (hasGetDevNums != DevNums && wait_count < 100) { + usleep(3 * 1000); // wait for GetDeviceCb finish + wait_count++; + } + wl_seat_send_capabilities(object->WlResource(), cap); } WaylandSeatObject::WaylandSeatObject(struct wl_client *client, uint32_t version, uint32_t id) diff --git a/wayland_adapter/framework/core/wayland_seat.h b/wayland_adapter/framework/core/wayland_seat.h index 2afb70e..b0281eb 100644 --- a/wayland_adapter/framework/core/wayland_seat.h +++ b/wayland_adapter/framework/core/wayland_seat.h @@ -38,6 +38,7 @@ public: private: WaylandSeat(struct wl_display *display); void Bind(struct wl_client *client, uint32_t version, uint32_t id) override; + void UpdateCapabilities(OHOS::sptr object); }; class WaylandSeatObject final : public WaylandResourceObject { diff --git a/wayland_adapter/test/wayland_demo.cpp b/wayland_adapter/test/wayland_demo.cpp index a5b7965..9bc7ff7 100644 --- a/wayland_adapter/test/wayland_demo.cpp +++ b/wayland_adapter/test/wayland_demo.cpp @@ -54,6 +54,7 @@ struct display { struct wl_compositor *compositor; struct xdg_wm_base *wm_base; struct wl_shm *shm; + struct wl_seat *seat; bool has_rgba8888 = false; }; @@ -534,11 +535,34 @@ static void XdgWmBasePing(void *data, struct xdg_wm_base *shell, uint32_t serial static const struct xdg_wm_base_listener xdg_wm_base_listener = {XdgWmBasePing}; +void wl_seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities) +{ + fprintf(stderr, "wl_seat_capabilities in\n"); + if (capabilities & WL_SEAT_CAPABILITY_POINTER) { + fprintf(stderr, "fangtian has a pointer\n"); + } + if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) { + fprintf(stderr, "fangtian has a keyboard\n"); + } + if (capabilities & WL_SEAT_CAPABILITY_TOUCH) { + fprintf(stderr, "fangtian has a touch screen\n"); + } +} + +void wl_seat_name(void *data, struct wl_seat *wl_seat, const char *name) +{ + fprintf(stderr, "[*] Get wl_seat name event. name: %s\n", name); +} + +struct wl_seat_listener seat_listener = { + wl_seat_capabilities, + wl_seat_name, +}; + static void RegistryGlobal(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { struct display *d = static_cast(data); - if (strcmp(interface, "wl_compositor") == 0) { d->compositor = (struct wl_compositor *)wl_registry_bind(registry, id, &wl_compositor_interface, 1); } else if (strcmp(interface, "xdg_wm_base") == 0) { @@ -547,6 +571,9 @@ static void RegistryGlobal(void *data, struct wl_registry *registry, } else if (strcmp(interface, "wl_shm") == 0) { d->shm = (struct wl_shm *)wl_registry_bind(registry, id, &wl_shm_interface, 1); wl_shm_add_listener(d->shm, &shm_listener, d); + } else if (strcmp(interface, "wl_seat") == 0) { + d->seat = (struct wl_seat *)wl_registry_bind(registry, id, &wl_seat_interface, 1); + wl_seat_add_listener(d->seat, &seat_listener, d); } } diff --git a/wayland_adapter/utils/src/wayland_global.cpp b/wayland_adapter/utils/src/wayland_global.cpp index d4c14f0..7588dfc 100644 --- a/wayland_adapter/utils/src/wayland_global.cpp +++ b/wayland_adapter/utils/src/wayland_global.cpp @@ -28,6 +28,7 @@ WaylandGlobal::WaylandGlobal(struct wl_display *display, const struct wl_interfa global_(wl_global_create(display_, interface_, maxSupportVersion_, this, &WaylandGlobal::BindCallback)) { name_ = std::string(interface_->name) + "_" + std::to_string(maxSupportVersion_); + LOG_INFO("Fangtian wayland global create: %{public}s", name_.c_str()); } WaylandGlobal::~WaylandGlobal() noexcept diff --git a/wayland_adapter/wayland_server.cpp b/wayland_adapter/wayland_server.cpp index 7aee22e..e101978 100644 --- a/wayland_adapter/wayland_server.cpp +++ b/wayland_adapter/wayland_server.cpp @@ -38,6 +38,7 @@ void WaylandServer::CreateGlobalObjects() { compositorGlobal_ = WaylandCompositor::Create(display_); xdgWmBaseGlobal_ = WaylandXdgWmBase::Create(display_); + seatGlobal_ = WaylandSeat::Create(display_); wl_display_add_shm_format(display_, WL_SHM_FORMAT_RGBA8888); wl_display_init_shm(display_); @@ -102,6 +103,7 @@ void WaylandServer::OnStop() loop_ = nullptr; compositorGlobal_ = nullptr; xdgWmBaseGlobal_ = nullptr; + seatGlobal_ = nullptr; } void WaylandServer::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) diff --git a/wayland_adapter/wayland_server.h b/wayland_adapter/wayland_server.h index 5a22a60..babb7ba 100644 --- a/wayland_adapter/wayland_server.h +++ b/wayland_adapter/wayland_server.h @@ -23,6 +23,7 @@ #include "event_loop.h" #include "wayland_compositor.h" #include "wayland_xdg_wm_base.h" +#include "wayland_seat.h" namespace FT { namespace Wayland { @@ -50,6 +51,7 @@ private: std::shared_ptr loop_; OHOS::sptr compositorGlobal_; OHOS::sptr xdgWmBaseGlobal_; + OHOS::sptr seatGlobal_; }; } // namespace Wayland } // namespace FT -- Gitee