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"
25// libandroid-properties
26#include <hybris/properties/properties.h>
30#include "CachingNetworkManagerFactory.h"
31#include "MouseTouchAdaptor.h"
32#include "UnityCommandLineParser.h"
34ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
35 : QGuiApplication(argc, argv)
38 setApplicationName(QStringLiteral("unity8"));
40 connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
42 setupQmlEngine(isMirServer);
44 UnityCommandLineParser parser(*this);
46 if (!parser.deviceName().isEmpty()) {
47 m_deviceName = parser.deviceName();
50 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
51 m_deviceName = QString(buffer);
53 m_qmlArgs.setDeviceName(m_deviceName);
55 m_qmlArgs.setMode(parser.mode());
57 // The testability driver is only loaded by QApplication but not by QGuiApplication.
58 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
59 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
60 QLibrary testLib(QStringLiteral("qttestability"));
62 typedef void (*TasInitialize)(void);
63 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
67 qCritical("Library qttestability resolve failed!");
70 qCritical("Library qttestability load failed!");
74 bindtextdomain("unity8", translationDirectory().toUtf8().data());
77 m_shellView.reset(new ShellView(m_qmlEngine, &m_qmlArgs));
79 if (parser.windowGeometry().isValid()) {
80 m_shellView->setWidth(parser.windowGeometry().width());
81 m_shellView->setHeight(parser.windowGeometry().height());
84 if (parser.hasFrameless()) {
85 m_shellView->setFlags(Qt::FramelessWindowHint);
88 // You will need this if you want to interact with touch-only components using a mouse
89 // Needed only when manually testing on a desktop.
90 if (parser.hasMouseToTouch()) {
91 m_mouseTouchAdaptor.reset(MouseTouchAdaptor::instance());
95 // Some hard-coded policy for now.
96 // NB: We don't support more than two screens at the moment
98 // TODO: Support an arbitrary number of screens and different policies
99 // (eg cloned desktop, several desktops, etc)
100 if (isMirServer && screens().count() == 2) {
101 m_shellView->setScreen(screens().at(1));
102 m_qmlArgs.setDeviceName("desktop");
104 m_secondaryWindow.reset(new SecondaryWindow(m_qmlEngine));
105 m_secondaryWindow->setScreen(screens().at(0));
106 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
107 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
108 m_secondaryWindow->setVisible(true);
111 if (isMirServer || parser.hasFullscreen()) {
112 m_shellView->showFullScreen();
118void ShellApplication::setupQmlEngine(bool isMirServer)
120 m_qmlEngine = new QQmlEngine(this);
122 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
124 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
126 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
128 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
130 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
132 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
135void ShellApplication::onScreenAdded(QScreen * /*screen*/)
137 // TODO: Support an arbitrary number of screens and different policies
138 // (eg cloned desktop, several desktops, etc)
139 if (screens().count() == 2) {
140 m_shellView->setScreen(screens().at(1));
141 m_qmlArgs.setDeviceName("desktop");
142 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
143 // its backing QPlatformWindow recreated). So lets refocus it.
144 m_shellView->requestActivate();
146 m_secondaryWindow.reset(new SecondaryWindow(m_qmlEngine));
147 m_secondaryWindow->setScreen(screens().at(0));
149 // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
150 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
151 m_secondaryWindow->setVisible(true);
155void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
157 // TODO: Support an arbitrary number of screens and different policies
158 // (eg cloned desktop, several desktops, etc)
159 if (screen == m_shellView->screen()) {
160 Q_ASSERT(screens().count() > 1);
161 Q_ASSERT(screens().at(0) != screen);
162 Q_ASSERT(!m_secondaryWindow.isNull());
163 m_secondaryWindow.reset();
164 m_shellView->setScreen(screens().first());
165 m_qmlArgs.setDeviceName(m_deviceName);
166 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
167 // its backing QPlatformWindow recreated). So lets refocus it.
168 m_shellView->requestActivate();
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