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);
45 setupQmlEngine(isMirServer);
47 UnityCommandLineParser parser(*this);
49 if (!parser.deviceName().isEmpty()) {
50 m_deviceName = parser.deviceName();
53 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
54 m_deviceName = QString(buffer);
56 m_qmlArgs.setDeviceName(m_deviceName);
58 m_qmlArgs.setMode(parser.mode());
60 // The testability driver is only loaded by QApplication but not by QGuiApplication.
61 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
62 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
63 QLibrary testLib(QStringLiteral("qttestability"));
65 typedef void (*TasInitialize)(void);
66 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
70 qCritical("Library qttestability resolve failed!");
73 qCritical("Library qttestability load failed!");
77 bindtextdomain("unity8", translationDirectory().toUtf8().data());
80 QScopedPointer<QGSettings> gSettings(new QGSettings("com.canonical.Unity8"));
81 gSettings->reset(QStringLiteral("alwaysShowOsk"));
83 m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
85 if (parser.windowGeometry().isValid()) {
86 m_shellView->setWidth(parser.windowGeometry().width());
87 m_shellView->setHeight(parser.windowGeometry().height());
90 if (parser.hasFrameless()) {
91 m_shellView->setFlags(Qt::FramelessWindowHint);
95 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
96 // You will need this if you want to interact with touch-only components using a mouse
97 // Needed only when manually testing on a desktop.
98 if (parser.hasMouseToTouch()) {
99 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
103 new DebuggingController(this);
105 // Some hard-coded policy for now.
106 // NB: We don't support more than two screens at the moment
108 // TODO: Support an arbitrary number of screens and different policies
109 // (eg cloned desktop, several desktops, etc)
110 if (isMirServer && screens().count() == 2) {
111 m_shellView->setScreen(screens().at(1));
112 m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
114 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
115 m_secondaryWindow->setScreen(screens().at(0));
116 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
117 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
118 m_secondaryWindow->setVisible(true);
121 if (parser.mode().compare("greeter") == 0) {
122 QSize primaryScreenSize = this->primaryScreen()->size();
123 m_shellView->setHeight(primaryScreenSize.height());
124 m_shellView->setWidth(primaryScreenSize.width());
126 m_shellView->requestActivate();
127 if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
128 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
130 } else if (isMirServer || parser.hasFullscreen()) {
131 m_shellView->showFullScreen();
137ShellApplication::~ShellApplication()
142void ShellApplication::destroyResources()
144 // Deletion order is important. Don't use QScopedPointers and the like
145 // Otherwise the process will hang on shutdown (bug somewhere I guess).
147 m_shellView = nullptr;
149 delete m_secondaryWindow;
150 m_secondaryWindow = nullptr;
152 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
153 delete m_mouseTouchAdaptor;
154 m_mouseTouchAdaptor = nullptr;
158 m_qmlEngine = nullptr;
161void ShellApplication::setupQmlEngine(bool isMirServer)
163 m_qmlEngine = new QQmlEngine(this);
165 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
167 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
169 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
171 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
173 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
175 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
178void ShellApplication::onScreenAdded(QScreen * /*screen*/)
180 // TODO: Support an arbitrary number of screens and different policies
181 // (eg cloned desktop, several desktops, etc)
182 if (screens().count() == 2) {
183 m_shellView->setScreen(screens().at(1));
184 m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
185 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
186 // its backing QPlatformWindow recreated). So lets refocus it.
187 m_shellView->requestActivate();
188 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
189 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
190 m_shellView->setVisible(true);
192 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
193 m_secondaryWindow->setScreen(screens().at(0));
195 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
196 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
197 m_secondaryWindow->setVisible(true);
201void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
203 // TODO: Support an arbitrary number of screens and different policies
204 // (eg cloned desktop, several desktops, etc)
205 if (screen == m_shellView->screen()) {
206 const QList<QScreen *> allScreens = screens();
207 Q_ASSERT(allScreens.count() > 1);
208 Q_ASSERT(allScreens.at(0) != screen);
209 Q_ASSERT(m_secondaryWindow);
210 delete m_secondaryWindow;
211 m_secondaryWindow = nullptr;
212 m_shellView->setScreen(allScreens.first());
213 m_qmlArgs.setDeviceName(m_deviceName);
214 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
215 // its backing QPlatformWindow recreated). So lets refocus it.
216 m_shellView->requestActivate();
217 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
218 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
219 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