on xenial help sign in
Select the backend to use dynamically on runtime according to the QPA selected by the system.

Approved by Gerry Boland, PS Jenkins bot, Michael Zanetti.

commit6b8b30be3927d905820feb3367f8dfd9e96a54bf authorRicardo Mendoza <ricardo.mendoza@canonical.com> dateWed 11 Sep 2013, 12:45 (13 years ago) parent227062965486da
3 files changed+79−6
CMakeLists.txt+4 debian/control+2 main.cpp+73−6
CMakeLists.txt+4
@@ -62,10 +62,13 @@ set(SHELL_PRIVATE_LIBDIR ${CMAKE_INSTALL_LIBDIR}/unity8)
6262
6363configure_file(paths.h.in ${CMAKE_CURRENT_BINARY_DIR}/paths.h @ONLY)
6464
65+pkg_check_modules(UNITY-MIR REQUIRED unity-mir)
66+
6567include_directories(
6668 ${CMAKE_CURRENT_BINARY_DIR}
6769 ${CMAKE_CURRENT_SOURCE_DIR}
6870 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
71+ ${UNITY-MIR_INCLUDE_DIRS}
6972 )
7073
7174set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
@@ -118,6 +121,7 @@ target_link_libraries(${SHELL_APP}
118121 ${Qt5Qml_LIBRARIES}
119122 ${Qt5Quick_LIBRARIES}
120123 ${XCB_LDFLAGS}
124+ ${CMAKE_DL_LIBS}
121125 )
122126
123127# install binaries
debian/control+2
@@ -23,6 +23,7 @@ Build-Depends: cmake,
2323 libunity-api-dev (>= 7.80.3),
2424 libunity-core-6.0-dev (<< 7.80),
2525 libunity-dev (>= 7.0.12),
26+ libunity-mir-dev,
2627 libunity-scopes-json-def-phone,
2728 libupstart-dev,
2829 libusermetricsoutput1-dev,
@@ -65,6 +66,7 @@ Package: unity8
6566Architecture: any
6667Provides: indicator-renderer,
6768Depends: gsettings-desktop-schemas,
69+ libunity-mir1,
6870 qmenumodel-qml (>= 0.2.7),
6971 qtdeclarative5-dee-plugin,
7072 qtdeclarative5-gsettings1.0,
main.cpp+73−6
@@ -25,13 +25,17 @@
2525#include <QtQml/QQmlContext>
2626#include <qpa/qplatformnativeinterface.h>
2727#include <QLibrary>
28+#include <QDebug>
2829#include <libintl.h>
30+#include <dlfcn.h>
2931
3032// local
3133#include "paths.h"
3234#include "MouseTouchAdaptor.h"
3335#include "ApplicationArguments.h"
3436
37+#include <unity-mir/qmirserver.h>
38+
3539namespace {
3640
3741void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
@@ -72,7 +76,7 @@ void resolveIconTheme() {
7276}
7377} // namespace {
7478
75−int main(int argc, char** argv)
79+int startShell(int argc, const char** argv, void* server)
7680{
7781 /* Workaround Qt platform integration plugin not advertising itself
7882 as having the following capabilities:
@@ -82,12 +86,29 @@ int main(int argc, char** argv)
8286 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
8387 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
8488
89+ const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
90+
8591 QGuiApplication::setApplicationName("Unity 8");
86− QGuiApplication application(argc, argv);
92+ QGuiApplication *application;
93+ if (isUbuntuMirServer) {
94+ QLibrary unityMir("unity-mir");
95+ unityMir.load();
96+
97+ typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
98+ createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
99+ if (!createQMirServerApplication) {
100+ qDebug() << "unable to resolve symbol: createQMirServerApplication";
101+ return 4;
102+ }
103+
104+ application = createQMirServerApplication(argc, argv, server);
105+ } else {
106+ application = new QGuiApplication(argc, (char**)argv);
107+ }
87108
88109 resolveIconTheme();
89110
90− QStringList args = application.arguments();
111+ QStringList args = application->arguments();
91112 ApplicationArguments qmlArgs(args);
92113
93114 // The testability driver is only loaded by QApplication but not by QGuiApplication.
@@ -124,7 +145,7 @@ int main(int argc, char** argv)
124145 if (args.contains(QLatin1String("-mousetouch"))) {
125146 mouseTouchAdaptor = new MouseTouchAdaptor;
126147 mouseTouchAdaptor->setTargetWindow(view);
127− application.installNativeEventFilter(mouseTouchAdaptor);
148+ application->installNativeEventFilter(mouseTouchAdaptor);
128149 }
129150
130151 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
@@ -139,18 +160,64 @@ int main(int argc, char** argv)
139160 QUrl source("Shell.qml");
140161 prependImportPaths(view->engine(), ::overrideImportPaths());
141162 appendImportPaths(view->engine(), ::fallbackImportPaths());
163+
164+ QStringList importPath = view->engine()->importPathList().filter("qt5/imports");
165+ if (isUbuntuMirServer) {
166+ importPath.first().append("/Unity-Mir");
167+ view->engine()->addImportPath(importPath.first());
168+ }
169+
142170 view->setSource(source);
143171 view->setColor("transparent");
144172
145− if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || args.contains(QLatin1String("-fullscreen"))) {
173+ if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
146174 view->showFullScreen();
147175 } else {
148176 view->show();
149177 }
150178
151− int result = application.exec();
179+ int result = application->exec();
152180
153181 delete mouseTouchAdaptor;
182+ delete application;
154183
155184 return result;
156185}
186+
187+int main(int argc, const char *argv[])
188+{
189+ // For ubuntumirserver/ubuntumirclient
190+ if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
191+ setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
192+
193+ // If we use unity-mir directly, we automatically link to the Mir-server
194+ // platform-api bindings, which result in unexpected behaviour when
195+ // running the non-Mir scenario.
196+ QLibrary unityMir("unity-mir");
197+ unityMir.load();
198+ if (!unityMir.isLoaded()) {
199+ qDebug() << "Library unity-mir not found/loaded";
200+ return 1;
201+ }
202+
203+ typedef QMirServer* (*createServer_t)(int, const char **);
204+ createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
205+ if (!createQMirServer) {
206+ qDebug() << "unable to resolve symbol: createQMirServer";
207+ return 2;
208+ }
209+
210+ QMirServer* mirServer = createQMirServer(argc, argv);
211+
212+ typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
213+ runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
214+ if (!runWithClient) {
215+ qDebug() << "unable to resolve symbol: runWithClient";
216+ return 3;
217+ }
218+
219+ return runWithClient(mirServer, startShell);
220+ } else {
221+ return startShell(argc, argv, nullptr);
222+ }
223+}