on xenial help sign in
Implements usage-style documentation for unity8 executable.
9cb5e34Josh Arenson
src/ApplicationArguments.h+4−8
@@ -28,14 +28,10 @@ class ApplicationArguments : public QObject
28{
28{
29 Q_OBJECT
29 Q_OBJECT
30public:
30public:
31− ApplicationArguments(const QStringList& args) {
31+ // Not exposed to the app as setSize isn't invokable
32− if (args.contains(QLatin1String("-windowgeometry")) && args.size() > args.indexOf(QLatin1String("-windowgeometry")) + 1) {
32+ void setSize(int width, int height) {
33− QStringList geometryArg = args.at(args.indexOf(QLatin1String("-windowgeometry")) + 1).split('x');
34− if (geometryArg.size() == 2) {
35− m_size.rwidth() = geometryArg.at(0).toInt();
33+ m_size.rwidth() = width;
36− m_size.rheight() = geometryArg.at(1).toInt();
34+ m_size.rheight() = height;
37− }
38− }
39 }
35 }
40
36
41 Q_INVOKABLE bool hasGeometry() const { return m_size.isValid(); }
37 Q_INVOKABLE bool hasGeometry() const { return m_size.isValid(); }
src/main.cpp+43−6
@@ -18,6 +18,7 @@
18 */
18 */
19
19
20// Qt
20// Qt
21+#include <QCommandLineParser>
21#include <QtQuick/QQuickView>
22#include <QtQuick/QQuickView>
22#include <QtGui/QGuiApplication>
23#include <QtGui/QGuiApplication>
23#include <QtQml/QQmlEngine>
24#include <QtQml/QQmlEngine>
@@ -43,6 +44,32 @@ int startShell(int argc, const char** argv, void* server)
43
44
44 QGuiApplication::setApplicationName("Unity 8");
45 QGuiApplication::setApplicationName("Unity 8");
45 QGuiApplication *application;
46 QGuiApplication *application;
47+
48+ QCommandLineParser parser;
49+ parser.setApplicationDescription("Description: Unity 8 Shell");
50+ parser.addHelpOption();
51+
52+ QCommandLineOption fullscreenOption("fullscreen",
53+ "Run in fullscreen");
54+ parser.addOption(fullscreenOption);
55+
56+ QCommandLineOption framelessOption("frameless",
57+ "Run without window borders");
58+ parser.addOption(framelessOption);
59+
60+ QCommandLineOption mousetouchOption("mousetouch",
61+ "Allow the mouse to provide touch input");
62+ parser.addOption(mousetouchOption);
63+
64+ QCommandLineOption windowGeometryOption(QStringList() << "windowgeometry",
65+ "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
66+ parser.addOption(windowGeometryOption);
67+
68+ QCommandLineOption testabilityOption("testability",
69+ "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead. \n \
70+Load the testability driver");
71+ parser.addOption(testabilityOption);
72+
46 if (isUbuntuMirServer) {
73 if (isUbuntuMirServer) {
47 QLibrary unityMir("unity-mir", 1);
74 QLibrary unityMir("unity-mir", 1);
48 unityMir.load();
75 unityMir.load();
@@ -59,6 +86,11 @@ int startShell(int argc, const char** argv, void* server)
59 application = new QGuiApplication(argc, (char**)argv);
86 application = new QGuiApplication(argc, (char**)argv);
60 }
87 }
61
88
89+ // Treat args with single dashes the same as arguments with two dashes
90+ // Ex: -fullscreen == --fullscreen
91+ parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
92+ parser.process(*application);
93+
62 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
94 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
63 if (indicatorProfile.isEmpty()) {
95 if (indicatorProfile.isEmpty()) {
64 indicatorProfile = "phone";
96 indicatorProfile = "phone";
@@ -66,12 +98,17 @@ int startShell(int argc, const char** argv, void* server)
66
98
67 resolveIconTheme();
99 resolveIconTheme();
68
100
69− QStringList args = application->arguments();
101+ ApplicationArguments qmlArgs;
70− ApplicationArguments qmlArgs(args);
102+ if (parser.isSet(windowGeometryOption) &&
103+ parser.value(windowGeometryOption).split('x').size() == 2)
104+ {
105+ QStringList geom = parser.value(windowGeometryOption).split('x');
106+ qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
107+ }
71
108
72 // The testability driver is only loaded by QApplication but not by QGuiApplication.
109 // The testability driver is only loaded by QApplication but not by QGuiApplication.
73 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
110 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
74− if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
111+ if (parser.isSet(testabilityOption) || getenv("QT_LOAD_TESTABILITY")) {
75 QLibrary testLib(QLatin1String("qttestability"));
112 QLibrary testLib(QLatin1String("qttestability"));
76 if (testLib.load()) {
113 if (testLib.load()) {
77 typedef void (*TasInitialize)(void);
114 typedef void (*TasInitialize)(void);
@@ -94,14 +131,14 @@ int startShell(int argc, const char** argv, void* server)
94 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
131 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
95 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
132 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
96 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
133 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
97− if (args.contains(QLatin1String("-frameless"))) {
134+ if (parser.isSet(framelessOption)) {
98 view->setFlags(Qt::FramelessWindowHint);
135 view->setFlags(Qt::FramelessWindowHint);
99 }
136 }
100
137
101 // You will need this if you want to interact with touch-only components using a mouse
138 // You will need this if you want to interact with touch-only components using a mouse
102 // Needed only when manually testing on a desktop.
139 // Needed only when manually testing on a desktop.
103 MouseTouchAdaptor *mouseTouchAdaptor = 0;
140 MouseTouchAdaptor *mouseTouchAdaptor = 0;
104− if (args.contains(QLatin1String("-mousetouch"))) {
141+ if (parser.isSet(mousetouchOption)) {
105 mouseTouchAdaptor = new MouseTouchAdaptor;
142 mouseTouchAdaptor = new MouseTouchAdaptor;
106 application->installNativeEventFilter(mouseTouchAdaptor);
143 application->installNativeEventFilter(mouseTouchAdaptor);
107 }
144 }
@@ -125,7 +162,7 @@ int startShell(int argc, const char** argv, void* server)
125 view->setSource(source);
162 view->setSource(source);
126 view->setColor("transparent");
163 view->setColor("transparent");
127
164
128− if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
165+ if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
129 view->showFullScreen();
166 view->showFullScreen();
130 } else {
167 } else {
131 view->show();
168 view->show();