2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "ShellApplication.h"
28// libandroid-properties
29#include <hybris/properties/properties.h>
33#include "CachingNetworkManagerFactory.h"
34#include "UnityCommandLineParser.h"
35#include "DebuggingController.h"
37ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
38 : QGuiApplication(argc, argv)
40 setApplicationName(QStringLiteral("unity8"));
41 setOrganizationName(QStringLiteral("Canonical"));
43 connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
44 connect(this, &QGuiApplication::screenRemoved, this, &ShellApplication::onScreenRemoved);
46 setupQmlEngine(isMirServer);
48 UnityCommandLineParser parser(*this);
50 if (!parser.deviceName().isEmpty()) {
51 m_deviceName = parser.deviceName();
54 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
55 m_deviceName = QString(buffer);
57 m_qmlArgs.setDeviceName(m_deviceName);
59 m_qmlArgs.setMode(parser.mode());
63 property_get("ubuntu.unity8.interactive_blur", buffer, "false");
64 m_qmlArgs.setInteractiveBlur(QString(buffer) == QStringLiteral("true"));
67 // The testability driver is only loaded by QApplication but not by QGuiApplication.
68 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
69 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
70 QLibrary testLib(QStringLiteral("qttestability"));
72 typedef void (*TasInitialize)(void);
73 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
77 qCritical("Library qttestability resolve failed!");
80 qCritical("Library qttestability load failed!");
84 bindtextdomain("unity8", translationDirectory().toUtf8().data());
87 QScopedPointer<QGSettings> gSettings(new QGSettings("com.canonical.Unity8"));
88 gSettings->reset(QStringLiteral("alwaysShowOsk"));
90 m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
92 if (parser.windowGeometry().isValid()) {
93 m_shellView->setWidth(parser.windowGeometry().width());
94 m_shellView->setHeight(parser.windowGeometry().height());
97 if (parser.hasFrameless()) {
98 m_shellView->setFlags(Qt::FramelessWindowHint);
102 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
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 if (parser.hasMouseToTouch()) {
106 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
110 new DebuggingController(this);
112 // Some hard-coded policy for now.
113 // NB: We don't support more than two screens at the moment
115 // TODO: Support an arbitrary number of screens and different policies
116 // (eg cloned desktop, several desktops, etc)
117 if (isMirServer && screens().count() == 2) {
118 m_shellView->setScreen(screens().at(1));
119 m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
121 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
122 m_secondaryWindow->setScreen(screens().at(0));
123 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
124 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
125 m_secondaryWindow->setVisible(true);
128 if (parser.mode().compare("greeter") == 0) {
129 QSize primaryScreenSize = this->primaryScreen()->size();
130 m_shellView->setHeight(primaryScreenSize.height());
131 m_shellView->setWidth(primaryScreenSize.width());
133 m_shellView->requestActivate();
134 if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
135 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
137 } else if (isMirServer || parser.hasFullscreen()) {
138 m_shellView->showFullScreen();
144ShellApplication::~ShellApplication()
149void ShellApplication::destroyResources()
151 // Deletion order is important. Don't use QScopedPointers and the like
152 // Otherwise the process will hang on shutdown (bug somewhere I guess).
154 m_shellView = nullptr;
156 delete m_secondaryWindow;
157 m_secondaryWindow = nullptr;
159 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
160 delete m_mouseTouchAdaptor;
161 m_mouseTouchAdaptor = nullptr;
165 m_qmlEngine = nullptr;
168void ShellApplication::setupQmlEngine(bool isMirServer)
170 m_qmlEngine = new QQmlEngine(this);
172 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
174 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
176 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
178 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
180 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
182 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
185void ShellApplication::onScreenAdded(QScreen * /*screen*/)
187 // TODO: Support an arbitrary number of screens and different policies
188 // (eg cloned desktop, several desktops, etc)
189 if (screens().count() == 2) {
190 m_shellView->setScreen(screens().at(1));
191 m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
192 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
193 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
194 m_shellView->setVisible(true);
196 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
197 m_secondaryWindow->setScreen(screens().at(0));
199 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
200 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
201 m_secondaryWindow->setVisible(true);
203 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
204 // its backing QPlatformWindow recreated). So lets refocus it.
205 // This must be done after the creation of the SecondaryWindow, else
206 // the SecondaryWindow takes focus anyway.
207 m_shellView->requestActivate();
211void ShellApplication::onScreenRemoved(QScreen *screen)
213 // TODO: Support an arbitrary number of screens and different policies
214 // (eg cloned desktop, several desktops, etc)
215 if (screen == m_shellView->screen()) {
216 const QList<QScreen *> allScreens = screens();
217 Q_ASSERT(allScreens.count() > 1);
218 Q_ASSERT(allScreens.at(0) != screen);
219 Q_ASSERT(m_secondaryWindow);
220 delete m_secondaryWindow;
221 m_secondaryWindow = nullptr;
222 m_shellView->setScreen(allScreens.first());
223 m_qmlArgs.setDeviceName(m_deviceName);
224 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
225 // its backing QPlatformWindow recreated). So lets refocus it.
226 m_shellView->requestActivate();
227 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
228 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
229 m_shellView->setVisible(true);
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