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 windowGeometryOption(QStringList() << "windowgeometry",
65 "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
66 parser.addOption(windowGeometryOption);
68 QCommandLineOption testabilityOption("testability",
69 "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead. \n \
70Load the testability driver");
71 parser.addOption(testabilityOption);
73 if (isUbuntuMirServer) {
74 QLibrary unityMir("unity-mir", 1);
77 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
78 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
79 if (!createQMirServerApplication) {
80 qDebug() << "unable to resolve symbol: createQMirServerApplication";
84 application = createQMirServerApplication(argc, argv, server);
86 application = new QGuiApplication(argc, (char**)argv);
89 // Treat args with single dashes the same as arguments with two dashes
90 // Ex: -fullscreen == --fullscreen
91 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
92 parser.process(*application);
94 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
95 if (indicatorProfile.isEmpty()) {
96 indicatorProfile = "phone";
101 ApplicationArguments qmlArgs;
102 if (parser.isSet(windowGeometryOption) &&
103 parser.value(windowGeometryOption).split('x').size() == 2)
105 QStringList geom = parser.value(windowGeometryOption).split('x');
106 qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
109 // The testability driver is only loaded by QApplication but not by QGuiApplication.
110 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
111 if (parser.isSet(testabilityOption) || getenv("QT_LOAD_TESTABILITY")) {
112 QLibrary testLib(QLatin1String("qttestability"));
113 if (testLib.load()) {
114 typedef void (*TasInitialize)(void);
115 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
119 qCritical("Library qttestability resolve failed!");
122 qCritical("Library qttestability load failed!");
126 bindtextdomain("unity8", translationDirectory().toUtf8().data());
128 QQuickView* view = new QQuickView();
129 view->setResizeMode(QQuickView::SizeRootObjectToView);
130 view->setTitle("Qml Phone Shell");
131 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
132 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
133 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
134 if (parser.isSet(framelessOption)) {
135 view->setFlags(Qt::FramelessWindowHint);
138 // You will need this if you want to interact with touch-only components using a mouse
139 // Needed only when manually testing on a desktop.
140 MouseTouchAdaptor *mouseTouchAdaptor = 0;
141 if (parser.isSet(mousetouchOption)) {
142 mouseTouchAdaptor = new MouseTouchAdaptor;
143 application->installNativeEventFilter(mouseTouchAdaptor);
146 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
147 /* Shell is declared as a system session so that it always receives all
149 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
150 when it becomes available.
152 nativeInterface->setProperty("ubuntuSessionType", 1);
153 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
155 QUrl source(::qmlDirectory()+"Shell.qml");
156 prependImportPaths(view->engine(), ::overrideImportPaths());
157 if (!isUbuntuMirServer) {
158 prependImportPaths(view->engine(), ::nonMirImportPaths());
160 appendImportPaths(view->engine(), ::fallbackImportPaths());
162 view->setSource(source);
163 view->setColor("transparent");
164 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
166 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
167 view->showFullScreen();
172 int result = application->exec();
175 delete mouseTouchAdaptor;
181int main(int argc, const char *argv[])
183 /* Workaround Qt platform integration plugin not advertising itself
184 as having the following capabilities:
185 - QPlatformIntegration::ThreadedOpenGL
186 - QPlatformIntegration::BufferQueueingOpenGL
188 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
189 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
191 // For ubuntumirserver/ubuntumirclient
192 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
193 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
195 // If we use unity-mir directly, we automatically link to the Mir-server
196 // platform-api bindings, which result in unexpected behaviour when
197 // running the non-Mir scenario.
198 QLibrary unityMir("unity-mir", 1);
200 if (!unityMir.isLoaded()) {
201 qDebug() << "Library unity-mir not found/loaded";
205 typedef QMirServer* (*createServer_t)(int, const char **);
206 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
207 if (!createQMirServer) {
208 qDebug() << "unable to resolve symbol: createQMirServer";
212 QMirServer* mirServer = createQMirServer(argc, argv);
214 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
215 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
216 if (!runWithClient) {
217 qDebug() << "unable to resolve symbol: runWithClient";
221 return runWithClient(mirServer, startShell);
223 if (qgetenv("UPSTART_JOB") == "unity8") {
224 // Emit SIGSTOP as expected by upstart, under Mir it's unity-mir that will raise it.
225 // see http://upstart.ubuntu.com/cookbook/#expect-stop
228 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