#include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h"
#include <aura-shell-client-protocol.h>
#include <string>
#include "base/nix/xdg_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/unguessable_token.h"
#include "build/chromeos_buildflags.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_features.h"
#include "ui/display/types/display_constants.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/host/dump_util.h"
#include "ui/ozone/platform/wayland/host/gtk_shell1.h"
#include "ui/ozone/platform/wayland/host/gtk_surface1.h"
#include "ui/ozone/platform/wayland/host/shell_object_factory.h"
#include "ui/ozone/platform/wayland/host/shell_toplevel_wrapper.h"
#include "ui/ozone/platform/wayland/host/wayland_bubble.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_event_source.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_popup.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/host/wayland_window_drag_controller.h"
#include "ui/ozone/platform/wayland/host/wayland_zaura_shell.h"
#include "ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.h"
#include "ui/ozone/platform/wayland/host/xdg_activation.h"
#include "ui/platform_window/common/platform_window_defaults.h"
#include "ui/platform_window/extensions/wayland_extension.h"
#include "ui/platform_window/platform_window_delegate.h"
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/crosapi/cpp/crosapi_constants.h"
#endif
namespace ui {
namespace {
bool ShouldSetBounds(PlatformWindowState state) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool IsPinnedOrFullscreen(const WaylandWindow::WindowStates& states) {
return states.is_fullscreen || states.is_pinned_fullscreen ||
states.is_trusted_pinned_fullscreen;
}
#endif
}
constexpr int kVisibleOnAllWorkspaces = …;
WaylandToplevelWindow::WaylandToplevelWindow(PlatformWindowDelegate* delegate,
WaylandConnection* connection)
: … { … }
WaylandToplevelWindow::~WaylandToplevelWindow() = default;
bool WaylandToplevelWindow::CreateShellToplevel() { … }
void WaylandToplevelWindow::DispatchHostWindowDragMovement(
int hittest,
const gfx::Point& pointer_location_in_px) { … }
void WaylandToplevelWindow::Show(bool inactive) { … }
void WaylandToplevelWindow::Hide() { … }
bool WaylandToplevelWindow::IsVisible() const { … }
void WaylandToplevelWindow::SetTitle(const std::u16string& title) { … }
void WaylandToplevelWindow::SetFullscreen(bool fullscreen,
int64_t target_display_id) { … }
void WaylandToplevelWindow::Maximize() { … }
void WaylandToplevelWindow::Minimize() { … }
void WaylandToplevelWindow::Restore() { … }
void WaylandToplevelWindow::ActivateWithToken(std::string token) { … }
void WaylandToplevelWindow::Activate() { … }
void WaylandToplevelWindow::Deactivate() { … }
void WaylandToplevelWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) { … }
void WaylandToplevelWindow::SizeConstraintsChanged() { … }
void WaylandToplevelWindow::SetZOrderLevel(ZOrderLevel order) { … }
ZOrderLevel WaylandToplevelWindow::GetZOrderLevel() const { … }
void WaylandToplevelWindow::SetShape(std::unique_ptr<ShapeRects> native_shape,
const gfx::Transform& transform) { … }
std::string WaylandToplevelWindow::GetWindowUniqueId() const { … }
void WaylandToplevelWindow::SetUseNativeFrame(bool use_native_frame) { … }
bool WaylandToplevelWindow::ShouldUseNativeFrame() const { … }
bool WaylandToplevelWindow::ShouldUpdateWindowShape() const { … }
bool WaylandToplevelWindow::CanSetDecorationInsets() const { … }
void WaylandToplevelWindow::SetOpaqueRegion(
std::optional<std::vector<gfx::Rect>> region_px) { … }
void WaylandToplevelWindow::SetInputRegion(
std::optional<std::vector<gfx::Rect>> region_px) { … }
void WaylandToplevelWindow::NotifyStartupComplete(
const std::string& startup_id) { … }
void WaylandToplevelWindow::SetAspectRatio(const gfx::SizeF& aspect_ratio) { … }
bool WaylandToplevelWindow::IsScreenCoordinatesEnabled() const { … }
bool WaylandToplevelWindow::SupportsConfigureMinimizedState() const { … }
bool WaylandToplevelWindow::SupportsConfigurePinnedState() const { … }
void WaylandToplevelWindow::UpdateWindowScale(bool update_bounds) { … }
void WaylandToplevelWindow::OnRotateFocus(uint32_t serial,
uint32_t direction,
bool restart) { … }
void WaylandToplevelWindow::OnOverviewChange(uint32_t in_overview_as_int) { … }
void WaylandToplevelWindow::LockFrame() { … }
void WaylandToplevelWindow::UnlockFrame() { … }
void WaylandToplevelWindow::OcclusionStateChanged(
PlatformWindowOcclusionState occlusion_state) { … }
void WaylandToplevelWindow::DeskChanged(int state) { … }
void WaylandToplevelWindow::StartThrottle() { … }
void WaylandToplevelWindow::EndThrottle() { … }
void WaylandToplevelWindow::TooltipShown(const char* text,
int32_t x,
int32_t y,
int32_t width,
int32_t height) { … }
void WaylandToplevelWindow::TooltipHidden() { … }
WaylandToplevelWindow* WaylandToplevelWindow::AsWaylandToplevelWindow() { … }
void WaylandToplevelWindow::HandleToplevelConfigure(
int32_t width_dip,
int32_t height_dip,
const WindowStates& window_states) { … }
void WaylandToplevelWindow::HandleAuraToplevelConfigure(
int32_t x,
int32_t y,
int32_t width_dip,
int32_t height_dip,
const WindowStates& window_states) { … }
void WaylandToplevelWindow::SetBoundsInPixels(const gfx::Rect& bounds) { … }
void WaylandToplevelWindow::SetBoundsInDIP(const gfx::Rect& bounds_dip) { … }
void WaylandToplevelWindow::SetOrigin(const gfx::Point& origin) { … }
void WaylandToplevelWindow::HandleSurfaceConfigure(uint32_t serial) { … }
void WaylandToplevelWindow::OnSequencePoint(int64_t seq) { … }
bool WaylandToplevelWindow::OnInitialize(
PlatformWindowInitProperties properties,
PlatformWindowDelegate::State* state) { … }
bool WaylandToplevelWindow::IsActive() const { … }
bool WaylandToplevelWindow::IsSurfaceConfigured() { … }
void WaylandToplevelWindow::SetWindowGeometry(
const PlatformWindowDelegate::State& state) { … }
void WaylandToplevelWindow::AckConfigure(uint32_t serial) { … }
void WaylandToplevelWindow::PropagateBufferScale(float new_scale) { … }
base::WeakPtr<WaylandWindow> WaylandToplevelWindow::AsWeakPtr() { … }
void WaylandToplevelWindow::ShowTooltip(
const std::u16string& text,
const gfx::Point& position,
const PlatformWindowTooltipTrigger trigger,
const base::TimeDelta show_delay,
const base::TimeDelta hide_delay) { … }
void WaylandToplevelWindow::HideTooltip() { … }
bool WaylandToplevelWindow::IsClientControlledWindowMovementSupported() const { … }
bool WaylandToplevelWindow::ShouldReleaseCaptureForDrag(
ui::OSExchangeData* data) const { … }
bool WaylandToplevelWindow::RunMoveLoop(const gfx::Vector2d& drag_offset) { … }
void WaylandToplevelWindow::EndMoveLoop() { … }
void WaylandToplevelWindow::StartWindowDraggingSessionIfNeeded(
ui::mojom::DragEventSource event_source,
bool allow_system_drag) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void WaylandToplevelWindow::SetImmersiveFullscreenStatus(bool status) {
if (last_requested_immersive_status_ == status) {
return;
}
last_requested_immersive_status_ = std::make_optional(status);
if (shell_toplevel_) {
shell_toplevel_->SetUseImmersiveMode(status);
}
}
void WaylandToplevelWindow::SetTopInset(int height) {
if (shell_toplevel_) {
shell_toplevel_->SetTopInset(height);
}
}
gfx::RoundedCornersF WaylandToplevelWindow::GetWindowCornersRadii() {
auto* zaura_shell = connection()->zaura_shell();
return zaura_shell->GetWindowCornersRadii();
}
void WaylandToplevelWindow::SetShadowCornersRadii(
const gfx::RoundedCornersF& radii) {
if (shell_toplevel_) {
shell_toplevel_->SetShadowCornersRadii(radii);
}
}
#endif
void WaylandToplevelWindow::ShowSnapPreview(
WaylandWindowSnapDirection snap_direction,
bool allow_haptic_feedback) { … }
void WaylandToplevelWindow::CommitSnap(
WaylandWindowSnapDirection snap_direction,
float snap_ratio) { … }
void WaylandToplevelWindow::SetCanGoBack(bool value) { … }
void WaylandToplevelWindow::SetPip() { … }
void WaylandToplevelWindow::Lock(WaylandOrientationLockType lock_type) { … }
void WaylandToplevelWindow::Unlock() { … }
bool WaylandToplevelWindow::SupportsPointerLock() { … }
void WaylandToplevelWindow::LockPointer(bool enabled) { … }
int WaylandToplevelWindow::GetNumberOfDesks() const { … }
int WaylandToplevelWindow::GetActiveDeskIndex() const { … }
std::u16string WaylandToplevelWindow::GetDeskName(int index) const { … }
void WaylandToplevelWindow::SendToDeskAtIndex(int index) { … }
void WaylandToplevelWindow::Pin(bool trusted) { … }
void WaylandToplevelWindow::Unpin() { … }
void WaylandToplevelWindow::SetSystemModal(bool modal) { … }
void WaylandToplevelWindow::DumpState(std::ostream& out) const { … }
void WaylandToplevelWindow::UpdateSystemModal() { … }
std::string WaylandToplevelWindow::GetWorkspace() const { … }
void WaylandToplevelWindow::SetVisibleOnAllWorkspaces(bool always_visible) { … }
bool WaylandToplevelWindow::IsVisibleOnAllWorkspaces() const { … }
void WaylandToplevelWindow::SetWorkspaceExtensionDelegate(
WorkspaceExtensionDelegate* delegate) { … }
void WaylandToplevelWindow::TriggerStateChanges(
PlatformWindowState window_state) { … }
void WaylandToplevelWindow::SetWindowState(PlatformWindowState window_state,
int64_t target_display_id) { … }
bool WaylandToplevelWindow::ShouldTriggerStateChange(
PlatformWindowState window_state,
int64_t target_display_id) const { … }
WaylandOutput* WaylandToplevelWindow::GetWaylandOutputForDisplayId(
int64_t display_id) { … }
WmMoveResizeHandler* WaylandToplevelWindow::AsWmMoveResizeHandler() { … }
void WaylandToplevelWindow::SetSizeConstraints() { … }
void WaylandToplevelWindow::SetUpShellIntegration() { … }
void WaylandToplevelWindow::OnDecorationModeChanged() { … }
void WaylandToplevelWindow::OnFrameLockingChanged(bool lock) { … }
void WaylandToplevelWindow::OnDeskChanged(int state) { … }
void WaylandToplevelWindow::SetInitialWorkspace() { … }
void WaylandToplevelWindow::UpdateWindowMask() { … }
bool WaylandToplevelWindow::GetTabletMode() { … }
void WaylandToplevelWindow::SetFloatToLocation(
WaylandFloatStartLocation float_start_location) { … }
void WaylandToplevelWindow::UnSetFloat() { … }
}