summaryrefslogtreecommitdiff
path: root/src/window-lib/waylandcompositor.h
blob: 1d0b39c3ed72b404f3e9264e3fa9d5a3121063e9 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#pragma once

#include <QtAppManCommon/global.h>

#if defined(AM_MULTI_PROCESS)

#include <QtWaylandCompositor/QWaylandQuickCompositor>

#include <QtWaylandCompositor/QWaylandQuickSurface>
#include <QtWaylandCompositor/QWaylandQuickItem>

#include <QtCore/QMap>
#include <QtCore/QPointer>

QT_FORWARD_DECLARE_CLASS(QWaylandResource)
QT_FORWARD_DECLARE_CLASS(QWaylandWlShell)
QT_FORWARD_DECLARE_CLASS(QWaylandWlShellSurface)
QT_FORWARD_DECLARE_CLASS(QWaylandTextInputManager)
QT_FORWARD_DECLARE_CLASS(QWaylandQtTextInputMethodManager)

QT_FORWARD_DECLARE_CLASS(QWaylandXdgShell)
QT_FORWARD_DECLARE_CLASS(QWaylandXdgSurface)
QT_FORWARD_DECLARE_CLASS(QWaylandXdgToplevel)
QT_FORWARD_DECLARE_CLASS(QWaylandXdgPopup)


QT_BEGIN_NAMESPACE_AM

class WaylandCompositor;
class WaylandQtAMServerExtension;
class WindowSurfaceQuickItem;

// A WindowSurface object exists for every Wayland surface created in the Wayland server.
// Not every WindowSurface maybe an application's Window though - those that are, are available
// through the WindowManager model.
//
// we support wl-shell and xdg-shell shell integration extensions. Both wl-shell and xdg-shell-v5
// are deprecated and additionally xdg-shell-v5 is partially broken in qtwayland.
//
// In any case, wl-shell doesn't provide all the features needed by appman, so clients using it will never work
// perfectly.

class WindowSurface : public QWaylandQuickSurface
{
    Q_OBJECT
public:
    WindowSurface(WaylandCompositor *comp, QWaylandClient *client, uint id, int version);
    QWaylandSurface *surface() const;
    QWaylandWlShellSurface *shellSurface() const;
    QWaylandXdgSurface *xdgSurface() const;
    WaylandCompositor *compositor() const;

    QString applicationId() const;
    bool isPopup() const;
    QRect popupGeometry() const;
    void sendResizing(const QSize &size);

    qint64 processId() const;
    QWindow *outputWindow() const;

    void ping();
    void close();

signals:
    void pong();
    void popupGeometryChanged();
    void xdgSurfaceChanged();

private:
    void setShellSurface(QWaylandWlShellSurface *ss);

private:
    QWaylandSurface *m_surface;
    WaylandCompositor *m_compositor;
    QWaylandWlShellSurface *m_wlSurface = nullptr;

    QWaylandXdgSurface *m_xdgSurface = nullptr;
    QWaylandXdgToplevel *m_topLevel = nullptr;
    QWaylandXdgPopup *m_popup = nullptr;

    friend class WaylandCompositor;
};

class WaylandCompositor : public QWaylandQuickCompositor // clazy:exclude=missing-qobject-macro
{
    Q_OBJECT
public:
    WaylandCompositor(QQuickWindow* window, const QString &waylandSocketName);
    ~WaylandCompositor() override;

    void registerOutputWindow(QQuickWindow *window);

    WaylandQtAMServerExtension *amExtension();

    void xdgPing(WindowSurface*);

signals:
    void surfaceMapped(QT_PREPEND_NAMESPACE_AM(WindowSurface) *surface);

protected:
    void doCreateSurface(QWaylandClient *client, uint id, int version);
    void createWlSurface(QWaylandSurface *surface, const QWaylandResource &resource);
    void onXdgSurfaceCreated(QWaylandXdgSurface *xdgSurface);
    void onTopLevelCreated(QWaylandXdgToplevel *toplevel, QWaylandXdgSurface *xdgSurface);
    void onPopupCreated(QWaylandXdgPopup *popup, QWaylandXdgSurface *xdgSurface);
    void onXdgPongReceived(uint serial);

    QWaylandWlShell *m_wlShell;
    QWaylandXdgShell *m_xdgShell;
    QVector<QWaylandOutput *> m_outputs;
    WaylandQtAMServerExtension *m_amExtension;
    QWaylandQtTextInputMethodManager *m_qtTextInputMethodManager;
    QWaylandTextInputManager *m_textInputManager;
    QMap<uint, QPointer<WindowSurface>> m_xdgPingMap;
};

QT_END_NAMESPACE_AM

#endif // AM_MULTIPROCESS