~dandrader/unity8/childWindowFocus

« back to all changes in this revision

Viewing changes to tests/plugins/WindowManager/UnityApplicationMocks.h

  • Committer: Bileto Bot
  • Author(s): Daniel d'Andrada
  • Date: 2017-03-21 10:54:06 UTC
  • mfrom: (2868.4.2 hiddenWindows)
  • Revision ID: ci-train-bot@canonical.com-20170321105406-evdifktioahnr3o9
TopLevelWindowModel: don't put hidden windows in the model

From the UI point of view, it's as if they didn't exist. (LP: #1665286)

Approved by: Albert Astals Cid

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2017 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#ifndef UNITYAPPLICATIONMOCKS_H
 
18
#define UNITYAPPLICATIONMOCKS_H
 
19
 
 
20
#include <unity/shell/application/ApplicationInfoInterface.h>
 
21
#include <unity/shell/application/ApplicationManagerInterface.h>
 
22
#include <unity/shell/application/MirSurfaceInterface.h>
 
23
#include <unity/shell/application/SurfaceManagerInterface.h>
 
24
 
 
25
// from tests/mocks
 
26
#include <Unity/Application/MirSurfaceListModel.h>
 
27
 
 
28
using namespace unity::shell::application;
 
29
 
 
30
class MirSurface : public MirSurfaceInterface
 
31
{
 
32
    Q_OBJECT
 
33
public:
 
34
    Mir::Type type() const override { return m_type; }
 
35
    QString name() const override { return QString("foo"); }
 
36
    QString persistentId() const override { return QString("a-b-c-my-id"); }
 
37
    QString appId() const override { return QString(); }
 
38
    QPoint position() const override { return QPoint(); }
 
39
    QSize size() const override { return QSize(); }
 
40
    void resize(int, int) override {}
 
41
    void resize(const QSize &) override {}
 
42
    Mir::State state() const override { return m_state; }
 
43
    bool live() const override { return m_live; }
 
44
    bool visible() const override { return true; }
 
45
    Mir::OrientationAngle orientationAngle() const override { return Mir::Angle0; }
 
46
    void setOrientationAngle(Mir::OrientationAngle) override {}
 
47
 
 
48
    int minimumWidth() const override { return 0; }
 
49
    int minimumHeight() const override { return 0; }
 
50
    int maximumWidth() const override { return 0; }
 
51
    int maximumHeight() const override { return 0; }
 
52
    int widthIncrement() const override { return 0; }
 
53
    int heightIncrement() const override { return 0; }
 
54
 
 
55
    void setKeymap(const QString &) override {}
 
56
    QString keymap() const override { return QString(); }
 
57
    Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
 
58
    bool focused() const override { return true; }
 
59
    QRect inputBounds() const override { return QRect(); }
 
60
    bool confinesMousePointer() const override { return false; }
 
61
    bool allowClientResize() const override { return true; }
 
62
    void setAllowClientResize(bool) override {}
 
63
    QPoint requestedPosition() const override { return QPoint(); }
 
64
    void setRequestedPosition(const QPoint &) override {}
 
65
    MirSurfaceInterface* parentSurface() const override { return nullptr; }
 
66
    unity::shell::application::MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
 
67
    void close() override {}
 
68
    void activate() override {}
 
69
 
 
70
public Q_SLOTS:
 
71
    void requestState(Mir::State value) override
 
72
    {
 
73
        if (m_state != value) {
 
74
            m_state = value;
 
75
            Q_EMIT stateChanged(m_state);
 
76
        }
 
77
    }
 
78
 
 
79
public:
 
80
    Mir::Type m_type { Mir::NormalType };
 
81
    Mir::State m_state { Mir::RestoredState };
 
82
    bool m_live { true };
 
83
};
 
84
 
 
85
class SurfaceManager : public SurfaceManagerInterface
 
86
{
 
87
    Q_OBJECT
 
88
 
 
89
public:
 
90
    void raise(MirSurfaceInterface *) override {}
 
91
    void activate(MirSurfaceInterface *) override {}
 
92
};
 
93
 
 
94
class Application : public ApplicationInfoInterface
 
95
{
 
96
    Q_OBJECT
 
97
public:
 
98
    Application(QString appId) : ApplicationInfoInterface(appId, nullptr), m_appId(std::move(appId)) {}
 
99
 
 
100
    void close() override {}
 
101
    QString appId() const override { return m_appId;}
 
102
    QString name() const override { return "foo"; }
 
103
    QString comment() const override { return "bar"; }
 
104
    QUrl icon() const override { return QUrl(); }
 
105
    State state() const override { return m_state; }
 
106
    RequestedState requestedState() const override { return m_requestedState; }
 
107
    void setRequestedState(RequestedState value) override
 
108
    {
 
109
        if (value != m_requestedState) {
 
110
            m_requestedState = value;
 
111
            Q_EMIT requestedStateChanged(value);
 
112
        }
 
113
    }
 
114
    bool focused() const override { return false; }
 
115
    QString splashTitle() const override { return QString(); }
 
116
    QUrl splashImage() const override { return QUrl(); }
 
117
    bool splashShowHeader() const override { return false; }
 
118
    QColor splashColor() const override { return QColor(); }
 
119
    QColor splashColorHeader() const override { return QColor(); }
 
120
    QColor splashColorFooter() const override { return QColor(); }
 
121
    Qt::ScreenOrientations supportedOrientations() const override { return Qt::LandscapeOrientation; }
 
122
    bool rotatesWindowContents() const override { return false; }
 
123
    bool isTouchApp() const override { return false; }
 
124
    bool exemptFromLifecycle() const override { return false; }
 
125
    void setExemptFromLifecycle(bool) override {}
 
126
    QSize initialSurfaceSize() const override { return QSize(); }
 
127
    void setInitialSurfaceSize(const QSize &) override {}
 
128
    MirSurfaceListInterface* surfaceList() const override { return &m_surfaceList; }
 
129
    MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
 
130
    int surfaceCount() const override { return 0; }
 
131
 
 
132
    QString m_appId;
 
133
    State m_state;
 
134
    RequestedState m_requestedState;
 
135
    mutable MirSurfaceListModel m_surfaceList;
 
136
};
 
137
 
 
138
class ApplicationManager : public ApplicationManagerInterface
 
139
{
 
140
    Q_OBJECT
 
141
 
 
142
public:
 
143
 
 
144
    int rowCount(const QModelIndex &) const override
 
145
    {
 
146
        return m_applications.count();
 
147
    }
 
148
 
 
149
    QVariant data(const QModelIndex &/*index*/, int /*role*/) const override
 
150
    {
 
151
        return QVariant();
 
152
    }
 
153
 
 
154
    QString focusedApplicationId() const override {return QString();}
 
155
 
 
156
    ApplicationInfoInterface *get(int index) const override
 
157
    {
 
158
        return m_applications[index];
 
159
    }
 
160
 
 
161
    ApplicationInfoInterface *findApplication(const QString &appId) const override
 
162
    {
 
163
        Q_UNUSED(appId);
 
164
        return nullptr;
 
165
    }
 
166
 
 
167
    ApplicationInfoInterface *findApplicationWithSurface(MirSurfaceInterface* surface) const override
 
168
    {
 
169
        for (int i = 0; i < m_applications.count(); ++i) {
 
170
            if (m_applications[i]->m_surfaceList.contains(surface)) {
 
171
                return m_applications[i];
 
172
            }
 
173
        }
 
174
        return nullptr;
 
175
    }
 
176
 
 
177
    bool requestFocusApplication(const QString &appId) override
 
178
    {
 
179
        Q_UNUSED(appId);
 
180
        return false;
 
181
    }
 
182
 
 
183
    ApplicationInfoInterface *startApplication(const QString &appId, const QStringList &/*arguments*/) override
 
184
    {
 
185
        Application *application = new Application(appId);
 
186
        prepend(application);
 
187
        return application;
 
188
    }
 
189
 
 
190
    bool stopApplication(const QString &) override { return true; }
 
191
 
 
192
private:
 
193
    void prepend(Application *application)
 
194
    {
 
195
        beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
 
196
        m_applications.append(application);
 
197
        endInsertRows();
 
198
    }
 
199
 
 
200
    QList<Application*> m_applications;
 
201
};
 
202
 
 
203
#endif // UNITYAPPLICATIONMOCKS_H