diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index f8b2ef4e920974f1ae2e670566610f492e165ad0..3d7148d3f2dfebcd492b9e6c21d1096ffbd503c5 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -430,6 +430,7 @@ void WaylandSurface::CreateWindow() LOG_ERROR("Window::Create failed"); return; } + LOG_DEBUG("Window::Create success"); auto listener = std::make_shared(this); window_->SetInputEventConsumer(listener); window_->Show(); @@ -528,5 +529,109 @@ void WaylandSurface::OnModeChange(OHOS::Rosen::WindowMode mode) LOG_DEBUG("OnModeChange, window mode is %{public}d, ignore", mode); } +void WaylandSurface::SetTitle(const char *title) +{ + LOG_DEBUG("Window %{public}s, set Title %{public}s.", windowTitle_.c_str(), title); + windowTitle_ = title; + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + window_->SetAPPWindowLabel(title); +} + +void WaylandSurface::Resize(uint32_t serial, uint32_t edges) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + // window_->Resize(uint32_t width, uint32_t height); +} + +void WaylandSurface::SetMaxSize(int32_t width, int32_t height) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } +} + +void WaylandSurface::SetMinSize(int32_t width, int32_t height) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } +} + +void WaylandSurface::SetMaximized() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + if (maximized_) { + LOG_DEBUG("Window %{public}s already Maximized.", windowTitle_.c_str()); + return UnSetMaximized(); + } + window_->Maximize(); + maximized_ = true; +} + +void WaylandSurface::UnSetMaximized() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + window_->Recover(); + maximized_ = false; +} + +void WaylandSurface::SetFullscreen() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + window_->SetFullScreen(true); +} + +void WaylandSurface::UnSetFullscreen() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + window_->SetFullScreen(false); +} + +void WaylandSurface::SetMinimized() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + window_->Minimize(); +} + +void WaylandSurface::Close() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + if (window_ == nullptr) { + LOG_ERROR("window_ is nullptr"); + return; + } + window_->Close(); +} } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/core/wayland_surface.h b/wayland_adapter/framework/core/wayland_surface.h index 41801218290cb7b1b09e142cb8cd4873f618bf9c..8bc3bd3935f6ec89fe63a353a7a0ed1b62827a05 100644 --- a/wayland_adapter/framework/core/wayland_surface.h +++ b/wayland_adapter/framework/core/wayland_surface.h @@ -61,6 +61,18 @@ public: void OnSizeChange(const OHOS::Rosen::Rect& rect, OHOS::Rosen::WindowSizeChangeReason reason); void OnModeChange(OHOS::Rosen::WindowMode mode); + // form xdgsruface + void SetTitle(const char *title); + void Resize(uint32_t serial, uint32_t edges); + void SetMaxSize(int32_t width, int32_t height); + void SetMinSize(int32_t width, int32_t height); + void SetMaximized(); + void UnSetMaximized(); + void SetFullscreen(); + void UnSetFullscreen(); + void SetMinimized(); + void Close(); + private: WaylandSurface(struct wl_client *client, struct wl_resource *parent, uint32_t version, uint32_t id); @@ -93,6 +105,8 @@ private: OHOS::Rosen::WindowType type_ = OHOS::Rosen::WindowType::APP_WINDOW_BASE; std::shared_ptr surfaceNode_; std::shared_ptr rsSurface_; + std::string windowTitle_ = "unknow"; + bool maximized_ = false; }; } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/stable/wayland_xdg_surface.cpp b/wayland_adapter/framework/stable/wayland_xdg_surface.cpp index cfd820f126e0304fdea8139f459f221ff7fd0382..2604c248ccbdb497e0742821b3e6ae98975eab61 100644 --- a/wayland_adapter/framework/stable/wayland_xdg_surface.cpp +++ b/wayland_adapter/framework/stable/wayland_xdg_surface.cpp @@ -88,6 +88,7 @@ WaylandXdgSurface::~WaylandXdgSurface() noexcept {} void WaylandXdgSurface::GetToplevel(uint32_t id) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); toplevel_ = WaylandXdgToplevel::Create(this, id); if (toplevel_ == nullptr) { LOG_ERROR("no memory"); @@ -99,6 +100,7 @@ void WaylandXdgSurface::GetToplevel(uint32_t id) void WaylandXdgSurface::GetPopup(uint32_t id, struct wl_resource *parent, struct wl_resource *positioner) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); } void WaylandXdgSurface::SetWindowGeometry(int32_t x, int32_t y, int32_t width, int32_t height) @@ -111,6 +113,7 @@ void WaylandXdgSurface::AckConfigure(uint32_t serial) void WaylandXdgSurface::StartMove() { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); auto surface = surface_.promote(); if (surface != nullptr) { surface->StartMove(); @@ -119,6 +122,7 @@ void WaylandXdgSurface::StartMove() void WaylandXdgSurface::SetWindowMode(OHOS::Rosen::WindowMode mode) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); auto surface = surface_.promote(); if (surface != nullptr) { surface->SetWindowMode(mode); @@ -127,6 +131,7 @@ void WaylandXdgSurface::SetWindowMode(OHOS::Rosen::WindowMode mode) void WaylandXdgSurface::SetWindowType(OHOS::Rosen::WindowType type) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); auto surface = surface_.promote(); if (surface != nullptr) { surface->SetWindowType(type); @@ -147,6 +152,7 @@ void WaylandXdgSurface::OnSurfaceCommit() void WaylandXdgSurface::OnSurfaceRect(Rect rect) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); if (role_ == SurfaceRole::XDG_TOPLEVEL) { auto topLevel = toplevel_.promote(); if (topLevel != nullptr) { @@ -154,5 +160,96 @@ void WaylandXdgSurface::OnSurfaceRect(Rect rect) } } } + +void WaylandXdgSurface::SetTitle(const char *title) +{ + LOG_DEBUG("Window %{public}s, set Title %{public}s.", windowTitle_.c_str(), title); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->SetTitle(title); + } + windowTitle_ = title; +} + +void WaylandXdgSurface::Resize(uint32_t serial, uint32_t edges) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->Resize(serial, edges); + } +} + +void WaylandXdgSurface::SetMaxSize(int32_t width, int32_t height) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->SetMaxSize(width, height); + } +} + +void WaylandXdgSurface::SetMinSize(int32_t width, int32_t height) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->SetMinSize(width, height); + } +} + +void WaylandXdgSurface::SetMaximized() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->SetMaximized(); + } +} + +void WaylandXdgSurface::UnSetMaximized() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->UnSetMaximized(); + } +} + +void WaylandXdgSurface::SetFullscreen() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->SetFullscreen(); + } +} + +void WaylandXdgSurface::UnSetFullscreen() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->UnSetFullscreen(); + } +} + +void WaylandXdgSurface::SetMinimized() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->SetMinimized(); + } +} + +void WaylandXdgSurface::Close() +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto surface = surface_.promote(); + if (surface != nullptr) { + surface->Close(); + } +} } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/stable/wayland_xdg_surface.h b/wayland_adapter/framework/stable/wayland_xdg_surface.h index 6ca85c4898f30a7b6a71d73db44d2f12548de2c8..62d8951e101cfea72b8aa69273cfabbc5a41068f 100644 --- a/wayland_adapter/framework/stable/wayland_xdg_surface.h +++ b/wayland_adapter/framework/stable/wayland_xdg_surface.h @@ -45,6 +45,18 @@ public: void SetWindowMode(OHOS::Rosen::WindowMode mode); void SetWindowType(OHOS::Rosen::WindowType type); + // form toplevel + void SetTitle(const char *title); + void Resize(uint32_t serial, uint32_t edges); + void SetMaxSize(int32_t width, int32_t height); + void SetMinSize(int32_t width, int32_t height); + void SetMaximized(); + void UnSetMaximized(); + void SetFullscreen(); + void UnSetFullscreen(); + void SetMinimized(); + void Close(); + private: friend struct IWaylandXdgSurface; @@ -59,6 +71,7 @@ private: OHOS::wptr xdgWm_; OHOS::wptr surface_; OHOS::wptr toplevel_; + std::string windowTitle_ = "unknow"; }; } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/stable/wayland_xdg_toplevel.cpp b/wayland_adapter/framework/stable/wayland_xdg_toplevel.cpp index 7ad6df7b31d018820c6498feb761f9ef0b901769..23bab9fad9547fe9876c80b9f4b4cb9d854fb892 100644 --- a/wayland_adapter/framework/stable/wayland_xdg_toplevel.cpp +++ b/wayland_adapter/framework/stable/wayland_xdg_toplevel.cpp @@ -24,7 +24,7 @@ namespace { } struct xdg_toplevel_interface IWaylandXdgToplevel::impl_ = { - .destroy = &WaylandResourceObject::DefaultDestroyResource, + .destroy = DestroyResource, .set_parent = SetParent, .set_title = SetTitle, .set_app_id = SetAppId, @@ -116,6 +116,22 @@ void IWaylandXdgToplevel::SetMinimized(struct wl_client *client, struct wl_resou "IWaylandXdgToplevel::SetMinimized: failed to find object.", SetMinimized); } +void IWaylandXdgToplevel::DestroyResource(struct wl_client *client, struct wl_resource *resource) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandXdgToplevel, resource, + "IWaylandXdgToplevel::DestroyResource: failed to find object.", DestroyResource, client, resource); +} + +void WaylandXdgToplevel::DestroyResource(struct wl_client *client, struct wl_resource *resource) +{ + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->Close(); + } + WaylandResourceObject::DefaultDestroyResource(client, resource); +} + OHOS::sptr WaylandXdgToplevel::Create(const OHOS::sptr &xdgSurface, uint32_t id) { if (xdgSurface == nullptr) { @@ -131,14 +147,24 @@ OHOS::sptr WaylandXdgToplevel::Create(const OHOS::sptr &xdgSurface, uint32_t id) : WaylandResourceObject(xdgSurface->WlClient(), &xdg_toplevel_interface, xdgSurface->Version(), id, &IWaylandXdgToplevel::impl_), - xdgSurface_(xdgSurface) {} + xdgSurface_(xdgSurface) +{ + LOG_DEBUG("enter"); +} WaylandXdgToplevel::~WaylandXdgToplevel() noexcept { + LOG_DEBUG("exit : %{public}s.", windowTitle_.c_str()); } void WaylandXdgToplevel::SetTitle(const char *title) { + LOG_DEBUG("Window %{public}s, set Title %{public}s.", windowTitle_.c_str(), title); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->SetTitle(title); + } + windowTitle_ = title; } void WaylandXdgToplevel::Move(uint32_t serial) @@ -151,10 +177,16 @@ void WaylandXdgToplevel::Move(uint32_t serial) void WaylandXdgToplevel::Resize(uint32_t serial, uint32_t edges) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->Resize(serial, edges); + } } void WaylandXdgToplevel::SetAppId(const char *appId) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); if (strstr(appId, "desktop") != nullptr) { auto xdgSurface = xdgSurface_.promote(); if (xdgSurface != nullptr) { @@ -166,30 +198,65 @@ void WaylandXdgToplevel::SetAppId(const char *appId) void WaylandXdgToplevel::SetMaxSize(int32_t width, int32_t height) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->SetMaxSize(width, height); + } } void WaylandXdgToplevel::SetMinSize(int32_t width, int32_t height) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->SetMinSize(width, height); + } } void WaylandXdgToplevel::SetMaximized() { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->SetMaximized(); + } } void WaylandXdgToplevel::UnSetMaximized() { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->UnSetMaximized(); + } } void WaylandXdgToplevel::SetFullscreen() { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->SetFullscreen(); + } } void WaylandXdgToplevel::UnSetFullscreen() { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->UnSetFullscreen(); + } } void WaylandXdgToplevel::SetMinimized() { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); + auto xdgSurface = xdgSurface_.promote(); + if (xdgSurface != nullptr) { + xdgSurface->SetMinimized(); + } } void WaylandXdgToplevel::SendConfigure() @@ -207,6 +274,7 @@ void WaylandXdgToplevel::HandleCommit() void WaylandXdgToplevel::SetRect(Rect rect) { + LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); rect_ = rect; struct wl_array states; diff --git a/wayland_adapter/framework/stable/wayland_xdg_toplevel.h b/wayland_adapter/framework/stable/wayland_xdg_toplevel.h index 23fbb3752063a5139b2c1c7641cb6e48b1d97a51..e63e8098568982fd9d918a79fe1b114b6cd0ee05 100644 --- a/wayland_adapter/framework/stable/wayland_xdg_toplevel.h +++ b/wayland_adapter/framework/stable/wayland_xdg_toplevel.h @@ -21,6 +21,7 @@ namespace FT { namespace Wayland { struct IWaylandXdgToplevel { + static void DestroyResource(struct wl_client *client, struct wl_resource *resource); static void SetParent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent); static void SetTitle(struct wl_client *client, struct wl_resource *resource, const char *title); static void SetAppId(struct wl_client *client, struct wl_resource *resource, const char *app_id); @@ -45,6 +46,7 @@ public: static OHOS::sptr Create(const OHOS::sptr &xdgSurface, uint32_t id); ~WaylandXdgToplevel() noexcept override; + void DestroyResource(struct wl_client *client, struct wl_resource *resource); void SetTitle(const char *title); void SetAppId(const char *appId); void SetMaxSize(int32_t width, int32_t height); @@ -65,6 +67,7 @@ private: friend struct IWaylandXdgToplevel; OHOS::wptr xdgSurface_; + std::string windowTitle_ = "unknow"; Rect rect_; }; } // namespace Wayland