@@ -20,6 +20,7 @@
2020#include <QLibrary>
2121#include <QProcess>
2222#include <QScreen>
23+#include <QQmlContext>
2324
2425#include <libintl.h>
2526
@@ -33,31 +34,23 @@
3334
3435ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
3536 : QGuiApplication(argc, argv)
37+ , m_qmlArgs(this)
3638{
3739
3840 setApplicationName(QStringLiteral("unity8"));
3941 setOrganizationName(QStringLiteral("Canonical"));
4042
41− connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
42−
4343 setupQmlEngine(isMirServer);
4444
45− UnityCommandLineParser parser(*this);
46−
47− if (!parser.deviceName().isEmpty()) {
48− m_deviceName = parser.deviceName();
49− } else {
45+ if (m_qmlArgs.deviceName().isEmpty()) {
5046 char buffer[200];
5147 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
52− m_deviceName = QString(buffer);
48+ m_qmlArgs.setDeviceName(QString(buffer));
5349 }
54− m_qmlArgs.setDeviceName(m_deviceName);
55−
56− m_qmlArgs.setMode(parser.mode());
5750
5851 // The testability driver is only loaded by QApplication but not by QGuiApplication.
5952 // 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")) {
53+ if (m_qmlArgs.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
6154 QLibrary testLib(QStringLiteral("qttestability"));
6255 if (testLib.load()) {
6356 typedef void (*TasInitialize)(void);
@@ -75,57 +68,39 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
7568 bindtextdomain("unity8", translationDirectory().toUtf8().data());
7669 textdomain("unity8");
7770
78− m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
71+ m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("applicationArguments"), &m_qmlArgs);
7972
80− if (parser.windowGeometry().isValid()) {
81− m_shellView->setWidth(parser.windowGeometry().width());
82− m_shellView->setHeight(parser.windowGeometry().height());
73+ QByteArray pxpguEnv = qgetenv("GRID_UNIT_PX");
74+ bool ok;
75+ int pxpgu = pxpguEnv.toInt(&ok);
76+ if (!ok) {
77+ pxpgu = 8;
8378 }
84−
85− if (parser.hasFrameless()) {
86− m_shellView->setFlags(Qt::FramelessWindowHint);
87− }
88−
79+ m_qmlEngine->rootContext()->setContextProperty("internalGu", pxpgu);
80+ m_qmlEngine->load(::qmlDirectory() + "/ShellApplication.qml");
8981
9082 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
9183 // You will need this if you want to interact with touch-only components using a mouse
9284 // Needed only when manually testing on a desktop.
93− if (parser.hasMouseToTouch()) {
85+ if (m_qmlArgs.hasMouseToTouch()) {
9486 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
9587 }
9688 #endif
9789
98−
99− // Some hard-coded policy for now.
100− // NB: We don't support more than two screens at the moment
101− //
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"));
107−
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);
113− }
114−
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());
119− m_shellView->show();
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";
123− }
124− } else if (isMirServer || parser.hasFullscreen()) {
125− m_shellView->showFullScreen();
126− } else {
127− m_shellView->show();
128− }
90+// if (parser.mode().compare("greeter") == 0) {
91+// QSize primaryScreenSize = this->primaryScreen()->size();
92+// m_shellView->setHeight(primaryScreenSize.height());
93+// m_shellView->setWidth(primaryScreenSize.width());
94+// m_shellView->show();
95+// m_shellView->requestActivate();
96+// if (!QProcess::startDetached("/sbin/initctl emit --no-wait unity8-greeter-started")) {
97+// qDebug() << "Unable to send unity8-greeter-started event to Upstart";
98+// }
99+// } else if (isMirServer || parser.hasFullscreen()) {
100+// m_shellView->showFullScreen();
101+// } else {
102+// m_shellView->show();
103+// }
129104}
130105
131106ShellApplication::~ShellApplication()
@@ -135,14 +110,6 @@ ShellApplication::~ShellApplication()
135110
136111void ShellApplication::destroyResources()
137112{
138− // Deletion order is important. Don't use QScopedPointers and the like
139− // Otherwise the process will hang on shutdown (bug somewhere I guess).
140− delete m_shellView;
141− m_shellView = nullptr;
142−
143− delete m_secondaryWindow;
144− m_secondaryWindow = nullptr;
145−
146113 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
147114 delete m_mouseTouchAdaptor;
148115 m_mouseTouchAdaptor = nullptr;
@@ -154,7 +121,7 @@ void ShellApplication::destroyResources()
154121
155122void ShellApplication::setupQmlEngine(bool isMirServer)
156123{
157− m_qmlEngine = new QQmlEngine(this);
124+ m_qmlEngine = new QQmlApplicationEngine(this);
158125
159126 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
160127
@@ -168,48 +135,3 @@ void ShellApplication::setupQmlEngine(bool isMirServer)
168135
169136 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
170137}
171−
172−void ShellApplication::onScreenAdded(QScreen * /*screen*/)
173−{
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);
185−
186− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
187− m_secondaryWindow->setScreen(screens().at(0));
188−
189− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
190− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
191− m_secondaryWindow->setVisible(true);
192− }
193−}
194−
195−void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
196−{
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);
214− }
215−}