Changeset View
Changeset View
Standalone View
Standalone View
shell/main.cpp
Show All 32 Lines | |||||
33 | 33 | | |||
34 | #include <kdbusservice.h> | 34 | #include <kdbusservice.h> | ||
35 | #include <klocalizedstring.h> | 35 | #include <klocalizedstring.h> | ||
36 | #include <kcrash.h> | 36 | #include <kcrash.h> | ||
37 | #include <kworkspace.h> | 37 | #include <kworkspace.h> | ||
38 | 38 | | |||
39 | #include "shellcorona.h" | 39 | #include "shellcorona.h" | ||
40 | #include "standaloneappcorona.h" | 40 | #include "standaloneappcorona.h" | ||
41 | #include "shellmanager.h" | | |||
42 | #include "coronatesthelper.h" | 41 | #include "coronatesthelper.h" | ||
43 | #include "softwarerendernotifier.h" | 42 | #include "softwarerendernotifier.h" | ||
44 | 43 | | |||
45 | #include <QDir> | 44 | #include <QDir> | ||
46 | 45 | | |||
47 | int main(int argc, char *argv[]) | 46 | int main(int argc, char *argv[]) | ||
48 | { | 47 | { | ||
49 | //Plasma scales itself to font DPI | 48 | //Plasma scales itself to font DPI | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 93 | QCommandLineOption dbgOption(QStringList() << QStringLiteral("d") << | |||
96 | i18n("Enable QML Javascript debugger")); | 95 | i18n("Enable QML Javascript debugger")); | ||
97 | 96 | | |||
98 | QCommandLineOption noRespawnOption(QStringList() << QStringLiteral("n") << | 97 | QCommandLineOption noRespawnOption(QStringList() << QStringLiteral("n") << | ||
99 | QStringLiteral("no-respawn"), | 98 | QStringLiteral("no-respawn"), | ||
100 | i18n("Do not restart plasma-shell automatically after a crash")); | 99 | i18n("Do not restart plasma-shell automatically after a crash")); | ||
101 | 100 | | |||
102 | QCommandLineOption shellPluginOption(QStringList() << QStringLiteral("p") << QStringLiteral("shell-plugin"), | 101 | QCommandLineOption shellPluginOption(QStringList() << QStringLiteral("p") << QStringLiteral("shell-plugin"), | ||
103 | i18n("Force loading the given shell plugin"), | 102 | i18n("Force loading the given shell plugin"), | ||
104 | QStringLiteral("plugin")); | 103 | QStringLiteral("plugin"), QStringLiteral("org.kde.plasma.desktop")); | ||
105 | 104 | | |||
106 | QCommandLineOption standaloneOption(QStringList() << QStringLiteral("a") << QStringLiteral("standalone"), | 105 | QCommandLineOption standaloneOption(QStringList() << QStringLiteral("a") << QStringLiteral("standalone"), | ||
107 | i18n("Load plasmashell as a standalone application, needs the shell-plugin option to be specified")); | 106 | i18n("Load plasmashell as a standalone application, needs the shell-plugin option to be specified")); | ||
108 | 107 | | |||
109 | QCommandLineOption replaceOption({QStringLiteral("replace")}, | 108 | QCommandLineOption replaceOption({QStringLiteral("replace")}, | ||
110 | i18n("Replace an existing instance")); | 109 | i18n("Replace an existing instance")); | ||
111 | 110 | | |||
112 | QCommandLineOption testOption(QStringList() << QStringLiteral("test"), | 111 | QCommandLineOption testOption(QStringList() << QStringLiteral("test"), | ||
Show All 13 Lines | |||||
126 | QGuiApplication::setFallbackSessionManagementEnabled(false); | 125 | QGuiApplication::setFallbackSessionManagementEnabled(false); | ||
127 | 126 | | |||
128 | auto disableSessionManagement = [](QSessionManager &sm) { | 127 | auto disableSessionManagement = [](QSessionManager &sm) { | ||
129 | sm.setRestartHint(QSessionManager::RestartNever); | 128 | sm.setRestartHint(QSessionManager::RestartNever); | ||
130 | }; | 129 | }; | ||
131 | QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); | 130 | QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); | ||
132 | QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); | 131 | QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); | ||
133 | 132 | | |||
134 | ShellManager::s_fixedShell = cliOptions.value(shellPluginOption); | 133 | ShellCorona* corona = new ShellCorona(&app); | ||
134 | corona->setShell(cliOptions.value(shellPluginOption)); | ||||
135 | 135 | | |||
136 | if (!cliOptions.isSet(noRespawnOption) && !cliOptions.isSet(testOption)) { | 136 | if (!cliOptions.isSet(noRespawnOption) && !cliOptions.isSet(testOption)) { | ||
137 | KCrash::setFlags(KCrash::AutoRestart); | 137 | KCrash::setFlags(KCrash::AutoRestart); | ||
138 | } | 138 | } | ||
139 | 139 | | |||
140 | if (cliOptions.isSet(testOption)) { | 140 | if (cliOptions.isSet(testOption)) { | ||
141 | const QUrl layoutUrl = QUrl::fromUserInput(cliOptions.value(testOption), {}, QUrl::AssumeLocalFile); | 141 | const QUrl layoutUrl = QUrl::fromUserInput(cliOptions.value(testOption), {}, QUrl::AssumeLocalFile); | ||
142 | if (!layoutUrl.isLocalFile()) { | 142 | if (!layoutUrl.isLocalFile()) { | ||
143 | qWarning() << "ensure the layout file is local" << layoutUrl; | 143 | qWarning() << "ensure the layout file is local" << layoutUrl; | ||
144 | cliOptions.showHelp(1); | 144 | cliOptions.showHelp(1); | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | QStandardPaths::setTestModeEnabled(true); | 147 | QStandardPaths::setTestModeEnabled(true); | ||
148 | QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).removeRecursively(); | 148 | QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).removeRecursively(); | ||
149 | ShellManager::s_testModeLayout = layoutUrl.toLocalFile(); | 149 | corona->setTestModeLayout(layoutUrl.toLocalFile()); | ||
150 | 150 | | |||
151 | qApp->setProperty("org.kde.KActivities.core.disableAutostart", true); | 151 | qApp->setProperty("org.kde.KActivities.core.disableAutostart", true); | ||
152 | 152 | | |||
153 | QObject::connect(ShellManager::instance(), &ShellManager::shellChanged, | 153 | new CoronaTestHelper(corona); | ||
154 | ShellManager::instance(), | | |||
155 | [layoutUrl]() { | | |||
156 | new CoronaTestHelper(ShellManager::instance()->corona()); | | |||
157 | } | | |||
158 | ); | | |||
159 | } | 154 | } | ||
160 | 155 | | |||
161 | if (cliOptions.isSet(standaloneOption)) { | 156 | if (cliOptions.isSet(standaloneOption)) { | ||
162 | if (cliOptions.isSet(shellPluginOption)) { | 157 | if (cliOptions.isSet(shellPluginOption)) { | ||
163 | ShellManager::s_standaloneOption = true; | | |||
164 | app.setApplicationName(QStringLiteral("plasmashell_") + cliOptions.value(shellPluginOption)); | 158 | app.setApplicationName(QStringLiteral("plasmashell_") + cliOptions.value(shellPluginOption)); | ||
165 | app.setQuitOnLastWindowClosed(true); | 159 | app.setQuitOnLastWindowClosed(true); | ||
166 | 160 | | |||
167 | KDBusService service(KDBusService::Unique); | 161 | KDBusService service(KDBusService::Unique); | ||
168 | //This will not leak, because corona deletes itself on window close | 162 | //This will not leak, because corona deletes itself on window close | ||
169 | new StandaloneAppCorona(cliOptions.value(shellPluginOption)); | 163 | new StandaloneAppCorona(cliOptions.value(shellPluginOption)); | ||
170 | return app.exec(); | 164 | return app.exec(); | ||
171 | } else { | 165 | } else { | ||
172 | cliOptions.showHelp(1); | 166 | cliOptions.showHelp(1); | ||
173 | } | 167 | } | ||
174 | } else { | 168 | } else { | ||
175 | // Tells libnotificationmanager that we're the only true application that may own notification and job progress services | 169 | // Tells libnotificationmanager that we're the only true application that may own notification and job progress services | ||
176 | qApp->setProperty("_plasma_dbus_master", true); | 170 | qApp->setProperty("_plasma_dbus_master", true); | ||
177 | } | 171 | } | ||
178 | 172 | | |||
179 | if (cliOptions.isSet(replaceOption)) { | 173 | if (cliOptions.isSet(replaceOption)) { | ||
180 | auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), | 174 | auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), | ||
181 | QStringLiteral("/MainApplication"), | 175 | QStringLiteral("/MainApplication"), | ||
182 | QStringLiteral("org.qtproject.Qt.QCoreApplication"), | 176 | QStringLiteral("org.qtproject.Qt.QCoreApplication"), | ||
183 | QStringLiteral("quit")); | 177 | QStringLiteral("quit")); | ||
184 | QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits | 178 | QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits | ||
185 | } | 179 | } | ||
186 | } | 180 | QObject::connect(corona, &ShellCorona::glInitializationFailed, &app, [&app]() { | ||
187 | | ||||
188 | KDBusService service(KDBusService::Unique); | | |||
189 | | ||||
190 | QObject::connect(ShellManager::instance(), &ShellManager::glInitializationFailed, &app, [&app]() { | | |||
191 | //scene graphs errors come from a thread | 181 | //scene graphs errors come from a thread | ||
192 | //even though we process them in the main thread, app.exit could still process these events | 182 | //even though we process them in the main thread, app.exit could still process these events | ||
193 | static bool s_multipleInvokations = false; | 183 | static bool s_multipleInvokations = false; | ||
194 | if (s_multipleInvokations) { | 184 | if (s_multipleInvokations) { | ||
195 | return; | 185 | return; | ||
196 | } | 186 | } | ||
197 | s_multipleInvokations = true; | 187 | s_multipleInvokations = true; | ||
198 | 188 | | |||
199 | qCritical("Open GL context could not be created"); | 189 | qCritical("Open GL context could not be created"); | ||
200 | auto configGroup = KSharedConfig::openConfig()->group("QtQuickRendererSettings"); | 190 | auto configGroup = KSharedConfig::openConfig()->group("QtQuickRendererSettings"); | ||
201 | if (configGroup.readEntry("SceneGraphBackend") != QLatin1String("software")) { | 191 | if (configGroup.readEntry("SceneGraphBackend") != QLatin1String("software")) { | ||
202 | configGroup.writeEntry("SceneGraphBackend", "software", KConfigBase::Global | KConfigBase::Persistent); | 192 | configGroup.writeEntry("SceneGraphBackend", "software", KConfigBase::Global | KConfigBase::Persistent); | ||
203 | configGroup.sync(); | 193 | configGroup.sync(); | ||
204 | QProcess::startDetached(QStringLiteral("plasmashell"), app.arguments()); | 194 | QProcess::startDetached(QStringLiteral("plasmashell"), app.arguments()); | ||
205 | } else { | 195 | } else { | ||
206 | QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets); | 196 | QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets); | ||
207 | QMessageBox::critical(nullptr, i18n("Plasma Failed To Start"), | 197 | QMessageBox::critical(nullptr, i18n("Plasma Failed To Start"), | ||
208 | i18n("Plasma is unable to start as it could not correctly use OpenGL 2 or software fallback\nPlease check that your graphic drivers are set up correctly.")); | 198 | i18n("Plasma is unable to start as it could not correctly use OpenGL 2 or software fallback\nPlease check that your graphic drivers are set up correctly.")); | ||
209 | } | 199 | } | ||
210 | app.exit(-1); | 200 | app.exit(-1); | ||
211 | }); | 201 | }); | ||
202 | } | ||||
203 | | ||||
204 | KDBusService service(KDBusService::Unique); | ||||
205 | | ||||
212 | SoftwareRendererNotifier::notifyIfRelevant(); | 206 | SoftwareRendererNotifier::notifyIfRelevant(); | ||
213 | QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, ShellManager::instance(), &QObject::deleteLater); | | |||
214 | 207 | | |||
215 | return app.exec(); | 208 | return app.exec(); | ||
216 | } | 209 | } |