~ci-train-bot/miral/miral-ubuntu-zesty-2534

« back to all changes in this revision

Viewing changes to miral-qt/src/platforms/mirserver/mirserverintegration.cpp

  • Committer: Larry Price
  • Date: 2016-09-13 16:19:29 UTC
  • mto: This revision was merged to the branch mainline in revision 331.
  • Revision ID: larry.price@canonical.com-20160913161929-vs9ka1capmljq1es
Removing miral-qt from release branch, updating copyright file, and adding GPL3 license to root dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013-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
 
 */
16
 
 
17
 
#include "mirserverintegration.h"
18
 
 
19
 
#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
20
 
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
21
 
#include <QtPlatformSupport/private/qgenericunixservices_p.h>
22
 
 
23
 
#include <qpa/qplatformwindow.h>
24
 
#include <qpa/qplatformaccessibility.h>
25
 
#include <qpa/qplatforminputcontext.h>
26
 
#include <qpa/qplatforminputcontextfactory_p.h>
27
 
#include <qpa/qwindowsysteminterface.h>
28
 
 
29
 
#include <QGuiApplication>
30
 
#include <QStringList>
31
 
#include <QDebug>
32
 
 
33
 
// Mir
34
 
#include <mir/graphics/display.h>
35
 
#include <mir/graphics/display_configuration.h>
36
 
 
37
 
// local
38
 
#include "clipboard.h"
39
 
#include "miropenglcontext.h"
40
 
#include "nativeinterface.h"
41
 
#include "offscreensurface.h"
42
 
#include "qmirserver.h"
43
 
#include "screen.h"
44
 
#include "screensmodel.h"
45
 
#include "screenwindow.h"
46
 
#include "services.h"
47
 
#include "ubuntutheme.h"
48
 
#include "logging.h"
49
 
 
50
 
namespace mg = mir::graphics;
51
 
using qtmir::Clipboard;
52
 
 
53
 
MirServerIntegration::MirServerIntegration(int &argc, char **argv)
54
 
    : m_accessibility(new QPlatformAccessibility())
55
 
    , m_fontDb(new QGenericUnixFontDatabase())
56
 
    , m_services(new Services)
57
 
    , m_mirServer(new QMirServer(argc, argv))
58
 
    , m_nativeInterface(nullptr)
59
 
{
60
 
    // For access to sensors, qtmir uses qtubuntu-sensors. qtubuntu-sensors reads the
61
 
    // UBUNTU_PLATFORM_API_BACKEND variable to decide if to load a valid sensor backend or not.
62
 
    // For it to function we need to ensure a valid backend has been specified
63
 
    if (qEnvironmentVariableIsEmpty("UBUNTU_PLATFORM_API_BACKEND")) {
64
 
        if (qgetenv("DESKTOP_SESSION").contains("mir") || !qEnvironmentVariableIsSet("ANDROID_DATA")) {
65
 
            qputenv("UBUNTU_PLATFORM_API_BACKEND", "desktop_mirclient");
66
 
        } else {
67
 
            qputenv("UBUNTU_PLATFORM_API_BACKEND", "touch_mirclient");
68
 
        }
69
 
    }
70
 
 
71
 
    // If Mir shuts down, quit.
72
 
    QObject::connect(m_mirServer.data(), &QMirServer::stopped,
73
 
                     QCoreApplication::instance(), &QCoreApplication::quit);
74
 
 
75
 
    m_inputContext = QPlatformInputContextFactory::create();
76
 
 
77
 
    // Default Qt behaviour doesn't match a shell's intentions, so customize:
78
 
    qGuiApp->setQuitOnLastWindowClosed(false);
79
 
}
80
 
 
81
 
MirServerIntegration::~MirServerIntegration()
82
 
{
83
 
    delete m_nativeInterface;
84
 
}
85
 
 
86
 
bool MirServerIntegration::hasCapability(QPlatformIntegration::Capability cap) const
87
 
{
88
 
    switch (cap) {
89
 
    case ThreadedPixmaps: return true;
90
 
    case OpenGL: return true;
91
 
    case ThreadedOpenGL: return true;
92
 
    case BufferQueueingOpenGL: return true;
93
 
    case MultipleWindows: return true; // multi-monitor support
94
 
    case WindowManagement: return false; // platform has no WM, as this implements the WM!
95
 
    case NonFullScreenWindows: return false;
96
 
    default: return QPlatformIntegration::hasCapability(cap);
97
 
    }
98
 
}
99
 
 
100
 
QPlatformWindow *MirServerIntegration::createPlatformWindow(QWindow *window) const
101
 
{
102
 
    QWindowSystemInterface::flushWindowSystemEvents();
103
 
 
104
 
    auto screens = m_mirServer->screensModel();
105
 
    if (!screens) {
106
 
        qCritical("Screens are not initialized, unable to create a new QWindow/ScreenWindow");
107
 
        return nullptr;
108
 
    }
109
 
 
110
 
    auto platformWindow = new ScreenWindow(window);
111
 
    if (screens->compositing()) {
112
 
        platformWindow->setExposed(true);
113
 
    }
114
 
 
115
 
    qCDebug(QTMIR_SCREENS) << "QWindow" << window << "with geom" << window->geometry()
116
 
                           << "is backed by a" << static_cast<Screen *>(window->screen()->handle())
117
 
                           << "with geometry" << window->screen()->geometry();
118
 
    return platformWindow;
119
 
}
120
 
 
121
 
QPlatformBackingStore *MirServerIntegration::createPlatformBackingStore(QWindow */*window*/) const
122
 
{
123
 
    return nullptr;
124
 
}
125
 
 
126
 
QPlatformOpenGLContext *MirServerIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
127
 
{
128
 
    return m_mirServer->createPlatformOpenGLContext(context);
129
 
}
130
 
 
131
 
QAbstractEventDispatcher *MirServerIntegration::createEventDispatcher() const
132
 
{
133
 
    return createUnixEventDispatcher();
134
 
}
135
 
 
136
 
void MirServerIntegration::initialize()
137
 
{
138
 
    // Creates instance of and start the Mir server in a separate thread
139
 
    if (!m_mirServer->start()) {
140
 
        exit(2);
141
 
    }
142
 
 
143
 
    auto screens = m_mirServer->screensModel();
144
 
    if (!screens) {
145
 
        qFatal("ScreensModel not initialized");
146
 
    }
147
 
    QObject::connect(screens.data(), &ScreensModel::screenAdded,
148
 
            [this](Screen *screen) { this->screenAdded(screen); });
149
 
    QObject::connect(screens.data(), &ScreensModel::screenRemoved,
150
 
            [this](Screen *screen) {
151
 
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
152
 
        delete screen;
153
 
#else
154
 
        this->destroyScreen(screen);
155
 
#endif
156
 
    });
157
 
 
158
 
    Q_FOREACH(auto screen, screens->screens()) {
159
 
        screenAdded(screen);
160
 
    }
161
 
 
162
 
    m_nativeInterface = new NativeInterface(m_mirServer.data());
163
 
}
164
 
 
165
 
QPlatformAccessibility *MirServerIntegration::accessibility() const
166
 
{
167
 
    return m_accessibility.data();
168
 
}
169
 
 
170
 
QPlatformFontDatabase *MirServerIntegration::fontDatabase() const
171
 
{
172
 
    return m_fontDb.data();
173
 
}
174
 
 
175
 
QStringList MirServerIntegration::themeNames() const
176
 
{
177
 
    return QStringList(UbuntuTheme::name);
178
 
}
179
 
 
180
 
QPlatformTheme *MirServerIntegration::createPlatformTheme(const QString& name) const
181
 
{
182
 
    Q_UNUSED(name);
183
 
    return new UbuntuTheme;
184
 
}
185
 
 
186
 
QPlatformServices *MirServerIntegration::services() const
187
 
{
188
 
    return m_services.data();
189
 
}
190
 
 
191
 
QPlatformNativeInterface *MirServerIntegration::nativeInterface() const
192
 
{
193
 
    return m_nativeInterface;
194
 
}
195
 
 
196
 
QPlatformClipboard *MirServerIntegration::clipboard() const
197
 
{
198
 
    static QPlatformClipboard *clipboard = nullptr;
199
 
    if (!clipboard) {
200
 
        clipboard = new Clipboard;
201
 
    }
202
 
    return clipboard;
203
 
}
204
 
 
205
 
QPlatformOffscreenSurface *MirServerIntegration::createPlatformOffscreenSurface(
206
 
        QOffscreenSurface *surface) const
207
 
{
208
 
    return new OffscreenSurface(surface);
209
 
}