diff --git a/wayland_adapter/framework/BUILD.gn b/wayland_adapter/framework/BUILD.gn index b8feb357f14efd10c284f6c3957d8f59daa68dd5..27d151a43ca9e7ed5a638f29c55d1f8b9dd64c52 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 01909f288c25851c20916e006ffc87a7b6ed4a7a..397c16e6ee3f6db35804f6bc26e6f0a177abc21c 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 2afb70eba7e6035a0a8a8a3d56ac1638c3ac08a4..b0281eb178ab171826f8d1187fea72ba542e7005 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 a5b79650dd421bee0df7963c5beebd82812a1cc5..9bc7ff7b4cca0bf9588114a89968e0eae92b4ae9 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 d4c14f0b7cf6f64d792936e67de267a175e82aaf..7588dfcdef95e6cee82b43d438e22cb5c36860f2 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 7aee22ebc17c6e61767f9bc599f9228ebbd3b2d2..e101978208786af08fc7e2069c03219c6a0e9b06 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 5a22a6040461876e13e3266850cc99cbd12f46a1..babb7bafc623142adc3dd009999885b11d1967a4 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