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 <QCommandLineParser>
22#include <QtQuick/QQuickView>
23#include <QtGui/QGuiApplication>
24#include <QtQml/QQmlEngine>
25#include <QtQml/QQmlContext>
26#include <qpa/qplatformnativeinterface.h>
35#include "MouseTouchAdaptor.h"
36#include "ApplicationArguments.h"
38#include <unity-mir/qmirserver.h>
41int startShell(int argc, const char** argv, void* server)
43 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
45 QGuiApplication::setApplicationName("Unity 8");
46 QGuiApplication *application;
48 QCommandLineParser parser;
49 parser.setApplicationDescription("Description: Unity 8 Shell");
50 parser.addHelpOption();
52 QCommandLineOption fullscreenOption("fullscreen",
54 parser.addOption(fullscreenOption);
56 QCommandLineOption framelessOption("frameless",
57 "Run without window borders");
58 parser.addOption(framelessOption);
60 QCommandLineOption mousetouchOption("mousetouch",
61 "Allow the mouse to provide touch input");
62 parser.addOption(mousetouchOption);
64 QCommandLineOption testabilityOption("testability",
65 "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead. \n \
66Load the testability driver");
67 parser.addOption(testabilityOption);
69 if (isUbuntuMirServer) {
70 QLibrary unityMir("unity-mir", 1);
73 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
74 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
75 if (!createQMirServerApplication) {
76 qDebug() << "unable to resolve symbol: createQMirServerApplication";
80 application = createQMirServerApplication(argc, argv, server);
82 application = new QGuiApplication(argc, (char**)argv);
85 // Treat args with single dashes the same as arguments with two dashes
86 // Ex: -fullscreen == --fullscreen
87 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
88 parser.process(*application);
90 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
91 if (indicatorProfile.isEmpty()) {
92 indicatorProfile = "phone";
97 QStringList args = application->arguments();
98 ApplicationArguments qmlArgs(args);
100 // The testability driver is only loaded by QApplication but not by QGuiApplication.
101 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
102 if (parser.isSet(testabilityOption) || getenv("QT_LOAD_TESTABILITY")) {
103 QLibrary testLib(QLatin1String("qttestability"));
104 if (testLib.load()) {
105 typedef void (*TasInitialize)(void);
106 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
110 qCritical("Library qttestability resolve failed!");
113 qCritical("Library qttestability load failed!");
117 bindtextdomain("unity8", translationDirectory().toUtf8().data());
119 QQuickView* view = new QQuickView();
120 view->setResizeMode(QQuickView::SizeRootObjectToView);
121 view->setTitle("Qml Phone Shell");
122 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
123 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
124 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
125 if (parser.isSet(framelessOption)) {
126 view->setFlags(Qt::FramelessWindowHint);
129 // You will need this if you want to interact with touch-only components using a mouse
130 // Needed only when manually testing on a desktop.
131 MouseTouchAdaptor *mouseTouchAdaptor = 0;
132 if (parser.isSet(mousetouchOption)) {
133 mouseTouchAdaptor = new MouseTouchAdaptor;
134 application->installNativeEventFilter(mouseTouchAdaptor);
137 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
138 /* Shell is declared as a system session so that it always receives all
140 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
141 when it becomes available.
143 nativeInterface->setProperty("ubuntuSessionType", 1);
144 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
146 QUrl source(::qmlDirectory()+"Shell.qml");
147 prependImportPaths(view->engine(), ::overrideImportPaths());
148 if (!isUbuntuMirServer) {
149 prependImportPaths(view->engine(), ::nonMirImportPaths());
151 appendImportPaths(view->engine(), ::fallbackImportPaths());
153 view->setSource(source);
154 view->setColor("transparent");
156 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
157 view->showFullScreen();
162 int result = application->exec();
165 delete mouseTouchAdaptor;
171int main(int argc, const char *argv[])
173 /* Workaround Qt platform integration plugin not advertising itself
174 as having the following capabilities:
175 - QPlatformIntegration::ThreadedOpenGL
176 - QPlatformIntegration::BufferQueueingOpenGL
178 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
179 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
181 // For ubuntumirserver/ubuntumirclient
182 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
183 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
185 // If we use unity-mir directly, we automatically link to the Mir-server
186 // platform-api bindings, which result in unexpected behaviour when
187 // running the non-Mir scenario.
188 QLibrary unityMir("unity-mir", 1);
190 if (!unityMir.isLoaded()) {
191 qDebug() << "Library unity-mir not found/loaded";
195 typedef QMirServer* (*createServer_t)(int, const char **);
196 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
197 if (!createQMirServer) {
198 qDebug() << "unable to resolve symbol: createQMirServer";
202 QMirServer* mirServer = createQMirServer(argc, argv);
204 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
205 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
206 if (!runWithClient) {
207 qDebug() << "unable to resolve symbol: runWithClient";
211 return runWithClient(mirServer, startShell);
213 if (qgetenv("UPSTART_JOB") == "unity8") {
214 // Emit SIGSTOP as expected by upstart, under Mir it's unity-mir that will raise it.
215 // see http://upstart.ubuntu.com/cookbook/#expect-stop
218 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