2 * Copyright (C) 2012 Canonical, Ltd.
5 * Gerry Boland <gerry.boland@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include <QtQuick/QQuickView>
22#include <QtGui/QGuiApplication>
23#include <QtGui/QScreen>
24#include <QtQml/QQmlEngine>
25#include <QtQml/QQmlContext>
26#include <qpa/qplatformnativeinterface.h>
36#include "MouseTouchAdaptor.h"
37#include "ApplicationArguments.h"
39#include <unity-mir/qmirserver.h>
42int startShell(int argc, const char** argv, void* server)
44 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
46 QGuiApplication::setApplicationName(UNITY8_GREETER ? "Unity 8 Greeter" : "Unity 8");
47 QGuiApplication *application;
48 if (isUbuntuMirServer) {
49 QLibrary unityMir("unity-mir", 1);
52 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
53 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
54 if (!createQMirServerApplication) {
55 qDebug() << "unable to resolve symbol: createQMirServerApplication";
59 application = createQMirServerApplication(argc, argv, server);
61 application = new QGuiApplication(argc, (char**)argv);
64 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
65 if (indicatorProfile.isEmpty()) {
66 indicatorProfile = UNITY8_GREETER ? "phone_greeter" : "phone";
71 QStringList args = application->arguments();
72 ApplicationArguments qmlArgs(args);
74 // The testability driver is only loaded by QApplication but not by QGuiApplication.
75 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
76 if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
77 QLibrary testLib(QLatin1String("qttestability"));
79 typedef void (*TasInitialize)(void);
80 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
84 qCritical("Library qttestability resolve failed!");
87 qCritical("Library qttestability load failed!");
91 bindtextdomain("unity8", translationDirectory().toUtf8().data());
93 QQuickView* view = new QQuickView();
94 view->setResizeMode(QQuickView::SizeRootObjectToView);
95 view->setTitle("Qml Phone Shell");
96 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
97 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
98 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
99 if (args.contains(QLatin1String("-frameless"))) {
100 view->setFlags(Qt::FramelessWindowHint);
103 // You will need this if you want to interact with touch-only components using a mouse
104 // Needed only when manually testing on a desktop.
105 MouseTouchAdaptor *mouseTouchAdaptor = 0;
106 if (args.contains(QLatin1String("-mousetouch"))) {
107 mouseTouchAdaptor = new MouseTouchAdaptor;
108 application->installNativeEventFilter(mouseTouchAdaptor);
111 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
112 /* Shell is declared as a system session so that it always receives all
114 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
115 when it becomes available.
117 nativeInterface->setProperty("ubuntuSessionType", 1);
118 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
120 QUrl source(::qmlDirectory() + (UNITY8_GREETER ? "GreeterShell.qml" : "Shell.qml"));
121 prependImportPaths(view->engine(), ::overrideImportPaths());
122 if (!isUbuntuMirServer) {
123 prependImportPaths(view->engine(), ::nonMirImportPaths());
125 appendImportPaths(view->engine(), ::fallbackImportPaths());
128 if (isUbuntuMirServer) {
129 // Add alpha to surface, so that the greeter can bleed through
130 QSurfaceFormat format;
131 format.setAlphaBufferSize(8);
132 view->setFormat(format);
135 if (!QProcess::startDetached("/sbin/initctl emit --no-wait unity8-greeter-started")) {
136 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
140 view->setSource(source);
141 view->setColor(Qt::transparent);
143 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
144 // First, size window equal to screen (fake a real WM fullscreen mode).
145 // Then, in case we are actually running inside a windowing system,
146 // nicely set actual WM fullscreen hint for its benefit.
147 view->resize(view->screen()->size());
148 view->showFullScreen();
153 int result = application->exec();
156 delete mouseTouchAdaptor;
162int main(int argc, const char *argv[])
164 /* Workaround Qt platform integration plugin not advertising itself
165 as having the following capabilities:
166 - QPlatformIntegration::ThreadedOpenGL
167 - QPlatformIntegration::BufferQueueingOpenGL
169 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
170 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
172 // For ubuntumirserver/ubuntumirclient
173 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
174 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
176 // If we use unity-mir directly, we automatically link to the Mir-server
177 // platform-api bindings, which result in unexpected behaviour when
178 // running the non-Mir scenario.
179 QLibrary unityMir("unity-mir", 1);
181 if (!unityMir.isLoaded()) {
182 qDebug() << "Library unity-mir not found/loaded";
186 typedef QMirServer* (*createServer_t)(int, const char **);
187 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
188 if (!createQMirServer) {
189 qDebug() << "unable to resolve symbol: createQMirServer";
193 QMirServer* mirServer = createQMirServer(argc, argv);
195 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
196 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
197 if (!runWithClient) {
198 qDebug() << "unable to resolve symbol: runWithClient";
202 return runWithClient(mirServer, startShell);
204 if (qgetenv("UPSTART_JOB") == "unity8") {
205 // Emit SIGSTOP as expected by upstart, under Mir it's unity-mir that will raise it.
206 // see http://upstart.ubuntu.com/cookbook/#expect-stop
209 return startShell(argc, argv, nullptr);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list