~albaguirre/qtubuntu/mir-0.26.1-compat

« back to all changes in this revision

Viewing changes to src/ubuntumirclient/qmirclientintegration.cpp

Class renaming and syntax changes to shrink delta with upstream mirclient QPA plugin (which is equivalent to rev 360)

Changes:
- Rename classes to prefix "QMirClient" instead of "Ubuntu"
- Update licence headers to match Qt's
- change logging categories spec to match Qt: qt.qpa.mirclient
- Enforce American English
- some minor syntax tweaks

Some differences still exist:
- QPA plugin remains "ubuntumirclient" and not "mirclient" as used upstream.
- some header paths differ between in-Qt code and externally built code
- I've not included build-type switches for things like accessibility support
- relaxed switch cases to allow older versions of Mir not break a build
- panel height hack removed from upstream
- platform-api env var setting removed from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2014-2016 Canonical, Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it under
5
 
 * the terms of the GNU Lesser General Public License version 3, as published by
6
 
 * the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
 
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
 * Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2014-2016 Canonical, Ltd.
 
4
** Contact: https://www.qt.io/licensing/
 
5
**
 
6
** This file is part of the plugins of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and The Qt Company. For licensing terms
 
14
** and conditions see https://www.qt.io/terms-conditions. For further
 
15
** information use the contact form at https://www.qt.io/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 3 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL3 included in the
 
21
** packaging of this file. Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 3 requirements
 
23
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
 
24
**
 
25
** GNU General Public License Usage
 
26
** Alternatively, this file may be used under the terms of the GNU
 
27
** General Public License version 2.0 or (at your option) the GNU General
 
28
** Public license version 3 or any later version approved by the KDE Free
 
29
** Qt Foundation. The licenses are as published by the Free Software
 
30
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
 
31
** included in the packaging of this file. Please review the following
 
32
** information to ensure the GNU General Public License requirements will
 
33
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
 
34
** https://www.gnu.org/licenses/gpl-3.0.html.
 
35
**
 
36
** $QT_END_LICENSE$
 
37
**
 
38
****************************************************************************/
 
39
 
16
40
 
17
41
// Local
18
 
#include "integration.h"
19
 
#include "backingstore.h"
20
 
#include "clipboard.h"
21
 
#include "desktopwindow.h"
22
 
#include "debugextension.h"
23
 
#include "glcontext.h"
24
 
#include "input.h"
25
 
#include "logging.h"
26
 
#include "nativeinterface.h"
27
 
#include "screen.h"
28
 
#include "window.h"
 
42
#include "qmirclientintegration.h"
 
43
#include "qmirclientbackingstore.h"
 
44
#include "qmirclientclipboard.h"
 
45
#include "qmirclientdebugextension.h"
 
46
#include "qmirclientdesktopwindow.h"
 
47
#include "qmirclientglcontext.h"
 
48
#include "qmirclientinput.h"
 
49
#include "qmirclientlogging.h"
 
50
#include "qmirclientnativeinterface.h"
 
51
#include "qmirclientscreen.h"
 
52
#include "qmirclientwindow.h"
29
53
 
30
54
// Qt
31
55
#include <QFileInfo>
32
56
#include <QGuiApplication>
33
 
#include <private/qeglpbuffer_p.h>
34
57
#include <qpa/qplatformnativeinterface.h>
35
58
#include <qpa/qplatforminputcontextfactory_p.h>
36
59
#include <qpa/qplatforminputcontext.h>
71
94
 
72
95
static void resumedCallback(const UApplicationOptions */*options*/, void *context)
73
96
{
74
 
    auto integration = static_cast<UbuntuClientIntegration*>(context);
 
97
    auto integration = static_cast<QMirClientClientIntegration*>(context);
75
98
    integration->appStateController()->setResumed();
76
99
}
77
100
 
78
101
static void aboutToStopCallback(UApplicationArchive */*archive*/, void *context)
79
102
{
80
 
    auto integration = static_cast<UbuntuClientIntegration*>(context);
 
103
    auto integration = static_cast<QMirClientClientIntegration*>(context);
81
104
    auto inputContext = integration->inputContext();
82
105
    if (inputContext) {
83
106
        inputContext->hideInputPanel();
84
107
    } else {
85
 
        qCWarning(ubuntumirclient) << "aboutToStopCallback(): no input context";
 
108
        qCWarning(mirclient) << "aboutToStopCallback(): no input context";
86
109
    }
87
110
    integration->appStateController()->setSuspended();
88
111
}
89
112
 
90
113
 
91
 
UbuntuClientIntegration::UbuntuClientIntegration(int argc, char **argv)
 
114
QMirClientClientIntegration::QMirClientClientIntegration(int argc, char **argv)
92
115
    : QPlatformIntegration()
93
 
    , mNativeInterface(new UbuntuNativeInterface(this))
 
116
    , mNativeInterface(new QMirClientNativeInterface(this))
94
117
    , mFontDb(new QGenericUnixFontDatabase)
95
 
    , mServices(new UbuntuPlatformServices)
96
 
    , mAppStateController(new UbuntuAppStateController)
 
118
    , mServices(new QMirClientPlatformServices)
 
119
    , mAppStateController(new QMirClientAppStateController)
97
120
    , mScaleFactor(1.0)
98
121
{
99
122
    QByteArray sessionName;
108
131
    mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions);
109
132
 
110
133
    if (mInstance == nullptr) {
111
 
        qCritical("[QPA] UbuntuClientIntegration: connection to Mir server failed.\n");
 
134
        qCritical("[QPA] QMirClientClientIntegration: connection to Mir server failed.\n");
112
135
 
113
136
        // TODO: add API to platform-api to fetch Mir's error message (bug:1655970).
114
137
        // Workaround by retrying the connection here in order to get the message.
140
163
        }
141
164
    }
142
165
    if (testability) {
143
 
        mDebugExtension.reset(new UbuntuDebugExtension);
 
166
        mDebugExtension.reset(new QMirClientDebugExtension);
144
167
        if (!mDebugExtension->isEnabled()) {
145
168
            mDebugExtension.reset();
146
169
        }
147
170
    }
148
171
}
149
172
 
150
 
void UbuntuClientIntegration::initialize()
 
173
void QMirClientClientIntegration::initialize()
151
174
{
152
175
    // Init the ScreenObserver
153
 
    mScreenObserver.reset(new UbuntuScreenObserver(mMirConnection));
154
 
    connect(mScreenObserver.data(), &UbuntuScreenObserver::screenAdded,
155
 
            [this](UbuntuScreen *screen) { this->screenAdded(screen); });
156
 
    connect(mScreenObserver.data(), &UbuntuScreenObserver::screenRemoved,
157
 
                     this, &UbuntuClientIntegration::destroyScreen);
 
176
    mScreenObserver.reset(new QMirClientScreenObserver(mMirConnection));
 
177
    connect(mScreenObserver.data(), &QMirClientScreenObserver::screenAdded,
 
178
            [this](QMirClientScreen *screen) { this->screenAdded(screen); });
 
179
    connect(mScreenObserver.data(), &QMirClientScreenObserver::screenRemoved,
 
180
                     this, &QMirClientClientIntegration::destroyScreen);
158
181
 
159
 
    Q_FOREACH(auto screen, mScreenObserver->screens()) {
 
182
    Q_FOREACH (auto screen, mScreenObserver->screens()) {
160
183
        screenAdded(screen);
161
184
    }
162
185
 
163
186
    // Initialize input.
164
 
    mInput = new UbuntuInput(this);
 
187
    mInput = new QMirClientInput(this);
165
188
    mInputContext = QPlatformInputContextFactory::create();
166
189
 
167
190
    // compute the scale factor
178
201
    mScaleFactor = static_cast<qreal>(gridUnit) / defaultGridUnit;
179
202
}
180
203
 
181
 
UbuntuClientIntegration::~UbuntuClientIntegration()
 
204
QMirClientClientIntegration::~QMirClientClientIntegration()
182
205
{
183
206
    eglTerminate(mEglDisplay);
184
207
    delete mInput;
186
209
    delete mServices;
187
210
}
188
211
 
189
 
QPlatformServices *UbuntuClientIntegration::services() const
 
212
QPlatformServices *QMirClientClientIntegration::services() const
190
213
{
191
214
    return mServices;
192
215
}
193
216
 
194
 
void UbuntuClientIntegration::setupOptions(QStringList &args)
 
217
void QMirClientClientIntegration::setupOptions(QStringList &args)
195
218
{
196
219
    int argc = args.size() + 1;
197
220
    char **argv = new char*[argc];
206
229
    delete [] argv;
207
230
}
208
231
 
209
 
void UbuntuClientIntegration::setupDescription(QByteArray &sessionName)
 
232
void QMirClientClientIntegration::setupDescription(QByteArray &sessionName)
210
233
{
211
234
    mDesc = u_application_description_new();
212
235
 
220
243
    u_application_description_set_application_lifecycle_delegate(mDesc, delegate);
221
244
}
222
245
 
223
 
QByteArray UbuntuClientIntegration::generateSessionName(QStringList &args)
 
246
QByteArray QMirClientClientIntegration::generateSessionName(QStringList &args)
224
247
{
225
248
    // Try to come up with some meaningful session name to uniquely identify this session,
226
249
    // helping with shell debugging
236
259
    }
237
260
}
238
261
 
239
 
QByteArray UbuntuClientIntegration::generateSessionNameFromQmlFile(QStringList &args)
 
262
QByteArray QMirClientClientIntegration::generateSessionNameFromQmlFile(QStringList &args)
240
263
{
241
264
    Q_FOREACH (QString arg, args) {
242
265
        if (arg.endsWith(".qml")) {
249
272
    return "qmlscene";
250
273
}
251
274
 
252
 
QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window) const
 
275
QPlatformWindow* QMirClientClientIntegration::createPlatformWindow(QWindow* window) const
253
276
{
254
277
    if (window->type() == Qt::Desktop) {
255
278
        // Desktop windows should not be backed up by a mir surface as they don't draw anything (nor should).
256
 
        return new UbuntuDesktopWindow(window);
 
279
        return new QMirClientDesktopWindow(window);
257
280
    } else {
258
 
        return new UbuntuWindow(window, mInput, mNativeInterface, mAppStateController.data(),
259
 
                                mEglDisplay, mMirConnection, mDebugExtension.data());
 
281
        return new QMirClientWindow(window, mInput, mNativeInterface, mAppStateController.data(),
 
282
                                    mEglDisplay, mMirConnection, mDebugExtension.data());
260
283
    }
261
284
}
262
285
 
263
 
bool UbuntuClientIntegration::hasCapability(QPlatformIntegration::Capability cap) const
 
286
bool QMirClientClientIntegration::hasCapability(QPlatformIntegration::Capability cap) const
264
287
{
265
288
    switch (cap) {
266
289
    case ThreadedOpenGL:
267
290
        if (qEnvironmentVariableIsEmpty("QTUBUNTU_NO_THREADED_OPENGL")) {
268
291
            return true;
269
292
        } else {
270
 
            qCDebug(ubuntumirclient, "disabled threaded OpenGL");
 
293
            qCDebug(mirclient, "disabled threaded OpenGL");
271
294
            return false;
272
295
        }
273
296
 
286
309
    }
287
310
}
288
311
 
289
 
QAbstractEventDispatcher *UbuntuClientIntegration::createEventDispatcher() const
 
312
QAbstractEventDispatcher *QMirClientClientIntegration::createEventDispatcher() const
290
313
{
291
314
    return createUnixEventDispatcher();
292
315
}
293
316
 
294
 
QPlatformBackingStore* UbuntuClientIntegration::createPlatformBackingStore(QWindow* window) const
 
317
QPlatformBackingStore* QMirClientClientIntegration::createPlatformBackingStore(QWindow* window) const
295
318
{
296
 
    return new UbuntuBackingStore(window);
 
319
    return new QMirClientBackingStore(window);
297
320
}
298
321
 
299
 
QPlatformOpenGLContext* UbuntuClientIntegration::createPlatformOpenGLContext(
 
322
QPlatformOpenGLContext* QMirClientClientIntegration::createPlatformOpenGLContext(
300
323
        QOpenGLContext* context) const
301
324
{
302
325
    QSurfaceFormat format(context->format());
303
326
 
304
 
    auto platformContext = new UbuntuOpenGLContext(format, context->shareHandle(), mEglDisplay);
 
327
    auto platformContext = new QMirClientOpenGLContext(format, context->shareHandle(), mEglDisplay);
305
328
    if (!platformContext->isValid()) {
306
329
        // Older Intel Atom-based devices only support OpenGL 1.4 compatibility profile but by default
307
330
        // QML asks for at least OpenGL 2.0. The XCB GLX backend ignores this request and returns a
308
 
        // 1.4 context, but the XCB EGL backend tries to honour it, and fails. The 1.4 context appears to
 
331
        // 1.4 context, but the XCB EGL backend tries to honor it, and fails. The 1.4 context appears to
309
332
        // have sufficient capabilities on MESA (i915) to render correctly however. So reduce the default
310
333
        // requested OpenGL version to 1.0 to ensure EGL will give us a working context (lp:1549455).
311
334
        static const bool isMesa = QString(eglQueryString(mEglDisplay, EGL_VENDOR)).contains(QStringLiteral("Mesa"));
312
335
        if (isMesa) {
313
 
            qCDebug(ubuntumirclientGraphics, "Attempting to choose OpenGL 1.4 context which may suit Mesa");
 
336
            qCDebug(mirclientGraphics, "Attempting to choose OpenGL 1.4 context which may suit Mesa");
314
337
            format.setMajorVersion(1);
315
338
            format.setMinorVersion(4);
316
339
            delete platformContext;
317
 
            platformContext = new UbuntuOpenGLContext(format, context->shareHandle(), mEglDisplay);
 
340
            platformContext = new QMirClientOpenGLContext(format, context->shareHandle(), mEglDisplay);
318
341
        }
319
342
    }
320
343
    return platformContext;
321
344
}
322
345
 
323
 
QStringList UbuntuClientIntegration::themeNames() const
 
346
QStringList QMirClientClientIntegration::themeNames() const
324
347
{
325
348
    return QStringList(QStringLiteral("ubuntuappmenu"));
326
349
}
327
350
 
328
 
QPlatformTheme* UbuntuClientIntegration::createPlatformTheme(const QString& name) const
 
351
QPlatformTheme* QMirClientClientIntegration::createPlatformTheme(const QString& name) const
329
352
{
330
353
    Q_UNUSED(name);
331
354
    return new UbuntuIconTheme;
332
355
}
333
356
 
334
 
QVariant UbuntuClientIntegration::styleHint(StyleHint hint) const
 
357
QVariant QMirClientClientIntegration::styleHint(StyleHint hint) const
335
358
{
336
359
    switch (hint) {
337
360
        case QPlatformIntegration::StartDragDistance: {
348
371
    return QPlatformIntegration::styleHint(hint);
349
372
}
350
373
 
351
 
QPlatformClipboard* UbuntuClientIntegration::clipboard() const
 
374
QPlatformClipboard* QMirClientClientIntegration::clipboard() const
352
375
{
353
376
    static QPlatformClipboard *clipboard = nullptr;
354
377
    if (!clipboard) {
355
 
        clipboard = new UbuntuClipboard;
 
378
        clipboard = new QMirClientClipboard;
356
379
    }
357
380
    return clipboard;
358
381
}
359
382
 
360
 
QPlatformNativeInterface* UbuntuClientIntegration::nativeInterface() const
 
383
QPlatformNativeInterface* QMirClientClientIntegration::nativeInterface() const
361
384
{
362
385
    return mNativeInterface;
363
386
}
364
387
 
365
 
QPlatformOffscreenSurface *UbuntuClientIntegration::createPlatformOffscreenSurface(
 
388
QPlatformOffscreenSurface *QMirClientClientIntegration::createPlatformOffscreenSurface(
366
389
        QOffscreenSurface *surface) const
367
390
{
368
391
    return new QEGLPbuffer(mEglDisplay, surface->requestedFormat(), surface);
369
392
}
370
393
 
371
 
void UbuntuClientIntegration::destroyScreen(UbuntuScreen *screen)
 
394
void QMirClientClientIntegration::destroyScreen(QMirClientScreen *screen)
372
395
{
373
396
    // FIXME: on deleting a screen while a Window is on it, Qt will automatically
374
397
    // move the window to the primaryScreen(). This will trigger a screenChanged
391
414
        }
392
415
    }
393
416
 
394
 
    qCDebug(ubuntumirclient) << "Removing Screen with id" << screen->mirOutputId() << "and geometry" << screen->geometry();
 
417
    qCDebug(mirclient) << "Removing Screen with id" << screen->mirOutputId() << "and geometry" << screen->geometry();
395
418
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
396
419
    delete screen;
397
420
#else
399
422
#endif
400
423
}
401
424
 
402
 
QPlatformAccessibility *UbuntuClientIntegration::accessibility() const
 
425
QPlatformAccessibility *QMirClientClientIntegration::accessibility() const
403
426
{
404
427
    if (!mAccessibility) {
405
428
        mAccessibility.reset(new QSpiAccessibleBridge());