1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_TOPLEVEL_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_TOPLEVEL_H_
#include <xdg-shell-client-protocol.h>
#include <memory>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/ozone/platform/wayland/host/xdg_surface.h"
namespace ui {
class WaylandConnection;
class WaylandOutput;
class WaylandWindow;
// Wrapper class for xdg-shell's xdg_toplevel protocol objects. Used by
// WaylandToplevelWindow to set window-like properties such as maximize,
// fullscreen, and minimize, set application-specific metadata like title and
// id, as well as trigger user interactive operations such as interactive resize
// and move.
class XdgToplevel {
public:
using ShapeRects = std::vector<gfx::Rect>;
enum class DecorationMode { kNone, kClientSide, kServerSide };
explicit XdgToplevel(std::unique_ptr<XdgSurface> xdg_surface);
XdgToplevel(const XdgToplevel&) = delete;
XdgToplevel& operator=(const XdgToplevel&) = delete;
~XdgToplevel();
bool Initialize();
void SetMaximized();
void UnSetMaximized();
void SetFullscreen(WaylandOutput* wayland_output);
void UnSetFullscreen();
void SetMinimized();
void SurfaceMove(WaylandConnection* connection);
void SurfaceResize(WaylandConnection* connection, uint32_t hittest);
void SetTitle(const std::u16string& title);
void AckConfigure(uint32_t serial);
bool IsConfigured();
void SetWindowGeometry(const gfx::Rect& bounds);
void SetMinSize(int32_t width, int32_t height);
void SetMaxSize(int32_t width, int32_t height);
void SetAppId(const std::string& app_id);
void ShowWindowMenu(WaylandConnection* connection, const gfx::Point& point);
void SetDecoration(DecorationMode decoration);
void SetSystemModal(bool modal);
void SetIcon(const gfx::ImageSkia& icon);
struct xdg_surface* xdg_surface() const { return xdg_surface_->wl_object(); }
struct xdg_toplevel* wl_object() const { return xdg_toplevel_.get(); }
private:
// xdg_toplevel_listener callbacks:
static void OnToplevelConfigure(void* data,
xdg_toplevel* toplevel,
int32_t width,
int32_t height,
wl_array* states);
static void OnToplevelClose(void* data, xdg_toplevel* toplevel);
static void OnConfigureBounds(void* data,
xdg_toplevel* toplevel,
int32_t width,
int32_t height);
static void OnWmCapabilities(void* data,
xdg_toplevel* toplevel,
wl_array* capabilities);
// zxdg_decoration_listener callbacks:
static void OnDecorationConfigure(void* data,
zxdg_toplevel_decoration_v1* decoration,
uint32_t mode);
// Send request to wayland compositor to enable a requested decoration mode.
void SetTopLevelDecorationMode(DecorationMode requested_mode);
// Initializes the xdg-decoration protocol extension, if available.
void InitializeXdgDecoration();
// Creates a wl_region from `shape_rects`.
wl::Object<wl_region> CreateAndAddRegion(const ShapeRects& shape_rects);
WaylandConnection* connection() const { return xdg_surface_->connection_; }
WaylandWindow* window() const { return xdg_surface_->wayland_window_; }
// Ground surface for this toplevel wrapper.
const std::unique_ptr<XdgSurface> xdg_surface_;
// XDG Shell Stable object.
wl::Object<xdg_toplevel> xdg_toplevel_;
wl::Object<zxdg_toplevel_decoration_v1> zxdg_toplevel_decoration_;
// On client side, it keeps track of the decoration mode currently in
// use if xdg-decoration protocol extension is available.
DecorationMode decoration_mode_ = DecorationMode::kNone;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_TOPLEVEL_H_
|