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