on dff962b help sign in
unity8/src/UnityCommandLineParser.cpp
93 lines 3.3 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17#include "UnityCommandLineParser.h"
19#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
20#define DEFAULT_GRID_UNIT_PX 8
22UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
24 m_gridUnit = getenvFloat(ENV_GRID_UNIT_PX, DEFAULT_GRID_UNIT_PX);
26 QCommandLineParser parser;
27 parser.setApplicationDescription("Description: Unity 8 Shell");
28 parser.addHelpOption();
30 QCommandLineOption fullscreenOption("fullscreen",
31 "Run in fullscreen");
32 parser.addOption(fullscreenOption);
34 QCommandLineOption framelessOption("frameless",
35 "Run without window borders");
36 parser.addOption(framelessOption);
38 QCommandLineOption mousetouchOption("mousetouch",
39 "Allow the mouse to provide touch input");
40 parser.addOption(mousetouchOption);
42 QCommandLineOption windowGeometryOption(QStringList() << "windowgeometry",
43 "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
44 parser.addOption(windowGeometryOption);
46 QCommandLineOption testabilityOption("testability",
47 "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead.\nLoad the testability driver");
48 parser.addOption(testabilityOption);
50 QCommandLineOption devicenameOption(QStringList() << "devicename",
51 "Specify the device name instead of letting Unity 8 find it out", "devicename", "");
52 parser.addOption(devicenameOption);
54 // Treat args with single dashes the same as arguments with two dashes
55 // Ex: -fullscreen == --fullscreen
56 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
58 parser.process(app);
60 if (parser.isSet(windowGeometryOption))
61 {
62 QStringList geom = parser.value(windowGeometryOption).split('x');
63 if (geom.count() == 2) {
64 m_windowGeometry.rwidth() = parsePixelsValue(geom[0]);
65 m_windowGeometry.rheight() = parsePixelsValue(geom[1]);
66 }
67 }
69 m_hasTestability = parser.isSet(testabilityOption);
70 m_hasFrameless = parser.isSet(framelessOption);
71 m_hasMouseToTouch = parser.isSet(mousetouchOption);
72 m_hasFullscreen = parser.isSet(fullscreenOption);
73 m_deviceName = parser.value(devicenameOption);
76int UnityCommandLineParser::parsePixelsValue(const QString &str)
78 if (str.endsWith("gu", Qt::CaseInsensitive)) {
79 QString numStr = str;
80 numStr.remove(numStr.size() - 2, 2);
81 return numStr.toInt() * m_gridUnit;
82 } else {
83 return str.toInt();
84 }
87float UnityCommandLineParser::getenvFloat(const char* name, float defaultValue)
89 QByteArray stringValue = qgetenv(name);
90 bool ok;
91 float value = stringValue.toFloat(&ok);
92 return ok ? value : defaultValue;