@@ -27,29 +27,46 @@
27#include <qqml.h>
27#include <qqml.h>
28#include <QQmlEngine>
28#include <QQmlEngine>
32+// Creates the singletons that are called throughout C++ code
33+void createUnityApplicationSharedSingletons()
35+ // they have to be created in a specific order
36+ if (!MirFocusController::instance()) {
37+ new MirFocusController;
39+ if (!SurfaceManager::instance()) {
30−static QObject* applicationManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
44+QObject* applicationManagerSingleton(QQmlEngine*, QJSEngine*)
31− Q_UNUSED(engine);
45+{
32− Q_UNUSED(scriptEngine);
46+ createUnityApplicationSharedSingletons();
33− return ApplicationManager::singleton();
47+ return new ApplicationManager;
36−static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
50+QObject* surfaceManagerSingleton(QQmlEngine*, QJSEngine*)
37− Q_UNUSED(engine);
51+{
38− Q_UNUSED(scriptEngine);
52+ createUnityApplicationSharedSingletons();
39− // QQmlEngine takes ownership over it (ie, it's deleted on ~QQmlEngine)
40− return new SurfaceManager;
53+ return SurfaceManager::instance();
43−static QObject* ubuntuKeyboardInfoSingleton(QQmlEngine*, QJSEngine*) {
56+QObject* ubuntuKeyboardInfoSingleton(QQmlEngine*, QJSEngine*)
58+ createUnityApplicationSharedSingletons();
44− return UbuntuKeyboardInfo::singleton();
59+ return new UbuntuKeyboardInfo;
47−static QObject* mirFocusControllerSingleton(QQmlEngine*, QJSEngine*)
62+QObject* mirFocusControllerSingleton(QQmlEngine*, QJSEngine*)
49− // QQmlEngine takes ownership over it (ie, it's deleted on ~QQmlEngine)
64+ createUnityApplicationSharedSingletons();
50− return new MirFocusController;
65+ return MirFocusController::instance();
68+} // anonymous namespace
53void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
70void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
55 qRegisterMetaType<ApplicationInfo*>("ApplicationInfo*");
72 qRegisterMetaType<ApplicationInfo*>("ApplicationInfo*");