#include "ui/ozone/platform/wayland/host/xdg_toplevel_wrapper_impl.h"
#include <aura-shell-client-protocol.h>
#include <xdg-decoration-unstable-v1-client-protocol.h>
#include <xdg-toplevel-icon-v1-client-protocol.h>
#include <optional>
#include "base/bit_cast.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/image/image_skia_rep_default.h"
#include "ui/ozone/common/features.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h"
#include "ui/ozone/platform/wayland/host/shell_toplevel_wrapper.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_output.h"
#include "ui/ozone/platform/wayland/host/wayland_output_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_seat.h"
#include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h"
#include "ui/ozone/platform/wayland/host/wayland_shm_buffer.h"
#include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/host/wayland_zaura_shell.h"
#include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h"
namespace ui {
namespace {
static_assert …;
XDGToplevelWrapperImpl::DecorationMode ToDecorationMode(uint32_t mode) { … }
uint32_t ToInt32(XDGToplevelWrapperImpl::DecorationMode mode) { … }
std::optional<wl::Serial> GetSerialForMoveResize(
WaylandConnection* connection) { … }
zaura_toplevel_z_order_level ToZauraToplevelZOrderLevel(
ZOrderLevel z_order_level) { … }
}
XDGToplevelWrapperImpl::XDGToplevelWrapperImpl(
std::unique_ptr<XDGSurfaceWrapperImpl> surface,
WaylandWindow* wayland_window,
WaylandConnection* connection)
: … { … }
XDGToplevelWrapperImpl::~XDGToplevelWrapperImpl() = default;
bool XDGToplevelWrapperImpl::Initialize() { … }
bool XDGToplevelWrapperImpl::IsSupportedOnAuraToplevel(uint32_t version) const { … }
void XDGToplevelWrapperImpl::SetCanMaximize(bool can_maximize) { … }
void XDGToplevelWrapperImpl::SetMaximized() { … }
void XDGToplevelWrapperImpl::UnSetMaximized() { … }
void XDGToplevelWrapperImpl::SetCanFullscreen(bool can_fullscreen) { … }
void XDGToplevelWrapperImpl::SetFullscreen(WaylandOutput* wayland_output) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void XDGToplevelWrapperImpl::SetUseImmersiveMode(bool immersive) {
auto mode = immersive ? ZAURA_TOPLEVEL_FULLSCREEN_MODE_IMMERSIVE
: ZAURA_TOPLEVEL_FULLSCREEN_MODE_PLAIN;
zaura_toplevel_set_fullscreen_mode(aura_toplevel_.get(), mode);
}
void XDGToplevelWrapperImpl::SetTopInset(int height) {
if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >=
ZAURA_TOPLEVEL_SET_TOP_INSET_SINCE_VERSION) {
zaura_toplevel_set_top_inset(aura_toplevel_.get(), height);
}
}
void XDGToplevelWrapperImpl::SetShadowCornersRadii(
const gfx::RoundedCornersF& radii) {
if (aura_toplevel_ &&
zaura_toplevel_get_version(aura_toplevel_.get()) >=
ZAURA_TOPLEVEL_SET_SHADOW_CORNER_RADII_SINCE_VERSION) {
zaura_toplevel_set_shadow_corner_radii(
aura_toplevel_.get(), radii.upper_left(), radii.upper_right(),
radii.lower_right(), radii.lower_left());
}
}
#endif
void XDGToplevelWrapperImpl::UnSetFullscreen() { … }
void XDGToplevelWrapperImpl::SetMinimized() { … }
void XDGToplevelWrapperImpl::SurfaceMove(WaylandConnection* connection) { … }
void XDGToplevelWrapperImpl::SurfaceResize(WaylandConnection* connection,
uint32_t hittest) { … }
void XDGToplevelWrapperImpl::SetTitle(const std::u16string& title) { … }
void XDGToplevelWrapperImpl::SetWindowGeometry(const gfx::Rect& bounds) { … }
void XDGToplevelWrapperImpl::SetMinSize(int32_t width, int32_t height) { … }
void XDGToplevelWrapperImpl::SetMaxSize(int32_t width, int32_t height) { … }
void XDGToplevelWrapperImpl::SetAppId(const std::string& app_id) { … }
void XDGToplevelWrapperImpl::SetDecoration(DecorationMode decoration) { … }
void XDGToplevelWrapperImpl::AckConfigure(uint32_t serial) { … }
bool XDGToplevelWrapperImpl::IsConfigured() { … }
void XDGToplevelWrapperImpl::OnToplevelConfigure(void* data,
xdg_toplevel* toplevel,
int32_t width,
int32_t height,
wl_array* states) { … }
void XDGToplevelWrapperImpl::OnToplevelClose(void* data,
xdg_toplevel* toplevel) { … }
void XDGToplevelWrapperImpl::OnConfigureBounds(void* data,
xdg_toplevel* toplevel,
int32_t width,
int32_t height) { … }
void XDGToplevelWrapperImpl::OnWmCapabilities(void* data,
xdg_toplevel* toplevel,
wl_array* capabilities) { … }
void XDGToplevelWrapperImpl::OnDecorationConfigure(
void* data,
zxdg_toplevel_decoration_v1* decoration,
uint32_t mode) { … }
void XDGToplevelWrapperImpl::OnAuraToplevelConfigure(
void* data,
zaura_toplevel* aura_toplevel,
int32_t x,
int32_t y,
int32_t width,
int32_t height,
wl_array* states) { … }
void XDGToplevelWrapperImpl::OnOriginChange(void* data,
zaura_toplevel* aura_toplevel,
int32_t x,
int32_t y) { … }
void XDGToplevelWrapperImpl::OnConfigureRasterScale(
void* data,
zaura_toplevel* aura_toplevel,
uint32_t scale_as_uint) { … }
void XDGToplevelWrapperImpl::OnRotateFocus(void* data,
zaura_toplevel* aura_toplevel,
uint32_t serial,
uint32_t direction,
uint32_t restart) { … }
void XDGToplevelWrapperImpl::OnOverviewChange(void* data,
zaura_toplevel* aura_toplevel,
uint32_t in_overview_as_uint) { … }
void XDGToplevelWrapperImpl::OnConfigureOcclusionState(
void* data,
struct zaura_toplevel* zaura_toplevel,
uint32_t mode) { … }
void XDGToplevelWrapperImpl::SetTopLevelDecorationMode(
DecorationMode requested_mode) { … }
void XDGToplevelWrapperImpl::InitializeXdgDecoration() { … }
wl::Object<wl_region> XDGToplevelWrapperImpl::CreateAndAddRegion(
const std::vector<gfx::Rect>& shape) { … }
XDGSurfaceWrapperImpl* XDGToplevelWrapperImpl::xdg_surface_wrapper() const { … }
zaura_toplevel_orientation_lock ToZauraSurfaceOrientationLock(
WaylandOrientationLockType lock_type) { … }
void XDGToplevelWrapperImpl::Lock(WaylandOrientationLockType lock_type) { … }
void XDGToplevelWrapperImpl::Unlock() { … }
void XDGToplevelWrapperImpl::RequestWindowBounds(const gfx::Rect& bounds,
int64_t display_id) { … }
void XDGToplevelWrapperImpl::SetSystemModal(bool modal) { … }
bool XDGToplevelWrapperImpl::SupportsScreenCoordinates() const { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void XDGToplevelWrapperImpl::EnableScreenCoordinates() {
if (!SupportsScreenCoordinates()) {
LOG(WARNING) << "Server implementation of wayland is incompatible, "
"WaylandScreenCoordinatesEnabled has no effect.";
return;
}
zaura_toplevel_set_supports_screen_coordinates(aura_toplevel_.get());
static constexpr zaura_toplevel_listener kAuraToplevelListener = {
.configure = &OnAuraToplevelConfigure,
.origin_change = &OnOriginChange,
.configure_raster_scale = &OnConfigureRasterScale,
.rotate_focus = &OnRotateFocus,
.overview_change = &OnOverviewChange,
.configure_occlusion_state = &OnConfigureOcclusionState};
zaura_toplevel_add_listener(aura_toplevel_.get(), &kAuraToplevelListener,
this);
}
#endif
void XDGToplevelWrapperImpl::SetZOrder(ZOrderLevel z_order) { … }
bool XDGToplevelWrapperImpl::SupportsActivation() { … }
void XDGToplevelWrapperImpl::Activate() { … }
void XDGToplevelWrapperImpl::Deactivate() { … }
void XDGToplevelWrapperImpl::SetScaleFactor(float scale_factor) { … }
void XDGToplevelWrapperImpl::SetRestoreInfo(int32_t restore_session_id,
int32_t restore_window_id) { … }
void XDGToplevelWrapperImpl::SetRestoreInfoWithWindowIdSource(
int32_t restore_session_id,
const std::string& restore_window_id_source) { … }
void XDGToplevelWrapperImpl::SetFloatToLocation(
WaylandFloatStartLocation float_start_location) { … }
void XDGToplevelWrapperImpl::UnSetFloat() { … }
void XDGToplevelWrapperImpl::CommitSnap(
WaylandWindowSnapDirection snap_direction,
float snap_ratio) { … }
void XDGToplevelWrapperImpl::SetPersistable(bool persistable) const { … }
void XDGToplevelWrapperImpl::SetShape(std::unique_ptr<ShapeRects> shape_rects) { … }
void XDGToplevelWrapperImpl::ShowSnapPreview(
WaylandWindowSnapDirection snap_direction,
bool allow_haptic_feedback) { … }
void XDGToplevelWrapperImpl::AckRotateFocus(uint32_t serial, uint32_t handled) { … }
void XDGToplevelWrapperImpl::SetIcon(const gfx::ImageSkia& icon) { … }
XDGToplevelWrapperImpl* XDGToplevelWrapperImpl::AsXDGToplevelWrapper() { … }
}