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"
26// libandroid-properties
27#include <hybris/properties/properties.h>
31#include "CachingNetworkManagerFactory.h"
32#include "UnityCommandLineParser.h"
34ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
35 : QGuiApplication(argc, argv)
38 setApplicationName(QStringLiteral("unity8"));
39 setOrganizationName(QStringLiteral("Canonical"));
41 connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
43 setupQmlEngine(isMirServer);
45 UnityCommandLineParser parser(*this);
47 if (!parser.deviceName().isEmpty()) {
48 m_deviceName = parser.deviceName();
51 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
52 m_deviceName = QString(buffer);
54 m_qmlArgs.setDeviceName(m_deviceName);
56 m_qmlArgs.setMode(parser.mode());
58 // The testability driver is only loaded by QApplication but not by QGuiApplication.
59 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
60 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
61 QLibrary testLib(QStringLiteral("qttestability"));
63 typedef void (*TasInitialize)(void);
64 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
68 qCritical("Library qttestability resolve failed!");
71 qCritical("Library qttestability load failed!");
75 bindtextdomain("unity8", translationDirectory().toUtf8().data());
78 m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
80 if (parser.windowGeometry().isValid()) {
81 m_shellView->setWidth(parser.windowGeometry().width());
82 m_shellView->setHeight(parser.windowGeometry().height());
85 if (parser.hasFrameless()) {
86 m_shellView->setFlags(Qt::FramelessWindowHint);
90 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
91 // You will need this if you want to interact with touch-only components using a mouse
92 // Needed only when manually testing on a desktop.
93 if (parser.hasMouseToTouch()) {
94 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
99 // Some hard-coded policy for now.
100 // NB: We don't support more than two screens at the moment
102 // TODO: Support an arbitrary number of screens and different policies
103 // (eg cloned desktop, several desktops, etc)
104 if (isMirServer && screens().count() == 2) {
105 m_shellView->setScreen(screens().at(1));
106 m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
108 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
109 m_secondaryWindow->setScreen(screens().at(0));
110 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
111 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
112 m_secondaryWindow->setVisible(true);
115 if (parser.mode().compare("greeter") == 0) {
116 QSize primaryScreenSize = this->primaryScreen()->size();
117 m_shellView->setHeight(primaryScreenSize.height());
118 m_shellView->setWidth(primaryScreenSize.width());
120 m_shellView->requestActivate();
121 if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
122 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
124 } else if (isMirServer || parser.hasFullscreen()) {
125 m_shellView->showFullScreen();
131ShellApplication::~ShellApplication()
136void ShellApplication::destroyResources()
138 // Deletion order is important. Don't use QScopedPointers and the like
139 // Otherwise the process will hang on shutdown (bug somewhere I guess).
141 m_shellView = nullptr;
143 delete m_secondaryWindow;
144 m_secondaryWindow = nullptr;
146 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
147 delete m_mouseTouchAdaptor;
148 m_mouseTouchAdaptor = nullptr;
152 m_qmlEngine = nullptr;
155void ShellApplication::setupQmlEngine(bool isMirServer)
157 m_qmlEngine = new QQmlEngine(this);
159 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
161 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
163 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
165 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
167 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
169 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
172void ShellApplication::onScreenAdded(QScreen * /*screen*/)
174 // TODO: Support an arbitrary number of screens and different policies
175 // (eg cloned desktop, several desktops, etc)
176 if (screens().count() == 2) {
177 m_shellView->setScreen(screens().at(1));
178 m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
179 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
180 // its backing QPlatformWindow recreated). So lets refocus it.
181 m_shellView->requestActivate();
182 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
183 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
184 m_shellView->setVisible(true);
186 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
187 m_secondaryWindow->setScreen(screens().at(0));
189 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
190 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
191 m_secondaryWindow->setVisible(true);
195void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
197 // TODO: Support an arbitrary number of screens and different policies
198 // (eg cloned desktop, several desktops, etc)
199 if (screen == m_shellView->screen()) {
200 const QList<QScreen *> allScreens = screens();
201 Q_ASSERT(allScreens.count() > 1);
202 Q_ASSERT(allScreens.at(0) != screen);
203 Q_ASSERT(m_secondaryWindow);
204 delete m_secondaryWindow;
205 m_secondaryWindow = nullptr;
206 m_shellView->setScreen(allScreens.first());
207 m_qmlArgs.setDeviceName(m_deviceName);
208 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
209 // its backing QPlatformWindow recreated). So lets refocus it.
210 m_shellView->requestActivate();
211 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
212 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
213 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