summaryrefslogtreecommitdiffstats
path: root/examples/wayland/custom-extension/client-common/customextension.h
blob: c3a9a4939cd2dced6653ed42dcc8391675e26baa (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef CUSTOMEXTENSION_H
#define CUSTOMEXTENSION_H

#include <QtWaylandClient/QWaylandClientExtension>
#include <QtGui/QWindow>
#include "qwayland-custom.h"

QT_BEGIN_NAMESPACE

class CustomExtensionObject;

class CustomExtension : public QWaylandClientExtensionTemplate<CustomExtension>
        , public QtWayland::qt_example_extension
{
    Q_OBJECT
public:
    CustomExtension();
    Q_INVOKABLE void registerWindow(QWindow *window);

    CustomExtensionObject *createCustomObject(const QString &color, const QString &text);

public slots:
    void sendBounce(QWindow *window, uint ms);
    void sendSpin(QWindow *window, uint ms);

signals:
    void eventReceived(const QString &text, uint value);
    void fontSize(QWindow *window, uint pixelSize);
    void showDecorations(bool);

private slots:
    void handleExtensionActive();

private:
    void example_extension_close(wl_surface *surface) override;
    void example_extension_set_font_size(wl_surface *surface, uint32_t pixel_size) override;
    void example_extension_set_window_decoration(uint32_t state) override;

    bool eventFilter(QObject *object, QEvent *event) override;

    QWindow *windowForSurface(struct ::wl_surface *);
    void sendWindowRegistration(QWindow *);

    QList<QWindow *> m_windows;
    bool m_activated = false;
};

class CustomExtensionObject : public QWaylandClientExtensionTemplate<CustomExtensionObject>
        , public QtWayland::qt_example_local_object
{
    Q_OBJECT
    Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
public:
    CustomExtensionObject(struct ::qt_example_local_object *wl_object, const QString &text);

    QString text() const
    {
        return m_text;
    }

protected:
    void example_local_object_clicked() override;

public slots:
    void setText(const QString &text);


signals:
    void textChanged(const QString &text);
    void clicked();

private:
    QString m_text;
};



QT_END_NAMESPACE

#endif // CUSTOMEXTENSION_H