summaryrefslogtreecommitdiffstats
path: root/src/compositor/extensions/qwaylandshell_p.h
blob: 4aeef67f49edcc1282b738d40c6745246173ac59 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QWAYLANDSHELL_P_H
#define QWAYLANDSHELL_P_H

#include <QtCompositor/qwaylandexport.h>
#include <QtCompositor/qwaylandsurface.h>
#include <QtCompositor/private/qwaylandextension_p.h>
#include <QtCompositor/QWaylandPointerGrabber>
#include <QtCompositor/QWaylandShellSurface>
#include <QtCompositor/QWaylandInputDevice>

#include <wayland-server.h>
#include <QHash>
#include <QPoint>
#include <QSet>

#include <QtCompositor/private/qwayland-server-wayland.h>

QT_BEGIN_NAMESPACE

class QWaylandView;

class QWaylandShellSurfaceResizeGrabber;
class QWaylandShellSurfaceMoveGrabber;
class QWaylandShellSurfacePopupGrabber;

class Q_COMPOSITOR_EXPORT QWaylandShellPrivate
                                        : public QWaylandExtensionTemplatePrivate
                                        , public QtWaylandServer::wl_shell
{
    Q_DECLARE_PUBLIC(QWaylandShell)
public:
    QWaylandShellPrivate();
    static QWaylandShellPrivate *get(QWaylandShell *shell) { return shell->d_func(); }

    QWaylandShellSurfacePopupGrabber* getPopupGrabber(QWaylandInputDevice *input);
protected:
    void shell_get_shell_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface) Q_DECL_OVERRIDE;

    QHash<QWaylandInputDevice *, QWaylandShellSurfacePopupGrabber*> m_popupGrabber;
};

class Q_COMPOSITOR_EXPORT QWaylandShellSurfacePrivate
                                        : public QWaylandExtensionTemplatePrivate
                                        , public QtWaylandServer::wl_shell_surface
{
    Q_DECLARE_PUBLIC(QWaylandShellSurface)
public:
    QWaylandShellSurfacePrivate();
    ~QWaylandShellSurfacePrivate();

    static QWaylandShellSurfacePrivate *get(QWaylandShellSurface *surface) { return surface->d_func(); }

    void resetResizeGrabber();
    void resetMoveGrabber();

    void setSurfaceType(QWaylandShellSurface::SurfaceType type);

    void setOffset(const QPointF &offset) { m_transientOffset = offset; }

    void requestSize(const QSize &size);

    void ping();
    void ping(uint32_t serial);

private:
    QWaylandShell *m_shell;
    QWaylandSurface *m_surface;
    QWaylandView *m_view;

    QWaylandShellSurfaceResizeGrabber *m_resizeGrabber;
    QWaylandShellSurfaceMoveGrabber *m_moveGrabber;
    QWaylandShellSurfacePopupGrabber *m_popupGrabber;

    uint32_t m_popupSerial;

    QSet<uint32_t> m_pings;

    QWaylandShellSurface::SurfaceType m_surfaceType;
    bool m_transientInactive;

    QWaylandSurface *m_transientParent;
    QPointF m_transientOffset;

    QString m_title;
    QString m_className;

    void shell_surface_destroy_resource(Resource *resource) Q_DECL_OVERRIDE;

    void shell_surface_move(Resource *resource,
                            struct wl_resource *input_device_super,
                            uint32_t time) Q_DECL_OVERRIDE;
    void shell_surface_resize(Resource *resource,
                              struct wl_resource *input_device,
                              uint32_t time,
                              uint32_t edges) Q_DECL_OVERRIDE;
    void shell_surface_set_toplevel(Resource *resource) Q_DECL_OVERRIDE;
    void shell_surface_set_transient(Resource *resource,
                                     struct wl_resource *parent_surface_resource,
                                     int x,
                                     int y,
                                     uint32_t flags) Q_DECL_OVERRIDE;
    void shell_surface_set_fullscreen(Resource *resource,
                                      uint32_t method,
                                      uint32_t framerate,
                                      struct wl_resource *output_resource) Q_DECL_OVERRIDE;
    void shell_surface_set_popup(Resource *resource,
                                 struct wl_resource *input_device,
                                 uint32_t time,
                                 struct wl_resource *parent,
                                 int32_t x,
                                 int32_t y,
                                 uint32_t flags) Q_DECL_OVERRIDE;
    void shell_surface_set_maximized(Resource *resource,
                                     struct wl_resource *output_resource) Q_DECL_OVERRIDE;
    void shell_surface_pong(Resource *resource,
                            uint32_t serial) Q_DECL_OVERRIDE;
    void shell_surface_set_title(Resource *resource,
                                 const QString &title) Q_DECL_OVERRIDE;
    void shell_surface_set_class(Resource *resource,
                                 const QString &class_) Q_DECL_OVERRIDE;

};

class QWaylandShellSurfaceGrabber : public QWaylandPointerGrabber
{
public:
    QWaylandShellSurfaceGrabber(QWaylandShellSurface *shellSurface);
    ~QWaylandShellSurfaceGrabber();

    QWaylandShellSurface *shell_surface;
};

class QWaylandShellSurfaceResizeGrabber : public QWaylandShellSurfaceGrabber
{
public:
    QWaylandShellSurfaceResizeGrabber(QWaylandShellSurface *shellSurface);

    QPointF point;
    enum wl_shell_surface_resize resize_edges;
    int32_t width;
    int32_t height;

    void focus() Q_DECL_OVERRIDE;
    void motion(uint32_t time) Q_DECL_OVERRIDE;
    void button(uint32_t time, Qt::MouseButton button, uint32_t state) Q_DECL_OVERRIDE;
};

class QWaylandShellSurfaceMoveGrabber : public QWaylandShellSurfaceGrabber
{
public:
    QWaylandShellSurfaceMoveGrabber(QWaylandShellSurface *shellSurface, const QPointF &offset);

    void focus() Q_DECL_OVERRIDE;
    void motion(uint32_t time) Q_DECL_OVERRIDE;
    void button(uint32_t time, Qt::MouseButton button, uint32_t state) Q_DECL_OVERRIDE;

private:
    QPointF m_offset;
};

class QWaylandShellSurfacePopupGrabber : public QWaylandDefaultPointerGrabber
{
public:
    QWaylandShellSurfacePopupGrabber(QWaylandInputDevice *inputDevice);

    uint32_t grabSerial() const { return m_inputDevice->pointer()->grabSerial(); }

    struct ::wl_client *client() const { return m_client; }
    void setClient(struct ::wl_client *client) { m_client = client; }

    void addPopup(QWaylandShellSurface *surface);
    void removePopup(QWaylandShellSurface *surface);

    void button(uint32_t time, Qt::MouseButton button, uint32_t state) Q_DECL_OVERRIDE;

private:
    QWaylandInputDevice *m_inputDevice;
    struct ::wl_client *m_client;
    QList<QWaylandShellSurface *> m_surfaces;
    bool m_initialUp;
};

QT_END_NAMESPACE

#endif // QWAYLANDSHELL_P_H