on xenial help sign in
better surface/session registration
936f3afNick Dedekind
qml/Shell.qml+9
@@ -233,6 +233,15 @@ Item {
233 }
233 }
234 }
234 }
235 }
235 }
236+ Connections {
237+ target: SessionManager
238+ onSessionStopping: {
239+ if (!session.parent) {
240+ // there's no one displaying it. delete it right away
241+ session.release();
242+ }
243+ }
244+ }
236
245
237 Lockscreen {
246 Lockscreen {
238 id: lockscreen
247 id: lockscreen
tests/mocks/Unity/Application/ApplicationInfo.cpp+2
@@ -72,6 +72,7 @@ void ApplicationInfo::setSession(Session* session)
72 disconnect(this, 0, m_session, 0);
72 disconnect(this, 0, m_session, 0);
73 m_session->setApplication(nullptr);
73 m_session->setApplication(nullptr);
74 m_session->setParent(nullptr);
74 m_session->setParent(nullptr);
75+ Q_EMIT m_session->deregister();
75 }
76 }
76
77
77 m_session = session;
78 m_session = session;
@@ -79,6 +80,7 @@ void ApplicationInfo::setSession(Session* session)
79 if (m_session) {
80 if (m_session) {
80 m_session->setApplication(this);
81 m_session->setApplication(this);
81 m_session->setParent(this);
82 m_session->setParent(this);
83+ SessionManager::singleton()->registerSession(m_session);
82
84
83 if (!m_manualSurfaceCreation) {
85 if (!m_manualSurfaceCreation) {
84 QTimer::singleShot(500, m_session, SLOT(createSurface()));
86 QTimer::singleShot(500, m_session, SLOT(createSurface()));
tests/mocks/Unity/Application/MirObjectModel.h+1−1
@@ -43,7 +43,7 @@ public:
43
43
44 int existingIndex = m_items.indexOf(item);
44 int existingIndex = m_items.indexOf(item);
45 if (existingIndex != -1) {
45 if (existingIndex != -1) {
46− move(existingIndex, index);
46+ move(existingIndex, qMin(index, (uint)(m_items.count()-1)));
47 } else {
47 } else {
48 beginInsertRows(QModelIndex(), index, index);
48 beginInsertRows(QModelIndex(), index, index);
49 m_items.insert(index, item);
49 m_items.insert(index, item);
tests/mocks/Unity/Application/MirSurfaceItem.cpp−2
@@ -82,8 +82,6 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
82MirSurfaceItem::~MirSurfaceItem()
82MirSurfaceItem::~MirSurfaceItem()
83{
83{
84 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
84 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
85− Q_EMIT aboutToBeDestroyed();
86−
87 if (m_session) {
85 if (m_session) {
88 m_session->setSurface(nullptr);
86 m_session->setSurface(nullptr);
89 }
87 }
tests/mocks/Unity/Application/MirSurfaceItem.h+2−1
@@ -79,7 +79,8 @@ Q_SIGNALS:
79 void inputMethodRequested();
79 void inputMethodRequested();
80 void inputMethodDismissed();
80 void inputMethodDismissed();
81
81
82− void aboutToBeDestroyed();
82+ // internal mock use
83+ void deregister();
83
84
84private Q_SLOTS:
85private Q_SLOTS:
85 void onFocusChanged();
86 void onFocusChanged();
tests/mocks/Unity/Application/Session.cpp+5−1
@@ -16,6 +16,7 @@
16
16
17#include "Session.h"
17#include "Session.h"
18#include "ApplicationInfo.h"
18#include "ApplicationInfo.h"
19+#include "SessionManager.h"
19#include "SurfaceManager.h"
20#include "SurfaceManager.h"
20
21
21#include <QPainter>
22#include <QPainter>
@@ -59,7 +60,6 @@ Session::~Session()
59void Session::release()
60void Session::release()
60{
61{
61 qDebug() << "Session::release " << name();
62 qDebug() << "Session::release " << name();
62− Q_EMIT aboutToBeDestroyed();
63
63
64 if (m_parentSession) {
64 if (m_parentSession) {
65 m_parentSession->removeChildSession(this);
65 m_parentSession->removeChildSession(this);
@@ -89,6 +89,7 @@ void Session::setSurface(MirSurfaceItem* surface)
89 if (m_surface) {
89 if (m_surface) {
90 m_surface->setSession(nullptr);
90 m_surface->setSession(nullptr);
91 m_surface->setParent(nullptr);
91 m_surface->setParent(nullptr);
92+ Q_EMIT m_surface->deregister();
92 }
93 }
93
94
94 m_surface = surface;
95 m_surface = surface;
@@ -96,6 +97,7 @@ void Session::setSurface(MirSurfaceItem* surface)
96 if (m_surface) {
97 if (m_surface) {
97 m_surface->setSession(this);
98 m_surface->setSession(this);
98 m_surface->setParent(this);
99 m_surface->setParent(this);
100+ SurfaceManager::singleton()->registerSurface(m_surface);
99 }
101 }
100
102
101 Q_EMIT surfaceChanged(m_surface);
103 Q_EMIT surfaceChanged(m_surface);
@@ -141,6 +143,7 @@ void Session::insertChildSession(uint index, Session* session)
141
143
142 session->setParentSession(this);
144 session->setParentSession(this);
143 m_children->insert(index, session);
145 m_children->insert(index, session);
146+ SessionManager::singleton()->registerSession(session);
144}
147}
145
148
146void Session::removeChildSession(Session* session)
149void Session::removeChildSession(Session* session)
@@ -150,6 +153,7 @@ void Session::removeChildSession(Session* session)
150 if (m_children->contains(session)) {
153 if (m_children->contains(session)) {
151 m_children->remove(session);
154 m_children->remove(session);
152 session->setParentSession(nullptr);
155 session->setParentSession(nullptr);
156+ Q_EMIT session->deregister();
153 }
157 }
154}
158}
155
159
tests/mocks/Unity/Application/Session.h+2−1
@@ -57,7 +57,8 @@ Q_SIGNALS:
57 void surfaceChanged(MirSurfaceItem*);
57 void surfaceChanged(MirSurfaceItem*);
58 void parentSessionChanged(Session*);
58 void parentSessionChanged(Session*);
59 void removed();
59 void removed();
60− void aboutToBeDestroyed();
60+ // internal mock use
61+ void deregister();
61
62
62public Q_SLOTS:
63public Q_SLOTS:
63 Q_INVOKABLE void createSurface();
64 Q_INVOKABLE void createSurface();
tests/mocks/Unity/Application/SessionManager.cpp+11−4
@@ -38,10 +38,17 @@ Session *SessionManager::createSession(const QString& name,
38 const QUrl& screenshot)
38 const QUrl& screenshot)
39{
39{
40 Session* session = new Session(name, screenshot);
40 Session* session = new Session(name, screenshot);
41− connect(session, &Session::aboutToBeDestroyed, this, [&] {
42− Q_EMIT sessionStopping(qobject_cast<Session*>(sender()));
43− });
44−
45 Q_EMIT sessionStarting(session);
41 Q_EMIT sessionStarting(session);
46 return session;
42 return session;
47}
43}
44+
45+void SessionManager::registerSession(Session *session)
46+{
47+ connect(session, &Session::deregister, this, [this] {
48+ Session* session = qobject_cast<Session*>(sender());
49+
50+ disconnect(session, 0, this, 0);
51+ Q_EMIT sessionStopping(session);
52+ });
53+}
54+
tests/mocks/Unity/Application/SessionManager.h+2
@@ -31,6 +31,8 @@ public:
31
31
32 Q_INVOKABLE Session* createSession(const QString& name, const QUrl& screenshot);
32 Q_INVOKABLE Session* createSession(const QString& name, const QUrl& screenshot);
33
33
34+ void registerSession(Session *session);
35+
34Q_SIGNALS:
36Q_SIGNALS:
35 void sessionStarting(Session *session);
37 void sessionStarting(Session *session);
36 void sessionStopping(Session *session);
38 void sessionStopping(Session *session);
tests/mocks/Unity/Application/SurfaceManager.cpp+5−4
@@ -44,16 +44,17 @@ MirSurfaceItem *SurfaceManager::createSurface(const QString& name,
44 type,
44 type,
45 state,
45 state,
46 screenshot);
46 screenshot);
47− registerSurface(surface);
48− connect(surface, &MirSurfaceItem::aboutToBeDestroyed, this, [&] {
49− Q_EMIT surfaceDestroyed(qobject_cast<MirSurfaceItem*>(sender()));
50− });
51 Q_EMIT surfaceCreated(surface);
47 Q_EMIT surfaceCreated(surface);
52 return surface;
48 return surface;
53}
49}
54
50
55void SurfaceManager::registerSurface(MirSurfaceItem *surface)
51void SurfaceManager::registerSurface(MirSurfaceItem *surface)
56{
52{
53+ connect(surface, &MirSurfaceItem::deregister, this, [this] {
54+ MirSurfaceItem* surface = qobject_cast<MirSurfaceItem*>(sender());
55+ disconnect(surface, 0, this, 0);
56+ Q_EMIT surfaceDestroyed(surface);
57+ });
57 connect(surface, &MirSurfaceItem::inputMethodRequested,
58 connect(surface, &MirSurfaceItem::inputMethodRequested,
58 this, &SurfaceManager::showInputMethod);
59 this, &SurfaceManager::showInputMethod);
59 connect(surface, &MirSurfaceItem::inputMethodDismissed,
60 connect(surface, &MirSurfaceItem::inputMethodDismissed,
tests/mocks/Unity/Application/SurfaceManager.h−1
@@ -36,7 +36,6 @@ public:
36
36
37 // Internal mock use
37 // Internal mock use
38 void registerSurface(MirSurfaceItem *surface);
38 void registerSurface(MirSurfaceItem *surface);
39− void unregisterSurface(MirSurfaceItem *surface);
40
39
41 // To be used in the tests
40 // To be used in the tests
42 Q_INVOKABLE MirSurfaceItem *inputMethodSurface();
41 Q_INVOKABLE MirSurfaceItem *inputMethodSurface();